{% extends "base.html" %}
{% block title %}{{ lang.menu_links.monitoring.smon.admin }}{% endblock %}
{% block h2 %}{{ lang.menu_links.monitoring.smon.admin }}{% endblock %}
{% block content %}
{% from 'include/input_macros.html' import input, checkbox, select %}
<script src="/inc/smon.js"></script>
<script src="/inc/users.js"></script>
<script src="/inc/fontawesome.min.js"></script>
<script src="/inc/jquery.timeago.js" type="text/javascript"></script>
{% if user_status == 0 %}
	{% include 'include/no_sub.html' %}
{% elif smon_error != '' %}
<div style="text-align: center;">
	<br />
	<h3>{{lang.smon_page.desc.not_installed}}</h3>.
	<img src="{{ url_for('static', filename='images/no_servers.png')}}" alt="There is no server">
	<h4>{{lang.words.read|title()}} <a href="https://roxy-wi.org/services/smon" title="Simple monitoring network ports with alerting via Telegram and WEB panel" target="_blank">{{lang.words.here}}</a>
		{{lang.phrases.how_to_install}} SMON {{lang.words.service}}.</h4>
</div>
{% elif smon_status.0 == 'failed' or smon_status.0 == 'inactive' %}
<div style="text-align: center;">
	<br />
	<h3>{{lang.smon_page.desc.smon_is_not_run}}</h3>
	<img src="{{ url_for('static', filename='images/no_servers.png')}}" alt="There is no server">
	<h4>{{lang.smon_page.desc.run_smon}} <a href="/app/users/services" title="Roxy-WI services" target="_blank">{{lang.words.here}}</a> {{lang.smon_page.desc.before_use}}</h4>
</div>
{% else %}
<table class="overview overview-overflow" id="ajax-smon-http">
	<thead>
	<caption><h3>HTTP {{lang.words.checking}}</h3></caption>
		<tr class="overviewHead">
			<th class="padding10 first-collumn" style="width: 200px;">{{lang.words.name|title()}}</th>
			<th style="width: 15%;">URL</th>
			<th style="width: 5%;">{{lang.words.enabled|title()}}</th>
			<th style="width: 20%;">{{lang.words.body|title()}}</th>
			<th style="width: 20%;">HTTP {{lang.words.method}}</th>
			<th style="width: 11%;">Telegram</th>
			<th style="width: 11%;">Slack</th>
			<th style="width: 11%;">PagerDuty</th>
			<th style="width: 10%;">{{lang.words.group|title()}}</th>
			<th style="width: 100%;">{{lang.words.desc|title()}}</th>
			<th></th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		{% for s in smon %}
			{% if s.check_type == 'http' %}
				{% for s_service in smon_http %}
					{% if s_service.smon_id|string() == s.id|string() %}
						<tr id="smon-http-{{s.id}}">
							{% include 'include/smon/smon_http_server.html' %}
					{% endif %}
				{% endfor %}
			{% endif %}
		{% endfor %}
	</tbody>
</table>
<br /><span class="add-button" title="{{lang.words.add|title()}} {{lang.words.w_a}} {{lang.words.new}} {{lang.words.server}}" id="add-smon-button-http">+ {{lang.words.add|title()}}</span>
<br /><br />
<table class="overview overview-overflow" id="ajax-smon-tcp">
	<thead>
	<caption><h3>TCP/UDP {{lang.words.checking}}</h3></caption>
		<tr class="overviewHead">
			<th class="padding10 first-collumn" style="width: 200px;">{{lang.words.name|title()}}</th>
			<th style="width: 15%;">{{lang.words.Hostname}}</th>
			<th style="width: 5%;">{{lang.words.port|title()}}</th>
			<th style="width: 5%;">{{lang.words.enabled|title()}}</th>
			<th style="width: 11%;">Telegram</th>
			<th style="width: 11%;">Slack</th>
			<th style="width: 11%;">PagerDuty</th>
			<th style="width: 10%;">{{lang.words.group|title()}}</th>
			<th style="width: 100%;">{{lang.words.desc|title()}}</th>
			<th></th>
			<th></th>
		</tr>
	</thead>
	<tbody>
	{% for s_service in smon_tcp %}
		{% for s in smon %}
			{% if s.id|string() == s_service.smon_id|string() %}
				<tr id="smon-tcp-{{s.id}}">
					{% include 'include/smon/smon_tcp_server.html' %}
			{% endif %}
		{% endfor %}
	{% endfor %}
	</tbody>
