diff --git a/app/modules/config/runtime.py b/app/modules/config/runtime.py index 65e21e9b..2e01f961 100644 --- a/app/modules/config/runtime.py +++ b/app/modules/config/runtime.py @@ -1,6 +1,6 @@ import json -from flask import render_template +from flask import render_template, jsonify import app.modules.db.sql as sql import app.modules.db.server as server_sql @@ -438,14 +438,14 @@ def clear_stick_table(serv, table) -> str: return 'ok' -def list_of_lists(serv) -> str: +def list_of_lists(serv) -> dict: haproxy_sock_port = sql.get_setting('haproxy_sock_port') cmd = f'echo "show acl"|nc {serv} {haproxy_sock_port} |grep "loaded from" |awk \'{{print $1,$2}}\'' output, stderr = server_mod.subprocess_execute(cmd) - try: - return output[0] - except Exception: - return '------' + acl_lists = [] + for i in output: + acl_lists.append(i) + return jsonify(acl_lists) def show_lists(serv, list_id, color, list_name) -> str: diff --git a/app/routes/runtime/routes.py b/app/routes/runtime/routes.py index a6bcf3f1..cfc369b7 100644 --- a/app/routes/runtime/routes.py +++ b/app/routes/runtime/routes.py @@ -5,6 +5,7 @@ from app.routes.runtime import bp from app.middleware import get_user_params import app.modules.common.common as common import app.modules.config.runtime as runtime +import app.modules.db.server as server_sql import app.modules.service.haproxy as service_haproxy @@ -21,10 +22,14 @@ def runtimeapi(): return render_template('runtimeapi.html', lang=g.user_params['lang']) +@bp.route('/backends/') @bp.route('/backends/') def show_backends(server_ip): - server_ip = common.is_ip_or_dns(server_ip) - + if isinstance(server_ip, str): + server_ip = common.is_ip_or_dns(server_ip) + elif isinstance(server_ip, int): + server = server_sql.get_server_by_id(server_ip) + server_ip = server.ip try: return runtime.show_backends(server_ip) except Exception as e: diff --git a/app/static/js/metrics.js b/app/static/js/metrics.js index 4e451dc9..610afd4a 100644 --- a/app/static/js/metrics.js +++ b/app/static/js/metrics.js @@ -73,7 +73,7 @@ function stream_chart(chart_id, service, service_ip, is_http=0) { } chart_id.data.labels.push(data.time); chart_id.data.datasets[0].data.push(data.value); - if (service == 'haproxy') { + if (service === 'haproxy') { chart_id.data.datasets[1].data.push(data.value1); chart_id.data.datasets[2].data.push(data.value2); } @@ -85,7 +85,7 @@ function stream_chart(chart_id, service, service_ip, is_http=0) { } function getHttpChartData(server) { let hide_http_metrics = localStorage.getItem('hide_http_metrics'); - if (hide_http_metrics == 'disabled') { + if (hide_http_metrics === 'disabled') { return false; } $.ajax({ @@ -94,7 +94,7 @@ function getHttpChartData(server) { time_range: $( "#time-range option:selected" ).val(), }, type: "POST", - success: function (result) { + success: function (result) { let data = []; data.push(result.chartData.http_2xx); data.push(result.chartData.http_3xx); @@ -207,6 +207,7 @@ function renderHttpChart(data, labels, server) { }, }, }); + charts.push(myChart) stream_chart(myChart, 'haproxy', server, 1); } function getChartData(server) { @@ -311,6 +312,7 @@ function renderChart(data, labels, server) { } } }); + charts.push(myChart) stream_chart(myChart, 'haproxy', server); } function getWafChartData(server) { @@ -343,7 +345,7 @@ function renderServiceChart(data, labels, server, service) { if (service === 'waf') { additional_title = 'WAF '; } - config = return_service_chart_config(); + let config = return_service_chart_config(); for (let i=0; i") - .attr("value", id) - .text(text_option)); + for (let value of data ) { + try { + value = value.replace(/\'/g, ''); + value = value.replace('(', ''); + value = value.replace(')', ''); + value = value.replace('[', ''); + value = value.replace(']', ''); + id = value.split(' ')[0]; + full_text_option = value.split(' ')[1] + text_option = full_text_option.split('/').slice(-2)[0]; + text_option = text_option + '/' + full_text_option.split('/').slice(-1)[0]; + } catch (err) { + text_option = value; } + $('#list_select').append($("") + .attr("value", id) + .text(text_option)); } $('#list_select').selectmenu("refresh"); } @@ -333,7 +329,6 @@ function getTable() { function getList() { let color = $('#list_select option:selected').text().split('/')[0]; let list_name = $('#list_select option:selected').text().split('/')[1]; - console.log(list_name) $.ajax({ url: "/runtimeapi/list/" + $('#list_serv_select').val() + "/" + $('#list_select').val() + "/" + color + "/" + list_name, success: function (data) { diff --git a/app/views/ha/views.py b/app/views/ha/views.py index 80103fad..8e4164f6 100644 --- a/app/views/ha/views.py +++ b/app/views/ha/views.py @@ -11,7 +11,6 @@ import app.modules.service.ha_cluster as ha_cluster import app.modules.service.installation as service_mod from app.middleware import get_user_params, page_for_admin, check_group, check_services from app.modules.roxywi.class_models import BaseResponse, IdResponse, HAClusterRequest, HAClusterVIP -from app.routes.service.routes import services class HAView(MethodView): diff --git a/app/views/service/views.py b/app/views/service/views.py index b4776cf2..fe3911aa 100644 --- a/app/views/service/views.py +++ b/app/views/service/views.py @@ -170,16 +170,8 @@ class ServiceView(MethodView): except Exception as e: data = ErrorResponse(error=str(e)).model_dump(mode='json') elif service == 'keepalived': - try: - os_info = server_sql.select_os_info(server_id) - except RoxywiResourceNotFound: - raise RoxywiResourceNotFound('Cannot find system information') - if "CentOS" in os_info or "Redhat" in os_info: - kp_proc_name = 'keepalived -D' - else: - kp_proc_name = 'keepalived --dont-fork' cmd = ("sudo /usr/sbin/keepalived -v 2>&1|head -1|awk '{print $2}' && sudo systemctl status keepalived |grep -e 'Active'" - f"|awk '{{print $2, $9$10$11$12$13}}' && ps ax |grep '{kp_proc_name}'|grep -v grep |wc -l") + f"|awk '{{print $2, $9$10$11$12$13}}' && ps ax |grep keepalived|grep -v udp|grep -v grep |wc -l") try: out = server_mod.ssh_command(server.ip, cmd) out1 = out.split()