mirror of https://github.com/Aidaho12/haproxy-wi
v8.0.1: Remove keepalived service and improve service status handling
Removed all references and functionality related to keepalived service. Added detailed status handling for various services including nginx, haproxy, and apache, improving the accuracy of the status checks and error handling for each service. Adjusted user interface elements to reflect the service status changes more clearly.pull/399/head
parent
52cafa9013
commit
3423595d9b
|
@ -86,8 +86,9 @@ def update_user_status() -> None:
|
|||
try:
|
||||
status = roxy_wi_get_plan.json()
|
||||
roxy_sql.update_user_status(status['status'], status['plan'], status['method'])
|
||||
roxywi_common.logging('Roxy-WI server', 'Update Roxy-WI user status', roxywi=1)
|
||||
except Exception as e:
|
||||
roxywi_common.logging('Roxy-WI server', f'error: Cannot get user status {e}', roxywi=1)
|
||||
roxywi_common.logging('Roxy-WI server', f'error: Cannot get Roxy-WI user status {e}', roxywi=1)
|
||||
|
||||
|
||||
def action_service(action: str, service: str) -> str:
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
import app.modules.server.server as server_mod
|
||||
|
||||
|
||||
def get_status(server_ip: str) -> tuple:
|
||||
out1 = []
|
||||
h = (['', ''],)
|
||||
try:
|
||||
cmd = ("/usr/sbin/keepalived -v 2>&1|head -1|awk '{print $2}' && systemctl status keepalived |"
|
||||
"grep -e 'Active' |awk '{print $2, $9$10$11$12$13}' && ps ax |grep keepalived|grep -v grep |wc -l")
|
||||
out = server_mod.ssh_command(server_ip, cmd)
|
||||
for k in out.split():
|
||||
out1.append(k)
|
||||
h = (out1,)
|
||||
servers_with_status1 = h
|
||||
servers_with_status2 = h
|
||||
except Exception:
|
||||
servers_with_status1 = h
|
||||
servers_with_status2 = h
|
||||
|
||||
return servers_with_status1, servers_with_status2
|
|
@ -126,23 +126,3 @@ def get_settings():
|
|||
'timezones': pytz.all_timezones,
|
||||
}
|
||||
return render_template('include/admin_settings.html', **kwargs)
|
||||
|
||||
|
||||
@bp.post('/setting/<param>')
|
||||
def update_settings(param):
|
||||
roxywi_auth.page_for_admin(level=2)
|
||||
val = request.form.get('val').replace('92', '/')
|
||||
user_group = roxywi_common.get_user_group(id=1)
|
||||
try:
|
||||
sql.update_setting(param, val, user_group)
|
||||
except Exception as e:
|
||||
roxywi_common.handle_json_exceptions(e, 'Cannot update settings')
|
||||
roxywi_common.logging('Roxy-WI server', f'The {param} setting has been changed to: {val}', roxywi=1, login=1)
|
||||
|
||||
if param == 'master_port':
|
||||
try:
|
||||
smon_mod.change_smon_port(int(val))
|
||||
except Exception as e:
|
||||
return f'{e}'
|
||||
|
||||
return 'Ok'
|
||||
|
|
|
@ -10,7 +10,6 @@ import app.modules.db.server as server_sql
|
|||
import app.modules.db.service as service_sql
|
||||
import app.modules.server.server as server_mod
|
||||
import app.modules.roxywi.common as roxywi_common
|
||||
import app.modules.service.keepalived as keepalived
|
||||
from app.views.ha.views import HAView
|
||||
|
||||
bp.add_url_rule('/<service>', view_func=HAView.as_view('ha_cluster'), methods=['GET'], defaults={'cluster_id': None})
|
||||
|
@ -71,10 +70,6 @@ def show_ha_cluster(service, cluster_id):
|
|||
servers_with_status.append(s[1])
|
||||
servers_with_status.append(s[2])
|
||||
servers_with_status.append(s[11])
|
||||
status1, status2 = keepalived.get_status(s[2])
|
||||
servers_with_status.append(status1)
|
||||
servers_with_status.append(status2)
|
||||
servers_with_status.append(s[22])
|
||||
servers_with_status.append(server_sql.is_master(s[2]))
|
||||
servers_with_status.append(server_sql.select_servers(server=s[2]))
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ from app.middleware import check_services, get_user_params
|
|||
import app.modules.common.common as common
|
||||
import app.modules.server.server as server_mod
|
||||
import app.modules.service.common as service_common
|
||||
import app.modules.service.keepalived as keepalived
|
||||
import app.modules.roxywi.common as roxywi_common
|
||||
import app.modules.roxywi.overview as roxy_overview
|
||||
from app.views.service.views import ServiceActionView, ServiceBackendView, ServiceView
|
||||
|
@ -43,7 +42,6 @@ def services(service, serv):
|
|||
service_desc = service_sql.select_service(service)
|
||||
servers = roxywi_common.get_dick_permit(virt=1, service=service_desc.slug)
|
||||
servers_with_status1 = []
|
||||
autorefresh = 0
|
||||
waf_server = ''
|
||||
cmd = "ps ax |grep -e 'keep_alive.py' |grep -v grep |wc -l"
|
||||
keep_alive, stderr = server_mod.subprocess_execute(cmd)
|
||||
|
@ -57,7 +55,6 @@ def services(service, serv):
|
|||
if serv:
|
||||
if roxywi_common.check_is_server_in_group(serv):
|
||||
servers = server_sql.select_servers(server=serv)
|
||||
autorefresh = 1
|
||||
waf_server = waf_sql.select_waf_servers(serv)
|
||||
server_id = server_sql.select_server_id_by_ip(serv)
|
||||
docker_settings = service_sql.select_docker_service_settings(server_id, service_desc.slug)
|
||||
|
@ -87,67 +84,6 @@ def services(service, serv):
|
|||
servers_with_status.append(s[1])
|
||||
servers_with_status.append(s[2])
|
||||
servers_with_status.append(s[11])
|
||||
if service == 'nginx':
|
||||
h = (['', ''],)
|
||||
cmd = ("/usr/sbin/nginx -v 2>&1|awk '{print $3}' && systemctl status nginx |grep -e 'Active' |awk "
|
||||
"'{print $2, $9$10$11$12$13}' && ps ax |grep nginx:|grep -v grep |wc -l")
|
||||
for service_set in docker_settings:
|
||||
if service_set.server_id == s[0] and service_set.setting == 'dockerized' and service_set.value == '1':
|
||||
container_name = sql.get_setting('nginx_container_name')
|
||||
cmd = ("docker exec -it " + container_name + " /usr/sbin/nginx -v 2>&1|awk '{print $3}' "
|
||||
"&& docker ps -a -f name=" + container_name + " --format '{{.Status}}'|tail -1 && ps ax |grep nginx:|grep -v grep |wc -l")
|
||||
try:
|
||||
out = server_mod.ssh_command(s[2], cmd)
|
||||
h = ()
|
||||
out1 = []
|
||||
for k in out.split():
|
||||
out1.append(k)
|
||||
h = (out1,)
|
||||
servers_with_status.append(h)
|
||||
servers_with_status.append(h)
|
||||
servers_with_status.append(s[17])
|
||||
except Exception:
|
||||
servers_with_status.append(h)
|
||||
servers_with_status.append(h)
|
||||
servers_with_status.append(s[17])
|
||||
elif service == 'keepalived':
|
||||
status1, status2 = keepalived.get_status(s[2])
|
||||
servers_with_status.append(status1)
|
||||
servers_with_status.append(status2)
|
||||
servers_with_status.append(s[22])
|
||||
elif service == 'apache':
|
||||
h = (['', ''],)
|
||||
apache_stats_user = sql.get_setting('apache_stats_user')
|
||||
apache_stats_password = sql.get_setting('apache_stats_password')
|
||||
apache_stats_port = sql.get_setting('apache_stats_port')
|
||||
apache_stats_page = sql.get_setting('apache_stats_page')
|
||||
cmd = "curl -s -u %s:%s http://%s:%s/%s?auto |grep 'ServerVersion\|Processes\|ServerUptime:'" % (
|
||||
apache_stats_user, apache_stats_password, s[2], apache_stats_port, apache_stats_page
|
||||
)
|
||||
try:
|
||||
out = server_mod.subprocess_execute(cmd)
|
||||
if out != '':
|
||||
for k in out:
|
||||
servers_with_status.append(k)
|
||||
servers_with_status.append(s[22])
|
||||
except Exception:
|
||||
servers_with_status.append(h)
|
||||
servers_with_status.append(h)
|
||||
servers_with_status.append(s[22])
|
||||
else:
|
||||
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
|
||||
cmd = f'echo "show info" |nc {s[2]} {haproxy_sock_port} -w 1 -v|grep -e "Ver\|Uptime:\|Process_num"'
|
||||
out = server_mod.subprocess_execute(cmd)
|
||||
|
||||
for k in out:
|
||||
if "Connection refused" not in k:
|
||||
out1 = out
|
||||
else:
|
||||
out1 = False
|
||||
servers_with_status.append(out1)
|
||||
|
||||
servers_with_status.append(s[12])
|
||||
|
||||
servers_with_status.append(server_sql.select_servers(server=s[2]))
|
||||
is_keepalived = service_sql.select_keepalived(s[2])
|
||||
|
||||
|
@ -169,7 +105,6 @@ def services(service, serv):
|
|||
'clusters': ha_sql.select_ha_cluster_name_and_slaves(),
|
||||
'master_slave': server_sql.is_master(0, master_slave=1),
|
||||
'user_subscription': roxywi_common.return_user_subscription(),
|
||||
'autorefresh': autorefresh,
|
||||
'servers': servers_with_status1,
|
||||
'lang': g.user_params['lang'],
|
||||
'serv': serv,
|
||||
|
|
|
@ -7,26 +7,22 @@ function showHapservers(serv, hostnamea, service) {
|
|||
}
|
||||
}
|
||||
function showHapserversCallBack(serv, hostnamea, service) {
|
||||
$.ajax( {
|
||||
$.ajax({
|
||||
url: "/service/" + service + "/" + serv + "/last-edit",
|
||||
beforeSend: function() {
|
||||
$("#edit_date_"+hostnamea).html('<img class="loading_small_haproxyservers" src="/static/images/loading.gif" />');
|
||||
beforeSend: function () {
|
||||
$("#edit_date_" + hostnamea).html('<img class="loading_small_haproxyservers" src="/static/images/loading.gif" />');
|
||||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
if (data.indexOf('error:') != '-1') {
|
||||
toastr.error(data);
|
||||
success: function (data) {
|
||||
if (data.indexOf('ls: cannot access') != '-1') {
|
||||
$("#edit_date_" + hostnamea).empty();
|
||||
$("#edit_date_" + hostnamea).html();
|
||||
} else {
|
||||
if (data.indexOf('ls: cannot access') != '-1') {
|
||||
$("#edit_date_" + hostnamea).empty();
|
||||
$("#edit_date_" + hostnamea).html();
|
||||
} else {
|
||||
$("#edit_date_" + hostnamea).empty();
|
||||
$("#edit_date_" + hostnamea).html(data);
|
||||
}
|
||||
$("#edit_date_" + hostnamea).empty();
|
||||
$("#edit_date_" + hostnamea).html(data);
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
}
|
||||
function overviewHapserverBackends(serv, hostname, service) {
|
||||
let div = '';
|
||||
|
@ -294,10 +290,6 @@ function updateHapWIServer(id, service_name) {
|
|||
function change_pos(pos, id) {
|
||||
$.ajax({
|
||||
url: "/service/position/" + id + "/" + pos,
|
||||
// data: {
|
||||
// token: $('#token').val()
|
||||
// },
|
||||
// type: "POST",
|
||||
error: function () {
|
||||
console.log(w.data_error);
|
||||
}
|
||||
|
@ -391,10 +383,6 @@ function keepalivedBecameMaster(serv) {
|
|||
function showUsersOverview() {
|
||||
$.ajax( {
|
||||
url: "overview/users",
|
||||
// data: {
|
||||
// show_users_ovw: 1,
|
||||
// token: $('#token').val()
|
||||
// },
|
||||
type: "GET",
|
||||
beforeSend: function() {
|
||||
$("#users-table").html('<img class="loading_small_bin_bout" style="padding-left: 100%;padding-top: 40px;padding-bottom: 40px;" src="/static/images/loading.gif" />');
|
||||
|
@ -412,10 +400,6 @@ function showUsersOverview() {
|
|||
function showSubOverview() {
|
||||
$.ajax( {
|
||||
url: "/overview/sub",
|
||||
// data: {
|
||||
// show_sub_ovw: 1,
|
||||
// token: $('#token').val()
|
||||
// },
|
||||
type: "GET",
|
||||
beforeSend: function() {
|
||||
$("#sub-table").html('<img class="loading_small_bin_bout" style="padding-left: 40%;padding-top: 40px;padding-bottom: 40px;" src="/static/images/loading.gif" />');
|
||||
|
@ -513,21 +497,23 @@ function serverSettingsSave(id, name, service, dialog_id) {
|
|||
});
|
||||
}
|
||||
function check_service_status(id, ip, service) {
|
||||
if (sessionStorage.getItem('check-service') == 0) {
|
||||
if (sessionStorage.getItem('check-service-'+service+'-'+id) === '0') {
|
||||
return false;
|
||||
}
|
||||
NProgress.configure({showSpinner: false});
|
||||
if (service === 'keepalived') return false;
|
||||
let server_div = $('#div-server-' + id);
|
||||
$.ajax({
|
||||
url: "/service/" + service + "/" + id + "/status",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
statusCode: {
|
||||
401: function (xhr) {
|
||||
sessionStorage.setItem('check-service', 0)
|
||||
sessionStorage.setItem('check-service-'+service+'-'+id, '0')
|
||||
},
|
||||
404: function (xhr) {
|
||||
sessionStorage.setItem('check-service', 0)
|
||||
sessionStorage.setItem('check-service-'+service+'-'+id, '0')
|
||||
},
|
||||
500: function (xhr) {
|
||||
sessionStorage.setItem('check-service-'+service+'-'+id, '0')
|
||||
}
|
||||
},
|
||||
success: function (data) {
|
||||
|
@ -545,13 +531,25 @@ function check_service_status(id, ip, service) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
console.log(data.length)
|
||||
if (data.status === 'failed') {
|
||||
server_div.removeClass('div-server-head-unknown');
|
||||
server_div.removeClass('div-server-head-up');
|
||||
server_div.addClass('div-server-head-down');
|
||||
} else {
|
||||
server_div.addClass('div-server-head-up');
|
||||
server_div.removeClass('div-server-head-down');
|
||||
if (data.Status === 'running') {
|
||||
server_div.addClass('div-server-head-up');
|
||||
server_div.removeClass('div-server-head-down');
|
||||
server_div.removeClass('div-server-head-unknown');
|
||||
$('#uptime-word-'+id).text(translate_div.attr('data-uptime'));
|
||||
} else {
|
||||
server_div.removeClass('div-server-head-up');
|
||||
server_div.removeClass('div-server-head-unknown');
|
||||
server_div.addClass('div-server-head-down');
|
||||
$('#uptime-word-'+id).text(translate_div.attr('data-downtime'));
|
||||
}
|
||||
$('#service-version-'+id).text(data.Version);
|
||||
$('#service-process_num-'+id).text(data.Process);
|
||||
$('#service-uptime-'+id).text(data.Uptime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
data-installing="{{lang.words.installing|title()}}" data-creating="{{lang.words.creating|title()}}" data-roxywi_timeout="{{lang.ha_page.roxywi_timeout}}"
|
||||
data-check_apache_log="{{lang.ha_page.check_apache_log}}" data-was_installed="{{lang.ha_page.was_installed}}" data-start_enter="{{lang.ha_page.start_enter}}"
|
||||
data-apply="{{lang.words.apply|title()}}" data-reconfigure="{{lang.words.reconfigure|title()}}" data-server="{{lang.words.server|title()}}" data-port="{{lang.words.port}}"
|
||||
data-weight="{{lang.words.weight}}" />
|
||||
data-weight="{{lang.words.weight}}" data-uptime="{{lang.words.uptime}}" data-downtime="{{lang.words.downtime}}" />
|
||||
{% include 'include/main_head.html' %}
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
removeData();
|
||||
{%- if service == 'haproxy' %}
|
||||
{%- for s in servers %}
|
||||
{%- if s.7.0.9 %}
|
||||
{%- if s.4.0.9 %}
|
||||
getChartData(server_ip)
|
||||
getHttpChartData(server_ip)
|
||||
getWafChartData(server_ip)
|
||||
|
@ -82,12 +82,12 @@
|
|||
showOverviewServer('{{s.1}}', server_ip, '{{s.0}}', '{{service}}');
|
||||
{%- if service == 'nginx' %}
|
||||
showNginxConnections(server_ip)
|
||||
{% if s.7.0.21 %}
|
||||
{% if s.4.0.21 %}
|
||||
getNginxChartData(server_ip)
|
||||
{% endif %}
|
||||
{%- elif service == 'apache' %}
|
||||
showApachekBytes(server_ip)
|
||||
{% if s.7.0.27 %}
|
||||
{% if s.4.0.27 %}
|
||||
getApacheChartData(server_ip)
|
||||
{% endif %}
|
||||
{%- elif service == 'haproxy' %}
|
||||
|
@ -164,42 +164,22 @@
|
|||
{% endif %}
|
||||
{% set checker_desc = lang.services.hapservers_desc %}
|
||||
{% if service == 'nginx' %}
|
||||
{% set is_auto_start_enabled = s.7.0.17 %}
|
||||
{% set is_checker_enabled = s.7.0.19 %}
|
||||
{% set is_metrics_enabled = s.7.0.21 %}
|
||||
{% if s.5.0.1 == 'active' or s.5.0.1 == 'Up' %}
|
||||
{% set additional_status_class = 'div-server-head-up' %}
|
||||
{% else %}
|
||||
{% set additional_status_class = 'div-server-head-down' %}
|
||||
{% endif %}
|
||||
{% set is_auto_start_enabled = s.4.0.17 %}
|
||||
{% set is_checker_enabled = s.4.0.19 %}
|
||||
{% set is_metrics_enabled = s.4.0.21 %}
|
||||
{% elif service == 'keepalived' %}
|
||||
{% set is_auto_start_enabled = s.7.0.22 %}
|
||||
{% set is_checker_enabled = s.7.0.23 %}
|
||||
{% if s.5.0.1 == 'active' %}
|
||||
{% set additional_status_class = 'div-server-head-up' %}
|
||||
{% else %}
|
||||
{% set additional_status_class = 'div-server-head-down' %}
|
||||
{% endif %}
|
||||
{% set is_auto_start_enabled = s.4.0.22 %}
|
||||
{% set is_checker_enabled = s.4.0.23 %}
|
||||
{% elif service == 'apache' %}
|
||||
{% set is_auto_start_enabled = s.7.0.25 %}
|
||||
{% set is_checker_enabled = s.7.0.26 %}
|
||||
{% set is_metrics_enabled = s.7.0.27 %}
|
||||
{% if 'Apache' in s.4.0 %}
|
||||
{% set additional_status_class = 'div-server-head-up' %}
|
||||
{% else %}
|
||||
{% set additional_status_class = 'div-server-head-down' %}
|
||||
{% endif %}
|
||||
{% set is_auto_start_enabled = s.4.0.25 %}
|
||||
{% set is_checker_enabled = s.4.0.26 %}
|
||||
{% set is_metrics_enabled = s.4.0.27 %}
|
||||
{% elif service == 'haproxy' %}
|
||||
{% set is_auto_start_enabled = s.7.0.12 %}
|
||||
{% set is_checker_enabled = s.7.0.8 %}
|
||||
{% set is_metrics_enabled = s.7.0.9 %}
|
||||
{% if s.5 != False %}
|
||||
{% set additional_status_class = 'div-server-head-up' %}
|
||||
{% else %}
|
||||
{% set additional_status_class = 'div-server-head-down' %}
|
||||
{% endif %}
|
||||
{% set is_auto_start_enabled = s.4.0.12 %}
|
||||
{% set is_checker_enabled = s.4.0.8 %}
|
||||
{% set is_metrics_enabled = s.4.0.9 %}
|
||||
{% endif %}
|
||||
<div id="div-server-{{s.0}}" class="div-server-hapwi {{additional_status_class}}">
|
||||
<div id="div-server-{{s.0}}" class="div-server-hapwi div-server-head-unknown">
|
||||
<div class="server-name">
|
||||
<input type="hidden" id="server-name-{{s.0}}" value="{{s.1}}" />
|
||||
<input type="hidden" id="service" value="{{service}}" />
|
||||
|
@ -208,7 +188,7 @@
|
|||
{% else %}
|
||||
{{s.1}}
|
||||
{% endif %}
|
||||
{% if s.6|int() >= 1 %}
|
||||
{% if s.5|int() >= 1 %}
|
||||
<span
|
||||
{% if keep_alive|int() >= 1 %}
|
||||
class="shield green" title="Autostart {{lang.words.is}} {{lang.words.enabled2}}">
|
||||
|
@ -217,7 +197,7 @@
|
|||
{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if s.7.0.20 == 1 %}
|
||||
{% if s.4.0.20 == 1 %}
|
||||
<span class="lock" title="{{lang.phrases.server_is_inaccessible_for_editing}}"></span>
|
||||
{% endif %}
|
||||
{% for set in docker_settings %}
|
||||
|
@ -230,11 +210,9 @@
|
|||
<a id="start-{{ s.2 }}" class="start" title="{{lang.words.start|title()}} {{service}} {{lang.words.service}}">
|
||||
<span class="service-start" onclick="confirmAjaxAction('start', '{{service}}', '{{s.0}}', '{{s.1}}')"></span>
|
||||
</a>
|
||||
{% if service != 'keepalived' %}
|
||||
<a id="reload-{{ s.2 }}" class="reload" title="{{lang.words.reload|title()}} {{service}} {{lang.words.service}}">
|
||||
<span class="service-reload" onclick="confirmAjaxAction('reload', '{{service}}', '{{s.0}}', '{{s.1}}')"></span>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% for set in restart_settings %}
|
||||
{% if set.server_id == s.0 and set.setting == 'restart' and set.value|int == 0 %}
|
||||
<a id="restart-{{ s.2 }}" class="restart" title="{{lang.words.restart|title()}} {{service}} {{lang.words.service}}">
|
||||
|
@ -270,32 +248,9 @@
|
|||
{{s.3}}
|
||||
{% endif %}
|
||||
<br />
|
||||
{% if service == 'nginx' or service == 'keepalived' %}
|
||||
<b>{{lang.words.version|title()}}</b>: {{s.5.0.0}} <b>{{lang.words.process_num|title()}}</b>: {{s.5.0.3}}
|
||||
<br />
|
||||
{% if s.5.0.1 == 'active' or s.5.0.1 == 'Up' %}
|
||||
{{lang.words.started|title()}}:
|
||||
{% else %}
|
||||
{{lang.words.stopped|title()}}:
|
||||
{% endif %}
|
||||
{{s.5.0.2}}
|
||||
{% elif service == 'apache' %}
|
||||
{% if s.4.0 is defined %}
|
||||
{{s.4.0.split(' ')[0].split('Server')[1]}} {{s.4.0.split(' ')[1]}} {{s.4.2}}
|
||||
<br />
|
||||
{{s.4.1.split(' ')[0].split('Server')[1]}} {% for i in s.4.1.split(' ')[1:5] %} {{i}}{% endfor %}
|
||||
{% else %}
|
||||
{{lang.errors.cannot_get_info}} Apache
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if s.5.0 is defined %}
|
||||
{{s.5.0.0}} {{s.5.0.1}}
|
||||
<br />
|
||||
{{s.5.0.2}}
|
||||
{% else %}
|
||||
{{lang.errors.cannot_get_info}} HAProxy
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<b>{{lang.words.version|title()}}</b>: <span id="service-version-{{ s.0 }}"></span>
|
||||
<b>{{lang.words.process_num|title()}}</b>: <span id="service-process_num-{{ s.0 }}"></span><br />
|
||||
<b id="uptime-word-{{ s.0 }}">{{lang.words.uptime|title()}}</b>: <span id="service-uptime-{{ s.0 }}"></span>
|
||||
<span title="Date of last configuration edit">
|
||||
<b>{{lang.services.last_edit}}</b>:
|
||||
<span id="edit_date_{{s.2}}"></span>
|
||||
|
@ -317,10 +272,10 @@
|
|||
{{lang.words.slave_for}}: <b>{{ copy_to_clipboard(value=master.0, style='font-weight: bold') }}</b>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if s.8.0 == '1' %}
|
||||
{% if s.5.0 == '1' %}
|
||||
VRRP: <b>
|
||||
{% if s.8.1 == 'MASTER' or s.8.1 == 'BACKUP' or s.8.1 == 'INIT' or s.8.1 == 'FAULT' %}
|
||||
{{s.8.1}}
|
||||
{% if s.5.1 == 'MASTER' or s.5.1 == 'BACKUP' or s.5.1 == 'INIT' or s.5.1 == 'FAULT' %}
|
||||
{{s.5.1}}
|
||||
{% else %}
|
||||
<span title="{{lang.errors.cannot_get_info}} Keepalived" class="help_cursor">{{lang.words.error|title()}}</span>
|
||||
{% endif %}
|
||||
|
@ -328,9 +283,9 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="server-act-links" id="server-{{s.7.0.0|string()}}-{{service}}">
|
||||
<div class="server-act-links" id="server-{{s.4.0.0|string()}}-{{service}}">
|
||||
{% if g.user_params['role'] <= 2 %}
|
||||
{% set id = 'alert-' + s.7.0.0|string() %}
|
||||
{% set id = 'alert-' + s.4.0.0|string() %}
|
||||
{% if is_checker_enabled == 1 %}
|
||||
{{ checkbox(id, title=checker_desc, value='1', desc='Checker', checked='checked') }}
|
||||
{% else %}
|
||||
|
@ -338,7 +293,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
{% if g.user_params['role'] <= 2 and service != 'keepalived' %}
|
||||
{% set id = 'metrics-' + s.7.0.0|string() %}
|
||||
{% set id = 'metrics-' + s.4.0.0|string() %}
|
||||
{% if is_metrics_enabled == 1 %}
|
||||
{{ checkbox(id, title='Collecting metrics is enabled', value='1', desc='Metrics', checked='checked') }}
|
||||
{% else %}
|
||||
|
@ -346,7 +301,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
{% if g.user_params['role'] <= 2 %}
|
||||
{% set id = 'active-' + s.7.0.0|string() %}
|
||||
{% set id = 'active-' + s.4.0.0|string() %}
|
||||
{% if is_auto_start_enabled == 1 %}
|
||||
{{ checkbox(id, title='Auto Start is enabled', value='1', desc='Auto Start', checked='checked') }}
|
||||
{% else %}
|
||||
|
@ -376,7 +331,7 @@
|
|||
{% if serv %}
|
||||
<div id="bin_bout"></div>
|
||||
<div id="ajax-server-{{s.0}}" class="ajax-server"></div>
|
||||
<div class="div-server div-backends" style="margin-bottom: 0px;">
|
||||
<div class="div-server div-backends" style="margin-bottom: 0;">
|
||||
<div class="server-name backends">
|
||||
{% if service == 'haproxy' %}
|
||||
{{lang.words.backends|title()}}:
|
||||
|
@ -394,9 +349,9 @@
|
|||
{% if serv %}
|
||||
{% for s in servers %}
|
||||
{% if service in ('haproxy', 'nginx', 'apache') %}
|
||||
{% if (service == 'haproxy' and s.7.0.9)
|
||||
or (service == 'nginx' and s.7.0.21)
|
||||
or (service == 'apache' and s.7.0.27) %}
|
||||
{% if (service == 'haproxy' and s.4.0.9)
|
||||
or (service == 'nginx' and s.4.0.21)
|
||||
or (service == 'apache' and s.4.0.27) %}
|
||||
<div class="metrics-time-range">
|
||||
<b>{{lang.words.time_range|title()}}:</b>
|
||||
<select title="Choose time range" id="time-range">
|
||||
|
@ -409,7 +364,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if service == 'haproxy' and s.7.0.9 %}
|
||||
{% if service == 'haproxy' and s.4.0.9 %}
|
||||
<div id="server_metrics_div" class="chart-container_overview" style="margin-top: -35px;">
|
||||
<canvas id="{{s.2}}" role="img"></canvas>
|
||||
</div>
|
||||
|
@ -421,11 +376,11 @@
|
|||
<canvas id="waf_{{s.2}}" role="img"></canvas>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% elif service == 'nginx' and s.7.0.21 %}
|
||||
{% elif service == 'nginx' and s.4.0.21 %}
|
||||
<div id="nginx_metrics_div" class="chart-container_overview" style="margin-top: -35px;">
|
||||
<canvas id="nginx_{{s.2}}" role="img"></canvas>
|
||||
</div>
|
||||
{% elif service == 'apache' and s.7.0.27 %}
|
||||
{% elif service == 'apache' and s.4.0.27 %}
|
||||
<div id="apache_metrics_div" class="chart-container_overview" style="margin-top: -35px;">
|
||||
<canvas id="apache_{{s.2}}" role="img"></canvas>
|
||||
</div>
|
||||
|
@ -441,5 +396,9 @@
|
|||
overviewHapserverBackends(ip, hostnamea, '{{service}}');
|
||||
{% endif %}
|
||||
showHapservers(ip, hostnamea, '{{service}}');
|
||||
{% for s in servers %}
|
||||
sessionStorage.removeItem('check-service-{{ service }}-{{s.2}}')
|
||||
check_service_status({{s.0}}, '{{s.2}}', '{{service}}');
|
||||
{% endfor %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,6 +7,7 @@ from playhouse.shortcuts import model_to_dict
|
|||
from flask_jwt_extended import jwt_required
|
||||
|
||||
import app.modules.db.sql as sql
|
||||
import app.modules.roxywi.roxy as roxy
|
||||
import app.modules.roxywi.common as roxywi_common
|
||||
import app.modules.tools.smon as smon_mod
|
||||
from app.middleware import get_user_params, page_for_admin, check_group
|
||||
|
@ -143,4 +144,6 @@ class SettingsView(MethodView):
|
|||
smon_mod.change_smon_port(int(val))
|
||||
except Exception as e:
|
||||
return f'{e}'
|
||||
if body.param == 'license':
|
||||
roxy.update_plan()
|
||||
return BaseResponse().model_dump(mode='json'), 201
|
||||
|
|
|
@ -74,6 +74,12 @@ class ServiceView(MethodView):
|
|||
Version:
|
||||
type: 'string'
|
||||
description: 'Version of the service'
|
||||
Process:
|
||||
type: 'string'
|
||||
description: 'Number of processes launched by the service'
|
||||
Status:
|
||||
type: 'string'
|
||||
description: 'Status of the service'
|
||||
default:
|
||||
description: Unexpected error
|
||||
"""
|
||||
|
@ -88,12 +94,15 @@ class ServiceView(MethodView):
|
|||
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot find a server')
|
||||
|
||||
if service == 'haproxy':
|
||||
cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:"' % (
|
||||
server.ip, sql.get_setting('haproxy_sock_port'))
|
||||
cmd = 'echo "show info" |nc %s %s -w 1|grep -e "Ver\|CurrConns\|Maxco\|MB\|Uptime:\|Process_num"' % (
|
||||
server.ip, sql.get_setting('haproxy_sock_port')
|
||||
)
|
||||
out = server_mod.subprocess_execute(cmd)
|
||||
data = self.return_dict_from_out(out[0])
|
||||
if len(data) == 0:
|
||||
data = ErrorResponse(error='Cannot get information').model_dump(mode='json')
|
||||
else:
|
||||
data['Status'] = self._service_status(data['Process'])
|
||||
elif service == 'nginx':
|
||||
is_dockerized = service_sql.select_service_setting(server_id, service, 'dockerized')
|
||||
if is_dockerized == '1':
|
||||
|
@ -105,7 +114,13 @@ class ServiceView(MethodView):
|
|||
try:
|
||||
out = server_mod.ssh_command(server.ip, cmd)
|
||||
out1 = out.split()
|
||||
data = {"Version": out1[0].split('/')[1], "Uptime": out1[2], "Process": out1[3]}
|
||||
data = {
|
||||
"Version": out1[0].split('/')[1],
|
||||
"Uptime": out1[2],
|
||||
"Process": out1[3],
|
||||
"Status": self._service_status(out1[3])}
|
||||
except IndexError:
|
||||
return ErrorResponse(error='NGINX service not found').model_dump(mode='json'), 404
|
||||
except Exception as e:
|
||||
data = ErrorResponse(error=str(e)).model_dump(mode='json')
|
||||
elif service == 'apache':
|
||||
|
@ -124,19 +139,24 @@ class ServiceView(MethodView):
|
|||
data = {
|
||||
"Version": servers_with_status[0][0].split('/')[1],
|
||||
"Uptime": servers_with_status[0][1].split(':')[1].strip(),
|
||||
"Process": servers_with_status[0][2].split(' ')[1]
|
||||
"Process": servers_with_status[0][2].split(' ')[1],
|
||||
"Status": self._service_status(servers_with_status[0][2].split(' ')[1])
|
||||
}
|
||||
except IndexError:
|
||||
return ErrorResponse(error='Apache service not found').model_dump(mode='json'), 404
|
||||
except Exception as e:
|
||||
data = ErrorResponse(error=str(e)).model_dump(mode='json')
|
||||
elif service == 'keepalived':
|
||||
cmd = "sudo /usr/sbin/keepalived -v 2>&1|head -1|awk '{print $2}'"
|
||||
cmd = ("sudo /usr/sbin/keepalived -v 2>&1|head -1|awk '{print $2}' && sudo systemctl status keepalived |grep -e 'Active'"
|
||||
"|awk '{print $2, $9$10$11$12$13}' && ps ax |grep 'keepalived -D'|grep -v grep |wc -l")
|
||||
try:
|
||||
version = server_mod.ssh_command(server.ip, cmd)
|
||||
out = server_mod.ssh_command(server.ip, cmd)
|
||||
out1 = out.split()
|
||||
data = {"Version": out1[0].split('\r')[0], "Uptime": out1[2], "Process": out1[3], 'Status': self._service_status(out1[3])}
|
||||
except IndexError:
|
||||
return ErrorResponse(error='Keepalived service not found').model_dump(mode='json'), 404
|
||||
except Exception as e:
|
||||
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot get version')
|
||||
if version == '/usr/sbin/keepalived:\r\n':
|
||||
return ErrorResponse(error='Cannot get keepalived').model_dump(mode='json')
|
||||
data = {'Version': version}
|
||||
return jsonify(data)
|
||||
|
||||
@staticmethod
|
||||
|
@ -145,12 +165,21 @@ class ServiceView(MethodView):
|
|||
for k in out:
|
||||
if "Ncat:" not in k:
|
||||
k = k.split(':')
|
||||
data[k[0]] = k[1].strip()
|
||||
if k[0] == 'Process_num':
|
||||
data['Process'] = k[1].strip()
|
||||
else:
|
||||
data[k[0]] = k[1].strip()
|
||||
else:
|
||||
data = {"error": "Cannot connect to HAProxy"}
|
||||
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def _service_status(process_num: int) -> str:
|
||||
if process_num == '0':
|
||||
return 'stopped'
|
||||
return 'running'
|
||||
|
||||
|
||||
class ServiceActionView(MethodView):
|
||||
methods = ['GET']
|
||||
|
@ -290,7 +319,7 @@ class ServiceConfigView(MethodView):
|
|||
description: Unexpected error
|
||||
"""
|
||||
if service in ('nginx', 'apache') and (query.file_path is None and query.version is None):
|
||||
return ErrorResponse(error=f'There is must be "file_name" as query parameter for {service.title()}')
|
||||
return ErrorResponse(error=f'There is must be "file_path" as query parameter for {service.title()}')
|
||||
if query.file_path:
|
||||
query.file_path = query.file_path.replace('/', '92')
|
||||
|
||||
|
@ -307,7 +336,7 @@ class ServiceConfigView(MethodView):
|
|||
else:
|
||||
cfg = config_common.generate_config_path(service, server_ip)
|
||||
try:
|
||||
config_mod.get_config(server_ip, cfg, service=service, config_file_name=query.file_name)
|
||||
config_mod.get_config(server_ip, cfg, service=service, config_file_name=query.file_path)
|
||||
except Exception as e:
|
||||
return ErrorResponse(error=str(e)).model_dump(mode='json')
|
||||
|
||||
|
@ -350,7 +379,7 @@ class ServiceConfigView(MethodView):
|
|||
type: string
|
||||
description: The configuration to be saved.
|
||||
required: true
|
||||
file_name:
|
||||
file_path:
|
||||
type: string
|
||||
description: Path to the configuration file. Only for NGINX and Apache services.
|
||||
config_local_path:
|
||||
|
@ -372,15 +401,15 @@ class ServiceConfigView(MethodView):
|
|||
default:
|
||||
description: Unexpected error
|
||||
"""
|
||||
if service in ('nginx', 'apache') and (body.file_name is None):
|
||||
return ErrorResponse(error=f'There is must be "file_name" as json parameter for {service.title()}')
|
||||
if service in ('nginx', 'apache') and (body.file_path is None):
|
||||
return ErrorResponse(error=f'There is must be "file_path" as json parameter for {service.title()}')
|
||||
try:
|
||||
server_ip = SupportClass(False).return_server_ip_or_id(server_id)
|
||||
except Exception as e:
|
||||
return roxywi_common.handler_exceptions_for_json_data(e, '')
|
||||
|
||||
try:
|
||||
cfg = config_mod.return_cfg(service, server_ip, body.file_name)
|
||||
cfg = config_mod.return_cfg(service, server_ip, body.file_path)
|
||||
except Exception as e:
|
||||
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot get config')
|
||||
|
||||
|
@ -395,7 +424,7 @@ class ServiceConfigView(MethodView):
|
|||
stderr = config_mod.upload_and_restart(server_ip, cfg, body.action, service, oldcfg=body.config_local_path)
|
||||
else:
|
||||
stderr = config_mod.master_slave_upload_and_restart(server_ip, cfg, body.action, service, oldcfg=body.config_local_path,
|
||||
config_file_name=body.file_name)
|
||||
config_file_name=body.file_path)
|
||||
except Exception as e:
|
||||
return f'error: {e}', 200
|
||||
|
||||
|
|
Loading…
Reference in New Issue