Esempio n. 1
0
async def async_get_overviewServers(serv1, serv2, desc):
    # commands =  [ "top -u haproxy -b -n 1" ]
    # commands =  [ "top -u haproxy -b -n 1 -o %MEM |grep -e 'haproxy\|PID' |awk '{print $1\"\t\"$5\"\t\"$9\"\t\"$10\"\t\"$11}'" ]
    commands = [
        "top -u haproxy -b -n 1 -w 67 |grep -e 'haproxy\|PID\|Cpu\|KiB' |grep -v Swap"
    ]
    if desc == "hapservers.py":
        cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:"' % (
            serv2, haproxy_sock_port)
    else:
        cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % (
            serv2, haproxy_sock_port)
    out = funct.subprocess_execute(cmd)
    out1 = ""
    user_id = cookie.get('uuid')
    role = sql.get_user_role_by_uuid(user_id.value)
    hap_configs_dir = funct.get_config_var('configs',
                                           'haproxy_save_configs_dir')
    cfg = hap_configs_dir + serv2 + "-" + funct.get_data('config') + ".cfg"
    funct.get_config(serv2, cfg)
    backends = funct.get_sections(cfg)
    os.system("/bin/rm -f " + cfg)

    for k in out:
        if "Ncat: Connection refused." not in k and "Ncat: Connection timed out." not in k:
            for r in k:
                out1 += r
                out1 += "<br />"
        else:
            out1 = "Can\'t connect to HAproxy"

    if role <= 2:
        server_status = (serv1, serv2, out1,
                         funct.ssh_command(serv2, commands), backends, desc)
    else:
        server_status = (serv1, serv2, out1,
                         funct.ssh_command(serv2, commands),
                         funct.show_backends(serv2, ret=1), desc)

    return server_status
Esempio n. 2
0
    servers_with_status.append(s[11])
    for k in out:
        if "Ncat:" not in k:
            out1 = out
        else:
            out1 = False
        servers_with_status.append(out1)
    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')

    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)

    servers_with_status1.append(servers_with_status)

template = template.render(h2=1,
                           autorefresh=autorefresh,
                           title="HAProxy servers overview",
Esempio n. 3
0
error = ""
aftersave = ""
start_line = ""
end_line = ""

try:
	user, user_id, role, token, servers = funct.get_users_params()
except Exception:
	pass

hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')

if serv is not None and open is not None:
	cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
	error = funct.get_config(serv, cfg)
	sections = funct.get_sections(cfg)

if serv is not None and section is not None:
	
	try:
		funct.logging(serv, "sections.py open config")
	except Exception:
		pass
	
	start_line, end_line, config_read = funct.get_section_from_config(cfg, section)

	os.system("/bin/mv %s %s.old" % (cfg, cfg))	

if serv is not None and form.getvalue('config') is not None:
	try:
		funct.logging(serv, "config.py edited config")