mirror of https://github.com/Aidaho12/haproxy-wi
parent
ee3a42a031
commit
d6f79bff7b
19
app/funct.py
19
app/funct.py
|
@ -108,10 +108,9 @@ def telegram_send_mess(mess, **kwargs):
|
|||
try:
|
||||
bot = telebot.TeleBot(token=token_bot)
|
||||
bot.send_message(chat_id=channel_name, text=mess)
|
||||
except:
|
||||
mess = " Fatal: Can't send message. Add Telegram chanel before use alerting at this servers group"
|
||||
print(mess)
|
||||
logging('localhost', mess, haproxywi=1)
|
||||
except Exception as e:
|
||||
print(str(e).decode(encoding='UTF-8'))
|
||||
logging('localhost', str(e).decode(encoding='UTF-8'), haproxywi=1)
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
@ -213,20 +212,20 @@ def ssh_connect(serv, **kwargs):
|
|||
ssh.connect(hostname = serv, port = ssh_port, username = ssh_user_name, password = ssh_user_password, timeout=11)
|
||||
return ssh
|
||||
except paramiko.AuthenticationException:
|
||||
return 'Authentication failed, please verify your credentials'
|
||||
return 'error: Authentication failed, please verify your credentials'
|
||||
pass
|
||||
except paramiko.SSHException as sshException:
|
||||
return 'Unable to establish SSH connection: %s ' % sshException
|
||||
return 'error: Unable to establish SSH connection: %s ' % sshException
|
||||
pass
|
||||
except paramiko.BadHostKeyException as badHostKeyException:
|
||||
return 'Unable to verify server\'s host key: %s ' % badHostKeyException
|
||||
return 'error: Unable to verify server\'s host key: %s ' % badHostKeyException
|
||||
pass
|
||||
except Exception as e:
|
||||
if e == "No such file or directory":
|
||||
return '%s. Check ssh key' % e
|
||||
return 'error: %s. Check ssh key' % e
|
||||
pass
|
||||
elif e == "Invalid argument":
|
||||
error = 'Check the IP of the server'
|
||||
error = 'error: Check the IP of the server'
|
||||
pass
|
||||
else:
|
||||
error = e
|
||||
|
@ -967,4 +966,4 @@ def check_service(serv, service_name):
|
|||
commands = [ "systemctl status "+service_name+" |grep Active |awk '{print $1}'" ]
|
||||
return ssh_command(serv, commands)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1379,6 +1379,7 @@ if form.getvalue('newserver') is not None:
|
|||
if form.getvalue('updatehapwiserver') is not None:
|
||||
id = form.getvalue('updatehapwiserver')
|
||||
active = form.getvalue('active')
|
||||
name = form.getvalue('name')
|
||||
alert = form.getvalue('alert_en')
|
||||
metrics = form.getvalue('metrics')
|
||||
sql.update_hapwi_server(id, alert, metrics, active)
|
||||
|
@ -1584,7 +1585,7 @@ if form.getvalue('telegramdel') is not None:
|
|||
if form.getvalue('updatetoken') is not None:
|
||||
token = form.getvalue('updatetoken')
|
||||
channel = form.getvalue('updategchanel')
|
||||
group = form.getvalue('updategroup')
|
||||
group = form.getvalue('updatetelegramgroup')
|
||||
id = form.getvalue('id')
|
||||
if token is None or channel is None or group is None:
|
||||
print(error_mess)
|
||||
|
|
|
@ -321,7 +321,7 @@ h3 {
|
|||
<div id="options-frontend-show-div" style="display: none;">
|
||||
<div style="font-size: 12px; padding-bottom: 10px;">
|
||||
<span style="padding-right: 10px;">Start typing options: </span>
|
||||
{{ input('options2') }}
|
||||
{{ input('options1') }}
|
||||
<span style="padding-left: 10px;">
|
||||
or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>
|
||||
</span>
|
||||
|
|
|
@ -40,6 +40,7 @@ def main(serv, port):
|
|||
|
||||
firstrun = False
|
||||
old_stat_service = cur_stat_service
|
||||
time.sleep(60)
|
||||
continue
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
|
26
inc/add.js
26
inc/add.js
|
@ -222,7 +222,7 @@ $( function() {
|
|||
|
||||
|
||||
var availableTags = [
|
||||
"acl", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "set cookie", "dynamic-cookie-key", "mysql-check", "tcpka", "tcplog", "forwardfor", "option"
|
||||
"acl", "hdr(host)", "hdr_beg(host)", "hdr_dom(host)", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "set cookie", "dynamic-cookie-key", "mysql-check", "tcpka", "tcplog", "forwardfor", "option"
|
||||
];
|
||||
|
||||
$( "#ip" ).autocomplete({
|
||||
|
@ -355,7 +355,8 @@ $( function() {
|
|||
minLength: -1,
|
||||
select: function( event, ui ) {
|
||||
$("#optionsInput").append(ui.item.value + " ");
|
||||
$("#options").empty();
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$( "#saved-options" ).autocomplete({
|
||||
|
@ -365,8 +366,8 @@ $( function() {
|
|||
minLength: 1,
|
||||
select: function( event, ui ) {
|
||||
$("#optionsInput").append(ui.item.value + " \n");
|
||||
$(this).val('');
|
||||
$(this).autocomplete( "close" );
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$( "#options1" ).autocomplete({
|
||||
|
@ -374,9 +375,12 @@ $( function() {
|
|||
autoFocus: true,
|
||||
minLength: -1,
|
||||
select: function( event, ui ) {
|
||||
$("#optionsInput1").append(ui.item.value + " ")
|
||||
$("#optionsInput1").append(ui.item.value + " ");
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$( "#saved-options1" ).autocomplete({
|
||||
dataType: "json",
|
||||
source: "sql.py?getoption="+$('#group').val()+'&token='+$('#token').val(),
|
||||
|
@ -384,8 +388,8 @@ $( function() {
|
|||
minLength: 1,
|
||||
select: function( event, ui ) {
|
||||
$("#optionsInput1").append(ui.item.value + " \n");
|
||||
$(this).val('');
|
||||
$(this).autocomplete( "close" );
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$( "#options2" ).autocomplete({
|
||||
|
@ -393,7 +397,9 @@ $( function() {
|
|||
autoFocus: true,
|
||||
minLength: -1,
|
||||
select: function( event, ui ) {
|
||||
$("#optionsInput2").append(ui.item.value + " ")
|
||||
$("#optionsInput2").append(ui.item.value + " ");
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$( "#saved-options2" ).autocomplete({
|
||||
|
@ -403,8 +409,8 @@ $( function() {
|
|||
minLength: 1,
|
||||
select: function( event, ui ) {
|
||||
$("#optionsInput2").append(ui.item.value + " \n");
|
||||
$(this).val('');
|
||||
$(this).autocomplete( "close" );
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#add-option-button').click(function() {
|
||||
|
|
|
@ -287,6 +287,7 @@ function updateHapWIServer(id) {
|
|||
url: "options.py",
|
||||
data: {
|
||||
updatehapwiserver: id,
|
||||
name: $('#server-name-'+id).val(),
|
||||
metrics: metrics,
|
||||
alert_en: alert_en,
|
||||
active: active,
|
||||
|
|
|
@ -409,6 +409,7 @@ function showCompareConfigs() {
|
|||
} );
|
||||
}
|
||||
function showConfig() {
|
||||
var service = $('#service').val();
|
||||
$("#ajax").empty();
|
||||
$("#ajax-compare").empty();
|
||||
$("#config").empty();
|
||||
|
@ -418,13 +419,14 @@ function showConfig() {
|
|||
data: {
|
||||
serv: $("#serv").val(),
|
||||
act: "configShow",
|
||||
service: service,
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
$("#ajax").html(data);
|
||||
$.getScript('/inc/configshow.js');
|
||||
window.history.pushState("Show config", "Show config", cur_url[0]+'?serv='+$("#serv").val()+'&showConfig');
|
||||
window.history.pushState("Show config", "Show config", cur_url[0]+"?service="+service+"&serv="+$("#serv").val()+"&showConfig");
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -819,53 +821,6 @@ $( function() {
|
|||
} );
|
||||
}
|
||||
}
|
||||
$( "#haproxyaddserv" ).on('selectmenuchange',function() {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
get_hap_v: 1,
|
||||
serv: $('#haproxyaddserv option:selected').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/^\s+|\s+$/g,'');
|
||||
if(data != '') {
|
||||
data = data+'-1';
|
||||
$('#cur_hap_ver').text(data);
|
||||
$('#install').text('Update');
|
||||
$('#install').attr('title', 'Update HAProxy');
|
||||
} else {
|
||||
$('#cur_hap_ver').text('HAProxy has not installed');
|
||||
$('#install').text('Install');
|
||||
$('#install').attr('title', 'Install HAProxy');
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
$( "#nginxaddserv" ).on('selectmenuchange',function() {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
get_nginx_v: 1,
|
||||
serv: $('#nginxaddserv option:selected').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/^\s+|\s+$/g,'');
|
||||
if(data.indexOf('bash') != '-1') {
|
||||
$('#cur_nginx_ver').text('Nginx has not installed');
|
||||
$('#nginx_install').text('Install');
|
||||
$('#nginx_install').attr('title', 'Install Nginx');
|
||||
} else {
|
||||
$('#cur_nginx_ver').text(data);
|
||||
$('#nginx_install').text('Update');
|
||||
$('#nginx_install').attr('title', 'Update Nginx');
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
});
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
|
99
inc/users.js
99
inc/users.js
|
@ -313,6 +313,101 @@ $( function() {
|
|||
}
|
||||
} );
|
||||
});
|
||||
$( "#haproxyaddserv" ).on('selectmenuchange',function() {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
get_hap_v: 1,
|
||||
serv: $('#haproxyaddserv option:selected').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/^\s+|\s+$/g,'');
|
||||
if(data != '') {
|
||||
data = data+'-1';
|
||||
$('#cur_hap_ver').text(data);
|
||||
$('#install').text('Update');
|
||||
$('#install').attr('title', 'Update HAProxy');
|
||||
} else {
|
||||
$('#cur_hap_ver').text('HAProxy has not installed');
|
||||
$('#install').text('Install');
|
||||
$('#install').attr('title', 'Install HAProxy');
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
$( "#nginxaddserv" ).on('selectmenuchange',function() {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
get_nginx_v: 1,
|
||||
serv: $('#nginxaddserv option:selected').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/^\s+|\s+$/g,'');
|
||||
if(data.indexOf('bash') != '-1') {
|
||||
$('#cur_nginx_ver').text('Nginx has not installed');
|
||||
$('#nginx_install').text('Install');
|
||||
$('#nginx_install').attr('title', 'Install Nginx');
|
||||
} else {
|
||||
$('#cur_nginx_ver').text(data);
|
||||
$('#nginx_install').text('Update');
|
||||
$('#nginx_install').attr('title', 'Update Nginx');
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
$( "#haproxy_exp_addserv" ).on('selectmenuchange',function() {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
get_exporter_v: 'haproxy_exporter',
|
||||
serv: $('#haproxy_exp_addserv option:selected').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/^\s+|\s+$/g,'');
|
||||
console.log(data)
|
||||
if(data == 'Active:') {
|
||||
$('#cur_haproxy_exp_ver').text('HAProxy expoter is installed');
|
||||
$('#haproxy_exp_install').text('Update');
|
||||
$('#haproxy_exp_install').attr('title', 'Update HAProxy expoter');
|
||||
} else {
|
||||
$('#cur_haproxy_exp_ver').text('HAProxy expoter has not installed');
|
||||
$('#haproxy_exp_install').text('Install');
|
||||
$('#haproxy_exp_install').attr('title', 'Install HAProxy expoter');
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
$( "#nginx_exp_addserv" ).on('selectmenuchange',function() {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
get_exporter_v: 'nginx_exporter',
|
||||
serv: $('#nginx_exp_addserv option:selected').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/^\s+|\s+$/g,'');
|
||||
console.log(data)
|
||||
if(data == 'Active:') {
|
||||
$('#cur_nginx_exp_ver').text('Nginx expoter is installed');
|
||||
$('#nginx_exp_install').text('Update');
|
||||
$('#nginx_exp_install').attr('title', 'Update Nginx expoter');
|
||||
} else {
|
||||
$('#cur_nginx_exp_ver').text('Nginx expoter has not installed');
|
||||
$('#nginx_exp_install').text('Install');
|
||||
$('#nginx_exp_install').attr('title', 'Install Nginx expoter');
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
$('#update_haproxy_wi').click(function() {
|
||||
$("#ajax-update").html('')
|
||||
$("#ajax-update").html('<div class="alert alert-warning">Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time </div>');
|
||||
|
@ -1419,7 +1514,7 @@ function updateTelegram(id) {
|
|||
data: {
|
||||
updatetoken: $('#telegram-token-'+id).val(),
|
||||
updategchanel: $('#telegram-chanel-'+id).val(),
|
||||
updategroup: $('#telegramgroup-'+id).val(),
|
||||
updatetelegramgroup: $('#telegramgroup-'+id).val(),
|
||||
id: id,
|
||||
token: $('#token').val()
|
||||
},
|
||||
|
@ -1525,7 +1620,7 @@ function checkSshConnect(ip) {
|
|||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
if (data.indexOf('danger') != '-1') {
|
||||
if (data.indexOf('error') != '-1') {
|
||||
$("#checkSshConnect").html(data);
|
||||
} else {
|
||||
$("#checkSshConnect").html("<div class='alert alert-success' style='margin: 0; margin-left: 15px;'>Connect is accepted<a title='Close' id='errorMess'><b>X</b></a></div>");
|
||||
|
|
Loading…
Reference in New Issue