</table>
<br /><span class="add-button" title="{{lang.words.add|title()}} {{lang.words.w_a}} {{lang.words.new}} {{lang.words.server}}" id="add-smon-button-tcp">+ {{lang.words.add|title()}}</span>
<br /><br />
<table class="overview overview-overflow" id="ajax-smon-ping" style="margin-bottom: 20px;">
	<thead>
	<caption><h3>Ping {{lang.words.checking}}</h3></caption>
	<tr class="overviewHead">
		<th class="padding10 first-collumn" style="width: 200px;">{{lang.words.name|title()}}</th>
		<th style="width: 15%;">{{lang.words.Hostname}}</th>
		<th style="width: 5%; padding-right: 10px;">{{lang.smon_page.desc.packet_size}}</th>
		<th style="width: 5%;">{{lang.words.enabled|title()}}</th>
		<th style="width: 15%;">Telegram</th>
		<th style="width: 15%;">Slack</th>
		<th style="width: 15%;">PagerDuty</th>
		<th style="width: 10%;">{{lang.words.group|title()}}</th>
		<th style="width: 100%;">{{lang.words.desc|title()}}</th>
		<th></th>
		<th></th>
	</tr>
	</thead>
	<tbody>
	{% for s in smon %}
		{% if s.check_type == 'ping' %}
			{% for s_service in smon_ping %}
				{% if s_service.smon_id|string() == s.id|string() %}
					<tr id="smon-ping-{{s.id}}">
						{% include 'include/smon/smon_ping_server.html' %}
				{% endif %}
			{% endfor %}
		{% endif %}
	{% endfor %}
	</tbody>
</table>
<br /><span class="add-button" title="{{lang.words.add|title()}} {{lang.words.w_a}} {{lang.words.new}} {{lang.words.server}}" id="add-smon-button-ping">+ {{lang.words.add|title()}}</span>
<br /><br />
<table class="overview overview-overflow" id="ajax-smon-dns" style="margin-bottom: 20px;">
	<thead>
	<caption><h3>DNS {{lang.words.checking}}</h3></caption>
	<tr class="overviewHead">
		<th class="padding10 first-collumn" style="width: 200px;">{{lang.words.name|title()}}</th>
		<th style="width: 15%;">{{lang.words.Hostname}}</th>
		<th style="width: 15%;">Resolver {{lang.words.server}}</th>
		<th style="width: 5%;">{{lang.words.port|title()}}</th>
		<th style="width: 10%;">{{lang.phrases.resource_record_type}}</th>
		<th style="width: 5%;">{{lang.words.enabled|title()}}</th>
		<th style="width: 15%;">Telegram</th>
		<th style="width: 15%;">Slack</th>
		<th style="width: 10%;">PagerDuty</th>
		<th style="width: 10%;">{{lang.words.group|title()}}</th>
		<th style="width: 100%;">{{lang.words.desc|title()}}</th>
		<th></th>
		<th></th>
	</tr>
	</thead>
	<tbody>
	{% for s in smon %}
		{% if s.check_type == 'dns' %}
			{% for s_service in smon_dns %}
				{% if s_service.smon_id|string() == s.id|string() %}
					<tr id="smon-dns-{{s.id}}">
						{% include 'include/smon/smon_dns_server.html' %}
				{% endif %}
			{% endfor %}
		{% endif %}
	{% endfor %}
	</tbody>
</table>
<br /><span class="add-button" title="{{lang.words.add|title()}} {{lang.words.w_a}} {{lang.words.new}} {{lang.words.server}}" id="add-smon-button-dns">+ {{lang.words.add|title()}}</span>
<br /><br />
<div id="ajax"></div>
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
	{{lang.phrases.read_about_parameters}} <a href="https://roxy-wi.org/services/smon" title="SMON service description" target="_blank">{{lang.words.here}}</a>
