mirror of https://github.com/Aidaho12/haproxy-wi
parent
ee3a42a031
commit
d6f79bff7b
17
app/funct.py
17
app/funct.py
|
@ -108,10 +108,9 @@ def telegram_send_mess(mess, **kwargs):
|
||||||
try:
|
try:
|
||||||
bot = telebot.TeleBot(token=token_bot)
|
bot = telebot.TeleBot(token=token_bot)
|
||||||
bot.send_message(chat_id=channel_name, text=mess)
|
bot.send_message(chat_id=channel_name, text=mess)
|
||||||
except:
|
except Exception as e:
|
||||||
mess = " Fatal: Can't send message. Add Telegram chanel before use alerting at this servers group"
|
print(str(e).decode(encoding='UTF-8'))
|
||||||
print(mess)
|
logging('localhost', str(e).decode(encoding='UTF-8'), haproxywi=1)
|
||||||
logging('localhost', mess, haproxywi=1)
|
|
||||||
sys.exit()
|
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)
|
ssh.connect(hostname = serv, port = ssh_port, username = ssh_user_name, password = ssh_user_password, timeout=11)
|
||||||
return ssh
|
return ssh
|
||||||
except paramiko.AuthenticationException:
|
except paramiko.AuthenticationException:
|
||||||
return 'Authentication failed, please verify your credentials'
|
return 'error: Authentication failed, please verify your credentials'
|
||||||
pass
|
pass
|
||||||
except paramiko.SSHException as sshException:
|
except paramiko.SSHException as sshException:
|
||||||
return 'Unable to establish SSH connection: %s ' % sshException
|
return 'error: Unable to establish SSH connection: %s ' % sshException
|
||||||
pass
|
pass
|
||||||
except paramiko.BadHostKeyException as badHostKeyException:
|
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
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if e == "No such file or directory":
|
if e == "No such file or directory":
|
||||||
return '%s. Check ssh key' % e
|
return 'error: %s. Check ssh key' % e
|
||||||
pass
|
pass
|
||||||
elif e == "Invalid argument":
|
elif e == "Invalid argument":
|
||||||
error = 'Check the IP of the server'
|
error = 'error: Check the IP of the server'
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
error = e
|
error = e
|
||||||
|
|
|
@ -1379,6 +1379,7 @@ if form.getvalue('newserver') is not None:
|
||||||
if form.getvalue('updatehapwiserver') is not None:
|
if form.getvalue('updatehapwiserver') is not None:
|
||||||
id = form.getvalue('updatehapwiserver')
|
id = form.getvalue('updatehapwiserver')
|
||||||
active = form.getvalue('active')
|
active = form.getvalue('active')
|
||||||
|
name = form.getvalue('name')
|
||||||
alert = form.getvalue('alert_en')
|
alert = form.getvalue('alert_en')
|
||||||
metrics = form.getvalue('metrics')
|
metrics = form.getvalue('metrics')
|
||||||
sql.update_hapwi_server(id, alert, metrics, active)
|
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:
|
if form.getvalue('updatetoken') is not None:
|
||||||
token = form.getvalue('updatetoken')
|
token = form.getvalue('updatetoken')
|
||||||
channel = form.getvalue('updategchanel')
|
channel = form.getvalue('updategchanel')
|
||||||
group = form.getvalue('updategroup')
|
group = form.getvalue('updatetelegramgroup')
|
||||||
id = form.getvalue('id')
|
id = form.getvalue('id')
|
||||||
if token is None or channel is None or group is None:
|
if token is None or channel is None or group is None:
|
||||||
print(error_mess)
|
print(error_mess)
|
||||||
|
|
|
@ -321,7 +321,7 @@ h3 {
|
||||||
<div id="options-frontend-show-div" style="display: none;">
|
<div id="options-frontend-show-div" style="display: none;">
|
||||||
<div style="font-size: 12px; padding-bottom: 10px;">
|
<div style="font-size: 12px; padding-bottom: 10px;">
|
||||||
<span style="padding-right: 10px;">Start typing options: </span>
|
<span style="padding-right: 10px;">Start typing options: </span>
|
||||||
{{ input('options2') }}
|
{{ input('options1') }}
|
||||||
<span style="padding-left: 10px;">
|
<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>
|
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>
|
</span>
|
||||||
|
|
|
@ -40,6 +40,7 @@ def main(serv, port):
|
||||||
|
|
||||||
firstrun = False
|
firstrun = False
|
||||||
old_stat_service = cur_stat_service
|
old_stat_service = cur_stat_service
|
||||||
|
time.sleep(60)
|
||||||
continue
|
continue
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
20
inc/add.js
20
inc/add.js
|
@ -222,7 +222,7 @@ $( function() {
|
||||||
|
|
||||||
|
|
||||||
var availableTags = [
|
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({
|
$( "#ip" ).autocomplete({
|
||||||
|
@ -355,7 +355,8 @@ $( function() {
|
||||||
minLength: -1,
|
minLength: -1,
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
$("#optionsInput").append(ui.item.value + " ");
|
$("#optionsInput").append(ui.item.value + " ");
|
||||||
$("#options").empty();
|
$(this).val('');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( "#saved-options" ).autocomplete({
|
$( "#saved-options" ).autocomplete({
|
||||||
|
@ -366,7 +367,7 @@ $( function() {
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
$("#optionsInput").append(ui.item.value + " \n");
|
$("#optionsInput").append(ui.item.value + " \n");
|
||||||
$(this).val('');
|
$(this).val('');
|
||||||
$(this).autocomplete( "close" );
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( "#options1" ).autocomplete({
|
$( "#options1" ).autocomplete({
|
||||||
|
@ -374,9 +375,12 @@ $( function() {
|
||||||
autoFocus: true,
|
autoFocus: true,
|
||||||
minLength: -1,
|
minLength: -1,
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
$("#optionsInput1").append(ui.item.value + " ")
|
$("#optionsInput1").append(ui.item.value + " ");
|
||||||
|
$(this).val('');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$( "#saved-options1" ).autocomplete({
|
$( "#saved-options1" ).autocomplete({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
source: "sql.py?getoption="+$('#group').val()+'&token='+$('#token').val(),
|
source: "sql.py?getoption="+$('#group').val()+'&token='+$('#token').val(),
|
||||||
|
@ -385,7 +389,7 @@ $( function() {
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
$("#optionsInput1").append(ui.item.value + " \n");
|
$("#optionsInput1").append(ui.item.value + " \n");
|
||||||
$(this).val('');
|
$(this).val('');
|
||||||
$(this).autocomplete( "close" );
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( "#options2" ).autocomplete({
|
$( "#options2" ).autocomplete({
|
||||||
|
@ -393,7 +397,9 @@ $( function() {
|
||||||
autoFocus: true,
|
autoFocus: true,
|
||||||
minLength: -1,
|
minLength: -1,
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
$("#optionsInput2").append(ui.item.value + " ")
|
$("#optionsInput2").append(ui.item.value + " ");
|
||||||
|
$(this).val('');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( "#saved-options2" ).autocomplete({
|
$( "#saved-options2" ).autocomplete({
|
||||||
|
@ -404,7 +410,7 @@ $( function() {
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
$("#optionsInput2").append(ui.item.value + " \n");
|
$("#optionsInput2").append(ui.item.value + " \n");
|
||||||
$(this).val('');
|
$(this).val('');
|
||||||
$(this).autocomplete( "close" );
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#add-option-button').click(function() {
|
$('#add-option-button').click(function() {
|
||||||
|
|
|
@ -287,6 +287,7 @@ function updateHapWIServer(id) {
|
||||||
url: "options.py",
|
url: "options.py",
|
||||||
data: {
|
data: {
|
||||||
updatehapwiserver: id,
|
updatehapwiserver: id,
|
||||||
|
name: $('#server-name-'+id).val(),
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
alert_en: alert_en,
|
alert_en: alert_en,
|
||||||
active: active,
|
active: active,
|
||||||
|
|
|
@ -409,6 +409,7 @@ function showCompareConfigs() {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
function showConfig() {
|
function showConfig() {
|
||||||
|
var service = $('#service').val();
|
||||||
$("#ajax").empty();
|
$("#ajax").empty();
|
||||||
$("#ajax-compare").empty();
|
$("#ajax-compare").empty();
|
||||||
$("#config").empty();
|
$("#config").empty();
|
||||||
|
@ -418,13 +419,14 @@ function showConfig() {
|
||||||
data: {
|
data: {
|
||||||
serv: $("#serv").val(),
|
serv: $("#serv").val(),
|
||||||
act: "configShow",
|
act: "configShow",
|
||||||
|
service: service,
|
||||||
token: $('#token').val()
|
token: $('#token').val()
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
$("#ajax").html(data);
|
$("#ajax").html(data);
|
||||||
$.getScript('/inc/configshow.js');
|
$.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) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, 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() {
|
$('#update_haproxy_wi').click(function() {
|
||||||
$("#ajax-update").html('')
|
$("#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>');
|
$("#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: {
|
data: {
|
||||||
updatetoken: $('#telegram-token-'+id).val(),
|
updatetoken: $('#telegram-token-'+id).val(),
|
||||||
updategchanel: $('#telegram-chanel-'+id).val(),
|
updategchanel: $('#telegram-chanel-'+id).val(),
|
||||||
updategroup: $('#telegramgroup-'+id).val(),
|
updatetelegramgroup: $('#telegramgroup-'+id).val(),
|
||||||
id: id,
|
id: id,
|
||||||
token: $('#token').val()
|
token: $('#token').val()
|
||||||
},
|
},
|
||||||
|
@ -1525,7 +1620,7 @@ function checkSshConnect(ip) {
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
if (data.indexOf('danger') != '-1') {
|
if (data.indexOf('error') != '-1') {
|
||||||
$("#checkSshConnect").html(data);
|
$("#checkSshConnect").html(data);
|
||||||
} else {
|
} 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>");
|
$("#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