Pavel Loginov 2020-09-26 23:37:14 +06:00
parent e5d2626b05
commit b5b9bff29b
7 changed files with 1902 additions and 1876 deletions

View File

@ -66,6 +66,7 @@ def get_user_group(**kwargs):
return user_group
def logging(serv, action, **kwargs):
import sql
import http.cookies
@ -203,7 +204,7 @@ def page_for_admin(**kwargs):
def return_ssh_keys_path(serv, **kwargs):
import sql
fullpath = get_config_var('main', 'fullpath')
full_path = get_config_var('main', 'fullpath')
ssh_enable = ''
ssh_user_name = ''
ssh_user_password = ''
@ -213,13 +214,13 @@ def return_ssh_keys_path(serv, **kwargs):
ssh_enable = sshs[2]
ssh_user_name = sshs[3]
ssh_user_password = sshs[4]
ssh_key_name = fullpath+'/keys/%s.pem' % sshs[1]
ssh_key_name = full_path+'/keys/%s.pem' % sshs[1]
else:
for sshs in sql.select_ssh(serv=serv):
ssh_enable = sshs[3]
ssh_user_name = sshs[4]
ssh_user_password = sshs[5]
ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2]
ssh_key_name = full_path+'/keys/%s.pem' % sshs[2]
return ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name
@ -325,7 +326,6 @@ def diff_config(oldcfg, cfg):
def get_sections(config, **kwargs):
record = False
return_config = list()
with open(config, 'r') as f:
for line in f:
@ -390,8 +390,8 @@ def get_section_from_config(config, section):
if end_line == "":
f = open(config, "r")
lineList = f.readlines()
end_line = len(lineList)
line_list = f.readlines()
end_line = len(line_list)
return start_line, end_line, return_config
@ -423,7 +423,6 @@ def rewrite_section(start_line, end_line, config, section):
def get_backends_from_config(serv, backends='', **kwargs):
configs_dir = get_config_var('configs', 'haproxy_save_configs_dir')
format = 'cfg'
record = False
try:
cfg = configs_dir+get_files(dir=configs_dir, format=format)[0]
@ -450,23 +449,23 @@ def get_backends_from_config(serv, backends='', **kwargs):
def get_all_stick_table():
import sql
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
cmd='echo "show table"|nc %s %s |awk \'{print $3}\' | tr -d \'\n\' | tr -d \'[:space:]\'' % (serv, haproxy_sock_port)
hap_sock_p = sql.get_setting('hap_sock_p')
cmd = 'echo "show table"|nc %s %s |awk \'{print $3}\' | tr -d \'\n\' | tr -d \'[:space:]\'' % (serv, hap_sock_p)
output, stderr = subprocess_execute(cmd)
return output[0]
def get_stick_table(table):
import sql
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
cmd='echo "show table %s"|nc %s %s |awk -F"#" \'{print $2}\' |head -1 | tr -d \'\n\'' % (table, serv, haproxy_sock_port)
hap_sock_p = sql.get_setting('hap_sock_p')
cmd = 'echo "show table %s"|nc %s %s |awk -F"#" \'{print $2}\' |head -1 | tr -d \'\n\'' % (table, serv, hap_sock_p)
output, stderr = subprocess_execute(cmd)
tables_head = []
for i in output[0].split(','):
i = i.split(':')[1]
tables_head.append(i)
cmd='echo "show table %s"|nc %s %s |grep -v "#"' % (table, serv, haproxy_sock_port)
cmd = 'echo "show table %s"|nc %s %s |grep -v "#"' % (table, serv, hap_sock_p)
output, stderr = subprocess_execute(cmd)
return tables_head, output
@ -475,7 +474,7 @@ def get_stick_table(table):
def install_haproxy(serv, **kwargs):
import sql
script = "install_haproxy.sh"
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
hap_sock_p = sql.get_setting('hap_sock_p')
stats_port = sql.get_setting('stats_port')
server_state_file = sql.get_setting('server_state_file')
stats_user = sql.get_setting('stats_user')
@ -504,10 +503,10 @@ def install_haproxy(serv, **kwargs):
syn_flood_protect = '1' if kwargs.get('syn_flood') == "1" else ''
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv +
" SOCK_PORT="+haproxy_sock_port+" STAT_PORT="+stats_port+" STAT_FILE="+server_state_file+
" SSH_PORT="+ssh_port+
" STATS_USER="+stats_user+" STATS_PASS="+stats_password+" HAPVER="+hapver +" SYN_FLOOD="+syn_flood_protect+" HOST="+serv+
" USER="+ssh_user_name+" PASS="+ssh_user_password+" KEY="+ssh_key_name ]
" SOCK_PORT=" + hap_sock_p + " STAT_PORT=" + stats_port + " STAT_FILE="+server_state_file +
" SSH_PORT=" + ssh_port + " STATS_USER=" + stats_user +
" STATS_PASS=" + stats_password + " HAPVER=" + hapver + " SYN_FLOOD=" + syn_flood_protect +
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
output, error = subprocess_execute(commands[0])
@ -589,10 +588,10 @@ def install_nginx(serv):
syn_flood_protect = '1' if form.getvalue('syn_flood') == "1" else ''
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+" STATS_USER="+stats_user+" STATS_PASS="+stats_password+
" SSH_PORT="+ssh_port+
" CONFIG_PATH="+config_path+" STAT_PORT="+stats_port+" STAT_PAGE="+stats_page+" SYN_FLOOD="+syn_flood_protect+" HOST="+serv+
" USER="+ssh_user_name+" PASS="+ssh_user_password+" KEY="+ssh_key_name ]
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " STATS_USER=" + stats_user +
" STATS_PASS=" + stats_password + " SSH_PORT="+ ssh_port + " CONFIG_PATH=" + config_path +
" STAT_PORT=" + stats_port +" STAT_PAGE=" + stats_page+" SYN_FLOOD=" + syn_flood_protect +
" HOST="+ serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
output, error = subprocess_execute(commands[0])
@ -628,9 +627,9 @@ def update_haproxy_wi(service):
def check_haproxy_version(serv):
import sql
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
hap_sock_p = sql.get_setting('hap_sock_p')
ver = ""
cmd="echo 'show info' |nc %s %s |grep Version |awk '{print $2}'" % (serv, haproxy_sock_port)
cmd = "echo 'show info' |nc %s %s |grep Version |awk '{print $2}'" % (serv, hap_sock_p)
output, stderr = subprocess_execute(cmd)
for line in output:
ver = line
@ -741,9 +740,9 @@ def upload_and_restart(serv, cfg, **kwargs):
def master_slave_upload_and_restart(serv, cfg, just_save, **kwargs):
import sql
MASTERS = sql.is_master(serv)
masters = sql.is_master(serv)
error = ""
for master in MASTERS:
for master in masters:
if master[0] != None:
error += upload_and_restart(master[0], cfg, just_save=just_save, nginx=kwargs.get('nginx'))
@ -822,7 +821,7 @@ def show_log(stdout, **kwargs):
if kwargs.get("html") != 0:
i = i + 1
if kwargs.get('grep'):
line = line.replace(grep, '<span style="color: red; font-weight: bold;">'+grep+'</span>');
line = line.replace(grep, '<span style="color: red; font-weight: bold;">'+grep+'</span>')
line_class = "line3" if i % 2 == 0 else "line"
out += '<div class="'+line_class+'">' + line + '</div>'
else:
@ -1007,8 +1006,8 @@ def subprocess_execute(cmd):
def show_backends(serv, **kwargs):
import json
import sql
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
cmd='echo "show backend" |nc %s %s' % (serv, haproxy_sock_port)
hap_sock_p = sql.get_setting('hap_sock_p')
cmd = 'echo "show backend" |nc %s %s' % (serv, hap_sock_p)
output, stderr = subprocess_execute(cmd)
if stderr:
logging('localhost', ' '+stderr, haproxywi=1)
@ -1176,7 +1175,6 @@ def check_user_group(**kwargs):
logging('localhost', ' has tried to actions in not his group ', haproxywi=1, login=1)
print('Atata!')
sys.exit()
return False
def check_is_server_in_group(serv):
@ -1190,7 +1188,6 @@ def check_is_server_in_group(serv):
logging('localhost', ' has tried to actions in not his group server ', haproxywi=1, login=1)
print('Atata!')
sys.exit()
return False
def check_service(serv, service_name):

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python3
import funct, sql
import funct
import sql
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True)
template = env.get_template('hapservers.html')
@ -11,6 +14,7 @@ try:
user, user_id, role, token, servers = funct.get_users_params()
users = sql.select_users()
groups = sql.select_groups()
services = []
except:
pass
@ -41,6 +45,19 @@ else:
else:
servers = sql.get_dick_permit(virt=1, haproxy=1)
services_name = {'checker_haproxy': 'Master backends checker service',
'keep_alive': 'Auto start service',
'metrics_haproxy': 'Master metrics service'}
for s, v in services_name.items():
if s != 'keep_alive':
service_name = s.split('_')[0]
else:
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/-/./'"
service_ver, stderr = funct.subprocess_execute(cmd)
services.append([s, service_ver[0]])
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
servers_with_status1 = []
out1 = ''
@ -51,7 +68,8 @@ for s in servers:
servers_with_status.append(s[2])
servers_with_status.append(s[11])
if service == 'nginx':
cmd = [ "/usr/sbin/nginx -v && systemctl status nginx |grep -e 'Active' |awk '{print $2, $9$10$11$12$13}' && ps ax |grep nginx:|grep -v grep |wc -l" ]
cmd = [
"/usr/sbin/nginx -v && systemctl status nginx |grep -e 'Active' |awk '{print $2, $9$10$11$12$13}' && ps ax |grep nginx:|grep -v grep |wc -l"]
out = funct.ssh_command(s[2], cmd)
h = ()
out1 = []
@ -76,7 +94,6 @@ for s in servers:
servers_with_status1.append(servers_with_status)
template = template.render(h2=1,
autorefresh=autorefresh,
title=title,
@ -89,5 +106,6 @@ template = template.render(h2 = 1,
keep_alive=''.join(keep_alive),
serv=serv,
service=service,
services=services,
token=token)
print(template)

View File

@ -11,6 +11,13 @@ funct.check_login()
try:
user, user_id, role, token, servers = funct.get_users_params()
cmd = "rpm --query haproxy-wi-metrics-* |awk -F\"metrics_haproxy\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'"
service_ver, stderr = funct.subprocess_execute(cmd)
if service_ver[0] == '* is not installed':
servers = ''
else:
servers = sql.select_servers_metrics(user_id.value)
except:
pass
@ -19,7 +26,8 @@ template = template.render(h2 = 1, title = "Metrics",
autorefresh=1,
role=role,
user=user,
servers = sql.select_servers_metrics(user_id.value),
servers=servers,
versions=funct.versions(),
services=service_ver[0],
token=token)
print(template)

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,17 @@
}
}
});
{% for s in services %}
{% if s.1 == '* is not installed' %}
{% if s.0 == 'checker_haproxy' %}
$(':regex(id, alert)').checkboxradio('disable');
{% elif s.0 == 'keep_alive' %}
$(':regex(id, active-)').checkboxradio('disable');
{% elif s.0 == 'metrics_haproxy' %}
$(':regex(id, metrics-)').checkboxradio('disable');
{% endif %}
{% endif %}
{% endfor %}
});
</script>
{% if serv %}
@ -165,19 +176,19 @@
{% if role <= 2 %}
{% set id = 'alert-' + s.8.0.0|string() %}
{% if s.8.0.8 == 1 %}
{{ checkbox(id, title='Enable alerting', value='1', desc='Alert', checked='checked') }}
{{ checkbox(id, title='Alerting is enabled', value='1', desc='Alert', checked='checked') }}
{% else %}
{{ checkbox(id, title='Enable alerting', value='1', desc='Alert') }}
{% endif %}
{% set id = 'metrics-' + s.8.0.0|string() %}
{% if s.8.0.9 == 1 %}
{{ checkbox(id, title='Enable collect metrics', value='1', desc='Metrics', checked='checked') }}
{{ checkbox(id, title='Collecting metrics is enabled', value='1', desc='Metrics', checked='checked') }}
{% else %}
{{ checkbox(id, title='Enable collect metrics', value='1', desc='Metrics') }}
{% endif %}
{% set id = 'active-' + s.8.0.0|string() %}
{% if s.8.0.12 == 1 %}
{{ checkbox(id, title='Enable Compression', value='1', desc='Auto Start', checked='checked') }}
{{ checkbox(id, title='Auto Start is enabled', value='1', desc='Auto Start', checked='checked') }}
{% else %}
{{ checkbox(id, title='Enable Auto Start', value='1', desc='Auto Start') }}
{% endif %}

