New logs, bugs fixed
pull/26/head
Aidaho12 2018-07-24 10:08:06 +06:00
parent aecebbb49e
commit 897e3dd126
11 changed files with 61 additions and 115 deletions

View File

@ -1,50 +0,0 @@
#!/usr/bin/env python3
import html
import cgi
import funct
import sql
import os, http
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('logs.html')
form = cgi.FieldStorage()
if form.getvalue('grep') is None:
grep = ""
else:
grep = form.getvalue('grep')
if form.getvalue('rows') is None:
rows = 10
else:
rows = form.getvalue('rows')
print('Content-type: text/html\n')
funct.check_login()
funct.page_for_admin()
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)
servers = [('haproxy-wi.error.log','error.log'), ('haproxy-wi.access.log','access.log')]
token = sql.get_token(user_id.value)
except:
pass
output_from_parsed_template = template.render(h2 = 1,
autorefresh = 1,
title = "Show Apache logs",
role = sql.get_user_role_by_uuid(user_id.value),
user = user,
onclick = "showApacheLog()",
select_id = "serv",
selects = servers,
serv = form.getvalue('serv'),
rows = rows,
grep = grep,
token = token)
print(output_from_parsed_template)

View File

@ -55,6 +55,7 @@ haproxy_dir = /etc/haproxy
haproxy_config_path = ${haproxy_dir}/haproxy.cfg
server_state_file = ${haproxy_dir}/haproxy.state
haproxy_sock = /var/run/haproxy.sock
haproxy_sock_port = 1999
#Temp store configs, for haproxy check
tmp_config_path = /tmp/
cert_path = /etc/ssl/certs/

View File

@ -202,8 +202,12 @@ if serv is not None and form.getvalue('rows1') is not None:
else:
grep_act = ''
grep = ''
cmd="cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % ('/var/log/httpd/'+serv, date, date1, rows, grep_act, grep)
if serv == 'haproxy-wi.access.log':
cmd="cat %s| awk -F\"/|:\" '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % ('/var/log/httpd/'+serv, date, date1, rows, grep_act, grep)
else:
cmd="cat %s| awk '$4>\"%s:00\" && $4<\"%s:00\"' |tail -%s %s %s" % ('/var/log/httpd/'+serv, date, date1, rows, grep_act, grep)
output, stderr = funct.subprocess_execute(cmd)
funct.show_log(output)

View File

@ -89,15 +89,14 @@
<li><a href=/app/users.py#roles title="Users roles" class="role head-submenu">Roles</a></li>
<li><a href=/app/users.py#ssh title="Manage SSH credentials" class="admin head-submenu">SSH credentials</a></li>
<li><a href=/app/settings.py title="View settings" class="settings head-submenu">View settings</a></li>
<li><a href=/app/viewlogs.py title="View users actions logs" class="logs head-submenu">Users logs</a></li>
<li><a href=/app/apachelogs.py title="View Apache logs" class="logs head-submenu">Apache logs</a></li>
<li><a href=/app/viewlogs.py title="View internal logs" class="logs head-submenu">Internal logs</a></li>
</li>
{% endif %}
{% endif %}
</ul>
</nav>
<div class="copyright-menu">
HAproxy-WI v2.7
HAproxy-WI v2.7.1
<br>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
</div>

View File

@ -1,12 +1,10 @@
{% extends "base.html" %}
{% block content %}
{% if onclick == 'showApacheLog()' %}
<script src="/inc/users.js"></script>
{% endif %}
<table class="overview">
<tr class="overviewHead">
<td class="padding10 first-collumn" style="width: 10%;">
{% if onclick == 'showApacheLog()' %}
{% if onclick == 'viewLogs()' %}
Log
{% else %}
Server
@ -25,7 +23,7 @@
<td class="padding10 first-collumn" style="width: 10%;">
<form action="logs.py" method="get">
<select autofocus required name="serv" id="{{ select_id }}">
{% if onclick == 'showApacheLog()' or onclick == 'viewLogs()' %}
{% if onclick == 'viewLogs()' %}
<option disabled selected>Choose log</option>
{% for select in selects %}
{% if select.2 == serv %}
@ -63,18 +61,4 @@
</table>
<div id="ajax">
</div>
<script>
{% if onclick == 'showApacheLog()' %}
window.onload = showApacheLog()
$('#serv').on('selectmenuchange',function() {
showApacheLog();
});
{% else %}
window.onload = showLog()
$('#serv').on('selectmenuchange',function() {
showLog();
});
{% endif %}
</script>
{% endblock %}

View File

@ -37,21 +37,22 @@ def main():
start_worker(serv)
def start_worker(serv):
cmd = "tools/checker_worker.py %s &" % serv
port = funct.get_config_var('haproxy', 'haproxy_sock_port')
cmd = "tools/checker_worker.py %s --port %s &" % (serv, port)
os.system(cmd)
funct.logging("localhost", " Start new worker for: "+serv, alerting=1)
funct.logging("localhost", " Masrer started new worker for: "+serv, alerting=1)
def kill_worker(serv):
cmd = "ps ax |grep 'tools/checker_worker.py %s'|grep -v grep |awk '{print $1}' |xargs kill" % serv
output, stderr = funct.subprocess_execute(cmd)
funct.logging("localhost", " Kill worker for: "+serv, alerting=1)
funct.logging("localhost", "Masrer killed worker for: "+serv, alerting=1)
if stderr:
funct.logging("localhost", stderr, alerting=1)
def kill_all_workers():
cmd = "ps ax |grep 'tools/checker_worker.py' |grep -v grep |awk '{print $1}' |xargs kill"
output, stderr = funct.subprocess_execute(cmd)
funct.logging("localhost", " Killed all workers", alerting=1)
funct.logging("localhost", " Masrer killing all workers", alerting=1)
if stderr:
funct.logging("localhost", stderr, alerting=1)

