From 5120e0a2006c6ed3709f776721375383751a4a4e Mon Sep 17 00:00:00 2001 From: Aidaho Date: Sat, 3 Jun 2023 18:04:22 +0300 Subject: [PATCH] v6.3.13.0 Changelog: https://roxy-wi.org/changelog#6_3_13 --- app/create_db.py | 95 ++++- app/modules/db/db_model.py | 58 ++- app/modules/db/sql.py | 390 ++++++++++++++++---- app/modules/roxywi/user.py | 5 +- app/modules/tools/smon.py | 109 ++++-- app/options.py | 13 +- app/smon.py | 68 +++- app/templates/ajax/show_new_smon.html | 12 +- app/templates/ajax/smon_dashboard.html | 39 +- app/templates/base.html | 5 +- app/templates/include/input_macros.html | 2 +- app/templates/include/smon_history.html | 96 +++++ app/templates/include/smon_http_server.html | 95 +++++ app/templates/include/smon_ping_server.html | 88 +++++ app/templates/include/smon_server.html | 114 ------ app/templates/include/smon_tcp_server.html | 95 +++++ app/templates/languages/en.html | 6 + app/templates/languages/fr.html | 6 + app/templates/languages/pt-br.html | 6 + app/templates/languages/ru.html | 6 + app/templates/smon.html | 125 +++++-- inc/css/smon.css | 72 ++++ inc/metrics.js | 76 +++- inc/script-6.3.9.js | 2 + inc/{smon.js => smon-6.3.13.js} | 155 ++++++-- 25 files changed, 1396 insertions(+), 342 deletions(-) create mode 100644 app/templates/include/smon_history.html create mode 100644 app/templates/include/smon_http_server.html create mode 100644 app/templates/include/smon_ping_server.html delete mode 100644 app/templates/include/smon_server.html create mode 100644 app/templates/include/smon_tcp_server.html create mode 100644 inc/css/smon.css rename inc/{smon.js => smon-6.3.13.js} (56%) diff --git a/app/create_db.py b/app/create_db.py index ee84ebec..1bd51d4d 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -827,9 +827,96 @@ def update_db_v_6_3_12(): else: print("Updating... DB has been updated to version 6.3.12") + +def update_db_v_6_3_13(): + cursor = conn.cursor() + sql = """ + ALTER TABLE `smon` ADD COLUMN check_type VARCHAR ( 64 ) DEFAULT 'tcp'; + """ + try: + cursor.execute(sql) + except Exception as e: + if e.args[0] == 'duplicate column name: check_type' or str(e) == '(1060, "Duplicate column name \'check_type\'")': + print('Updating... DB has been updated to version 6.3.13') + else: + print("An error occurred:", e) + else: + print("Updating... DB has been updated to version 6.3.13") + + +def update_db_v_6_3_13_1(): + try: + SmonTcpCheck.insert_from( + SMON.select(SMON.id, SMON.ip, SMON.port).where( + (SMON.http == '') & (SMON.check_type == 'tcp') + ), fields=[SmonTcpCheck.smon_id, SmonTcpCheck.ip, SmonTcpCheck.port] + ).on_conflict_ignore().execute() + except Exception as e: + if e.args[0] == 'duplicate column name: haproxy' or str(e) == 'type object \'SMON\' has no attribute \'ip\'': + print('Updating... DB has been updated to version 6.3.13-1') + else: + print("An error occurred:", e) + + +def update_db_v_6_3_13_2(): + query = SMON.select().where(SMON.http != '') + try: + query_res = query.execute() + except Exception as e: + print("An error occurred:", e) + else: + for i in query_res: + try: + proto = i.http.split(':')[0] + uri = i.http.split(':')[1] + except Exception: + proto = '' + uri = '' + url = f'{proto}://{i.name}:{i.port}{uri}' + SmonHttpCheck.insert(smon_id=i.id, url=url, body=i.body).on_conflict_ignore().execute() + + +def update_db_v_6_3_13_3(): + try: + SmonPingCheck.insert_from( + SMON.select(SMON.id, SMON.ip).where(SMON.check_type == 'ping'), fields=[SmonPingCheck.smon_id, SmonPingCheck.ip] + ).on_conflict_ignore().execute() + except Exception as e: + if e.args[0] == 'duplicate column name: haproxy' or str(e) == 'type object \'SMON\' has no attribute \'ip\'': + print('Updating... DB has been updated to version 6.3.13-2') + else: + print("An error occurred:", e) + + +def update_db_v_6_3_13_4(): + try: + migrate( + migrator.alter_column_type('smon', 'time_state', DateTimeField()), + migrator.rename_column('smon', 'ip', 'name'), + migrator.drop_column('smon', 'script', cascade=False), + migrator.drop_column('smon', 'http_status', cascade=False), + ) + except Exception as e: + if e.args[0] == 'duplicate column name: check_type' or str(e) == '(1091, "Can\'t DROP COLUMN `script`; check that it exists")': + print('Updating... DB has been updated to version 6.3.13-3') + elif e.args[0] == 'duplicate column name: check_type' or str(e) == '(1091, "Can\'t DROP COLUMN `http_status`; check that it exists")': + print('Updating... DB has been updated to version 6.3.13-3') + elif e.args[0] == 'duplicate column name: check_type' or str(e) == "'bool' object has no attribute 'sql'": + print('Updating... DB has been updated to version 6.3.13-3') + else: + print("An error occurred:", e) + + +def update_db_v_6_3_13_5(): + try: + SMON.update(check_type='http').where(SMON.http != '').execute() + except Exception: + print("An error occurred:", e) + + def update_ver(): try: - Version.update(version='6.3.12.0').execute() + Version.update(version='6.3.13.0').execute() except Exception: print('Cannot update version') @@ -860,6 +947,12 @@ def update_all(): update_db_v_6_3_9() update_db_v_6_3_11() update_db_v_6_3_12() + update_db_v_6_3_13() + update_db_v_6_3_13_1() + update_db_v_6_3_13_2() + update_db_v_6_3_13_3() + update_db_v_6_3_13_4() + update_db_v_6_3_13_5() update_ver() diff --git a/app/modules/db/db_model.py b/app/modules/db/db_model.py index c2a14db1..10f8b632 100644 --- a/app/modules/db/db_model.py +++ b/app/modules/db/db_model.py @@ -1,4 +1,5 @@ from peewee import * +from playhouse.migrate import * from datetime import datetime import modules.roxy_wi_tools as roxy_wi_tools @@ -13,9 +14,11 @@ if mysql_enable == '1': mysql_host = get_config.get_config_var('mysql', 'mysql_host') mysql_port = get_config.get_config_var('mysql', 'mysql_port') conn = MySQLDatabase(mysql_db, user=mysql_user, password=mysql_password, host=mysql_host, port=int(mysql_port)) + migrator = MySQLMigrator(conn) else: db = "/var/lib/roxy-wi/roxy-wi.db" conn = SqliteDatabase(db, pragmas={'timeout': 1000, 'foreign_keys': 1}) + migrator = SqliteMigrator(conn) class BaseModel(Model): @@ -412,17 +415,15 @@ class MetricsHttpStatus(BaseModel): class SMON(BaseModel): id = AutoField() - ip = CharField(null=True) + name = CharField(null=True) port = IntegerField(null=True) status = IntegerField(constraints=[SQL('DEFAULT 1')]) en = IntegerField(constraints=[SQL('DEFAULT 1')]) desc = CharField(null=True) response_time = CharField(null=True) - time_state = IntegerField(constraints=[SQL('DEFAULT 0')]) + time_state = DateTimeField(constraints=[SQL('DEFAULT "0000-00-00 00:00:00"')]) group = CharField(null=True) - script = CharField(null=True) http = CharField(null=True) - http_status = IntegerField(constraints=[SQL('DEFAULT 1')]) body = CharField(null=True) body_status = IntegerField(constraints=[SQL('DEFAULT 1')]) telegram_channel_id = IntegerField(null=True) @@ -432,6 +433,7 @@ class SMON(BaseModel): ssl_expire_critical_alert = IntegerField(constraints=[SQL('DEFAULT 0')]) ssl_expire_date = CharField(null=True) pd_channel_id = IntegerField(null=True) + check_type = CharField(constraints=[SQL('DEFAULT tcp')]) class Meta: table_name = 'smon' @@ -602,6 +604,51 @@ class KeepaliveRestart(BaseModel): constraints = [SQL('UNIQUE (server_id, service)')] +class SmonHistory(BaseModel): + smon_id = ForeignKeyField(SMON, on_delete='Cascade') + check_id = IntegerField() + response_time = FloatField() + status = IntegerField() + mes = CharField() + date = DateTimeField(default=datetime.now) + + class Meta: + table_name = 'smon_history' + primary_key = False + + +class SmonTcpCheck(BaseModel): + smon_id = ForeignKeyField(SMON, on_delete='Cascade', unique=True) + ip = CharField() + port = IntegerField() + + class Meta: + table_name = 'smon_tcp_check' + primary_key = False + + +class SmonHttpCheck(BaseModel): + smon_id = ForeignKeyField(SMON, on_delete='Cascade', unique=True) + url = CharField() + method = CharField(constraints=[SQL('DEFAULT "get"')]) + accepted_status_codes = CharField(constraints=[SQL('DEFAULT "200"')]) + body = CharField(null=True) + + class Meta: + table_name = 'smon_http_check' + primary_key = False + + +class SmonPingCheck(BaseModel): + smon_id = ForeignKeyField(SMON, on_delete='Cascade', unique=True) + ip = CharField() + packet_size = IntegerField(constraints=[SQL('DEFAULT 56')]) + + class Meta: + table_name = 'smon_ping_check' + primary_key = False + + def create_tables(): with conn: conn.create_tables([User, Server, Role, Telegram, Slack, UUID, Token, ApiToken, Groups, UserGroups, ConfigVersion, @@ -609,4 +656,5 @@ def create_tables(): PortScannerSettings, PortScannerPorts, PortScannerHistory, ProvidersCreds, ServiceSetting, ProvisionedServers, MetricsHttpStatus, SMON, WafRules, Alerts, GeoipCodes, NginxMetrics, SystemInfo, Services, UserName, GitSetting, CheckerSetting, ApacheMetrics, ProvisionParam, - WafNginx, ServiceStatus, KeepaliveRestart, PD]) + WafNginx, ServiceStatus, KeepaliveRestart, PD, SmonHistory, SmonTcpCheck, SmonHttpCheck, + SmonPingCheck]) diff --git a/app/modules/db/sql.py b/app/modules/db/sql.py index 5301d42a..5710df91 100755 --- a/app/modules/db/sql.py +++ b/app/modules/db/sql.py @@ -2474,16 +2474,11 @@ def check_token_exists(token): return False -def insert_smon(server, port, enable, proto, uri, body, group, desc, telegram, slack, pd, user_group): - try: - http = proto + ':' + uri - except Exception: - http = '' - +def insert_smon(name, enable, group, desc, telegram, slack, pd, user_group, check_type): try: last_id = SMON.insert( - ip=server, port=port, en=enable, desc=desc, group=group, http=http, body=body, - telegram_channel_id=telegram, slack_channel_id=slack, pd_channel_id=pd, user_group=user_group, status='3' + name=name, en=enable, desc=desc, group=group, telegram_channel_id=telegram, slack_channel_id=slack, + pd_channel_id=pd, user_group=user_group, status='3', check_type=check_type ).execute() except Exception as e: out_error(e) @@ -2492,50 +2487,136 @@ def insert_smon(server, port, enable, proto, uri, body, group, desc, telegram, s return last_id -def select_smon(user_group, **kwargs): - cursor = conn.cursor() - - if user_group == 1: - user_group = '' - else: - if kwargs.get('ip'): - user_group = f"and user_group = '{user_group}'" - else: - user_group = f"where user_group = '{user_group}'" - - if kwargs.get('ip'): - try: - http = kwargs.get('proto') + ':' + kwargs.get('uri') - except Exception: - http = '' - sql = """select id, ip, port, en, http, body, telegram_channel_id, `desc`, `group`, user_group, slack_channel_id, pd_channel_id from smon - where ip='%s' and port='%s' and http='%s' and body='%s' %s - """ % (kwargs.get('ip'), kwargs.get('port'), http, body, user_group) - elif kwargs.get('action') == 'add': - sql = """select id, ip, port, en, http, body, telegram_channel_id, `desc`, `group`, user_group, slack_channel_id, pd_channel_id from smon - %s order by `group`""" % user_group - else: - sql = """select * from `smon` %s """ % user_group - +def insert_smon_ping(smon_id, hostname): try: - cursor.execute(sql) + SmonPingCheck.insert(smon_id=smon_id, ip=hostname).execute() + except Exception as e: + out_error(e) + + +def insert_smon_tcp(smon_id, hostname, port): + try: + SmonTcpCheck.insert(smon_id=smon_id, ip=hostname, port=port).execute() + except Exception as e: + out_error(e) + + +def insert_smon_http(smon_id, url, body): + try: + SmonHttpCheck.insert(smon_id=smon_id, url=url, body=body).execute() + except Exception as e: + out_error(e) + + +def select_smon(user_group): + if user_group == 1: + query = SMON.select() + else: + query = SMON.select().where(SMON.user_group == user_group) + try: + query_res = query.execute() except Exception as e: out_error(e) else: - return cursor.fetchall() + return query_res + + +def select_smon_ping(user_group): + if user_group == 1: + query = SmonPingCheck.select() + else: + query = SmonPingCheck.select().where(SMON.user_group == user_group) + + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def select_en_smon_ping() -> object: + query = SmonPingCheck.select(SmonPingCheck, SMON).join_from(SmonPingCheck, SMON).where(SMON.en == '1') + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def select_en_smon_tcp() -> object: + query = SmonTcpCheck.select(SmonTcpCheck, SMON).join_from(SmonTcpCheck, SMON).where(SMON.en == '1') + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def select_en_smon_http() -> object: + query = SmonHttpCheck.select(SmonHttpCheck, SMON).join_from(SmonHttpCheck, SMON).where(SMON.en == '1') + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def select_smon_tcp(user_group): + if user_group == 1: + query = SmonTcpCheck.select() + else: + query = SmonTcpCheck.select().where(SMON.user_group == user_group) + + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def select_smon_http(user_group): + if user_group == 1: + query = SmonHttpCheck.select() + else: + query = SmonHttpCheck.select().where(SMON.user_group == user_group) + + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res def select_smon_by_id(last_id): - cursor = conn.cursor() - sql = """select id, ip, port, en, http, body, telegram_channel_id, `desc`, `group`, user_group, slack_channel_id, pd_channel_id - from `smon` where id = {} """.format(last_id) - + query = SMON.select().where(SMON.id == last_id) try: - cursor.execute(sql) + query_res = query.execute() except Exception as e: out_error(e) else: - return cursor.fetchall() + return query_res + + +def select_smon_check_by_id(last_id, check_type): + if check_type == 'ping': + query = SmonPingCheck.select().where(SmonPingCheck.smon_id == last_id) + elif check_type == 'tcp': + query = SmonTcpCheck.select().where(SmonTcpCheck.smon_id == last_id) + else: + query = SmonHttpCheck.select().where(SmonHttpCheck.smon_id == last_id) + print(query) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res def delete_smon(smon_id, user_group): @@ -2549,9 +2630,39 @@ def delete_smon(smon_id, user_group): return True -def update_smon(smon_id, ip, port, body, telegram, slack, pd, group, desc, en): +def update_smonHttp(smon_id, url, body): + query = (SmonHttpCheck.update(url=url, body=body).where(SmonHttpCheck.smon_id == smon_id)) + try: + query.execute() + return True + except Exception as e: + out_error(e) + return False + + +def update_smonTcp(smon_id, ip, port): + query = (SmonTcpCheck.update(ip=ip, port=port).where(SmonTcpCheck.smon_id == smon_id)) + try: + query.execute() + return True + except Exception as e: + out_error(e) + return False + + +def update_smonPing(smon_id, ip, port): + query = (SmonPingCheck.update(ip=ip).where(SmonPingCheck.smon_id == smon_id)) + try: + query.execute() + return True + except Exception as e: + out_error(e) + return False + + +def update_smon(smon_id, name, telegram, slack, pd, group, desc, en): query = (SMON.update( - ip=ip, port=port, body=body, telegram_channel_id=telegram, slack_channel_id=slack, pd_channel_id=pd, group=group, desc=desc, en=en + name=name, telegram_channel_id=telegram, slack_channel_id=slack, pd_channel_id=pd, group=group, desc=desc, en=en ).where(SMON.id == smon_id)) try: query.execute() @@ -2587,16 +2698,6 @@ def alerts_history(service, user_group, **kwargs): return cursor.fetchall() -def select_en_service(): - query = SMON.select().where(SMON.en == 1) - try: - query_res = query.execute() - except Exception as e: - out_error(e) - else: - return query_res - - def select_status(smon_id): try: query_res = SMON.get(SMON.id == smon_id).status @@ -2662,17 +2763,6 @@ def change_status(status, smon_id): return True -def change_http_status(status, smon_id): - query = SMON.update(http_status=status).where(SMON.id == smon_id) - try: - query.execute() - except Exception as e: - out_error(e) - return False - else: - return True - - def change_body_status(status, smon_id): query = SMON.update(body_status=status).where(SMON.id == smon_id) try: @@ -2719,15 +2809,9 @@ def response_time(time, smon_id): def smon_list(user_group): if user_group == 1: - query = (SMON.select( - SMON.ip, SMON.port, SMON.status, SMON.en, SMON.desc, SMON.response_time, SMON.time_state, - SMON.group, SMON.script, SMON.http, SMON.http_status, SMON.body, SMON.body_status, SMON.ssl_expire_date - ).order_by(SMON.group)) + query = (SMON.select().order_by(SMON.group)) else: - query = (SMON.select( - SMON.ip, SMON.port, SMON.status, SMON.en, SMON.desc, SMON.response_time, SMON.time_state, - SMON.group, SMON.script, SMON.http, SMON.http_status, SMON.body, SMON.body_status - ).where(SMON.user_group == user_group).order_by(SMON.group)) + query = (SMON.select().where(SMON.user_group == user_group).order_by(SMON.group)) try: query_res = query.execute() @@ -2737,6 +2821,139 @@ def smon_list(user_group): return query_res +def select_one_smon(smon_id: int, check_id: int) -> object: + if check_id == 1: + query = SmonTcpCheck.select(SmonTcpCheck, SMON).join_from(SmonTcpCheck, SMON).where(SMON.id == smon_id) + elif check_id == 2: + query = SmonHttpCheck.select(SmonHttpCheck, SMON).join_from(SmonHttpCheck, SMON).where(SMON.id == smon_id) + else: + query = SmonPingCheck.select(SmonPingCheck, SMON).join_from(SmonPingCheck, SMON).where(SMON.id == smon_id) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def insert_smon_history(smon_id: int, response_time: float, status: int, check_id: int, mes='') -> None: + cur_date = get_date.return_date('regular') + try: + SmonHistory.insert(smon_id=smon_id, response_time=response_time, status=status, date=cur_date, + check_id=check_id, mes=mes).execute() + except Exception as e: + out_error(e) + + +def select_smon_history(smon_id: int, check_id: int) -> object: + query = SmonHistory.select().where( + (SmonHistory.smon_id == smon_id) & + (SmonHistory.check_id == check_id) + ).limit(40).order_by(SmonHistory.date.desc()) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + +def get_last_smon_status_by_check(smon_id: int, check_id: int) -> object: + query = SmonHistory.select().where( + (SmonHistory.smon_id == smon_id) & + (SmonHistory.check_id == check_id) + ).limit(1).order_by(SmonHistory.date.desc()) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + try: + for i in query_res: + return i.status + except Exception: + return '' + + +def get_last_smon_res_time_by_check(smon_id: int, check_id: int) -> object: + query = SmonHistory.select().where( + (SmonHistory.smon_id == smon_id) & + (SmonHistory.check_id == check_id) + ).limit(1).order_by(SmonHistory.date.desc()) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + try: + for i in query_res: + return i.response_time + except Exception: + return '' + + +def get_smon_history_count_checks(smon_id: int, check_id: int) -> dict: + count_checks = {} + query = SmonHistory.select(fn.Count(SmonHistory.status)).where( + (SmonHistory.smon_id == smon_id) & + (SmonHistory.check_id == check_id) + ) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + try: + for i in query_res: + count_checks['total'] = i.status + except Exception as e: + raise Exception(f'error: {e}') + + query = SmonHistory.select(fn.Count(SmonHistory.status)).where( + (SmonHistory.smon_id == smon_id) & + (SmonHistory.check_id == check_id) & + (SmonHistory.status == 1) + ) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + try: + for i in query_res: + count_checks['up'] = i.status + except Exception as e: + raise Exception(f'error: {e}') + + return count_checks + + +def get_smon_service_name_by_id(smon_id: int) -> str: + query = SMON.select().join(SmonHistory, on=(SmonHistory.smon_id == SMON.id)).where(SmonHistory.smon_id == smon_id) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + try: + for i in query_res: + return f'{i.name}' + except Exception: + return '' + + +def get_avg_resp_time(smon_id: int, check_id: int) -> object: + try: + query_res = SmonHistory.select(fn.AVG(SmonHistory.response_time)).where( + (SmonHistory.smon_id == smon_id) & + (SmonHistory.check_id == check_id) + ).scalar() + except Exception as e: + out_error(e) + else: + return query_res + + def insert_alerts(user_group, level, ip, port, message, service): cur_date = get_date.return_date('regular') try: @@ -3691,6 +3908,19 @@ def select_user_name(): return query_res +def get_super_admin_count() -> int: + query = UserGroups.select(UserGroups.user_id, UserGroups.user_role_id).distinct().where(UserGroups.user_role_id == 1).group_by(UserGroups.user_id) + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + try: + return len(list(query_res)) + except Exception as e: + raise Exception(f'error: {e}') + + def update_user_name(user_name): user_update = UserName.update(UserName=user_name) try: @@ -3967,31 +4197,31 @@ def inset_or_update_service_status( out_error(e) -def update_smon_ssl_expire_date(service_ip: str, expire_date: str) -> None: - SMON_update = SMON.update(ssl_expire_date=expire_date).where(SMON.ip == service_ip) +def update_smon_ssl_expire_date(smon_id: str, expire_date: str) -> None: + SMON_update = SMON.update(ssl_expire_date=expire_date).where(SMON.id == smon_id) try: SMON_update.execute() except Exception as e: out_error(e) -def update_smon_alert_status(service_ip: str, alert_value: int, alert: str) -> None: +def update_smon_alert_status(smon_id: str, alert_value: int, alert: str) -> None: if alert == 'ssl_expire_warning_alert': - SMON_update = SMON.update(ssl_expire_warning_alert=alert_value).where(SMON.ip == service_ip) + SMON_update = SMON.update(ssl_expire_warning_alert=alert_value).where(SMON.id == smon_id) else: - SMON_update = SMON.update(ssl_expire_critical_alert=alert_value).where(SMON.ip == service_ip) + SMON_update = SMON.update(ssl_expire_critical_alert=alert_value).where(SMON.id == smon_id) try: SMON_update.execute() except Exception as e: out_error(e) -def get_smon_alert_status(service_ip: str, alert: str) -> int: +def get_smon_alert_status(smon_id: str, alert: str) -> int: try: if alert == 'ssl_expire_warning_alert': - alert_value = SMON.get(SMON.ip == service_ip).ssl_expire_warning_alert + alert_value = SMON.get(SMON.id == smon_id).ssl_expire_warning_alert else: - alert_value = SMON.get(SMON.ip == service_ip).ssl_expire_critical_alert + alert_value = SMON.get(SMON.id == smon_id).ssl_expire_critical_alert except Exception as e: out_error(e) else: diff --git a/app/modules/roxywi/user.py b/app/modules/roxywi/user.py index e69c998e..2ec381ff 100644 --- a/app/modules/roxywi/user.py +++ b/app/modules/roxywi/user.py @@ -47,7 +47,10 @@ def create_user(new_user: str, email: str, password: str, role: str, activeuser: def delete_user(): - userdel = form.getvalue('userdel') + userdel = int(form.getvalue('userdel')) + count_super_admin_users = sql.get_super_admin_count() + if count_super_admin_users < 2: + raise Exception('error: you cannot delete a last user with superAdmin role') user = sql.select_users(id=userdel) username = '' for u in user: diff --git a/app/modules/tools/smon.py b/app/modules/tools/smon.py index c29bd34c..1949a2b2 100644 --- a/app/modules/tools/smon.py +++ b/app/modules/tools/smon.py @@ -1,3 +1,5 @@ +import json + from jinja2 import Environment, FileSystemLoader import modules.db.sql as sql @@ -9,80 +11,93 @@ form = common.form def create_smon() -> None: user_group = roxywi_common.get_user_group(id=1) - server = common.checkAjaxInput(form.getvalue('newsmon')) + name = common.checkAjaxInput(form.getvalue('newsmonname')) + hostname = common.checkAjaxInput(form.getvalue('newsmon')) port = common.checkAjaxInput(form.getvalue('newsmonport')) enable = common.checkAjaxInput(form.getvalue('newsmonenable')) - http = common.checkAjaxInput(form.getvalue('newsmonproto')) - uri = common.checkAjaxInput(form.getvalue('newsmonuri')) + url = common.checkAjaxInput(form.getvalue('newsmonurl')) body = common.checkAjaxInput(form.getvalue('newsmonbody')) group = common.checkAjaxInput(form.getvalue('newsmongroup')) desc = common.checkAjaxInput(form.getvalue('newsmondescription')) telegram = common.checkAjaxInput(form.getvalue('newsmontelegram')) slack = common.checkAjaxInput(form.getvalue('newsmonslack')) pd = common.checkAjaxInput(form.getvalue('newsmonpd')) + check_type = common.checkAjaxInput(form.getvalue('newsmonchecktype')) - try: - port = int(port) - except Exception: - print('SMON error: port must number') - return None - if port > 65535 or port < 0: - print('SMON error: port must be 0-65535') - return None - if port == 80 and http == 'https': - print('SMON error: Cannot be HTTPS with 80 port') - return None - if port == 443 and http == 'http': - print('SMON error: Cannot be HTTP with 443 port') - return None + if check_type == 'tcp': + try: + port = int(port) + except Exception: + print('SMON error: port must number') + return None + if port > 65535 or port < 0: + print('SMON error: port must be 0-65535') + return None + + last_id = sql.insert_smon(name, enable, group, desc, telegram, slack, pd, user_group, check_type) + + if check_type == 'ping': + sql.insert_smon_ping(last_id, hostname) + elif check_type == 'tcp': + sql.insert_smon_tcp(last_id, hostname, port) + elif check_type == 'http': + sql.insert_smon_http(last_id, url, body) - last_id = sql.insert_smon(server, port, enable, http, uri, body, group, desc, telegram, slack, pd, user_group) if last_id: lang = roxywi_common.get_user_lang() smon = sql.select_smon_by_id(last_id) pds = sql.get_user_pd_by_group(user_group) slacks = sql.get_user_slack_by_group(user_group) telegrams = sql.get_user_telegram_by_group(user_group) + smon_service = sql.select_smon_check_by_id(last_id, check_type) env = Environment(loader=FileSystemLoader('templates'), autoescape=True) template = env.get_template('ajax/show_new_smon.html') - template = template.render(smon=smon, telegrams=telegrams, slacks=slacks, pds=pds, lang=lang) + template = template.render(smon=smon, telegrams=telegrams, slacks=slacks, pds=pds, lang=lang, check_type=check_type, + smon_service=smon_service) print(template) - roxywi_common.logging('SMON', f' A new server {server} to SMON has been add ', roxywi=1, login=1) + roxywi_common.logging('SMON', f' A new server {name} to SMON has been add ', roxywi=1, login=1) def update_smon() -> None: smon_id = common.checkAjaxInput(form.getvalue('id')) + name = common.checkAjaxInput(form.getvalue('updateSmonName')) ip = common.checkAjaxInput(form.getvalue('updateSmonIp')) port = common.checkAjaxInput(form.getvalue('updateSmonPort')) en = common.checkAjaxInput(form.getvalue('updateSmonEn')) - http = common.checkAjaxInput(form.getvalue('updateSmonHttp')) + url = common.checkAjaxInput(form.getvalue('updateSmonUrl')) body = common.checkAjaxInput(form.getvalue('updateSmonBody')) telegram = common.checkAjaxInput(form.getvalue('updateSmonTelegram')) slack = common.checkAjaxInput(form.getvalue('updateSmonSlack')) pd = common.checkAjaxInput(form.getvalue('updateSmonPD')) group = common.checkAjaxInput(form.getvalue('updateSmonGroup')) desc = common.checkAjaxInput(form.getvalue('updateSmonDesc')) + check_type = common.checkAjaxInput(form.getvalue('check_type')) + is_edited = False + + if check_type == 'tcp': + try: + port = int(port) + except Exception: + print('SMON error: port must number') + return None + if port > 65535 or port < 0: + print('SMON error: port must be 0-65535') + return None - try: - port = int(port) - except Exception: - print('SMON error: port must number') - return None - if port > 65535 or port < 0: - print('SMON error: port must be 0-65535') - return None - if port == 80 and http == 'https': - print('SMON error: Cannot be https with 80 port') - return None - if port == 443 and http == 'http': - print('SMON error: Cannot be HTTP with 443 port') - return None roxywi_common.check_user_group() try: - if sql.update_smon(smon_id, ip, port, body, telegram, slack, pd, group, desc, en): - print("Ok") - roxywi_common.logging('SMON', f' The SMON server {ip} has been update ', roxywi=1, login=1) + if sql.update_smon(smon_id, name, telegram, slack, pd, group, desc, en): + if check_type == 'http': + is_edited = sql.update_smonHttp(smon_id, url, body) + elif check_type == 'tcp': + is_edited = sql.update_smonTcp(smon_id, ip, port) + elif check_type == 'ping': + is_edited = sql.update_smonTcp(smon_id, ip) + + if is_edited: + print("Ok") + roxywi_common.logging('SMON', f' The SMON server {name} has been update ', roxywi=1, login=1) except Exception as e: print(e) @@ -108,3 +123,21 @@ def delete_smon() -> None: roxywi_common.logging('SMON', ' The server from SMON has been delete ', roxywi=1, login=1) except Exception as e: print(e) + + +def history_metrics(server_id: int, check_id: int) -> None: + metric = sql.select_smon_history(server_id, check_id) + + metrics = {'chartData': {}} + metrics['chartData']['labels'] = {} + labels = '' + curr_con = '' + + for i in reversed(metric): + labels += f'{i.date.time()},' + curr_con += f'{i.response_time},' + + metrics['chartData']['labels'] = labels + metrics['chartData']['curr_con'] = curr_con + + print(json.dumps(metrics)) diff --git a/app/options.py b/app/options.py index 1295792a..aa16c422 100644 --- a/app/options.py +++ b/app/options.py @@ -31,7 +31,7 @@ token = form.getvalue("token") if any(( form.getvalue('new_metrics'), form.getvalue('new_http_metrics'), form.getvalue('new_waf_metrics'), form.getvalue('new_nginx_metrics'), form.getvalue('new_apache_metrics'), form.getvalue('metrics_hapwi_ram'), form.getvalue('metrics_hapwi_cpu'), form.getvalue('getoption'), - form.getvalue('getsavedserver')) + form.getvalue('getsavedserver'), form.getvalue('smon_history_check')) ): print('Content-type: application/json\n') else: @@ -981,7 +981,7 @@ if form.getvalue('getcurrentusergroup') is not None: roxy_user.get_user_active_group(user_id, group) -if form.getvalue('newsmon') is not None: +if form.getvalue('newsmonname') is not None: import modules.tools.smon as smon_mod smon_mod.create_smon() @@ -996,11 +996,18 @@ if form.getvalue('showsmon') is not None: smon_mod.show_smon() -if form.getvalue('updateSmonIp') is not None: +if form.getvalue('updateSmonName') is not None: import modules.tools.smon as smon_mod smon_mod.update_smon() +if form.getvalue('smon_history_check') is not None: + import modules.tools.smon as smon_mod + + server_id = int(form.getvalue('server_id')) + check_id = int(form.getvalue('check_id')) + smon_mod.history_metrics(server_id, check_id) + if form.getvalue('showBytes') is not None: import modules.roxywi.overview as roxywi_overview diff --git a/app/smon.py b/app/smon.py index b83b5da8..edd40c16 100644 --- a/app/smon.py +++ b/app/smon.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import sys +from datetime import datetime +from pytz import timezone from jinja2 import Environment, FileSystemLoader import modules.db.sql as sql @@ -33,13 +35,26 @@ pds = '' user_group = roxywi_common.get_user_group(id=1) cmd = "systemctl is-active roxy-wi-smon" smon_status, stderr = server_mod.subprocess_execute(cmd) +smon_statuses = '' +smon_ping = '' +smon_tcp = '' +smon_http = '' +smon = '' +try: + user_subscription = roxywi_common.return_user_status() +except Exception as e: + user_subscription = roxywi_common.return_unsubscribed_user_status() + roxywi_common.logging('Roxy-WI server', f'Cannot get a user plan: {e}', roxywi=1) if action == 'add': telegrams = sql.get_user_telegram_by_group(user_group) slacks = sql.get_user_slack_by_group(user_group) pds = sql.get_user_pd_by_group(user_group) - smon = sql.select_smon(user_group, action='add') + smon = sql.select_smon(user_group) + smon_ping = sql.select_smon_ping(user_group) + smon_tcp = sql.select_smon_tcp(user_group) + smon_http = sql.select_smon_http(user_group) roxywi_auth.page_for_admin(level=3) if lang == 'ru': title = "SMON: Админка" @@ -67,6 +82,48 @@ elif action == 'checker_history': title = "Checker: Histoire" else: title = "Checker: History" +elif action == 'dashboard': + dashboard_id = int(form.getvalue('dashboard_id')) + check_id = int(form.getvalue('check_id')) + smon_statuses = sql.select_smon_history(dashboard_id, check_id) + title = '' + smon_name = sql.get_smon_service_name_by_id(dashboard_id) + cur_status = sql.get_last_smon_status_by_check(dashboard_id, check_id) + check_interval = sql.get_setting('smon_check_interval') + smon = sql.select_one_smon(dashboard_id, check_id) + present = datetime.now(timezone('UTC')) + present = present.strftime('%b %d %H:%M:%S %Y %Z') + present = datetime.strptime(present, '%b %d %H:%M:%S %Y %Z') + cert_day_diff = 'N/A' + count_checks = sql.get_smon_history_count_checks(dashboard_id, check_id) + try: + uptime = round(count_checks['up'] * 100 / count_checks['total'], 2) + except Exception: + uptime = 0 + try: + avg_res_time = round(sql.get_avg_resp_time(dashboard_id, check_id), 2) + except Exception: + avg_res_time = 0 + try: + last_resp_time = round(sql.get_last_smon_res_time_by_check(dashboard_id, check_id), 2) + except Exception: + last_resp_time = 0 + template = env.get_template('include/smon_history.html') + + for s in smon: + if s.smon_id.ssl_expire_date is not None: + ssl_expire_date = datetime.strptime(s.smon_id.ssl_expire_date, '%Y-%m-%d %H:%M:%S') + cert_day_diff = (ssl_expire_date - present).days + + rendered_template = template.render( + h2=1, title=title, autorefresh=autorefresh, role=user_params['role'], user=user_params['user'], smon=smon, + group=user_group, lang=lang, user_status=user_subscription['user_status'], check_interval=check_interval, + user_plan=user_subscription['user_plan'], token=user_params['token'], smon_statuses=smon_statuses, uptime=uptime, + user_services=user_params['user_services'], cur_status=cur_status, avg_res_time=avg_res_time, smon_name=smon_name, + cert_day_diff=cert_day_diff, check_id=check_id, dashboard_id=dashboard_id, last_resp_time=last_resp_time + ) + print(rendered_template) + sys.exit() else: smon = sql.smon_list(user_group) if lang == 'ru': @@ -77,16 +134,11 @@ else: title = "SMON: Dashboard" autorefresh = 1 -try: - user_subscription = roxywi_common.return_user_status() -except Exception as e: - user_subscription = roxywi_common.return_unsubscribed_user_status() - roxywi_common.logging('Roxy-WI server', f'Cannot get a user plan: {e}', roxywi=1) - rendered_template = template.render( h2=1, title=title, autorefresh=autorefresh, role=user_params['role'], user=user_params['user'], group=user_group, telegrams=telegrams, slacks=slacks, pds=pds, lang=lang, smon=smon, smon_status=smon_status, smon_error=stderr, action=action, sort=sort, user_services=user_params['user_services'], user_status=user_subscription['user_status'], - user_plan=user_subscription['user_plan'], token=user_params['token'] + user_plan=user_subscription['user_plan'], token=user_params['token'], smon_ping=smon_ping, smon_tcp=smon_tcp, smon_http=smon_http + ) print(rendered_template) diff --git a/app/templates/ajax/show_new_smon.html b/app/templates/ajax/show_new_smon.html index 3802e832..6e2376f8 100644 --- a/app/templates/ajax/show_new_smon.html +++ b/app/templates/ajax/show_new_smon.html @@ -1,6 +1,14 @@ {% import 'languages/'+lang|default('en')+'.html' as lang %} {% from 'include/input_macros.html' import input, checkbox %} {% for s in smon %} - - {% include 'include/smon_server.html' %} + {% for s_service in smon_service %} + + {% if check_type == 'tcp' %} + {% include 'include/smon_tcp_server.html' %} + {% elif check_type == 'ping' %} + {% include 'include/smon_ping_server.html' %} + {% elif check_type == 'http' %} + {% include 'include/smon_http_server.html' %} + {% endif %} + {% endfor %} {% endfor %} diff --git a/app/templates/ajax/smon_dashboard.html b/app/templates/ajax/smon_dashboard.html index 166060fc..84947db4 100644 --- a/app/templates/ajax/smon_dashboard.html +++ b/app/templates/ajax/smon_dashboard.html @@ -26,21 +26,27 @@ {% set group = [] %} {% set group_prev = [] %} {%- for s in smon -%} - {% set checks = lang.smon_page.desc.enabled_checks +':
' + lang.phrases.port_check %} - {% if s.http %} - {% set checks = checks + ',
' + lang.smon_page.desc.http_status_check + ': ' + s.http.split(':')[0]|string() + '://' + s.ip|string() + ':' + s.port|string() + s.http.split(':')[1]|string() %} + {% set checks = lang.smon_page.desc.enabled_checks +':
' %} + {% if s.check_type == 'tcp' %} + {% set checks = checks + lang.phrases.port_check %} + {% set check_id = 1 %} {% endif %} - {% if s.body and s.body is not none %} - {% set checks = checks + ',
' + lang.smon_page.desc.body_status_check + ':' + s.body %} + {% if s.check_type == 'http' %} + {% set checks = checks + lang.smon_page.desc.http_status_check %} + {% set check_id = 2 %} + {% if s.ssl_expire_date %} + {% set checks = checks + ',
SSL ' + lang.words.expire + ': ' + s.ssl_expire_date %} + {% endif %} {% endif %} - {% if s.ssl_expire_date %} - {% set checks = checks + ',
SSL ' + lang.words.expire + ': ' + s.ssl_expire_date %} + {% if s.check_type == 'ping' %} + {% set check_id = 4 %} + {% set checks = lang.smon_page.desc.enabled_checks +': Ping' %} {% endif %} {% if s.en == 1 %} - {% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %} + {% if s.status == 1 and s.body_status == 1 %} {% set additional_classes = 'good div-server-head-up' %} {% set uptime_desc = lang.words.uptime + ': ' %} - {% elif s.status == 0 or s.http_status == 0 or s.body_status == 0 %} + {% elif s.status == 0 or s.body_status == 0 %} {% set additional_classes = 'err div-server-head-down' %} {% set uptime_desc = lang.words.downtime + ': ' %} {% else %} @@ -52,11 +58,11 @@ {% set uptime_desc = lang.words.uptime + ': N/A' %} {% endif %} {% set additional_style = '' %} - {% if s.ip|string|length > 23 %} + {% if s.name|string|length > 23 %} {% set additional_style = 'font-size: 11px;' %} - {% elif s.ip|string|length > 20 %} + {% elif s.name|string|length > 20 %} {% set additional_style = 'font-size: 12px;' %} - {% elif s.ip|string|length > 17 %} + {% elif s.name|string|length > 17 %} {% set additional_style = 'font-size: 15px;' %} {% endif %} {% if s.group not in group %} @@ -70,12 +76,13 @@
{% if s.desc %} - {{s.desc}} + {{s.desc.strip("'")}} {% else %} {{lang.words.desc|title()}}: {{lang.words.none}} {% endif %} @@ -100,11 +107,11 @@ {% endif %}
{% if s.en == 1 %} - {% if s.status == 1 and s.http_status == 1 and s.body_status == 1 %} + {% if s.status == 1 and s.body_status == 1 %}
{{lang.smon_page.desc.UP}}
- {% elif s.http_status == 0 %} + {% elif s.status == 0 and s.check_type == 'http' %}
{{lang.smon_page.desc.HTTP_FAILURE}}
diff --git a/app/templates/base.html b/app/templates/base.html index a6995dd4..1d5fbbfa 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -18,8 +18,9 @@ data-empty_name="{{lang.errors.empty_name}}" data-edit="{{lang.words.edit|title()}}" data-close="{{lang.words.close|title()}}" data-server_info="{{lang.phrases.server_info}}" data-generated_config="{{lang.words.generated|title()}} {{lang.words.config}}" data-restart="{{lang.words.restart|title()}}" data-start="{{lang.words.start|title()}}" data-stop="{{lang.words.stop|title()}}" data-reload="{{lang.words.reload|title()}}" data-user_groups="{{lang.phrases.user_groups}}" data-settings="{{lang.words.settings|title()}}" - data-for="{{lang.words.for}}" data-show="{{lang.words.show|title()}}" data-hide="{{lang.words.hide|title()}}" data-logs="{{lang.words.logs}}" - data-autorefresh="{{lang.words.auto|title()}}-{{lang.words.refresh}}" /> + data-for="{{lang.words.for}}" data-show="{{lang.words.show|title()}}" data-hide="{{lang.words.hide|title()}}" data-logs="{{lang.words.logs}}" data-name="{{lang.words.name}}" + data-value="{{lang.words.value}}" data-if-title="{{lang.words.if|title()}}" data-then="{{lang.words.then}}" data-autorefresh="{{lang.words.auto|title()}}-{{lang.words.refresh}}" + data-raw="{{lang.words.raw|title()}}" data-resp_time="{{lang.smon_page.desc.resp_time}}" /> {% if title == 'Login page' %} {% endif %} diff --git a/app/templates/include/input_macros.html b/app/templates/include/input_macros.html index 0d3d69ca..fe95bac5 100644 --- a/app/templates/include/input_macros.html +++ b/app/templates/include/input_macros.html @@ -32,7 +32,7 @@ {% endif %} {% for v, des in values.items() %} - {% if v == selected %} + {% if v == selected|string() %} {% else %} diff --git a/app/templates/include/smon_history.html b/app/templates/include/smon_history.html new file mode 100644 index 00000000..e133b4c7 --- /dev/null +++ b/app/templates/include/smon_history.html @@ -0,0 +1,96 @@ +{% extends "base.html" %} +{% from 'include/input_macros.html' import select %} +{% block title %}{{ lang.menu_links.history.title }} {{ smon_name }}{% endblock %} +{% block h2 %}{{ lang.menu_links.history.title }} {{ smon_name }}{% endblock %} +{% block content %} +{% set checking_types = {'1': 'TCP/UDP', '2': 'HTTP', '4': 'Ping'} %} +{% if user_status == 0 or user_plan == 'user' %} + {% include 'include/no_sub.html' %} +{% else %} + + + + +
+{% set service_status = [] %} +{% for s in smon %} + {% set service_status = service_status.append(s.smon_id.en) %} + {% if check_id == 2 %} + + {% elif check_id == 1 %} +
{{s.ip}}:{{s.port}}
+ {% else %} +
{{s.smon_id.name}}
+ {% endif %} +{% endfor %} +
+
+
+ {% for s in smon_statuses|reverse %} + {% if s.status %} + {% set add_class = 'serverUp' %} + {% else %} + {% set add_class = 'serverDown' %} + {% endif %} +
+ {% endfor %} +
{{lang.words.checking|title()}} {{lang.words.every}} {{check_interval}} {{lang.words.minutes2}}
+
+
+ {% if service_status.0 %} + {% if cur_status %} + {% set add_class = 'serverUp' %} + {% set status = lang.smon_page.desc.UP %} + {% else %} + {% set add_class = 'serverDown' %} + {% set status = lang.smon_page.desc.DOWN %} + {% endif %} + {% else %} + {% set add_class = 'serverNone' %} + {% set status = lang.smon_page.desc.DISABLED %} + {% endif %} + {{status}} +
+
+
+ {% for s in smon %} +
+