View File

@ -1,3 +1,6 @@
{% for s in services %}
{% if s.0 == 'checker_haproxy' %}
{% if s.3 != '* is not installed' %}
<table id="checker_table" class="overview">
<tr class="overviewHead" style="width: 50%;">
<td class="padding10 first-collumn" style="width: 25%;">
@ -49,3 +52,13 @@
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
You can read the description of all parameters <a href="https://haproxy-wi.org/description.py?description=checker" title="Servers description" target="_blank">here</a>
</div>
{% else %}
<center>
<h4 style="font-size: 25px">Welcome and let's get started!</h4>
You do not have installed Backends checker.
Read <a href="https://haproxy-wi.org/services.py?service=checker#installation" title="Checker installation" style="color: #5d9ceb;" target="_blank">hear</a>
how to install it
</center>
{% endif %}
{% endif %}
{% endfor %}

View File

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% block content %}
<style>
table, th, tr, td {
border: 1px solid #ddd;
@ -15,6 +16,15 @@ th, tr, td {
<link href="/inc/chart.min.css" rel="stylesheet">
<script src="/inc/metrics.js"></script>
<script src="/inc/chart.min.js"></script>
{% if services == '* is not installed' %}
<center>
<h4 style="font-size: 25px">Welcome and let's get started!</h4>
You do not have installed Metrics service.
Read <a href="https://haproxy-wi.org/services.py?service=metrics#installation" title="Metrics installation" style="color: #5d9ceb;" target="_blank">hear</a>
how to install it
</center>
{% else %}
{% if servers|length == 0 %}
{% include 'include/getstarted.html' %}
{% else %}
@ -43,4 +53,5 @@ th, tr, td {
showMetrics()
</script>
{% endif %}
{% endif %}
{% endblock %}