View File

@ -19,8 +19,8 @@ class GracefulKiller:
def main(serv, port):
port = str(port)
firstrun = True
currentstat=[]
readstats=""
currentstat = []
readstats = ""
killer = GracefulKiller()
while True:
@ -44,18 +44,18 @@ def main(serv, port):
if firstrun == False:
if (currentstat[i] != oldstat[i] and currentstat[i]!="none") and ("FRONTEND" not in str(vips[i]) and "BACKEND" not in str(vips[i])):
servername= str(vips[i])
servername=servername.split(",")
servername = str(vips[i])
servername = servername.split(",")
realserver = servername[0]
alert=realserver[2:]+ " has changed status and is now "+ currentstat[i] + " at " + serv
alert = realserver[2:]+ " has changed status and is now "+ currentstat[i] + " at " + serv
funct.telegram_send_mess(str(alert))
firstrun=False
oldstat=[]
oldstat=currentstat
currentstat=[]
time.sleep(30)
funct.logging("localhost", " "+alert, alerting=1)
firstrun = False
oldstat = []
oldstat = currentstat
currentstat = []
time.sleep(60)
if killer.kill_now:
break

View File

@ -46,6 +46,7 @@ try:
user_id = cookie.get('uuid')
user = sql.get_user_name_by_uuid(user_id.value)
token = sql.get_token(user_id.value)
servers = [('haproxy-wi.error.log','error.log'), ('haproxy-wi.access.log','access.log')]
except:
pass
@ -55,6 +56,9 @@ def get_files():
file += [(files.split('/')[5], files.split('/')[5])]
return sorted(file, reverse=True)
selects = get_files()
selects.append(['haproxy-wi.error.log','error.log'])
selects.append(['haproxy-wi.access.log','access.log'])
output_from_parsed_template = template.render(h2 = 1,
autorefresh = 1,
title = "View logs",
@ -63,7 +67,7 @@ output_from_parsed_template = template.render(h2 = 1,
onclick = "viewLogs()",
serv = form.getvalue('viewlogs'),
select_id = "viewlogs",
selects = get_files(),
selects = selects,
rows = rows,
grep = grep,
token = token)

View File

@ -50,6 +50,7 @@ function setRefreshInterval(interval) {
Cookies.remove('auto-refresh');
pauseAutoRefresh();
$('.auto-refresh').prepend('<img src=/image/pic/update.png alt="restart" class="icon">');
$('.auto-refresh').css('margin-top', '-3px');
$('#1').text('Auto-refresh');
$('#0').text('Auto-refresh');
$('.auto-refresh-pause').css('display', 'none');
@ -80,10 +81,7 @@ function startSetInterval(interval) {
} else if (cur_url[0] == "viewlogs.py") {
intervalId = setInterval('viewLogs()', interval);
viewLogs();
} else if (cur_url[0] == "apachelogs.py") {
intervalId = setInterval('showApacheLog()', interval);
showApacheLog();
}
}
}
function pauseAutoRefresh() {
clearInterval(intervalId);
@ -291,24 +289,29 @@ function showUploadConfig() {
} );
}
function viewLogs() {
$.ajax( {
url: "options.py",
data: {
viewlogs: $('#viewlogs').val(),
rows2: $('#rows').val(),
grep: $("#grep").val(),
hour: $('#time_range_out_hour').val(),
minut: $('#time_range_out_minut').val(),
hour1: $('#time_range_out_hour1').val(),
minut1: $('#time_range_out_minut1').val(),
token: $('#token').val()
},
type: "GET",
success: function( data ) {
$("#ajax").html(data);
window.history.pushState("View logs", "View logs", cur_url[0]+"?viewlogs="+$("#viewlogs").val());
}
} );
if($('#viewlogs').val() == 'haproxy-wi.error.log' || $('#viewlogs').val() == 'haproxy-wi.access.log') {
showApacheLog($('#viewlogs').val());
} else {
$.ajax( {
url: "options.py",
data: {
viewlogs: $('#viewlogs').val(),
rows2: $('#rows').val(),
grep: $("#grep").val(),
hour: $('#time_range_out_hour').val(),
minut: $('#time_range_out_minut').val(),
hour1: $('#time_range_out_hour1').val(),
minut1: $('#time_range_out_minut1').val(),
token: $('#token').val(),
},
type: "GET",
success: function( data ) {
$("#ajax").html(data);
window.history.pushState("View logs", "View logs", cur_url[0]+"?viewlogs="+$("#viewlogs").val());
}
} );
}
}
$( function() {

View File

@ -84,7 +84,7 @@ pre {
margin-top: 5px;
margin-left: 14px;
margin-right: 15px;
color: #fff;
color: #fff !important;
font-size: 15px;
}
.auto-refresh {

View File

@ -653,12 +653,12 @@ function updateSSH(id) {
}
} );
}
function showApacheLog() {
function showApacheLog(serv) {
$.ajax( {
url: "options.py",
data: {
rows1: $('#rows').val(),
serv: $("#serv").val(),
serv: serv,
grep: $("#grep").val(),
hour: $('#time_range_out_hour').val(),
minut: $('#time_range_out_minut').val(),