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 haproxy_config_path = ${haproxy_dir}/haproxy.cfg
server_state_file = ${haproxy_dir}/haproxy.state server_state_file = ${haproxy_dir}/haproxy.state
haproxy_sock = /var/run/haproxy.sock haproxy_sock = /var/run/haproxy.sock
haproxy_sock_port = 1999
#Temp store configs, for haproxy check #Temp store configs, for haproxy check
tmp_config_path = /tmp/ tmp_config_path = /tmp/
cert_path = /etc/ssl/certs/ cert_path = /etc/ssl/certs/

View File

@ -202,8 +202,12 @@ if serv is not None and form.getvalue('rows1') is not None:
else: else:
grep_act = '' grep_act = ''
grep = '' 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) output, stderr = funct.subprocess_execute(cmd)
funct.show_log(output) 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#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/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/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/viewlogs.py title="View internal logs" class="logs head-submenu">Internal logs</a></li>
<li><a href=/app/apachelogs.py title="View Apache logs" class="logs head-submenu">Apache logs</a></li>
</li> </li>
{% endif %} {% endif %}
{% endif %} {% endif %}
</ul> </ul>
</nav> </nav>
<div class="copyright-menu"> <div class="copyright-menu">
HAproxy-WI v2.7 HAproxy-WI v2.7.1
<br> <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> <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> </div>

View File

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

View File

@ -37,21 +37,22 @@ def main():
start_worker(serv) start_worker(serv)
def 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) 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): def kill_worker(serv):
cmd = "ps ax |grep 'tools/checker_worker.py %s'|grep -v grep |awk '{print $1}' |xargs kill" % 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) 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: if stderr:
funct.logging("localhost", stderr, alerting=1) funct.logging("localhost", stderr, alerting=1)
def kill_all_workers(): def kill_all_workers():
cmd = "ps ax |grep 'tools/checker_worker.py' |grep -v grep |awk '{print $1}' |xargs kill" cmd = "ps ax |grep 'tools/checker_worker.py' |grep -v grep |awk '{print $1}' |xargs kill"
output, stderr = funct.subprocess_execute(cmd) 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: if stderr:
funct.logging("localhost", stderr, alerting=1) funct.logging("localhost", stderr, alerting=1)

View File

@ -19,8 +19,8 @@ class GracefulKiller:
def main(serv, port): def main(serv, port):
port = str(port) port = str(port)
firstrun = True firstrun = True
currentstat=[] currentstat = []
readstats="" readstats = ""
killer = GracefulKiller() killer = GracefulKiller()
while True: while True:
@ -44,18 +44,18 @@ def main(serv, port):
if firstrun == False: 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])): 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 = str(vips[i])
servername=servername.split(",") servername = servername.split(",")
realserver = servername[0] 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)) funct.telegram_send_mess(str(alert))
firstrun=False funct.logging("localhost", " "+alert, alerting=1)
oldstat=[] firstrun = False
oldstat=currentstat oldstat = []
currentstat=[] oldstat = currentstat
time.sleep(30) currentstat = []
time.sleep(60)
if killer.kill_now: if killer.kill_now:
break break

View File

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

View File

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

View File

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

View File

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