Pavel Loginov 2022-05-23 21:23:01 +03:00
parent 56b2c8639b
commit ecaff8ef7a
5 changed files with 171 additions and 164 deletions

View File

@ -90,7 +90,7 @@ def return_dict_from_out(server_id, out):
k = k.split(':') k = k.split(':')
data[server_id][k[0]] = k[1].strip() data[server_id][k[0]] = k[1].strip()
else: else:
data[server_id] = {"error":"Cannot connect to HAProxy"} data[server_id] = {"error": "Cannot connect to HAProxy"}
return data return data
@ -130,14 +130,14 @@ def get_server(server_id, service):
for s in servers: for s in servers:
data = { data = {
'server_id':s[0], 'server_id': s[0],
'hostname':s[1], 'hostname': s[1],
'ip':s[2], 'ip': s[2],
'group':s[3], 'group': s[3],
'virt':s[4], 'virt': s[4],
'enable':s[5], 'enable': s[5],
'master':s[6], 'master': s[6],
'creds':s[7] 'creds': s[7]
} }
except: except:
data = '' data = ''
@ -170,8 +170,10 @@ def get_status(server_id, service):
apache_stats_password = sql.get_setting('apache_stats_password') apache_stats_password = sql.get_setting('apache_stats_password')
apache_stats_port = sql.get_setting('apache_stats_port') apache_stats_port = sql.get_setting('apache_stats_port')
apache_stats_page = sql.get_setting('apache_stats_page') apache_stats_page = sql.get_setting('apache_stats_page')
cmd = "curl -s -u %s:%s http://%s:%s/%s?auto |grep 'ServerVersion\|Processes\|ServerUptime:'" % ( cmd = "curl -s -u %s:%s http://%s:%s/%s?auto |grep 'ServerVersion\|Processes\|ServerUptime:'" % \
apache_stats_user, apache_stats_password, s[2], apache_stats_port, apache_stats_page) (
apache_stats_user, apache_stats_password, s[2], apache_stats_port, apache_stats_page
)
servers_with_status = list() servers_with_status = list()
try: try:
out = funct.subprocess_execute(cmd) out = funct.subprocess_execute(cmd)
@ -214,7 +216,7 @@ def get_all_statuses():
out = funct.subprocess_execute(cmd) out = funct.subprocess_execute(cmd)
data[s[2]] = return_dict_from_out(s[1], out[0]) data[s[2]] = return_dict_from_out(s[1], out[0])
except: except:
data = {"error":"Cannot find the server"} data = {"error": "Cannot find the server"}
return dict(error=data) return dict(error=data)
return dict(status=data) return dict(status=data)
@ -484,7 +486,7 @@ def add_to_config(server_id):
data = {server_id: return_mess} data = {server_id: return_mess}
except: except:
data[server_id] = {"error":"cannot find the server"} data[server_id] = {"error": "cannot find the server"}
return dict(error=data) return dict(error=data)
return dict(config=data) return dict(config=data)
@ -520,7 +522,7 @@ def show_log(server_id):
ip = s[2] ip = s[2]
except: except:
data[server_id] = {"error":"Cannot find the server"} data[server_id] = {"error": "Cannot find the server"}
return dict(error=data) return dict(error=data)
out = funct.show_haproxy_log(ip, rows=rows, waf=str(waf), grep=grep, hour=str(hour), minut=str(minute), hour1=str(hour1), minut1=str(minute1), html=0) out = funct.show_haproxy_log(ip, rows=rows, waf=str(waf), grep=grep, hour=str(hour), minut=str(minute), hour1=str(hour1), minut1=str(minute1), html=0)

View File

