mirror of https://github.com/Aidaho12/haproxy-wi
parent
e2f1cf7896
commit
87fbee9a5e
17
app/funct.py
17
app/funct.py
|
@ -1441,7 +1441,7 @@ def show_backends(server_ip, **kwargs):
|
|||
else:
|
||||
ret = ""
|
||||
for line in output:
|
||||
if "#" in line or "stats" in line or "MASTER" in line:
|
||||
if any(s in line for s in ('#', 'stats', 'MASTER', '<')):
|
||||
continue
|
||||
if len(line) > 1:
|
||||
back = json.dumps(line).split("\"")
|
||||
|
@ -2061,14 +2061,6 @@ def is_docker() -> bool:
|
|||
|
||||
def send_email(email_to: str, subject: str, message: str) -> None:
|
||||
import sql
|
||||
|
||||
mail_ssl = sql.get_setting('mail_ssl')
|
||||
mail_from = sql.get_setting('mail_from')
|
||||
mail_smtp_host = sql.get_setting('mail_smtp_host')
|
||||
mail_smtp_port = sql.get_setting('mail_smtp_port')
|
||||
mail_smtp_user = sql.get_setting('mail_smtp_user')
|
||||
mail_smtp_password = sql.get_setting('mail_smtp_password')
|
||||
|
||||
from smtplib import SMTP
|
||||
|
||||
try:
|
||||
|
@ -2076,7 +2068,12 @@ def send_email(email_to: str, subject: str, message: str) -> None:
|
|||
except Exception:
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from email.message import EmailMessage
|
||||
mail_ssl = sql.get_setting('mail_ssl')
|
||||
mail_from = sql.get_setting('mail_from')
|
||||
mail_smtp_host = sql.get_setting('mail_smtp_host')
|
||||
mail_smtp_port = sql.get_setting('mail_smtp_port')
|
||||
mail_smtp_user = sql.get_setting('mail_smtp_user')
|
||||
mail_smtp_password = sql.get_setting('mail_smtp_password')
|
||||
|
||||
msg = MIMEText(message)
|
||||
msg['Subject'] = 'Roxy-WI: ' + subject
|
||||
|
|
|
@ -101,8 +101,8 @@ def send_cookie(login):
|
|||
sql.update_user_name(user_name)
|
||||
else:
|
||||
sql.insert_user_name(user_name)
|
||||
except Exception:
|
||||
funct.logging('Cannot update sbscription ', str(e), haproxywi=1)
|
||||
except Exception as e:
|
||||
funct.logging('Cannot update subscription: ', str(e), haproxywi=1)
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
|
|
@ -1830,8 +1830,17 @@ if form.getvalue('metrics_hapwi_ram'):
|
|||
rams = ''
|
||||
|
||||
if ip == '1':
|
||||
cmd = "free -m |grep Mem |awk '{print $2,$3,$4,$5,$6,$7}'"
|
||||
metric, error = funct.subprocess_execute(cmd)
|
||||
# cmd = "free -m |grep Mem |awk '{print $2,$3,$4,$5,$6,$7}'"
|
||||
# metric, error = funct.subprocess_execute(cmd)
|
||||
import psutil
|
||||
|
||||
rams_list = psutil.virtual_memory()
|
||||
rams += str(round(rams_list.total/1048576, 2)) + ' '
|
||||
rams += str(round(rams_list.used/1048576, 2)) + ' '
|
||||
rams += str(round(rams_list.free/1048576, 2)) + ' '
|
||||
rams += str(round(rams_list.shared/1048576, 2)) + ' '
|
||||
rams += str(round(rams_list.cached/1048576, 2)) + ' '
|
||||
rams += str(round(rams_list.available/1048576, 2)) + ' '
|
||||
else:
|
||||
commands = ["free -m |grep Mem |awk '{print $2,$3,$4,$5,$6,$7}'"]
|
||||
metric, error = funct.subprocess_execute(commands[0])
|
||||
|
@ -1851,8 +1860,19 @@ if form.getvalue('metrics_hapwi_cpu'):
|
|||
cpus = ''
|
||||
|
||||
if ip == '1':
|
||||
cmd = "top -b -n 1 |grep Cpu |awk -F':' '{print $2}'|awk -F' ' 'BEGIN{ORS=\" \";} { for (i=1;i<=NF;i+=2) print $i}'"
|
||||
metric, error = funct.subprocess_execute(cmd)
|
||||
# cmd = "top -b -n 1 |grep Cpu |awk -F':' '{print $2}'|awk -F' ' 'BEGIN{ORS=\" \";} { for (i=1;i<=NF;i+=2) print $i}'"
|
||||
# metric, error = funct.subprocess_execute(cmd)
|
||||
import psutil
|
||||
|
||||
cpus_list = psutil.cpu_times_percent(interval=1, percpu=False)
|
||||
cpus += str(cpus_list.user) + ' '
|
||||
cpus += str(cpus_list.system) + ' '
|
||||
cpus += str(cpus_list.nice) + ' '
|
||||
cpus += str(cpus_list.idle) + ' '
|
||||
cpus += str(cpus_list.iowait) + ' '
|
||||
cpus += str(cpus_list.irq) + ' '
|
||||
cpus += str(cpus_list.softirq) + ' '
|
||||
cpus += str(cpus_list.steal) + ' '
|
||||
else:
|
||||
commands = [
|
||||
"top -b -n 1 |grep Cpu |awk -F':' '{print $2}'|awk -F' ' 'BEGIN{ORS=\" \";} { for (i=1;i<=NF;i+=2) print $i}'"]
|
||||
|
@ -4447,8 +4467,7 @@ if form.getvalue('updateHaproxyCheckerSettings'):
|
|||
slack_id = form.getvalue('slack_id')
|
||||
|
||||
if sql.update_haproxy_checker_settings(email, telegram_id, slack_id, service_alert, backend_alert,
|
||||
maxconn_alert, setting_id
|
||||
):
|
||||
maxconn_alert, setting_id):
|
||||
print('ok')
|
||||
else:
|
||||
print('error: Cannot update Checker settings')
|
||||
|
|
Loading…
Reference in New Issue