From 69ad8101bcc1a1396a64f1e02698a9d2bc5b2482 Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Wed, 3 Nov 2021 02:57:54 +0600 Subject: [PATCH] v5.3.2.0 Changelog: https://haproxy-wi.org/changelog.py#5_3_2 --- README.md | 5 ++-- app/create_db.py | 45 +++++++++++++++++++++++++++++++++-- app/db_model.py | 1 + app/funct.py | 12 ++++++++-- app/options.py | 42 +++++++++++++++++++++++++------- app/sql.py | 25 +++++++++++++++---- app/templates/hapservers.html | 8 ++++++- app/templates/nettools.html | 37 +++++++++++++++------------- 8 files changed, 139 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 0de61f16..4412ace7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ Web interface(user-friendly web GUI, alerting, monitoring and secure) for managi ![alt text](https://roxy-wi.org/inc/images/viewstat.png "HAProxy state page") # Features: -1. Installation and updating HAProxy, Nginx and Keepalived with Roxy-WI +1. Installation and updating HAProxy, Nginx and Keepalived with Roxy-WI as system service +1. Installation and updating HAProxy and Nginx with Roxy-WI as Docker service 2. Installation and updating Grafana, Prometheus servers with Roxy-WI 3. Installation and updating HAProxy and Nginx exporters with Roxy-WI 4. Server provisioning on AWS, DigitalOcean and G-Core Labs @@ -125,4 +126,4 @@ and check executeble py files If you see plain text, check section "Directory" in httpd conf -[Read more] (https://roxy-wi.org/troubleshooting.py) +[Read more](https://roxy-wi.org/troubleshooting.py) diff --git a/app/create_db.py b/app/create_db.py index c2259296..21a029f8 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -805,7 +805,6 @@ def update_db_v_5_3_0(**kwargs): print("An error occurred:", e) - def update_db_v_5_3_1(**kwargs): cursor = conn.cursor() sql = """ @@ -823,8 +822,46 @@ def update_db_v_5_3_1(**kwargs): print("Updating... DB has been updated to version 5.3.1") + +def update_db_v_5_3_2(**kwargs): + try: + Setting.insert(param='checker_maxconn_threshold', value=90, section='monitoring', + desc='Threshold value for alerting, in %').execute() + except Exception as e: + if kwargs.get('silent') != 1: + if ( + str(e) == 'columns param, group are not unique' or + str(e) == '(1062, "Duplicate entry \'checker_maxconn_threshold-1\' for key \'param\'")' or + str(e) == 'UNIQUE constraint failed: settings.param, settings.group' + ): + pass + else: + print("An error occurred:", e) + else: + if kwargs.get('silent') != 1: + print('Updating... DB has been updated to version 5.3.2') + + + +def update_db_v_5_3_2_2(**kwargs): + cursor = conn.cursor() + sql = """ + ALTER TABLE `servers` ADD COLUMN keepalived_alert INTEGER NOT NULL DEFAULT 0; + """ + try: + cursor.execute(sql) + except Exception as e: + if kwargs.get('silent') != 1: + if e.args[0] == 'duplicate column name: keepalived_alert' or str(e) == '(1060, "Duplicate column name \'keepalived_alert\'")': + print('Updating... DB has been updated to version 5.3.2') + else: + print("An error occurred:", e) + else: + print("Updating... DB has been updated to version 5.3.2") + + def update_ver(): - query = Version.update(version='5.3.1.0') + query = Version.update(version='5.3.2.0') try: query.execute() except: @@ -858,6 +895,8 @@ def update_all(): update_db_v_5_2_6() update_db_v_5_3_0() update_db_v_5_3_1() + update_db_v_5_3_2() + update_db_v_5_3_2_2() update_ver() @@ -888,6 +927,8 @@ def update_all_silent(): update_db_v_5_2_6(silent=1) update_db_v_5_3_0(silent=1) update_db_v_5_3_1(silent=1) + update_db_v_5_3_2(silent=1) + update_db_v_5_3_2_2(silent=1) update_ver() diff --git a/app/db_model.py b/app/db_model.py index 7b9b5832..c3230247 100644 --- a/app/db_model.py +++ b/app/db_model.py @@ -62,6 +62,7 @@ class Server(BaseModel): protected = IntegerField(constraints=[SQL('DEFAULT 0')]) nginx_metrics = IntegerField(constraints=[SQL('DEFAULT 0')]) keepalived_active = IntegerField(constraints=[SQL('DEFAULT 0')]) + keepalived_alert = IntegerField(constraints=[SQL('DEFAULT 0')]) class Meta: table_name = 'servers' diff --git a/app/funct.py b/app/funct.py index fe7cd6cb..1102b238 100644 --- a/app/funct.py +++ b/app/funct.py @@ -119,6 +119,8 @@ def logging(server_ip, action, **kwargs): import http.cookies import distro + login = '' + log_path = get_config_var('main', 'log_path') try: user_group = get_user_group() @@ -817,15 +819,21 @@ def install_nginx(server_ip, **kwargs): def update_haproxy_wi(service): import distro + restart_service = '' if distro.id() == 'ubuntu': try: if service == 'roxy-wi-keep_alive': service = 'roxy-wi-keep-alive' except Exception: pass - cmd = 'sudo -S apt-get update && sudo apt-get install ' + service +' && sudo systemctl restart ' + service + + if service == 'roxy-wi': + restart_service = ' && sudo systemctl restart ' + service + + cmd = 'sudo -S apt-get update && sudo apt-get install ' + service + restart_service else: - cmd = 'sudo -S yum -y update ' + service +' && sudo systemctl restart ' + service + cmd = 'sudo -S yum -y update ' + service + restart_service + output, stderr = subprocess_execute(cmd) print(output) print(stderr) diff --git a/app/options.py b/app/options.py index 71948176..9c963c4f 100644 --- a/app/options.py +++ b/app/options.py @@ -2051,7 +2051,7 @@ if form.getvalue('updatehapwiserver') is not None: service = form.getvalue('service_name') sql.update_hapwi_server(hapwi_id, alert, metrics, active, service) server_ip = sql.select_server_ip_by_id(hapwi_id) - funct.logging(server_ip, 'the server ' + name, ' has been updated ', haproxywi=1, login=1, keep_history=1, service=service) + funct.logging(server_ip, 'The server ' + name + ' has been updated ', haproxywi=1, login=1, keep_history=1, service=service) if form.getvalue('updateserver') is not None: name = form.getvalue('updateserver') @@ -2780,9 +2780,14 @@ if form.getvalue('geoip_install'): if form.getvalue('nettools_icmp_server_from'): server_from = form.getvalue('nettools_icmp_server_from') server_to = form.getvalue('nettools_icmp_server_to') + server_to = funct.is_ip_or_dns(server_to) action = form.getvalue('nettools_action') stderr = '' + if server_to == '': + print('warning: enter a correct IP or DNS name') + sys.exit() + if action == 'nettools_ping': action_for_sending = 'ping -c 4 -W 1 -s 56 -O ' elif action == 'nettools_trace': @@ -2800,17 +2805,31 @@ if form.getvalue('nettools_icmp_server_from'): print('error: '+stderr) sys.exit() for i in output: - if i == ' ': + if i == ' ' or i == '': continue i = i.strip() - print(i + '
') + if 'PING' in i: + print('') + elif 'no reply' in i or 'no answer yet' in i or 'Too many hops' in i or '100% packet loss' in i: + print('') + elif 'ms' in i and '100% packet loss' not in i: + print('') + else: + print('') + + print(i + '
') if form.getvalue('nettools_telnet_server_from'): server_from = form.getvalue('nettools_telnet_server_from') server_to = form.getvalue('nettools_telnet_server_to') + server_to = funct.is_ip_or_dns(server_to) port_to = form.getvalue('nettools_telnet_port_to') stderr = '' + if server_to == '': + print('warning: enter a correct IP or DNS name') + sys.exit() + if server_from == 'localhost': action_for_sending = 'echo "exit"|nc ' + server_to + ' ' + port_to + ' -t -w 1s' output, stderr = funct.subprocess_execute(action_for_sending) @@ -2819,7 +2838,7 @@ if form.getvalue('nettools_telnet_server_from'): output = funct.ssh_command(server_from, action_for_sending, raw=1) if stderr != '': - print('error: '+stderr[5:-1]) + print('error: ' + stderr[5:] + '') sys.exit() count_string = 0 for i in output: @@ -2827,7 +2846,7 @@ if form.getvalue('nettools_telnet_server_from'): continue i = i.strip() if i == 'Ncat: Connection timed out.': - print('error: ' + i[5:-1]) + print('error: ' + i[5:] + '') break print(i + '
') count_string += 1 @@ -2837,9 +2856,14 @@ if form.getvalue('nettools_telnet_server_from'): if form.getvalue('nettools_nslookup_server_from'): server_from = form.getvalue('nettools_nslookup_server_from') dns_name = form.getvalue('nettools_nslookup_name') + dns_name = funct.is_ip_or_dns(dns_name) record_type = form.getvalue('nettools_nslookup_record_type') stderr = '' + if dns_name == '': + print('warning: enter a correct DNS name') + sys.exit() + action_for_sending = 'dig ' + dns_name + ' ' + record_type + ' |grep -e "SERVER\|' + dns_name + '"' if server_from == 'localhost': @@ -2852,7 +2876,7 @@ if form.getvalue('nettools_nslookup_server_from'): print('error: '+stderr[5:-1]) sys.exit() count_string = 0 - print('There are the next records for ' + dns_name + ' domain:
') + print('The ' + dns_name + ' domain has the following records:') for i in output: if 'dig: command not found.' in i: print('error: Install bind-utils before using NSLookup') @@ -2860,13 +2884,13 @@ if form.getvalue('nettools_nslookup_server_from'): if ';' in i and ';; SERVER:' not in i: continue if 'SOA' in i and record_type != 'SOA': - print('There are not any records for this type') + print('There are not any records for this type') break if ';; SERVER:' in i: - i = i[10:-1] + i = i[10:] print('
From NS server:
') i = i.strip() - print(i + '
') + print('' + i + '
') count_string += 1 if form.getvalue('portscanner_history_server_id'): diff --git a/app/sql.py b/app/sql.py index a954178f..857ff87b 100644 --- a/app/sql.py +++ b/app/sql.py @@ -259,10 +259,10 @@ def update_hapwi_server(server_id, alert, metrics, active, service_name): try: if service_name == 'nginx': update_hapwi = Server.update(nginx_alert=alert, metrics=metrics, nginx_active=active, - nginx_metrics=metrics).where( - Server.server_id == server_id) + nginx_metrics=metrics).where(Server.server_id == server_id) elif service_name == 'keepalived': - update_hapwi = Server.update(keepalived_active=active).where(Server.server_id == server_id) + update_hapwi = Server.update(keepalived_alert=alert, keepalived_active=active).where( + Server.server_id == server_id) else: update_hapwi = Server.update(alert=alert, metrics=metrics, active=active).where( Server.server_id == server_id) @@ -1766,7 +1766,7 @@ def get_setting(param, **kwargs): param == 'syslog_server_enable' or param == 'smon_check_interval' or param == 'checker_check_interval' or param == 'port_scan_interval' or param == 'smon_keep_history_range' or param == 'checker_keep_history_range' or - param == 'portscanner_keep_history_range' + param == 'portscanner_keep_history_range' or param == 'checker_maxconn_threshold' ): return int(setting.value) else: @@ -1852,6 +1852,23 @@ def select_nginx_alert(**kwargs): return query_res +def select_keepalived_alert(**kwargs): + if kwargs.get("group") is not None: + query = Server.select(Server.ip).where( + (Server.keepalived_alert == 1) & + (Server.enable == 1) & + (Server.groups == kwargs.get('group'))) + else: + query = Server.select(Server.ip).where((Server.keepalived_alert == 1) & (Server.enable == 1)) + + try: + query_res = query.execute() + except Exception as e: + out_error(e) + else: + return query_res + + def select_keep_alive(): query = Server.select(Server.ip).where(Server.active == 1) try: diff --git a/app/templates/hapservers.html b/app/templates/hapservers.html index 370ce78e..c2305082 100644 --- a/app/templates/hapservers.html +++ b/app/templates/hapservers.html @@ -101,8 +101,10 @@ {% set additional_status_class = 'div-server-head-down' %} {% endif %} {% elif service == 'keepalived' %} + {% set checker_desc = 'Checker monitors Keepalived services. If Keepalived service is down, Checker will alert via Telegram and/or Slack' %} {% set is_auto_start_enabled = s.8.0.22 %} {% set action_service = 'keepalived' %} + {% set is_checker_enabled = s.8.0.23 %} {% if s.5.0.1 == 'active' %} {% set additional_status_class = 'div-server-head-up' %} {% else %} @@ -212,13 +214,15 @@ {% endif %}