{{lang.words.checking|title()}}

+

({{lang.words.type|title()}})

+ {{checking_types[check_id|string()]}} +
+
+

{{lang.words.response|title()}}

+

({{lang.words.current|title()}})

+ {{last_resp_time}}ms +
+
+

{{lang.words.average2|title()}} {{lang.words.response}}

+

(24-{{lang.words.hours}})

+ {{avg_res_time}}ms +
+
+

{{lang.words.uptime}}

+

(24-{{lang.words.hours}})

+ {{uptime}}% +
+
+

{{lang.words.cert_expire}}

+ {% if s.smon_id.ssl_expire_date is not none %} + {% set ssl_date = s.smon_id.ssl_expire_date.split()[0] %} + {% else %} + {% set ssl_date = 'N/A' %} + {% endif %} +

({{ssl_date}})

+ {{cert_day_diff}} {{lang.words.days}} +
+ {% endfor %} +
+
+ +
+{% endif %} + +{% endblock %} diff --git a/app/templates/include/smon_http_server.html b/app/templates/include/smon_http_server.html new file mode 100644 index 00000000..74bd3b34 --- /dev/null +++ b/app/templates/include/smon_http_server.html @@ -0,0 +1,95 @@ + + {% set id = 'smon-name-' + s.id|string() %} + {{ input(id, value=s.name.strip("'"), size='20') }} + + + {% set id = 'smon-url-' + s.id|string() %} + {{ input(id, value=s_service.url, size='20') }} + + + {% set id = 'smon-enable-' + s.id|string() %} + {% if s.en == 1 %} + {{ checkbox(id, checked='checked') }} + {% else %} + {{ checkbox(id) }} + {% endif %} + + + {% set id = 'smon-body-' + s.id|string() %} + {{ input(id, value=s_service.body, size='20') }} + + + + + + + + + + + + {% set id = 'smon-group-' + s.id|string() %} + {% if s.group is not none %} + {{ input(id, value=s.group, size='15') }} + {% else %} + {{ input(id, size='15') }} + {% endif %} + + + {% set id = 'smon-desc-' + s.id|string() %} + {% if s.desc is not none %} + {{ input(id, value=s.desc.strip("'"), size='20') }} + {% else %} + {{ input(id, size='20') }} + {% endif %} + + + + + + + + + diff --git a/app/templates/include/smon_ping_server.html b/app/templates/include/smon_ping_server.html new file mode 100644 index 00000000..a67801c4 --- /dev/null +++ b/app/templates/include/smon_ping_server.html @@ -0,0 +1,88 @@ + + {% set id = 'smon-name-' + s.id|string() %} + {{ input(id, value=s.name, size='20') }} + + + {% set id = 'smon-ip-' + s.id|string() %} + {{ input(id, value=s_service.ip, size='20') }} + + + {% set id = 'smon-enable-' + s.id|string() %} + {% if s.en == 1 %} + {{ checkbox(id, checked='checked') }} + {% else %} + {{ checkbox(id) }} + {% endif %} + + + + + + + + + + + + {% set id = 'smon-group-' + s.id|string() %} + {% if s.group is not none %} + {{ input(id, value=s_service.group, size='15') }} + {% else %} + {{ input(id, size='15') }} + {% endif %} + + + {% set id = 'smon-desc-' + s.id|string() %} + {% if s.desc is not none %} + {{ input(id, value=s.desc.strip("'"), size='20') }} + {% else %} + {{ input(id, size='20') }} + {% endif %} + + + + + + + + + diff --git a/app/templates/include/smon_server.html b/app/templates/include/smon_server.html deleted file mode 100644 index 71be6b44..00000000 --- a/app/templates/include/smon_server.html +++ /dev/null @@ -1,114 +0,0 @@ -{% from 'include/input_macros.html' import input, checkbox %} - - {% set id = 'smon-ip-' + s.0|string() %} - {{ input(id, value=s.1, size='20') }} - - - {% set id = 'smon-port-' + s.0|string() %} - {{ input(id, value=s.2, size='5') }} - - - {% set id = 'smon-enable-' + s.0|string() %} - {% if s.3 == 1 %} - {{ checkbox(id, checked='checked') }} - {% else %} - {{ checkbox(id) }} - {% endif %} - - - {{ s.4.split(':')[0] }} - {# {% if s.4|length > 0 %} - {% set values = dict() %} - {% set id = 'smon-proto-' + s.0|string() %} - {% set values = {'':'', 'http':'http','https':'https'} %} - {{ select(id, values=values, selected=s.4.split(':')[0]) }} - {% endif %} #} - - - {% if s.4|length > 0 %} - {{ s.4.split(':')[1] }} - {% endif %} - - - {% set id = 'smon-body-' + s.0|string() %} - {% if s.5 is not none %} - {{s.5}} - {% else %} - - {% endif %} - - - - - - - - - - - - {% set id = 'smon-group-' + s.0|string() %} - {% if s.8 is not none %} - {{ input(id, value=s.8, size='15') }} - {% else %} - {{ input(id, size='15') }} - {% endif %} - - - {% set id = 'smon-desc-' + s.0|string() %} - {% if s.7 is not none %} - {{ input(id, value=s.7, size='20') }} - {% else %} - {{ input(id, size='20') }} - {% endif %} - - - - - - - - - diff --git a/app/templates/include/smon_tcp_server.html b/app/templates/include/smon_tcp_server.html new file mode 100644 index 00000000..89c54b32 --- /dev/null +++ b/app/templates/include/smon_tcp_server.html @@ -0,0 +1,95 @@ + + {% set id = 'smon-name-' + s.id|string() %} + {{ input(id, value=s.name.strip("'"), size='20') }} + + + {% set id = 'smon-ip-' + s.id|string() %} + {{ input(id, value=s_service.ip, size='20') }} + + + {% set id = 'smon-port-' + s.id|string() %} + {{ input(id, value=s_service.port, size='5') }} + + + {% set id = 'smon-enable-' + s.id|string() %} + {% if s.en == 1 %} + {{ checkbox(id, checked='checked') }} + {% else %} + {{ checkbox(id) }} + {% endif %} + + + + + + + + + + + + {% set id = 'smon-group-' + s.id|string() %} + {% if s.group is not none %} + {{ input(id, value=s.group, size='15') }} + {% else %} + {{ input(id, size='15') }} + {% endif %} + + + {% set id = 'smon-desc-' + s.id|string() %} + {% if s.desc is not none %} + {{ input(id, value=s.desc.strip("'"), size='20') }} + {% else %} + {{ input(id, size='20') }} + {% endif %} + + + + + + + + + diff --git a/app/templates/languages/en.html b/app/templates/languages/en.html index 8aa4cc7c..6bdebbfa 100644 --- a/app/templates/languages/en.html +++ b/app/templates/languages/en.html @@ -671,6 +671,7 @@ "minute": "minute", "minute2": "minute", "minutes": "minutes", + "minutes2": "minutes", "hour": "hour", "hours": "hours", "hours2": "hours", @@ -867,5 +868,10 @@ "value": "value", "if": "if", "then": "then", + "response": "response", + "average": "average", + "average2": "average", + "cert_expire": "Cert Expire", + "Hostname": "Hostname", } %} diff --git a/app/templates/languages/fr.html b/app/templates/languages/fr.html index 806a7a83..ab19c52c 100644 --- a/app/templates/languages/fr.html +++ b/app/templates/languages/fr.html @@ -671,6 +671,7 @@ "minute": "minute", "minute2": "minute", "minutes": "minutes", + "minutes2": "minutes", "hour": "heure", "hours": "heures", "hours2": "heures", @@ -867,5 +868,10 @@ "value": "valeur", "if": "si", "then": "alors", + "response": "réponse", + "average": "moyenne", + "average2": "moyenne", + "cert_expire": "Expiration du certificat", + "Hostname": "Nome de anfitrião", } %} diff --git a/app/templates/languages/pt-br.html b/app/templates/languages/pt-br.html index e9418bd2..b8d671e0 100644 --- a/app/templates/languages/pt-br.html +++ b/app/templates/languages/pt-br.html @@ -671,6 +671,7 @@ "minute": "minuto", "minute2": "minuto", "minutes": "minutos", + "minutes2": "minutos", "hour": "hora", "hours": "horas", "hours2": "horas", @@ -867,5 +868,10 @@ "value": "valor", "if": "se", "then": "então", + "response": "resposta", + "average": "média", + "average2": "médio", + "cert_expire": "Expiração do certificado", + "Hostname": "Nom d'hôte", } %} diff --git a/app/templates/languages/ru.html b/app/templates/languages/ru.html index 0151a2a0..2041911b 100644 --- a/app/templates/languages/ru.html +++ b/app/templates/languages/ru.html @@ -671,6 +671,7 @@ "minute": "минута", "minute2": "минуту", "minutes": "минут", + "minutes2": "минуты", "hour": "час", "hours": "часа", "hours2": "часов", @@ -867,5 +868,10 @@ "value": "значение", "if": "если", "then": "тогда", + "response": "отклик", + "average": "среднее", + "average2": "средний", + "cert_expire": "Срок действия сертификата", + "Hostname": "Имя хоста", } %} diff --git a/app/templates/smon.html b/app/templates/smon.html index f350c271..d97bb73f 100644 --- a/app/templates/smon.html +++ b/app/templates/smon.html @@ -3,7 +3,7 @@ {% block h2 %}{{ title }}{% endblock %} {% block content %} {% from 'include/input_macros.html' import input, checkbox, select %} - + @@ -53,15 +53,13 @@
{% else %} {% if action == 'add' %} - +
- + - - + + - - @@ -73,14 +71,80 @@ - {{env}} {% for s in smon %} - - {% include 'include/smon_server.html' %} + {% if s.check_type == 'http' %} + {% for s_service in smon_http %} + {% if s_service.smon_id|string() == s.id|string() %} + + {% include 'include/smon_http_server.html' %} + {% endif %} + {% endfor %} + {% endif %} {% endfor %}

TCP/UDP check

HTTP {{lang.words.checking}}

Hostname{{lang.words.port|title()}}{{lang.words.name|title()}}URL {{lang.words.enabled|title()}}{{lang.words.protocol|title()}}URI {{lang.words.body|title()}} Telegram Slack
-
+ {{lang.words.add|title()}} +
+ {{lang.words.add|title()}} +

+ + + + + + + + + + + + + + + + + + + {% for s_service in smon_tcp %} + {% for s in smon %} + {% if s.id|string() == s_service.smon_id|string() %} + + {% include 'include/smon_tcp_server.html' %} + {% endif %} + {% endfor %} + {% endfor %} + +

TCP/UDP {{lang.words.checking}}

{{lang.words.name|title()}}{{lang.words.Hostname}}{{lang.words.port|title()}}{{lang.words.enabled|title()}}TelegramSlackPagerDuty{{lang.words.group|title()}}{{lang.words.desc|title()}}
+
+ {{lang.words.add|title()}} +

+ + + + + + + + + + + + + + + + + + {% for s in smon %} + {% if s.check_type == 'ping' %} + {% for s_service in smon_ping %} + {% if s_service.smon_id|string() == s.id|string() %} + + {% include 'include/smon_ping_server.html' %} + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + +

Ping {{lang.words.checking}}

{{lang.words.name|title()}}{{lang.words.Hostname}}{{lang.words.enabled|title()}}TelegramSlackPagerDuty{{lang.words.group|title()}}{{lang.words.desc|title()}}
+
+ {{lang.words.add|title()}}

@@ -91,14 +155,33 @@ {% include 'include/tr_validate_tips.html' %} - IP + {{lang.words.name|title()}} + * + + + {{ input('new-smon-name') }} + + + + + {{lang.words.checking|title()}} + * + + + {% set check_types = {'ping': 'Ping', 'tcp': 'TCP/UDP', 'http': 'HTTP(s)'} %} + {{ select('check_type', values=check_types, selected='http') }} + + + + + {{lang.words.Hostname}} * {{ input('new-smon-ip') }} - + {{lang.words.port|title()}} * @@ -113,19 +196,11 @@ {{ checkbox('new-smon-enable', checked='checked') }} - - {{lang.words.protocol|title()}} - - {% set values = dict() %} - {% set values = {'':'', 'http':'http','https':'https'} %} - {{ select('new-smon-proto', values=values, selected='') }} - + + URL + {{ input('new-smon-url', value='https://', title='proto://url[:port]/') }} - - URI - {{ input('new-smon-uri') }} - - + {{lang.words.body|title()}} {{ input('new-smon-body') }} diff --git a/inc/css/smon.css b/inc/css/smon.css new file mode 100644 index 00000000..c7dbc2d2 --- /dev/null +++ b/inc/css/smon.css @@ -0,0 +1,72 @@ +h4 { + font-size: 1.5rem; + font-weight: 500; + line-height: 1.2; +} +.wrap { + margin-left: var(--indent); + margin-top: 20px; + margin-bottom: 20px; + padding-bottom: 10px; + padding-top: 10px; +} +.wrap1 { + margin-left: var(--indent); +} +.statuses { + border-bottom: 1px solid #ddd; + border-top: 1px solid #ddd; +} +.smon_server_statuses { + width: 5px; + height: 25px; + margin: 4px; + display: inline-block; + border-radius: 50rem; + transition: all .2s ease-in-out; +} +.smon_server_statuses:hover { + transform: scale(1.5); +} +*:before, *:after { + box-sizing: border-box; +} +#smon_name { + font-size: 25px; +} +#check_interval { + color: #aaa; + font-size: 14px; + padding-top: 10px; +} +.col-md-8 { + flex: 0 0 auto; + width: 76%; + margin-top: 5px; +} +.col-md-4 { + flex: 0 0 auto; + width: 23%; + margin-top: 10px; +} +.row { + --bs-gutter-x: 1.5rem; + --bs-gutter-y: 0; + display: flex; + flex-wrap: wrap; +} +.cur_status { + font-size: 30px; + border-radius: 50rem !important; + min-width: 92px; + font-weight: 700; + padding: 0.35em 0.65em; +} +.col { + flex: 1 0 0%; + text-align: center !important; +} +.smon_stats { + font-size: 13px; + color: #aaa; +} diff --git a/inc/metrics.js b/inc/metrics.js index 573fc5c9..46ece03c 100644 --- a/inc/metrics.js +++ b/inc/metrics.js @@ -322,15 +322,10 @@ function getApacheChartData(server) { }); } function loadMetrics() { - var service = findGetParameter('service'); - if (!service) { - service = 'haproxy'; - } $.ajax({ url: "options.py", data: { table_metrics: '1', - service: service, token: $('#token').val() }, beforeSend: function() { @@ -558,3 +553,74 @@ function updatingCpuRamCharts() { getWafChartData(server_ip); } } +function getSmonHistoryCheckData(server, check_id) { + $.ajax({ + url: "options.py", + data: { + smon_history_check: '1', + check_id: check_id, + server_id: server, + // time_range: $( "#time-range option:selected" ).val(), + token: $('#token').val() + }, + type: "POST", + success: function (result) { + var data = []; + data.push(result.chartData.curr_con); + var labels = result.chartData.labels; + renderSMONChart(data, labels, '3'); + } + }); +} +function renderSMONChart(data, labels, server) { + var resp_time_word = $('#translate').attr('data-resp_time'); + var ctx = 'metrics_' + server; + var myChart = new Chart(ctx, { + type: 'line', + data: { + labels: labels.split(','), + datasets: [ + { + parsing: false, + normalized: true, + label: resp_time_word+' (ms)', + data: data[0].split(','), + borderColor: 'rgba(92, 184, 92, 1)', + backgroundColor: 'rgba(92, 184, 92, 0.2)', + } + ] + }, + options: { + animation: false, + maintainAspectRatio: false, + scales: { + yAxes: [{ + ticks: { + beginAtZero: true, + } + }], + xAxes: [{ + ticks: { + major: { + enabled: true, + fontStyle: 'bold' + }, + source: 'data', + autoSkip: true, + autoSkipPadding: 45, + maxRotation: 0 + } + }] + }, + legend: { + display: true, + labels: { + fontColor: 'rgb(255, 99, 132)', + defaultFontSize: '10', + defaultFontFamily: 'BlinkMacSystemFont' + }, + } + } + }); + charts.push(myChart); +} \ No newline at end of file diff --git a/inc/script-6.3.9.js b/inc/script-6.3.9.js index 9c170ed0..1ebe8989 100644 --- a/inc/script-6.3.9.js +++ b/inc/script-6.3.9.js @@ -80,6 +80,8 @@ $( function() { show_current_page($(this)) } else if(cur_url[0] == 'smon.py' && cur_url[1].split('&')[0] == 'action=checker_history' && link2 == 'smon.py?action=checker_history'){ show_current_page($(this)) + } else if(cur_url[0] == 'smon.py' && cur_url[1].split('&')[0] == 'action=dashboard' && link2.indexOf('smon.py?action=view') != '-1'){ + show_current_page($(this)) } else if(cur_url[0] == 'add.py' && cur_url[1].split('&')[0] == 'service=nginx#ssl' && link2 == 'add.py?service=nginx#ssl'){ show_current_page($(this)) } else if(cur_url[0] == 'viewlogs.py' && cur_url[1].split('&')[0] == 'type=2' && link2 == 'viewlogs.py?type=2') { diff --git a/inc/smon.js b/inc/smon-6.3.13.js similarity index 56% rename from inc/smon.js rename to inc/smon-6.3.13.js index 73155e6d..e35a9489 100644 --- a/inc/smon.js +++ b/inc/smon-6.3.13.js @@ -48,28 +48,25 @@ function showSmon(action) { } function addNewSmonServer(dialog_id) { var valid = true; - allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') ) - allFields.removeClass( "ui-state-error" ); - valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 ); - valid = valid && checkLength( $('#new-smon-port'), "Port", 1 ); - if ($('#new-smon-proto').val() != '' || $('#new-smon-uri').val() != '') { - allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') ) - .add( $('#new-smon-proto') ).add( $('#new-smon-uri') ); - allFields.removeClass( "ui-state-error" ); - valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 ); - valid = valid && checkLength( $('#new-smon-port'), "Port", 1 ); - valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 ); - valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 ); + var check_type = $('#check_type').val(); + if (check_type == 'tcp') { + allFields = $([]).add($('#new-smon-ip')).add($('#new-smon-port')).add($('#new-smon-hostname')).add($('#new-smon-name')) + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#new-smon-ip'), "Hostname", 1); + valid = valid && checkLength($('#new-smon-name'), "Name", 1); + valid = valid && checkLength($('#new-smon-port'), "Port", 1); } - if( $('#new-smon-body').val() != '') { - allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') ) - .add( $('#new-smon-proto') ).add( $('#new-smon-uri') ); - allFields.removeClass( "ui-state-error" ); - valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 ); - valid = valid && checkLength( $('#new-smon-port'), "Port", 1 ); - valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 ); - valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 ); - valid = valid && checkLength( $('#new-smon-body'), "Body", 1 ); + if (check_type == 'http') { + allFields = $([]).add($('#new-smon-url')).add($('#new-smon-name')) + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#new-smon-name'), "Name", 1); + valid = valid && checkLength($('#new-smon-url'), "URL", 1); + } + if (check_type == 'ping') { + allFields = $([]).add($('#new-smon-ip')).add($('#new-smon-name')) + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#new-smon-name'), "Name", 1); + valid = valid && checkLength($('#new-smon-ip'), "Hostname", 1); } var enable = 0; if ($('#new-smon-enable').is(':checked')) { @@ -79,17 +76,18 @@ function addNewSmonServer(dialog_id) { $.ajax( { url: "options.py", data: { + newsmonname: $('#new-smon-name').val(), newsmon: $('#new-smon-ip').val(), newsmonport: $('#new-smon-port').val(), newsmonenable: enable, - newsmonproto: $('#new-smon-proto').val(), - newsmonuri: $('#new-smon-uri').val(), + newsmonurl: $('#new-smon-url').val(), newsmonbody: $('#new-smon-body').val(), newsmongroup: $('#new-smon-group').val(), newsmondescription: $('#new-smon-description').val(), newsmontelegram: $('#new-smon-telegram').val(), newsmonslack: $('#new-smon-slack').val(), newsmonpd: $('#new-smon-pd').val(), + newsmonchecktype: check_type, token: $('#token').val() }, type: "POST", @@ -98,7 +96,15 @@ function addNewSmonServer(dialog_id) { if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') { toastr.error(data); } else { - common_ajax_action_after_success(dialog_id, 'newserver', 'ajax-smon', data); + if (check_type == 'ping') { + table_id = 'ajax-smon-ping'; + } else if (check_type == 'tcp') { + table_id = 'ajax-smon-tcp'; + } + else { + table_id = 'ajax-smon-http'; + } + common_ajax_action_after_success(dialog_id, 'newserver', table_id, data); $( "input[type=submit], button" ).button(); $( "input[type=checkbox]" ).checkboxradio(); $( "select" ).selectmenu(); @@ -108,7 +114,7 @@ function addNewSmonServer(dialog_id) { } ); } } -function confirmDeleteSmon(id) { +function confirmDeleteSmon(id, check_type) { var delete_word = $('#translate').attr('data-delete'); var cancel_word = $('#translate').attr('data-cancel'); $( "#dialog-confirm" ).dialog({ @@ -121,7 +127,7 @@ function confirmDeleteSmon(id) { text: delete_word, click: function () { $(this).dialog("close"); - removeSmon(id); + removeSmon(id, check_type); } }, { text: cancel_word, @@ -131,7 +137,7 @@ function confirmDeleteSmon(id) { }] }); } -function removeSmon(id) { +function removeSmon(id, check_type) { $("#smon-"+id).css("background-color", "#f2dede"); $.ajax( { url: "options.py", @@ -143,7 +149,7 @@ function removeSmon(id) { success: function( data ) { data = data.replace(/\s+/g,' '); if(data == "Ok ") { - $("#smon-"+id).remove(); + $("#smon-"+check_type+"-"+id).remove(); } else { toastr.error(data); } @@ -151,7 +157,7 @@ function removeSmon(id) { } ); } -function updateSmon(id) { +function updateSmon(id, check_type) { toastr.clear(); var enable = 0; if ($('#smon-enable-'+id).is(':checked')) { @@ -160,16 +166,18 @@ function updateSmon(id) { $.ajax( { url: "options.py", data: { + updateSmonName: $('#smon-name-'+id).val(), updateSmonIp: $('#smon-ip-'+id).val(), updateSmonPort: $('#smon-port-'+id).val(), + updateSmonUrl: $('#smon-url-'+id).val(), updateSmonEn: enable, - updateSmonHttp: $('#smon-proto1-'+id).text(), - updateSmonBody: $('#smon-body-'+id).text(), + updateSmonBody: $('#smon-body-'+id).val(), updateSmonTelegram: $('#smon-telegram-'+id).val(), updateSmonSlack: $('#smon-slack-'+id).val(), updateSmonPD: $('#smon-pd-'+id).val(), updateSmonGroup: $('#smon-group-'+id).val(), updateSmonDesc: $('#smon-desc-'+id).val(), + check_type: check_type, id: id, token: $('#token').val() }, @@ -180,24 +188,27 @@ function updateSmon(id) { toastr.error(data); } else { toastr.clear(); - $("#smon-"+id).addClass( "update", 1000 ); + $("#smon-"+check_type+"-"+id).addClass( "update", 1000 ); setTimeout(function() { - $( "#smon-"+id ).removeClass( "update" ); + $("#smon-"+check_type+"-"+id).removeClass( "update" ); }, 2500 ); } } } ); } -function cloneSmom(id) { - $( "#add-smon-button" ).trigger( "click" ); +function cloneSmom(id, check_type) { + check_and_clear_check_type(check_type); + $( "#add-smon-button-"+check_type ).trigger( "click" ); if ($('#smon-enable-'+id).is(':checked')) { $('#new-smon-enable').prop('checked', true) } else { $('#new-smon-enable').prop('checked', false) } $('#new-smon-enable').checkboxradio("refresh"); + $('#new-smon-name').val($('#smon-name-'+id).val()); $('#new-smon-ip').val($('#smon-ip-'+id).val()); $('#new-smon-port').val($('#smon-port-'+id).val()); + $('#new-smon-url').val($('#smon-url-'+id).val()); $('#new-smon-group').val($('#smon-group-'+id).val()); $('#new-smon-description').val($('#smon-desc-'+id).val()) $('#new-smon-telegram').val($('#smon-telegram-'+id+' option:selected').val()).change() @@ -208,16 +219,44 @@ function cloneSmom(id) { $('#new-smon-pd').selectmenu("refresh"); } $( function() { - $('#add-smon-button').click(function() { + $('#add-smon-button-http').click(function() { addSmonServer.dialog('open'); + check_and_clear_check_type('http'); }); - $( "#ajax-smon input" ).change(function() { - var id = $(this).attr('id').split('-'); - updateSmon(id[2]) + $('#add-smon-button-tcp').click(function() { + addSmonServer.dialog('open'); + check_and_clear_check_type('tcp'); }); - $( "#ajax-smon select" ).on('selectmenuchange',function() { + $('#add-smon-button-ping').click(function() { + addSmonServer.dialog('open'); + check_and_clear_check_type('ping'); + }); + $( "#ajax-smon-http input" ).change(function() { var id = $(this).attr('id').split('-'); - updateSmon(id[2]) + updateSmon(id[2], 'http'); + }); + $( "#ajax-smon-http select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateSmon(id[2], 'http'); + }); + $( "#ajax-smon-tcp input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateSmon(id[2], 'tcp'); + }); + $( "#ajax-smon-tcp select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateSmon(id[2], 'tcp'); + }); + $( "#ajax-smon-ping input" ).change(function() { + var id = $(this).attr('id').split('-'); + updateSmon(id[2], 'ping'); + }); + $( "#ajax-smon-ping select" ).on('selectmenuchange',function() { + var id = $(this).attr('id').split('-'); + updateSmon(id[2], 'ping'); + }); + $( "#check_type" ).on('selectmenuchange',function() { + check_and_clear_check_type($('#check_type').val()); }); var add_word = $('#translate').attr('data-add'); var cancel_word = $('#translate').attr('data-cancel'); @@ -251,3 +290,37 @@ $( function() { }] }); }); +function check_and_clear_check_type(check_type) { + if (check_type == 'http') { + $('.smon_http_check').show(); + $('.smon_tcp_check').hide(); + $('.new_smon_hostname').hide(); + $("#check_type").val('http'); + $('#check_type').selectmenu("refresh"); + $('.smon_http_check').show(); + $('.smon_tcp_check').hide(); + $('#new-smon-port').val(''); + $('#new_smon_hostname').val(''); + } else if (check_type == 'tcp') { + $('.smon_http_check').hide(); + $('.smon_tcp_check').show(); + $("#check_type").val('tcp'); + $('#check_type').selectmenu("refresh"); + $('.smon_tcp_check').show(); + $('.new_smon_hostname').show(); + $('.smon_http_check').hide(); + $('#new-smon-url').val(''); + $('#new-smon-body').val(''); + } else { + $('.smon_http_check').hide(); + $('.new_smon_hostname').show(); + $('.smon_tcp_check').hide(); + $("#check_type").val('ping'); + $('#check_type').selectmenu("refresh"); + $('.smon_tcp_check').hide(); + $('.smon_http_check').hide(); + $('#new-smon-url').val(''); + $('#new-smon-body').val(''); + $('#new-smon-port').val(''); + } +}