diff --git a/app/create_db.py b/app/create_db.py index ed29383a..e65e0d74 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -998,7 +998,7 @@ def update_db_v_6_3_5(): def update_ver(): try: - Version.update(version='6.3.5.0').execute() + Version.update(version='6.3.6.0').execute() except Exception: print('Cannot update version') diff --git a/app/modules/db/db_model.py b/app/modules/db/db_model.py index 013f6ea8..1797f2aa 100644 --- a/app/modules/db/db_model.py +++ b/app/modules/db/db_model.py @@ -578,6 +578,16 @@ class ServiceStatus(BaseModel): constraints = [SQL('UNIQUE (server_id, service_id, service_check)')] +class KeepaliveRestart(BaseModel): + server_id = ForeignKeyField(Server, on_delete='Cascade') + service = CharField() + restarted = IntegerField(constraints=[SQL('DEFAULT 1')]) + + class Meta: + table_name = 'keepaplive_restarted' + constraints = [SQL('UNIQUE (server_id, service)')] + + def create_tables(): with conn: conn.create_tables([User, Server, Role, Telegram, Slack, UUID, Token, ApiToken, Groups, UserGroups, ConfigVersion, @@ -585,4 +595,4 @@ def create_tables(): PortScannerSettings, PortScannerPorts, PortScannerHistory, ProvidersCreds, ServiceSetting, ProvisionedServers, MetricsHttpStatus, SMON, WafRules, Alerts, GeoipCodes, NginxMetrics, SystemInfo, Services, UserName, GitSetting, CheckerSetting, ApacheMetrics, ProvisionParam, - WafNginx, ServiceStatus]) + WafNginx, ServiceStatus, KeepaliveRestart]) diff --git a/app/modules/db/sql.py b/app/modules/db/sql.py index b048f148..a85e2781 100755 --- a/app/modules/db/sql.py +++ b/app/modules/db/sql.py @@ -2242,7 +2242,7 @@ def select_keepalived_alert(**kwargs): def select_keep_alive(): - query = Server.select(Server.ip, Server.groups).where(Server.active == 1) + query = Server.select(Server.ip, Server.groups, Server.server_id).where(Server.active == 1) try: query_res = query.execute() except Exception as e: @@ -2252,7 +2252,7 @@ def select_keep_alive(): def select_nginx_keep_alive(): - query = Server.select(Server.ip, Server.groups).where(Server.nginx_active == 1) + query = Server.select(Server.ip, Server.groups, Server.server_id).where(Server.nginx_active == 1) try: query_res = query.execute() except Exception as e: @@ -2262,7 +2262,7 @@ def select_nginx_keep_alive(): def select_apache_keep_alive(): - query = Server.select(Server.ip, Server.groups).where(Server.apache_active == 1) + query = Server.select(Server.ip, Server.groups, Server.server_id).where(Server.apache_active == 1) try: query_res = query.execute() except Exception as e: @@ -2272,7 +2272,7 @@ def select_apache_keep_alive(): def select_keepalived_keep_alive(): - query = Server.select(Server.ip, Server.port, Server.groups).where(Server.keepalived_active == 1) + query = Server.select(Server.ip, Server.port, Server.groups, Server.server_id).where(Server.keepalived_active == 1) try: query_res = query.execute() except Exception as e: @@ -2290,6 +2290,26 @@ def select_keepalived(serv): return keepalived +def select_update_keep_alive_restart(server_id: int, service: str) -> int: + try: + restarted = KeepaliveRestart.get( + (KeepaliveRestart.server_id == server_id) & + (KeepaliveRestart.service == service) + ).restarted + except Exception as e: + out_error(e) + else: + return restarted or 0 + + +def update_keep_alive_restart(server_id: int, service: str, restarted: int) -> None: + query = KeepaliveRestart.insert(server_id=server_id, service=service, restarted=restarted).on_conflict('replace') + try: + query.execute() + except Exception as e: + out_error(e) + + def update_keepalived(serv): query = Server.update(keepalived='1').where(Server.ip == serv) try: diff --git a/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 b/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 index de9a53ad..454b8130 100644 --- a/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 +++ b/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 @@ -1,5 +1,6 @@ global - log 127.0.0.1 local2 + log 127.0.0.2 local0 + log 127.0.0.1 local1 notice chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 @@ -31,9 +32,7 @@ defaults listen stats bind *:{{STAT_PORT}} - {% if ansible_os_family == "RedHat" %} http-request use-service prometheus-exporter if { path /metrics } - {% endif %} stats enable stats uri /stats stats realm HAProxy-04\ Statistics diff --git a/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 b/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 index 212449d8..e152cefe 100644 --- a/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 +++ b/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 @@ -7,10 +7,8 @@ module(load="builtin:omfile") if $programname startswith 'haproxy' then { if $syslogseverity == 6 then action(type="omfile" file="/var/log/haproxy/access.log") - stop if $syslogseverity <= 3 then action(type="omfile" file="/var/log/haproxy/error.log") - stop if $syslogseverity <= 5 then action(type="omfile" file="/var/log/haproxy/status.log") stop diff --git a/app/templates/ajax/show_system_info.html b/app/templates/ajax/show_system_info.html index dbc543a6..d75ccda2 100644 --- a/app/templates/ajax/show_system_info.html +++ b/app/templates/ajax/show_system_info.html @@ -156,4 +156,10 @@ {% endfor %} {% endfor %} -{% endif %} \ No newline at end of file +{% endif %} + diff --git a/app/templates/base.html b/app/templates/base.html index 1659b773..b78bcf75 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -13,7 +13,7 @@ data-something_wrong="{{lang.words.something_wrong}}" data-check_logs="{{lang.words.check_logs}}" data-wait_mess="{{lang.phrases.wait_mess}}" data-just_save="{{lang.words.just|title()}} {{lang.words.save}}" data-upload_and_restart="{{lang.phrases.upload_and_restart|title()}}" data-are_you_sure="{{lang.phrases.are_you_sure}}" data-upload_and_reload="{{lang.phrases.upload_and_reload|title()}}" data-select_server="{{lang.errors.select_server}}" - data-empty_name="{{lang.errors.empty_name}}" data-edit="{{lang.words.edit|title()}}" data-close="{{lang.words.close|title()}}" + 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}}" /> {% if title == 'Login page' %} diff --git a/app/templates/include/mon_installation.html b/app/templates/include/mon_installation.html index dfa8aecf..712fa93f 100644 --- a/app/templates/include/mon_installation.html +++ b/app/templates/include/mon_installation.html @@ -54,7 +54,7 @@