</div>
<div id="smon-add-table" style="display: none;">
	<table class="overview" id="smon-add-table-overview" title="{{lang.words.create|title()}} {{lang.words.w_a}} {{lang.words.new}} {{lang.words.server}} {{lang.words.for}} {{lang.words.monitoring}}">
		{% include 'include/tr_validate_tips.html' %}
		<tr>
			<td class="padding20">
				{{lang.words.name|title()}}
				<span class="need-field">*</span>
			</td>
			<td>
				{{ input('new-smon-name') }}
			</td>
		</tr>
		<tr>
			<td class="padding20">
				{{lang.words.checking|title()}}
				<span class="need-field">*</span>
			</td>
			<td>
				{% set check_types = {'dns': 'DNS', 'ping': 'Ping', 'tcp': 'TCP/UDP', 'http': 'HTTP(s)'} %}
				{{ select('check_type', values=check_types, selected='http') }}
			</td>
		</tr>
		<tr class="new_smon_hostname">
			<td class="padding20">
				{{lang.words.Hostname}}
				<span class="need-field">*</span>
			</td>
			<td>
				{{ input('new-smon-ip') }}
			</td>
		</tr>
		<tr class="smon_ping_check">
			<td class="padding20">
				{{lang.smon_page.desc.packet_size}}
				<span class="need-field">*</span>
			</td>
			<td>
				{{ input('new-smon-packet_size', value='56', type='number', placeholder='56') }}
			</td>
		</tr>
		<tr class="smon_dns_check">
			<td class="padding20">
				Resolver {{lang.words.server}}
				<span class="need-field">*</span>
			</td>
			<td>
				{{ input('new-smon-resolver-server', value='8.8.8.8') }}
			</td>
		</tr>
		<tr class="smon_tcp_check smon_dns_check">
			<td class="padding20">
				{{lang.words.port|title()}}
				<span class="need-field">*</span>
			</td>
			<td>
				{{ input('new-smon-port', type='number', size='4') }}
			</td>
		</tr>
		<tr class="smon_http_check">
			<td class="padding20">
				URL
				<span class="need-field">*</span>
			</td>
			<td>{{ input('new-smon-url', value='https://', title='proto://url[:port]/') }}</td>
		</tr>
		<tr class="smon_http_check">
			<td class="padding20">{{lang.words.body|title()}}</td>
			<td>{{ input('new-smon-body') }}</td>
		</tr>
		<tr class="smon_http_check">
			<td class="padding20">HTTP {{lang.words.method}}</td>
			<td>
				{% set http_methods = {'get': 'GET', 'post': 'POST', 'put': 'PUT', 'patch': 'PATCH', 'delete': 'DELETE',
				'head': 'HEAD', 'options': 'OPTIONS'} %}
				{{ select('new-smon-method', values=http_methods, selected='get') }}
			</td>
		</tr>
		<tr>
			<td class="padding20">{{lang.words.enable|title()}}</td>
			<td>
				{{ checkbox('new-smon-enable', checked='checked') }}
			</td>
		</tr>
		<tr class="smon_dns_check">
			<td class="padding20">
				{{lang.phrases.resource_record_type}}
				<span class="need-field">*</span>
			</td>
			<td>
				{% set check_types = {'a': 'A', 'aaa': 'AAA', 'caa': 'CAA', 'cname': 'CNAME', 'mx': 'MX', 'ns': 'NS',
				'ptr': 'PTR', 'sao': 'SAO', 'srv': 'SRV', 'txt': 'TXT'} %}
				{{ select('new-smon-dns_record_type', values=check_types, selected='a') }}
			</td>
		</tr>
		<tr>
			<td class="padding20">Telegram</td>
			<td>
				<select id="new-smon-telegram">
					<option value="0">{{lang.words.disabled|title()}}</option>
				{% for t in telegrams %}
					<option value="{{t.id}}">{{t.chanel_name}}</option>
				{% endfor %}
				</select>
			</td>
		</tr>
		<tr>
			<td class="padding20">Slack</td>
			<td>
				<select id="new-smon-slack">
					<option value="0">{{lang.words.disabled|title()}}</option>
				{% for t in slacks %}
					<option value="{{t.id}}">{{t.chanel_name}}</option>
				{% endfor %}
				</select>
			</td>
		</tr>
		<tr>
			<td class="padding20">PagerDuty</td>
			<td>
				<select id="new-smon-pd">
					<option value="0">{{lang.words.disabled|title()}}</option>
				{% for t in pds %}
					<option value="{{t.id}}">{{t.chanel_name}}</option>
				{% endfor %}
				</select>
			</td>
		</tr>
		<tr>
			<td class="padding20">{{lang.words.group|title()}}</td>
			<td>{{ input('new-smon-group') }}</td>
		</tr>
		<tr>
			<td class="padding20">{{lang.words.desc|title()}}</td>
			<td>{{ input('new-smon-description') }}</td>
		</tr>
	</table>
	{% include 'include/del_confirm.html' %}
</div>
{% endif %}
{% endblock %}