Pavel Loginov 2020-11-16 18:31:52 +06:00
parent b5ce83d999
commit 769df0f6c4
11 changed files with 228 additions and 168 deletions

View File

@ -188,7 +188,6 @@ def update_db_v_31(**kwargs):
sql.append("INSERT INTO settings (param, value, section, `desc`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_enable', '0', 'ldap', 'If 1 ldap enabled');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_enable', '0', 'ldap', 'If 1 ldap enabled');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_server', '', 'ldap', 'IP address ldap server');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_server', '', 'ldap', 'IP address ldap server');")
@ -434,25 +433,6 @@ def update_db_v_42(**kwargs):
con.close() con.close()
def update_db_v_4_2_3(**kwargs):
con, cur = get_cur()
sql = """
update settings set section = 'main' where param = 'firewall_enable';
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: haproxy' or e == " 1060 (42S21): Duplicate column name 'haproxy' ":
print('Updating... go to version 4.3.0')
else:
print("An error occurred:", e)
cur.close()
con.close()
def update_db_v_4_3(**kwargs): def update_db_v_4_3(**kwargs):
con, cur = get_cur() con, cur = get_cur()
sql = """ sql = """
@ -707,9 +687,29 @@ def update_db_v_4_5_1(**kwargs):
con.close() con.close()
def update_db_v_4_5_4(**kwargs):
con, cur = get_cur()
sql = list()
sql.append("ALTER TABLE `servers` ADD COLUMN `nginx_active` INTEGER NOT NULL DEFAULT 0;")
sql.append("ALTER TABLE `servers` ADD COLUMN `firewall_enable` INTEGER NOT NULL DEFAULT 0;")
sql.append("delete from settings where param = 'firewall_enable';")
for i in sql:
try:
cur.execute(i)
con.commit()
except sqltool.Error as e:
pass
else:
if kwargs.get('silent') != 1:
print('DB was update to 4.5.4')
cur.close()
con.close()
def update_ver(**kwargs): def update_ver(**kwargs):
con, cur = get_cur() con, cur = get_cur()
sql = """update version set version = '4.5.3.0'; """ sql = """update version set version = '4.5.4.0'; """
try: try:
cur.execute(sql) cur.execute(sql)
con.commit() con.commit()
@ -733,7 +733,6 @@ def update_all():
update_db_v_4() update_db_v_4()
update_db_v_41() update_db_v_41()
update_db_v_42() update_db_v_42()
update_db_v_4_2_3()
update_db_v_4_3() update_db_v_4_3()
update_db_v_4_3_0() update_db_v_4_3_0()
update_db_v_4_3_1() update_db_v_4_3_1()
@ -744,6 +743,7 @@ def update_all():
update_db_v_4_3_2_1() update_db_v_4_3_2_1()
update_db_v_4_5() update_db_v_4_5()
update_db_v_4_5_1() update_db_v_4_5_1()
update_db_v_4_5_4()
update_ver() update_ver()
@ -761,7 +761,6 @@ def update_all_silent():
update_db_v_4(silent=1) update_db_v_4(silent=1)
update_db_v_41(silent=1) update_db_v_41(silent=1)
update_db_v_42(silent=1) update_db_v_42(silent=1)
update_db_v_4_2_3(silent=1)
update_db_v_4_3(silent=1) update_db_v_4_3(silent=1)
update_db_v_4_3_0(silent=1) update_db_v_4_3_0(silent=1)
update_db_v_4_3_1(silent=1) update_db_v_4_3_1(silent=1)
@ -772,6 +771,7 @@ def update_all_silent():
update_db_v_4_3_2_1(silent=1) update_db_v_4_3_2_1(silent=1)
update_db_v_4_5(silent=1) update_db_v_4_5(silent=1)
update_db_v_4_5_1(silent=1) update_db_v_4_5_1(silent=1)
update_db_v_4_5_4(silent=1)
update_ver() update_ver()

View File

@ -22,11 +22,11 @@ form = funct.form
serv = form.getvalue('serv') serv = form.getvalue('serv')
service = form.getvalue('service') service = form.getvalue('service')
autorefresh = 0 autorefresh = 0
cmd = "ps ax |grep -e 'keep_alive.py' |grep -v grep |wc -l"
keep_alive, stderr = funct.subprocess_execute(cmd)
if service == 'nginx': if service == 'nginx':
title = "Nginx servers overview" title = "Nginx servers overview"
keep_alive = ''
stderr = ''
servers = sql.get_dick_permit(virt=1, nginx=1) servers = sql.get_dick_permit(virt=1, nginx=1)
service = 'nginx' service = 'nginx'
if serv: if serv:
@ -35,8 +35,6 @@ if service == 'nginx':
autorefresh = 1 autorefresh = 1
else: else:
title = "HAProxy servers overview" title = "HAProxy servers overview"
cmd = "ps ax |grep -e 'keep_alive.py' |grep -v grep |wc -l"
keep_alive, stderr = funct.subprocess_execute(cmd)
service = 'haproxy' service = 'haproxy'
if serv: if serv:
if funct.check_is_server_in_group(serv): if funct.check_is_server_in_group(serv):
@ -45,15 +43,15 @@ else:
else: else:
servers = sql.get_dick_permit(virt=1, haproxy=1) servers = sql.get_dick_permit(virt=1, haproxy=1)
services_name = {'checker_haproxy': 'Master backends checker service', services_name = {'checker_haproxy': 'Master backends checker service',
'keep_alive': 'Auto start service', 'keep_alive': 'Auto start service',
'metrics_haproxy': 'Master metrics service'} 'metrics_haproxy': 'Master metrics service'}
for s, v in services_name.items(): for s, v in services_name.items():
if s != 'keep_alive': if s != 'keep_alive':
service_name = s.split('_')[0] service_name = s.split('_')[0]
else: else:
service_name = s service_name = s
cmd = "rpm --query haproxy-wi-" + service_name + "-* |awk -F\"" + service_name +"\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'" cmd = "rpm --query haproxy-wi-" + service_name + "-* |awk -F\"" + service_name + "\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'"
service_ver, stderr = funct.subprocess_execute(cmd) service_ver, stderr = funct.subprocess_execute(cmd)
services.append([s, service_ver[0]]) services.append([s, service_ver[0]])
@ -87,8 +85,10 @@ for s in servers:
else: else:
out1 = False out1 = False
servers_with_status.append(out1) servers_with_status.append(out1)
if service == 'haproxy':
servers_with_status.append(s[12]) servers_with_status.append(s[12])
else:
servers_with_status.append(s[17])
servers_with_status.append(sql.is_master(s[2])) servers_with_status.append(sql.is_master(s[2]))
servers_with_status.append(sql.select_servers(server=s[2])) servers_with_status.append(sql.select_servers(server=s[2]))

View File

@ -43,9 +43,9 @@ if form.getvalue('checkSshConnect') is not None and serv is not None:
print(funct.ssh_command(serv, ["ls -1t"])) print(funct.ssh_command(serv, ["ls -1t"]))
if form.getvalue('getcert') is not None and serv is not None: if form.getvalue('getcert') is not None and serv is not None:
id = form.getvalue('getcert') cert_id = form.getvalue('getcert')
cert_path = sql.get_setting('cert_path') cert_path = sql.get_setting('cert_path')
commands = ["cat " + cert_path + "/" + id] commands = ["cat " + cert_path + "/" + cert_id]
try: try:
funct.ssh_command(serv, commands, ip="1") funct.ssh_command(serv, commands, ip="1")
except Exception as e: except Exception as e:
@ -206,12 +206,12 @@ if form.getvalue('table_select') is not None:
table = [] table = []
for t in tables.split(','): for t in tables.split(','):
if t != '': if t != '':
id = [] table_id = []
tables_head = [] tables_head = []
tables_head1, table1 = funct.get_stick_table(t) tables_head1, table1 = funct.get_stick_table(t)
id.append(tables_head1) table_id.append(tables_head1)
id.append(table1) table_id.append(table1)
table.append(id) table.append(table_id)
template = template.render(table=table) template = template.render(table=table)
else: else:
@ -561,8 +561,7 @@ if act == "overviewServers":
async def async_get_overviewServers(serv1, serv2, service): async def async_get_overviewServers(serv1, serv2, service):
if service == 'haproxy': if service == 'haproxy':
cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:"' % ( cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:"' % (serv2, sql.get_setting('haproxy_sock_port'))
serv2, sql.get_setting('haproxy_sock_port'))
out = funct.subprocess_execute(cmd) out = funct.subprocess_execute(cmd)
out1 = "" out1 = ""
@ -1061,7 +1060,7 @@ if form.getvalue('masteradd'):
print(output) print(output)
break break
else: else:
print('success: Master VRRP address was added<br>') print('success: Master VRRP address has been added<br>')
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(slave) ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(slave)
@ -1094,7 +1093,7 @@ if form.getvalue('masteradd'):
print(output) print(output)
break break
else: else:
print('success: Slave VRRP address was added<br>') print('success: Slave VRRP address has been added<br>')
os.system("rm -f %s" % script) os.system("rm -f %s" % script)
@ -1127,7 +1126,7 @@ if form.getvalue('install_grafana'):
l = l.split('"')[1] l = l.split('"')[1]
print(l + "<br>") print(l + "<br>")
break break
except: except Exception:
print(output) print(output)
break break
else: else:
@ -1182,7 +1181,7 @@ if form.getvalue('haproxy_exp_install'):
l = l.split('"')[1] l = l.split('"')[1]
print(l + "<br>") print(l + "<br>")
break break
except: except Exception:
print(output) print(output)
break break
else: else:
@ -1232,7 +1231,7 @@ if form.getvalue('nginx_exp_install'):
l = l.split('"')[1] l = l.split('"')[1]
print(l + "<br>") print(l + "<br>")
break break
except: except Exception:
print(output) print(output)
break break
else: else:
@ -1288,7 +1287,7 @@ if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupup
l = l.split('"')[1] l = l.split('"')[1]
print('error: ' + l + "<br>") print('error: ' + l + "<br>")
break break
except: except Exception:
print('error: ' + output) print('error: ' + output)
break break
else: else:
@ -1674,12 +1673,13 @@ if form.getvalue('newserver') is not None:
funct.logging('a new server ' + hostname, ' has created ', haproxywi=1, login=1) funct.logging('a new server ' + hostname, ' has created ', haproxywi=1, login=1)
if form.getvalue('updatehapwiserver') is not None: if form.getvalue('updatehapwiserver') is not None:
id = form.getvalue('updatehapwiserver') hapwi_id = form.getvalue('updatehapwiserver')
active = form.getvalue('active') active = form.getvalue('active')
name = form.getvalue('name') name = form.getvalue('name')
alert = form.getvalue('alert_en') alert = form.getvalue('alert_en')
metrics = form.getvalue('metrics') metrics = form.getvalue('metrics')
sql.update_hapwi_server(id, alert, metrics, active) service_name = form.getvalue('service_name')
sql.update_hapwi_server(hapwi_id, alert, metrics, active, service_name)
funct.logging('the server ' + name, ' has updated ', haproxywi=1, login=1) funct.logging('the server ' + name, ' has updated ', haproxywi=1, login=1)
if form.getvalue('updateserver') is not None: if form.getvalue('updateserver') is not None:
@ -1690,7 +1690,7 @@ if form.getvalue('updateserver') is not None:
nginx = form.getvalue('nginx') nginx = form.getvalue('nginx')
enable = form.getvalue('enable') enable = form.getvalue('enable')
master = form.getvalue('slave') master = form.getvalue('slave')
id = form.getvalue('id') serv_id = form.getvalue('id')
cred = form.getvalue('cred') cred = form.getvalue('cred')
port = form.getvalue('port') port = form.getvalue('port')
desc = form.getvalue('desc') desc = form.getvalue('desc')
@ -1698,7 +1698,7 @@ if form.getvalue('updateserver') is not None:
if name is None or port is None: if name is None or port is None:
print(error_mess) print(error_mess)
else: else:
sql.update_server(name, group, typeip, enable, master, id, cred, port, desc, haproxy, nginx) sql.update_server(name, group, typeip, enable, master, serv_id, cred, port, desc, haproxy, nginx)
funct.logging('the server ' + name, ' has updated ', haproxywi=1, login=1) funct.logging('the server ' + name, ' has updated ', haproxywi=1, login=1)
if form.getvalue('serverdel') is not None: if form.getvalue('serverdel') is not None:
@ -1743,14 +1743,14 @@ if form.getvalue('groupdel') is not None:
if form.getvalue('updategroup') is not None: if form.getvalue('updategroup') is not None:
name = form.getvalue('updategroup') name = form.getvalue('updategroup')
descript = form.getvalue('descript') descript = form.getvalue('descript')
id = form.getvalue('id') group_id = form.getvalue('id')
if name is None: if name is None:
print(error_mess) print(error_mess)
else: else:
group = sql.select_groups(id=id) group = sql.select_groups(id=group_id)
for g in group: for g in group:
groupname = g[1] groupname = g[1]
sql.update_group(name, descript, id) sql.update_group(name, descript, group_id)
funct.logging('the group ' + groupname, ' has update ', haproxywi=1, login=1) funct.logging('the group ' + groupname, ' has update ', haproxywi=1, login=1)
if form.getvalue('new_ssh'): if form.getvalue('new_ssh'):
@ -1797,7 +1797,7 @@ if form.getvalue('sshdel') is not None:
funct.logging(name, ' has deleted the SSH credentials ', haproxywi=1, login=1) funct.logging(name, ' has deleted the SSH credentials ', haproxywi=1, login=1)
if form.getvalue('updatessh'): if form.getvalue('updatessh'):
id = form.getvalue('id') ssh_id = form.getvalue('id')
name = form.getvalue('name') name = form.getvalue('name')
enable = form.getvalue('ssh_enable') enable = form.getvalue('ssh_enable')
group = form.getvalue('group') group = form.getvalue('group')
@ -1810,7 +1810,7 @@ if form.getvalue('updatessh'):
fullpath = funct.get_config_var('main', 'fullpath') fullpath = funct.get_config_var('main', 'fullpath')
for sshs in sql.select_ssh(id=id): for sshs in sql.select_ssh(id=ssh_id):
ssh_enable = sshs[2] ssh_enable = sshs[2]
ssh_key_name = fullpath + '/keys/%s.pem' % sshs[1] ssh_key_name = fullpath + '/keys/%s.pem' % sshs[1]
new_ssh_key_name = fullpath + '/keys/%s.pem' % name new_ssh_key_name = fullpath + '/keys/%s.pem' % name
@ -1821,9 +1821,9 @@ if form.getvalue('updatessh'):
try: try:
funct.subprocess_execute(cmd) funct.subprocess_execute(cmd)
funct.subprocess_execute(cmd1) funct.subprocess_execute(cmd1)
except: except Exception:
pass pass
sql.update_ssh(id, name, enable, group, username, password) sql.update_ssh(ssh_id, name, enable, group, username, password)
funct.logging('the SSH ' + name, ' has updated credentials ', haproxywi=1, login=1) funct.logging('the SSH ' + name, ' has updated credentials ', haproxywi=1, login=1)
if form.getvalue('ssh_cert'): if form.getvalue('ssh_cert'):
@ -1900,11 +1900,11 @@ if form.getvalue('updatetoken') is not None:
token = form.getvalue('updatetoken') token = form.getvalue('updatetoken')
channel = form.getvalue('updategchanel') channel = form.getvalue('updategchanel')
group = form.getvalue('updatetelegramgroup') group = form.getvalue('updatetelegramgroup')
id = form.getvalue('id') user_id = form.getvalue('id')
if token is None or channel is None or group is None: if token is None or channel is None or group is None:
print(error_mess) print(error_mess)
else: else:
sql.update_telegram(token, channel, group, id) sql.update_telegram(token, channel, group, user_id)
funct.logging('group ' + group, ' telegram token has updated channel: ' + channel, haproxywi=1, login=1) funct.logging('group ' + group, ' telegram token has updated channel: ' + channel, haproxywi=1, login=1)
if form.getvalue('updatesettings') is not None: if form.getvalue('updatesettings') is not None:

View File

@ -101,35 +101,35 @@ except Exception as e:
is_metrics_worker = '' is_metrics_worker = ''
token = '' token = ''
template = template.render(h2 = 1, template = template.render(h2=1,
autorefresh = 1, autorefresh=1,
title = "Overview", title="Overview",
role = role, role=role,
user = user, user=user,
users = users, users=users,
groups = groups, groups=groups,
users_groups = sql.select_user_groups_with_names(1, all=1), users_groups=sql.select_user_groups_with_names(1, all=1),
roles = sql.select_roles(), roles=sql.select_roles(),
metrics_master = ''.join(metrics_master), metrics_master=''.join(metrics_master),
metrics_worker = ''.join(metrics_worker), metrics_worker=''.join(metrics_worker),
checker_master = ''.join(checker_master), checker_master=''.join(checker_master),
checker_worker = ''.join(checker_worker), checker_worker=''.join(checker_worker),
keep_alive = ''.join(keep_alive), keep_alive=''.join(keep_alive),
smon = ''.join(smon), smon=''.join(smon),
grafana = ''.join(grafana), grafana=''.join(grafana),
prometheus = ''.join(prometheus), prometheus=''.join(prometheus),
haproxy_wi_log_id = funct.haproxy_wi_log(log_id=1, file="haproxy-wi-", with_date=1), haproxy_wi_log_id=funct.haproxy_wi_log(log_id=1, file="haproxy-wi-", with_date=1),
metrics_log_id = funct.haproxy_wi_log(log_id=1, file="metrics-", with_date=1), metrics_log_id=funct.haproxy_wi_log(log_id=1, file="metrics-", with_date=1),
checker_log_id = funct.haproxy_wi_log(log_id=1, file="checker-", with_date=1), checker_log_id=funct.haproxy_wi_log(log_id=1, file="checker-", with_date=1),
keep_alive_log_id = funct.haproxy_wi_log(log_id=1, file="keep_alive"), keep_alive_log_id=funct.haproxy_wi_log(log_id=1, file="keep_alive"),
checker_error_log_id = funct.haproxy_wi_log(log_id=1, file="checker-error"), checker_error_log_id=funct.haproxy_wi_log(log_id=1, file="checker-error"),
metrics_error_log_id = funct.haproxy_wi_log(log_id=1, file="metrics-error"), metrics_error_log_id=funct.haproxy_wi_log(log_id=1, file="metrics-error"),
error = stderr, error=stderr,
versions = funct.versions(), versions=funct.versions(),
haproxy_wi_log = funct.haproxy_wi_log(), haproxy_wi_log=funct.haproxy_wi_log(),
servers = servers, servers=servers,
is_checker_worker = is_checker_worker, is_checker_worker=is_checker_worker,
is_metrics_worker = is_metrics_worker, is_metrics_worker=is_metrics_worker,
host = host, host=host,
token = token) token=token)
print(template) print(template)

View File

@ -201,7 +201,6 @@ def add_setting_for_new_group(group_id):
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file','" + group_id + "');") sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file','" + group_id + "');")
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file','" + group_id + "');") sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file','" + group_id + "');")
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port','" + group_id + "');") sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port','" + group_id + "');")
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port','" + group_id + "');")
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('nginx_path_error_logs', '/var/log/nginx/error.log', 'nginx', 'Nginx error log','" + group_id + "');") sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('nginx_path_error_logs', '/var/log/nginx/error.log', 'nginx', 'Nginx error log','" + group_id + "');")
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('nginx_stats_user', 'admin', 'nginx', 'Username for Stats web page Nginx','" + group_id + "');") sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('nginx_stats_user', 'admin', 'nginx', 'Username for Stats web page Nginx','" + group_id + "');")
sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('nginx_stats_password', 'password', 'nginx', 'Password for Stats web page Nginx','" + group_id + "');") sql.append("INSERT INTO settings (param, value, section, `desc`, `group`) values('nginx_stats_password', 'password', 'nginx', 'Password for Stats web page Nginx','" + group_id + "');")
@ -326,13 +325,17 @@ def delete_server(id):
con.close() con.close()
def update_hapwi_server(id, alert, metrics, active): def update_hapwi_server(server_id, alert, metrics, active, service_name):
con, cur = get_cur() con, cur = get_cur()
updated_service = 'active'
if service_name == 'nginx':
updated_service = 'nginx_active'
sql = """ update servers set sql = """ update servers set
alert = '%s', alert = '%s',
metrics = '%s', metrics = '%s',
active = '%s' '%s' = '%s'
where id = '%s'""" % (alert, metrics, active, id) where id = '%s'""" % (alert, metrics, updated_service, active, server_id)
try: try:
cur.execute(sql) cur.execute(sql)
con.commit() con.commit()
@ -1269,10 +1272,32 @@ def select_waf_servers_metrics(uuid, **kwargs):
def select_waf_metrics(serv, **kwargs): def select_waf_metrics(serv, **kwargs):
con, cur = get_cur() con, cur = get_cur()
if mysql_enable == '1': if mysql_enable == '1':
sql = """ select * from waf_metrics where serv = '%s' order by `date` desc limit 60 """ % serv if kwargs.get('time_range') == '60':
date_from = "and date > now() - INTERVAL 60 minute and rowid % 2 = 0"
elif kwargs.get('time_range') == '180':
date_from = "and date > now() - INTERVAL 180 minute and rowid % 5 = 0"
elif kwargs.get('time_range') == '360':
date_from = "and date > now() - INTERVAL 360 minute and rowid % 7 = 0"
elif kwargs.get('time_range') == '720':
date_from = "and date > now() - INTERVAL 720 minute and rowid % 9 = 0"
else: else:
sql = """ select * from (select * from waf_metrics where serv = '%s' order by `date` desc limit 60) order by `date`""" % serv date_from = "and date > now() - INTERVAL 30 minute"
sql = """ select * from waf_metrics where serv = '{serv}' {date_from} order by `date` desc limit 60 """.format(serv=serv, date_from=date_from)
else:
if kwargs.get('time_range') == '60':
date_from = "and date > datetime('now', '-60 minutes', 'localtime') and rowid % 2 = 0"
elif kwargs.get('time_range') == '180':
date_from = "and date > datetime('now', '-180 minutes', 'localtime') and rowid % 5 = 0"
elif kwargs.get('time_range') == '360':
date_from = "and date > datetime('now', '-360 minutes', 'localtime') and rowid % 7 = 0"
elif kwargs.get('time_range') == '720':
date_from = "and date > datetime('now', '-720 minutes', 'localtime') and rowid % 9 = 0"
else:
date_from = "and date > datetime('now', '-30 minutes', 'localtime')"
sql = """ select * from (select * from waf_metrics where serv = '{serv}' {date_from} order by `date`) order by `date` """.format(serv=serv, date_from=date_from)
try: try:
cur.execute(sql) cur.execute(sql)
except sqltool.Error as e: except sqltool.Error as e:
@ -1451,26 +1476,26 @@ def select_metrics(serv, **kwargs):
con, cur = get_cur() con, cur = get_cur()
if mysql_enable == '1': if mysql_enable == '1':
if kwargs.get('time_range') == 60: if kwargs.get('time_range') == '60':
date_from = "and date > now() - INTERVAL 60 minute and rowid % 2 = 0" date_from = "and date > now() - INTERVAL 60 minute and rowid % 2 = 0"
elif kwargs.get('time_range') == 180: elif kwargs.get('time_range') == '180':
date_from = "and date > now() - INTERVAL 180 minute and rowid % 5 = 0" date_from = "and date > now() - INTERVAL 180 minute and rowid % 5 = 0"
elif kwargs.get('time_range') == 720: elif kwargs.get('time_range') == '360':
date_from = "and date > now() - INTERVAL 360 minute and rowid % 7 = 0"
elif kwargs.get('time_range') == '720':
date_from = "and date > now() - INTERVAL 720 minute and rowid % 9 = 0" date_from = "and date > now() - INTERVAL 720 minute and rowid % 9 = 0"
elif kwargs.get('time_range') == 1440:
date_from = "and date > now() - INTERVAL 1440 minute and rowid % 17 = 0"
else: else:
date_from = "and date > now() - INTERVAL 30 minute" date_from = "and date > now() - INTERVAL 30 minute"
sql = """ select * from metrics where serv = '{serv}' {date_from} order by `date` desc limit 60 """.format(serv=serv, date_from=date_from) sql = """ select * from metrics where serv = '{serv}' {date_from} order by `date` desc limit 60 """.format(serv=serv, date_from=date_from)
else: else:
if kwargs.get('time_range') == 60: if kwargs.get('time_range') == '60':
date_from = "and date > datetime('now', '-60 minutes', 'localtime') and rowid % 2 = 0" date_from = "and date > datetime('now', '-60 minutes', 'localtime') and rowid % 2 = 0"
elif kwargs.get('time_range') == 180: elif kwargs.get('time_range') == '180':
date_from = "and date > datetime('now', '-180 minutes', 'localtime') and rowid % 5 = 0" date_from = "and date > datetime('now', '-180 minutes', 'localtime') and rowid % 5 = 0"
elif kwargs.get('time_range') == 720: elif kwargs.get('time_range') == '360':
date_from = "and date > datetime('now', '-360 minutes', 'localtime') and rowid % 7 = 0"
elif kwargs.get('time_range') == '720':
date_from = "and date > datetime('now', '-720 minutes', 'localtime') and rowid % 9 = 0" date_from = "and date > datetime('now', '-720 minutes', 'localtime') and rowid % 9 = 0"
elif kwargs.get('time_range') == 1440:
date_from = "and date > datetime('now', '-1440 minutes', 'localtime') and rowid % 17 = 0"
else: else:
date_from = "and date > datetime('now', '-30 minutes', 'localtime')" date_from = "and date > datetime('now', '-30 minutes', 'localtime')"
@ -2052,13 +2077,25 @@ def update_smon(id, ip, port, body, telegram, group, desc, en):
con.close() con.close()
def alerts_history(service, user_group):
con, cur = get_cur()
sql = """ select message, level, ip, port, date from alerts
where service = '%s' and user_group = '%s' order by date desc; """ % (service, user_group)
try:
cur.execute(sql)
except sqltool.Error as e:
funct.out_error(e)
else:
return cur.fetchall()
def select_en_service(): def select_en_service():
con, cur = get_cur() con, cur = get_cur()
sql = """ select ip, port, telegram_channel_id, id, user_group from smon where en = 1""" sql = """ select ip, port, telegram_channel_id, id, user_group from smon where en = 1"""
try: try:
cur.execute(sql) cur.execute(sql)
except sqltool.Error as e: except sqltool.Error as e:
out_error(e) funct.out_error(e)
else: else:
return cur.fetchall() return cur.fetchall()
@ -2069,7 +2106,7 @@ def select_status(id):
try: try:
cur.execute(sql) cur.execute(sql)
except sqltool.Error as e: except sqltool.Error as e:
print("An error occurred:", e) funct.out_error(e)
else: else:
for status in cur: for status in cur:
return status[0] return status[0]

View File

@ -99,6 +99,7 @@
<a title="Simple monitoring network ports" class="stats">SMON</a> <a title="Simple monitoring network ports" class="stats">SMON</a>
<ul class="v_menu"> <ul class="v_menu">
<li><a href="/app/smon.py?action=view" title="SMON Dashboard" class="overview-link head-submenu">Dashboard</a></li> <li><a href="/app/smon.py?action=view" title="SMON Dashboard" class="overview-link head-submenu">Dashboard</a></li>
<li><a href="/app/smon.py?action=history" title="SMON History" class="lists head-submenu">History</a></li>
{% if role <= 3 %} {% if role <= 3 %}
<li><a href="/app/smon.py?action=add" title="SMON admin panel" class="edit head-submenu">Admin panel</a></li> <li><a href="/app/smon.py?action=add" title="SMON admin panel" class="edit head-submenu">Admin panel</a></li>
{% endif %} {% endif %}

View File

@ -102,6 +102,7 @@
{% endif %} {% endif %}
{% if service == 'nginx' %} {% if service == 'nginx' %}
{% set checker_desc = 'Checker monitors Nginx services. If Nginx service is down, Checker will alert via Telegram' %} {% set checker_desc = 'Checker monitors Nginx services. If Nginx service is down, Checker will alert via Telegram' %}
{% set is_checker_enabled = s.8.0.17 %}
{% if s.5.0.3 == 'active' %} {% if s.5.0.3 == 'active' %}
{% set additional_status_class = 'div-server-head-up' %} {% set additional_status_class = 'div-server-head-up' %}
{% else %} {% else %}
@ -109,6 +110,7 @@
{% endif %} {% endif %}
{% else %} {% else %}
{% set checker_desc = 'Checker monitors HAProxy services and its backends. If some backend or HAProxy service is down, Checker will alert via Telegram' %} {% set checker_desc = 'Checker monitors HAProxy services and its backends. If some backend or HAProxy service is down, Checker will alert via Telegram' %}
{% set is_checker_enabled = s.8.0.12 %}
{% if s.5 != False %} {% if s.5 != False %}
{% set additional_status_class = 'div-server-head-up' %} {% set additional_status_class = 'div-server-head-up' %}
{% else %} {% else %}
@ -137,7 +139,6 @@
{% else %} {% else %}
{{s.1}} {{s.1}}
{% endif %} {% endif %}
{% if service == 'haproxy' %}
{% if s.6|int() >= 1 %} {% if s.6|int() >= 1 %}
<img <img
{% if keep_alive|int() >= 1 %} {% if keep_alive|int() >= 1 %}
@ -145,8 +146,7 @@
{% else %} {% else %}
src="/inc/images/shield-red.png" title="Auto start enabled, but keep alive service does not work" src="/inc/images/shield-red.png" title="Auto start enabled, but keep alive service does not work"
{% endif %} {% endif %}
width=18 style="padding-left: 5px; margin-bottom: -3px;"> width=18 style="padding-left: 5px; margin-bottom: -3px;" />
{% endif %}
{% endif %} {% endif %}
{% if role <= 2 %} {% if role <= 2 %}
<span class="server-action"> <span class="server-action">
@ -170,11 +170,7 @@
</span> </span>
{% endif %} {% endif %}
</div> </div>
{% if service == 'nginx' %}
<div class="server-desc" style="height: 110px;">
{% else %}
<div class="server-desc"> <div class="server-desc">
{% endif %}
{{s.3}} {{s.3}}
<br /> <br />
{% if service == 'nginx' %} {% if service == 'nginx' %}
@ -183,13 +179,13 @@
Uptime: {% else %} Downtime: {% endif %} {{s.5.0.4}} Uptime: {% else %} Downtime: {% endif %} {{s.5.0.4}}
{% else %} {% else %}
{% if s.5.0 is defined %} {% if s.5.0 is defined %}
{{s.5.0.0}} {{s.5.0.1}} {{s.5.0.2}} {{s.5.0.0}} {{s.5.0.1}}
<br />{{s.5.0.2}}
{% else %} {% else %}
Cannot get information about HAProxy Cannot get information about HAProxy
{% endif %} {% endif %}
{% endif %} {% endif %}
<br /> <span title="Date of last configuration edit" >
<span title="Date of last edit config" >
Last edit: Last edit:
<span id="{{s.1}}"></span> <span id="{{s.1}}"></span>
</span> </span>
@ -199,9 +195,10 @@
Master for: {{ s.7.0.1 }} Master for: {{ s.7.0.1 }}
{% endif %} {% endif %}
</div> </div>
{% if service == 'haproxy' %} <div class="server-act-links" id="server-{{s.8.0.0|string()}}-{{service}}">
<div class="server-act-links" id="server-{{s.8.0.0|string()}}">
{% if role <= 2 %} {% if role <= 2 %}
{% if service == 'haproxy' %}
{% set id = 'alert-' + s.8.0.0|string() %} {% set id = 'alert-' + s.8.0.0|string() %}
{% if s.8.0.8 == 1 %} {% if s.8.0.8 == 1 %}
{{ checkbox(id, title=checker_desc, value='1', desc='Checker', checked='checked') }} {{ checkbox(id, title=checker_desc, value='1', desc='Checker', checked='checked') }}
@ -214,13 +211,14 @@
{% else %} {% else %}
{{ checkbox(id, title='Enable collecting metrics', value='1', desc='Metrics') }} {{ checkbox(id, title='Enable collecting metrics', value='1', desc='Metrics') }}
{% endif %} {% endif %}
{% endif %}
{% set id = 'active-' + s.8.0.0|string() %} {% set id = 'active-' + s.8.0.0|string() %}
{% if s.8.0.12 == 1 %} {% if is_checker_enabled == 1 %}
{{ checkbox(id, title='Auto Start is enabled', value='1', desc='Auto Start', checked='checked') }} {{ checkbox(id, title='Auto Start is enabled', value='1', desc='Auto Start', checked='checked') }}
{% else %} {% else %}
{{ checkbox(id, title='Enable Auto Start', value='1', desc='Auto Start') }} {{ checkbox(id, title='Enable Auto Start', value='1', desc='Auto Start') }}
{% endif %} {% endif %}
{% endif %}
</div> </div>
{% endif %} {% endif %}
<div class="server-act-links"> <div class="server-act-links">

View File

@ -1365,11 +1365,15 @@ function editList(list, color) {
} ); } );
} }
function saveList(action, list, color) { function saveList(action, list, color) {
$.ajax( { var serv = $( "#serv-"+color+"-list option:selected" ).val();
if (serv == 'Choose server') {
toastr.warning('Choose a server before updating');
} else {
$.ajax({
url: "options.py", url: "options.py",
data: { data: {
bwlists_save: list, bwlists_save: list,
serv: $( "#serv-"+color+"-list option:selected" ).val(), serv: serv,
bwlists_content: $('#edit_lists').val(), bwlists_content: $('#edit_lists').val(),
color: color, color: color,
group: $('#group').val(), group: $('#group').val(),
@ -1377,7 +1381,7 @@ function saveList(action, list, color) {
token: $('#token').val() token: $('#token').val()
}, },
type: "POST", type: "POST",
success: function( data ) { success: function (data) {
data = data.split(" , "); data = data.split(" , ");
for (i = 0; i < data.length; i++) { for (i = 0; i < data.length; i++) {
@ -1390,5 +1394,6 @@ function saveList(action, list, color) {
} }
} }
} }
} ); });
}
} }

View File

@ -128,7 +128,7 @@
.version::before { .version::before {
display: none; display: none;
font-family: "Font Awesome 5 Solid"; font-family: "Font Awesome 5 Solid";
content: "\f021"; content: "\f1da";
} }
.services::before { .services::before {
display: none; display: none;

View File

@ -246,7 +246,15 @@ $( function() {
}); });
$( ".server-act-links" ).change(function() { $( ".server-act-links" ).change(function() {
var id = $(this).attr('id').split('-'); var id = $(this).attr('id').split('-');
updateHapWIServer(id[1])
try {
var service_name = id[2]
}
catch (err) {
var service_name = 'haproxy'
}
updateHapWIServer(id[1], service_name)
}); });
}); });
function confirmAjaxAction(action, service, id) { function confirmAjaxAction(action, service, id) {
@ -279,7 +287,7 @@ function confirmAjaxAction(action, service, id) {
} }
}); });
} }
function updateHapWIServer(id) { function updateHapWIServer(id, service_name) {
var alert_en = 0; var alert_en = 0;
var metrics = 0; var metrics = 0;
var active = 0; var active = 0;
@ -300,6 +308,7 @@ function updateHapWIServer(id) {
metrics: metrics, metrics: metrics,
alert_en: alert_en, alert_en: alert_en,
active: active, active: active,
service_name: service_name,
token: $('#token').val() token: $('#token').val()
}, },
type: "POST", type: "POST",
@ -309,9 +318,10 @@ function updateHapWIServer(id) {
toastr.error(data); toastr.error(data);
} else { } else {
toastr.clear(); toastr.clear();
$("#server-"+id).addClass( "update", 1000 ); console.log("#server-"+id+"-"+service_name)
$("#server-"+id+"-"+service_name).addClass( "update", 1000 );
setTimeout(function() { setTimeout(function() {
$( "#server-"+id ).removeClass( "update" ); $( "#server-"+id+"-"+service_name).removeClass( "update" );
}, 2500 ); }, 2500 );
} }
} }

View File

@ -95,6 +95,15 @@ $( function() {
$(this).parent().find('a').css('padding-left', '20px'); $(this).parent().find('a').css('padding-left', '20px');
$(this).find('a').css('padding-left', '30px'); $(this).find('a').css('padding-left', '30px');
$(this).find('a').css('border-left', '4px solid #5D9CEB'); $(this).find('a').css('border-left', '4px solid #5D9CEB');
} else if(cur_url[0] == 'smon.py' && cur_url[1].split('&')[0] == 'action=history' && link2 == 'smon.py?action=history'){
$(this).parent().css('display', 'contents');
$(this).parent().css('font-size', '13px');
$(this).parent().css('top', '0');
$(this).parent().css('left', '0');
$(this).parent().children().css('margin-left', '-20px');
$(this).parent().find('a').css('padding-left', '20px');
$(this).find('a').css('padding-left', '30px');
$(this).find('a').css('border-left', '4px solid #5D9CEB');
} else if(cur_url[0] == 'add.py' && cur_url[1].split('&')[0] == 'service=nginx#ssl' && link2 == 'add.py?service=nginx#ssl'){ } else if(cur_url[0] == 'add.py' && cur_url[1].split('&')[0] == 'service=nginx#ssl' && link2 == 'add.py?service=nginx#ssl'){
$(this).parent().css('display', 'contents'); $(this).parent().css('display', 'contents');
$(this).parent().css('font-size', '13px'); $(this).parent().css('font-size', '13px');