Pavel Loginov 2020-07-02 16:44:13 +02:00
parent e8229080f0
commit d3dc41715e
6 changed files with 259 additions and 38 deletions

View File

@ -96,7 +96,10 @@ def telegram_send_mess(mess, **kwargs):
from telebot import apihelper
import sql
telegrams = sql.get_telegram_by_ip(kwargs.get('ip'))
if kwargs.get('telegram_channel_id'):
telegrams = sql.get_telegram_by_id(kwargs.get('telegram_channel_id'))
else:
telegrams = sql.get_telegram_by_ip(kwargs.get('ip'))
proxy = sql.get_setting('proxy')
for telegram in telegrams:
@ -115,7 +118,7 @@ def telegram_send_mess(mess, **kwargs):
bot = telebot.TeleBot(token=token_bot)
bot.send_message(chat_id=channel_name, text=mess)
except Exception as e:
print(str(e).decode(encoding='UTF-8'))
print(str(e))
logging('localhost', str(e).decode(encoding='UTF-8'), haproxywi=1)
sys.exit()
@ -1044,7 +1047,7 @@ def out_error(e):
error = e
else:
error = e.args[0]
print(error)
print('error: '+error)
def get_users_params(**kwargs):

View File

@ -133,8 +133,8 @@
<span class="auto-refresh">
<a onclick="pauseAutoRefresh()" class="auto-refresh-pause" style="display: none; margin-top: 4px;"></a>
<a onclick="pauseAutoResume()" class="auto-refresh-resume" style="display: none; margin-top: 4px;"></a>
<a id="0"><span class="service-reload"></span> Auto-refresh</a>
<a id="1" style="display: none;"><span class="service-reload"></span> Auto-refresh</a>
<a id="0"><span class="service-reload auto-refresh-reload-icon"></span> Auto-refresh</a>
<a id="1" style="display: none;"><span class="service-reload auto-refresh-reload-icon"></span> Auto-refresh</a>
</span>
{% endif %}
</h2>
@ -146,14 +146,14 @@
</div>
<div class="auto-refresh-interval">
<div class="auto-refresh-ul">
<ul>
<ul style="width: 60px;">
<li>
<a class="ui-button ui-widget ui-corner-all" onclick="setRefreshInterval(0)" title="Turn off auto-refresh">Off</a>
</li>
</ul>
</div>
<div class="auto-refresh-ul" id="secIntervals">
<ul>
<ul style="width: 100px;">
<li>
<a title="Auto-refresh every 5 seconds" onclick="setRefreshInterval(5000)">5 seconds</a>
</li>
@ -169,7 +169,7 @@
</ul>
</div>
<div class="auto-refresh-ul">
<ul>
<ul style="width: 100px;">
<li>
<a title="Auto-refresh every 1 minute" onclick="setRefreshInterval(60000)">1 minute</a>
</li>
@ -185,7 +185,7 @@
</ul>
</div>
<div class="auto-refresh-ul">
<ul>
<ul style="width: 100px;">
<li>
<a title="Auto-refresh every 1 hour" onclick="setRefreshInterval(3600000)">1 hour</a>
</li>

View File

@ -51,9 +51,9 @@
<tr class="{{ loop.cycle('odd', 'even') }}" id="{{s[1]}}"></tr>
{% endfor %}
</table>
<table class="overview-wi" style="height: 170;">
<table class="overview-wi">
<tr class="overviewHead" style="height: 40px;">
<td class="padding10 first-collumn-wi">
<td class="padding10 first-collumn-wi" colspan="2">
{% if role <= 1 %}
<a href="/app/viewlogs.py?viewlogs={{haproxy_wi_log_id}}&rows=10&grep=&hour=00&minut=00&hour1=24&minut1=00" title="View HAProxy-WI logs" class="logs_link">
HAProxy-WI server status
@ -79,8 +79,8 @@
</td>
</tr>
</table>
<table class="overview-wi" style="height: 160;">
<tr class="overviewHead" style="height: 40px;">
<table class="overview-wi">
<tr class="overviewHead">
<td class="padding10 first-collumn-wi" colspan=4>
Tools status
</td>