@ -28,32 +28,40 @@ if service == 'nginx':
if serv: if serv:
if funct.check_is_server_in_group(serv): if funct.check_is_server_in_group(serv):
server_id = sql.select_server_id_by_ip(serv) server_id = sql.select_server_id_by_ip(serv)
history = sql.select_action_history_by_server_id_and_service(server_id, history = sql.select_action_history_by_server_id_and_service(
service) server_id,
service
)
elif service == 'keepalived': elif service == 'keepalived':
if funct.check_login(service=3): if funct.check_login(service=3):
title = 'Keepalived service history' title = 'Keepalived service history'
if serv: if serv:
if funct.check_is_server_in_group(serv): if funct.check_is_server_in_group(serv):
server_id = sql.select_server_id_by_ip(serv) server_id = sql.select_server_id_by_ip(serv)
history = sql.select_action_history_by_server_id_and_service(server_id, history = sql.select_action_history_by_server_id_and_service(
service) server_id,
service
)
elif service == 'apache': elif service == 'apache':
if funct.check_login(service=4): if funct.check_login(service=4):
title = 'Apache service history' title = 'Apache service history'
if serv: if serv:
if funct.check_is_server_in_group(serv): if funct.check_is_server_in_group(serv):
server_id = sql.select_server_id_by_ip(serv) server_id = sql.select_server_id_by_ip(serv)
history = sql.select_action_history_by_server_id_and_service(server_id, history = sql.select_action_history_by_server_id_and_service(
service) server_id,
service
)
elif service == 'haproxy': elif service == 'haproxy':
if funct.check_login(service=1): if funct.check_login(service=1):
title = "HAProxy service history" title = "HAProxy service history"
if serv: if serv:
if funct.check_is_server_in_group(serv): if funct.check_is_server_in_group(serv):
server_id = sql.select_server_id_by_ip(serv) server_id = sql.select_server_id_by_ip(serv)
history = sql.select_action_history_by_server_id_and_service(server_id, history = sql.select_action_history_by_server_id_and_service(
service) server_id,
service
)
elif service == 'server': elif service == 'server':
if serv: if serv:
title = serv + ' history' title = serv + ' history'
@ -67,7 +75,8 @@ elif service == 'user':
users = sql.select_users() users = sql.select_users()
template = template.render(h2=1, template = template.render(
h2=1,
autorefresh=0, autorefresh=0,
title=title, title=title,
role=role, role=role,
@ -77,5 +86,6 @@ template = template.render(h2=1,
service=service, service=service,
history=history, history=history,
user_services=user_services, user_services=user_services,
token=token) token=token
)
print(template) print(template)

View File

@ -17,7 +17,7 @@ try:
geoip_country_codes = sql.select_geoip_country_codes() geoip_country_codes = sql.select_geoip_country_codes()
services = sql.select_services() services = sql.select_services()
gits = sql.select_gits() gits = sql.select_gits()
except Exception as e: except Exception:
pass pass
try: try:

View File

@ -339,22 +339,17 @@ def select_users(**kwargs):
query = User.select().where(User.user_id == kwargs.get("id")) query = User.select().where(User.user_id == kwargs.get("id"))
elif kwargs.get("group") is not None: elif kwargs.get("group") is not None:
query = (User. query = (User.
select( select(User, UserGroups, Case(0, [((
User,
UserGroups,
Case(0, [((
User.last_login_date >= funct.get_data('regular', timedelta_minutes_minus=15) User.last_login_date >= funct.get_data('regular', timedelta_minutes_minus=15)
), 0)], 1).alias('last_login')). ), 0)], 1).
alias('last_login')).
join(UserGroups, on=(User.user_id == UserGroups.user_id)). join(UserGroups, on=(User.user_id == UserGroups.user_id)).
where(UserGroups.user_group_id == kwargs.get("group")) where(UserGroups.user_group_id == kwargs.get("group"))
) )
else: else:
query = User.select( query = User.select(User,Case(0, [((
User,
Case(0, [((
User.last_login_date >= funct.get_data('regular', timedelta_minutes_minus=15) User.last_login_date >= funct.get_data('regular', timedelta_minutes_minus=15)
), 0)], 1).alias('last_login') ), 0)], 1).alias('last_login')).order_by(User.user_id)
).order_by(User.user_id)
try: try:
query_res = query.execute() query_res = query.execute()
@ -823,7 +818,7 @@ def get_dick_permit(**kwargs):
ip = '' ip = ''
if kwargs.get('virt'): if kwargs.get('virt'):
type_ip = "and type_ip = 1" type_ip = ""
else: else:
type_ip = "and type_ip = 0" type_ip = "and type_ip = 0"
if kwargs.get('disable') == 0: if kwargs.get('disable') == 0: