2019-09-22 15:46:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import funct, sql
|
|
|
|
import os, http.cookies
|
2019-10-25 07:18:57 +00:00
|
|
|
import cgi
|
2019-09-22 15:46:26 +00:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
env = Environment(loader=FileSystemLoader('templates/'))
|
|
|
|
template = env.get_template('hapservers.html')
|
|
|
|
|
|
|
|
print('Content-type: text/html\n')
|
2019-10-01 05:35:05 +00:00
|
|
|
funct.check_login()
|
2019-09-22 15:46:26 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
|
|
|
user_id = cookie.get('uuid')
|
|
|
|
user = sql.get_user_name_by_uuid(user_id.value)
|
|
|
|
users = sql.select_users()
|
|
|
|
groups = sql.select_groups()
|
|
|
|
token = sql.get_token(user_id.value)
|
2019-10-14 06:55:29 +00:00
|
|
|
cmd = "ps ax |grep -e 'keep_alive.py' |grep -v grep |wc -l"
|
|
|
|
keep_alive, stderr = funct.subprocess_execute(cmd)
|
2019-09-22 15:46:26 +00:00
|
|
|
except:
|
|
|
|
pass
|
2019-10-25 07:18:57 +00:00
|
|
|
|
|
|
|
form = cgi.FieldStorage()
|
|
|
|
serv = form.getvalue('serv')
|
2019-09-22 15:46:26 +00:00
|
|
|
|
2019-10-25 07:18:57 +00:00
|
|
|
if serv:
|
|
|
|
servers = sql.select_servers(server=serv)
|
|
|
|
autorefresh = 1
|
2019-11-11 21:59:09 +00:00
|
|
|
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
2019-10-25 07:18:57 +00:00
|
|
|
else:
|
|
|
|
servers = sql.get_dick_permit()
|
|
|
|
autorefresh = 0
|
|
|
|
|
2019-09-22 15:46:26 +00:00
|
|
|
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
|
2019-10-14 06:55:29 +00:00
|
|
|
haproxy_config_path = sql.get_setting('haproxy_config_path')
|
|
|
|
commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]
|
2019-09-22 15:46:26 +00:00
|
|
|
servers_with_status1 = []
|
|
|
|
out1 = ""
|
|
|
|
for s in servers:
|
|
|
|
servers_with_status = list()
|
2019-09-22 17:41:01 +00:00
|
|
|
cmd = 'echo "show info" |nc %s %s -w 1 |grep -e "Ver\|Uptime:\|Process_num"' % (s[2], haproxy_sock_port)
|
2019-09-22 15:46:26 +00:00
|
|
|
out = funct.subprocess_execute(cmd)
|
|
|
|
servers_with_status.append(s[0])
|
|
|
|
servers_with_status.append(s[1])
|
|
|
|
servers_with_status.append(s[2])
|
|
|
|
servers_with_status.append(s[11])
|
|
|
|
for k in out:
|
2019-10-04 06:23:48 +00:00
|
|
|
if "Ncat:" not in k:
|
2019-09-22 15:46:26 +00:00
|
|
|
out1 = out
|
|
|
|
else:
|
|
|
|
out1 = False
|
|
|
|
servers_with_status.append(out1)
|
2019-10-14 06:55:29 +00:00
|
|
|
servers_with_status.append(s[12])
|
|
|
|
try:
|
|
|
|
servers_with_status.append(funct.ssh_command(s[2], commands))
|
|
|
|
except:
|
|
|
|
servers_with_status.append('Cannot get last date')
|
|
|
|
|
2019-11-11 21:59:09 +00:00
|
|
|
if serv:
|
|
|
|
try:
|
|
|
|
sections = funct.get_sections(hap_configs_dir +funct.get_files()[0])
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
cfg = hap_configs_dir + s[2] + "-" + funct.get_data('config') + ".cfg"
|
|
|
|
error = funct.get_config(s[2], cfg)
|
|
|
|
sections = funct.get_sections(cfg)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
servers_with_status.append(sections)
|
|
|
|
|
2019-09-22 15:46:26 +00:00
|
|
|
servers_with_status1.append(servers_with_status)
|
2019-10-25 07:18:57 +00:00
|
|
|
|
2019-09-22 15:46:26 +00:00
|
|
|
|
|
|
|
template = template.render(h2 = 1,
|
2019-10-25 07:18:57 +00:00
|
|
|
autorefresh = autorefresh,
|
2019-09-22 15:46:26 +00:00
|
|
|
title = "HAProxy servers overview",
|
|
|
|
role = sql.get_user_role_by_uuid(user_id.value),
|
|
|
|
user = user,
|
|
|
|
users = users,
|
|
|
|
groups = groups,
|
|
|
|
servers = servers_with_status1,
|
|
|
|
versions = funct.versions(),
|
2019-10-14 06:55:29 +00:00
|
|
|
keep_alive = ''.join(keep_alive),
|
2019-10-25 07:18:57 +00:00
|
|
|
serv = serv,
|
2019-09-22 15:46:26 +00:00
|
|
|
token = token)
|
|
|
|
print(template)
|