View File

@ -157,20 +157,24 @@ function autoRefreshStyle(autoRefresh) {
$('.auto-refresh-resume').css('display', 'none');
$('.auto-refresh-pause').css('margin-left', "-25px");
$('.auto-refresh-resume').css('margin-left', "-25px");
$('#browse_histroy').css("border-bottom", "none");
$('.auto-refresh img').remove();
}
function setRefreshInterval(interval) {
if (interval == "0") {
Cookies.remove('auto-refresh');
pauseAutoRefresh();
$('.auto-refresh').prepend('<span class="service-reload"></span>');
$('.auto-refresh').css('margin-top', '-3px');
$('#1').text('Auto-refresh');
$('#0').text('Auto-refresh');
$('.auto-refresh-pause').css('display', 'none');
$('.auto-refresh-resume').css('display', 'none');
var autoRefresh = Cookies.get('auto-refresh');
if (autoRefresh !== undefined) {
Cookies.remove('auto-refresh');
pauseAutoRefresh();
$('.auto-refresh').prepend('<span class="service-reload auto-refresh-reload-icon"></span>');
$('.auto-refresh').css('font-size', '15px');
$('#1').text('Auto-refresh');
$('#0').text('Auto-refresh');
$('.auto-refresh-pause').css('display', 'none');
$('.auto-refresh-resume').css('display', 'none');
$.getScript("/inc/fontawesome.min.js")
}
hideAutoRefreshDiv();
$.getScript("/inc/fontawesome.min.js")
} else {
clearInterval(intervalId);
Cookies.set('auto-refresh', interval, { expires: 365 });
@ -302,6 +306,9 @@ function showLog() {
var hour1 = $('#time_range_out_hour1').val()
var minut1 = $('#time_range_out_minut1').val()
var service = $('#service').val()
if (service == 'None') {
service = 'haproxy';
}
$.ajax( {
url: "options.py",
data: {

View File

@ -31,10 +31,12 @@ h3 {
}
ul#browse_histroy {
padding-left: 10px;
margin-bottom: 5px;
display: block;
margin-top: 1px;
list-style: none;
border-bottom: 1px solid #D9D9D9;
padding-bottom: 5px;
clear: both;
}
ul#browse_histroy li {
display: inline;
@ -197,7 +199,7 @@ pre {
position: relative;
padding: 10px;
background-color: #F5F5F5;
border-bottom: solid 1px #D9D9D9;
//border-bottom: solid 1px #D9D9D9;
border-top: solid 1px #D9D9D9;
margin-bottom: 10px;
line-height: 20px;
@ -217,8 +219,7 @@ pre {
padding: 0px 15px;
margin-top: 5px;
margin-bottom: 10px;
margin-left: 70%;
border-bottom: solid 1px #D9D9D9;
margin-left: 60%;
}
.auto-refresh-ul{
float: left;
@ -243,6 +244,12 @@ pre {
font-size: 12px;
height: 15;
}
.auto-refresh-reload-icon {
margin-top: 3px;
display: block;
float: left;
margin-right: 5px;
}
.configShow, .diff {
margin-left: 16%;
overflow: auto;
@ -371,6 +378,7 @@ pre {
min-height: 160px;
float: left;
margin: 20px;
margin-top: 0;
}
.overviewHead {
border-radius: 5px;
@ -866,6 +874,74 @@ label {
.restart, .reload, .stop, .stop-waf, .restart-waf {
padding-left: 4px;
}
.main {
margin: 20px;
}
.sort_menu {
clear: both;
margin-bottom: 20px;
}
.smon_group {
clear: both;
}
.group_name {
font-size: 18px;
padding: 20px;
padding-left:15px;
padding-bottom: 0px;
}
.smon_services {
width: 190px;
height: 160px;
float: left;
background-color: #fbfbfb;;
margin: 10px;
padding-left: 15px;
border: 1px solid #A4C7F5;
}
#good_services {
clear: both;
margin-bottom: 30px;
}
#err_services {
clear: both;
margin-bottom: 30px;
}
.ip {
font-size: 18px;
padding-top: 5px;
padding-bottom: 3px;
color: #5d9ceb;
border-bottom: 1px solid #A4C7F5;
width: 93%;
margin-bottom: 5px;
}
.desc, .res_time {
color: #999;
}
.desc {
height: 20px;
}
.res_time {
height: 25px;
}
.up, .down, .disable {
height: 45px;
width: 177px;
font-size: 30px;
color: #fff;
}
.up {
background-color: #5CB85C;
}
.down {
background-color: red;
font-size: 22px;
}
.disable {
background-color: grey;
color: #aaa;
}
@media (max-width: 1920px) {
#logo_span {
margin-left: 17%;

View File

@ -478,7 +478,7 @@ $( function() {
type: "POST",
success: function( data ) {
if (data.indexOf('error') != '-1') {
$("#ajax-group").append(data);
$("#ajax-group").append('<div class="alert alert-danger" style="width: 100%;">'+data+'</div><br /><br />');
$('#errorMess').click(function() {
$('#error').remove();
$('.alert-danger').remove();
@ -515,7 +515,7 @@ $( function() {
type: "POST",
success: function( data ) {
if (data.indexOf('error') != '-1') {
$("#ajax-ssh").append(data);
$("#ajax-ssh").append('<div class="alert alert-danger" style="width: 100%;">'+data+'</div><br /><br />');
$('#errorMess').click(function() {
$('#error').remove();
$('.alert-danger').remove();
@ -554,7 +554,7 @@ $( function() {
type: "POST",
success: function( data ) {
if (data.indexOf('error') != '-1') {
$("#ajax-telegram").append(data);
$("#ajax-telegram").append('<div class="alert alert-danger" style="width: 100%;">'+data+'</div><br /><br />');
$('#errorMess').click(function() {
$('#error').remove();
$('.alert-danger').remove();
@ -677,6 +677,34 @@ $( function() {
$('#add-backup-button').click(function() {
addBackupDialog.dialog('open');
});
var addSmonServer = $( "#smon-add-table" ).dialog({
autoOpen: false,
resizable: false,
height: "auto",
width: 600,
modal: true,
title: "Create a new server for monitoring",
show: {
effect: "fade",
duration: 200
},
hide: {
effect: "fade",
duration: 200
},
buttons: {
"Add": function() {
addNewSmonServer();
},
Cancel: function() {
$( this ).dialog( "close" );
clearTips();
}
}
});
$('#add-smon-button').click(function() {
addSmonServer.dialog('open');
});
$( "#ajax-users input" ).change(function() {
var id = $(this).attr('id').split('-');
updateUser(id[1])
@ -791,12 +819,84 @@ function clearTips() {
function checkLength( o, n, min ) {
if ( o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips("Filed "+n+" required");
updateTips("Filed "+n+" is required");
return false;
} else {
return true;
}
}
function addNewSmonServer() {
var valid = true;
$('#error').remove();
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
if ($('#new-smon-proto').val() != '' || $('#new-smon-uri').val() != '') {
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
.add( $('#new-smon-proto') ).add( $('#new-smon-uri') );
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 );
valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 );
}
if( $('#new-smon-body').val() != '') {
allFields = $( [] ).add( $('#new-smon-ip') ).add( $('#new-smon-port') )
.add( $('#new-smon-proto') ).add( $('#new-smon-uri') );
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( $('#new-smon-ip'), "IP", 1 );
valid = valid && checkLength( $('#new-smon-port'), "Port", 1 );
valid = valid && checkLength( $('#new-smon-proto'), "Protocol", 1 );
valid = valid && checkLength( $('#new-smon-uri'), "URI", 1 );
valid = valid && checkLength( $('#new-smon-body'), "Body", 1 );
}
var enable = 0;
if ($('#new-smon-enable').is(':checked')) {
enable = '1';
}
if (valid) {
$.ajax( {
url: "options.py",
data: {
newsmon: $('#new-smon-ip').val(),
newsmonport: $('#new-smon-port').val(),
newsmonenable: enable,
newsmonproto: $('#new-smon-proto').val(),
newsmonuri: $('#new-smon-uri').val(),
newsmonbody: $('#new-smon-body').val(),
newsmongroup: $('#new-smon-group').val(),
newsmondescription: $('#new-smon-description').val(),
newsmontelegram: $('#new-smon-telegram').val(),
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error') != '-1' || data.indexOf('unique') != '-1') {
$("#ajax").html('<div class="alert alert-danger" style="width: 50%;">'+data+'</div><br /><br />');;
$('#errorMess').click(function() {
$('#error').remove();
$('.alert-danger').remove();
});
} else {
$('.alert-danger').remove();
$("#ajax-smon").append(data);
$(".newserver").addClass( "update", 1000 );
$( "input[type=submit], button" ).button();
$( "input[type=checkbox]" ).checkboxradio();
$( "select" ).selectmenu();
$.getScript(awesome);
setTimeout(function() {
$( ".newserver" ).removeClass( "update" );
}, 2500 );
}
}
} );
clearTips();
$( "#smon-add-table" ).dialog("close" );
}
}
function addUser() {
var valid = true;
$('#error').remove();
@ -826,7 +926,7 @@ function addUser() {
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error') != '-1') {
$("#ajax-users").append(data);
$("#ajax-users").append('<div class="alert alert-danger" style="width: 100%;">'+data+'</div><br /><br />');
$('#errorMess').click(function() {
$('#error').remove();
$('.alert-danger').remove();
@ -836,7 +936,6 @@ function addUser() {
$("#ajax-users").append(data);
var getId = new RegExp('[0-9]+');
var id = data.match(getId);
console.log(id[0])
addUserGroup(id[0]);
}
}
@ -897,7 +996,7 @@ function addServer() {
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error') != '-1') {
$("#ajax-servers").append(data);
$("#ajax-servers").append('<div class="alert alert-danger" style="width: 100%;">'+data+'</div><br /><br />');
$('#errorMess').click(function() {
$('#error').remove();
$('.alert-danger').remove();
@ -1124,6 +1223,24 @@ function confirmDeleteBackup(id) {
}
});
}
function confirmDeleteSmon(id) {
$( "#dialog-confirm" ).dialog({
resizable: false,
height: "auto",
width: 400,
modal: true,
title: "Are you sure you want to delete server " +$('#smon-ip-'+id).val() + "?",
buttons: {
"Delete": function() {
$( this ).dialog( "close" );
removeSmon(id);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
}
function cloneServer(id) {
$( "#add-server-button" ).trigger( "click" );
if ($('#enable-'+id).is(':checked')) {
@ -1305,6 +1422,25 @@ function removeBackup(id) {
}
} );
}
function removeSmon(id) {
$("#smon-"+id).css("background-color", "#f2dede");
$.ajax( {
url: "options.py",
data: {
smondel: id,
token: $('#token').val()
},
type: "POST",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if(data == "Ok ") {
$("#smon-"+id).remove();
} else {
alert(data);
}
}
} );
}
function updateUser(id) {
$('.alert-danger').remove();
cur_url[0] = cur_url[0].split('#')[0]
@ -1396,7 +1532,6 @@ function updateServer(id) {
if (cur_url[0].split('#')[0] == "servers.py") {
servergroup = $('#new-server-group-add').val();
}
console.log(servergroup)
$.ajax( {
url: "options.py",
data: {