From 37c63dd269387ac7bed1dd4a23f76f2a97b77ef7 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Wed, 20 Nov 2024 15:43:04 +0300 Subject: [PATCH] v1.2.2: Change ignore_unreachable to ignore_errors and add region and country routes Updated Ansible task files to use `ignore_errors` instead of `ignore_unreachable` for better error handling. Added new routes and templates to handle region and country details and their respective checks in the monitoring system. --- app/modules/db/smon.py | 16 +++ app/modules/roxywi/class_models.py | 1 - app/routes/smon/agent_routes.py | 34 +++++ .../roles/rmon_agent/tasks/install-debian.yml | 8 +- app/templates/ajax/smon/country.html | 2 +- app/templates/ajax/smon/region.html | 2 +- app/templates/ajax/smon/smon_dashboard.html | 2 +- .../include/smon/checks_for_overview.html | 116 +++++++++++++++++ app/templates/smon/agent.html | 117 +----------------- app/templates/smon/country.html | 58 +++++++++ app/templates/smon/region.html | 53 ++++++++ 11 files changed, 285 insertions(+), 124 deletions(-) create mode 100644 app/templates/include/smon/checks_for_overview.html create mode 100644 app/templates/smon/country.html create mode 100644 app/templates/smon/region.html diff --git a/app/modules/db/smon.py b/app/modules/db/smon.py index 2124719..67f2275 100644 --- a/app/modules/db/smon.py +++ b/app/modules/db/smon.py @@ -681,6 +681,22 @@ def select_checks_for_agent_by_check_type(agent_id: int, check_type: str) -> dic out_error(e) +def select_checks_for_region_by_check_type(region_id: int, check_type: str) -> dict: + correct_model = tool_common.get_model_for_check(check_type=check_type) + try: + return correct_model.select(correct_model, SMON).join(SMON).where(SMON.region_id == region_id).objects().execute() + except Exception as e: + out_error(e) + + +def select_checks_for_country_by_check_type(country_id: int, check_type: str) -> dict: + correct_model = tool_common.get_model_for_check(check_type=check_type) + try: + return correct_model.select(correct_model, SMON).join(SMON).where(SMON.country_id == country_id).objects().execute() + except Exception as e: + out_error(e) + + def get_smon_group_by_name(group_id: int, name: str) -> int: try: return SmonGroup.select().where((SmonGroup.name == name) & (SmonGroup.group_id == group_id)).get().id diff --git a/app/modules/roxywi/class_models.py b/app/modules/roxywi/class_models.py index f9a3993..0db5a0f 100644 --- a/app/modules/roxywi/class_models.py +++ b/app/modules/roxywi/class_models.py @@ -259,7 +259,6 @@ class RegionRequest(BaseModel): shared: Optional[bool] = 0 enabled: Optional[bool] = 1 group_id: Optional[int] = None - country_id: Optional[int] = None agents: Optional[list[int]] = None diff --git a/app/routes/smon/agent_routes.py b/app/routes/smon/agent_routes.py index 97c6b85..d479ec8 100644 --- a/app/routes/smon/agent_routes.py +++ b/app/routes/smon/agent_routes.py @@ -47,6 +47,40 @@ def get_agent(agent_id): return render_template('smon/agent.html', **kwargs) +@bp.get('/region/') +@jwt_required() +@get_user_params() +def get_region(region_id): + kwargs = { + 'region': region_sql.get_region_with_group(region_id, g.user_params['group_id']), + 'lang': roxywi_common.get_user_lang_for_flask(), + 'smon_status': tools_common.is_tool_active('rmon-server'), + 'region_id': region_id + } + + for check_type in ('http', 'tcp', 'dns', 'ping', 'smtp', 'rabbitmq'): + kwargs[f'{check_type}_checks'] = smon_sql.select_checks_for_region_by_check_type(region_id, check_type) + + return render_template('smon/region.html', **kwargs) + + +@bp.get('/country/') +@jwt_required() +@get_user_params() +def get_country(country_id): + kwargs = { + 'country': country_sql.get_country_with_group(country_id, g.user_params['group_id']), + 'lang': roxywi_common.get_user_lang_for_flask(), + 'smon_status': tools_common.is_tool_active('rmon-server'), + 'country_id': country_id + } + + for check_type in ('http', 'tcp', 'dns', 'ping', 'smtp', 'rabbitmq'): + kwargs[f'{check_type}_checks'] = smon_sql.select_checks_for_country_by_check_type(country_id, check_type) + + return render_template('smon/country.html', **kwargs) + + @bp.post('/agent/hello') def agent_get_checks(): json_data = request.json diff --git a/app/scripts/ansible/roles/rmon_agent/tasks/install-debian.yml b/app/scripts/ansible/roles/rmon_agent/tasks/install-debian.yml index 8791d48..6461ab1 100644 --- a/app/scripts/ansible/roles/rmon_agent/tasks/install-debian.yml +++ b/app/scripts/ansible/roles/rmon_agent/tasks/install-debian.yml @@ -11,13 +11,13 @@ executable: pip3 state: latest extra_args: --upgrade --break-system-packages - ignore_unreachable: true + ignore_errors: true - name: Install RMON Agent python requirements for new Debian ansible.builtin.pip: requirements: /var/lib/rmon/rmon-agent/requirements.txt extra_args: --break-system-packages - ignore_unreachable: true + ignore_errors: true - name: Upgrade pip3 for old Debian pip: @@ -25,9 +25,9 @@ executable: pip3 state: latest extra_args: --upgrade - ignore_unreachable: true + ignore_errors: true - name: Install RMON Agent python requirements for old Debian ansible.builtin.pip: requirements: /var/lib/rmon/rmon-agent/requirements.txt - ignore_unreachable: true + ignore_errors: true diff --git a/app/templates/ajax/smon/country.html b/app/templates/ajax/smon/country.html index 59cf914..ed0f1ae 100644 --- a/app/templates/ajax/smon/country.html +++ b/app/templates/ajax/smon/country.html @@ -4,7 +4,7 @@
- {{country.name.replace("'","")}} + {{country.name.replace("'","")}} {% if country.description %} ({{country.description.replace("'", "")}}) {% endif %} diff --git a/app/templates/ajax/smon/region.html b/app/templates/ajax/smon/region.html index ea7545e..153f2b7 100644 --- a/app/templates/ajax/smon/region.html +++ b/app/templates/ajax/smon/region.html @@ -4,7 +4,7 @@
- {{region.name.replace("'","")}} + {{region.name.replace("'","")}} {% if region.description %} ({{region.description.replace("'", "")}}) {% endif %} diff --git a/app/templates/ajax/smon/smon_dashboard.html b/app/templates/ajax/smon/smon_dashboard.html index 3697d43..853ccec 100644 --- a/app/templates/ajax/smon/smon_dashboard.html +++ b/app/templates/ajax/smon/smon_dashboard.html @@ -43,7 +43,7 @@ {% set down = [] %} {% set up = [] %} {% set dis = [] %} - {% for s in smon %} + {% for s in multi_checks %} {% if s.enabled == 1 %} {% if s.status == 1 and s.body_status == 1 %} {% if up.append('1') %} {% endif %} diff --git a/app/templates/include/smon/checks_for_overview.html b/app/templates/include/smon/checks_for_overview.html new file mode 100644 index 0000000..1e5ef5e --- /dev/null +++ b/app/templates/include/smon/checks_for_overview.html @@ -0,0 +1,116 @@ +
+
+
{{ lang.words.checks|title() }} {{ lang.words.on }} {{ lang.words.the }} {{ lang.words.agent3 }}
+ {% if http_checks %} +
HTTP:
+
+ {% for check in http_checks %} +
+ {{ lang.words.name|title() }}: + {{ check.name|replace("'", "") }} + + {{ lang.words.interval|title() }}: {{ check.interval }} + URL: {{ check.url }} + {{ lang.words.method|title() }}: {{ check.method|upper() }} + + + +
+ {% endfor %} +
+ {% endif %} + {% if tcp_checks %} +
TCP:
+
+ {% for check in tcp_checks %} +
+ {{ lang.words.name|title() }}: + {{ check.name|replace("'", "") }} + + {{ lang.words.interval|title() }}: {{ check.interval }} + {{ lang.words.Hostname }}: {{ check.ip }} + {{ lang.words.port|title() }}: {{ check.port }} + + + +
+ {% endfor %} +
+ {% endif %} + {% if dns_checks %} +
DNS:
+
+ {% for check in dns_checks %} +
+ {{ lang.words.name|title() }}: + {{ check.name|replace("'", "") }} + + {{ lang.words.interval|title() }}: {{ check.interval }} + {{ lang.words.record|title() }}: {{ check.ip }} + Resolver:{{ check.resolver }} + {{ lang.words.record_type|title() }}: {{ check.record_type|upper() }} + {{ lang.words.port|title() }}: {{ check.port }} + + + +
+ {% endfor %} +
+ {% endif %} + {% if ping_checks %} +
Ping:
+
+ {% for check in ping_checks %} +
+ {{ lang.words.name|title() }}: + {{ check.name|replace("'", "") }} + + {{ lang.words.interval|title() }}: {{ check.interval }} + {{ lang.words.Hostname }}: {{ check.ip }} + {{ lang.smon_page.desc.packet_size }}: {{ check.packet_size }} + + + +
+ {% endfor %} +
+ {% endif %} + {% if smtp_checks %} +
SMTP:
+
+ {% for check in smtp_checks %} +
+ {{ lang.words.name|title() }}: + {{ check.name|replace("'", "") }} + + {{ lang.words.interval|title() }}: {{ check.interval }} + {{ lang.words.Hostname }}: {{ check.ip }} + {{ lang.words.port|title() }}: {{ check.port }} + + + +
+ {% endfor %} +
+ {% endif %} + {% if rabbitmq_checks %} +
RabbitMQ:
+
+ {% for check in rabbitmq_checks %} +
+ {{ lang.words.name|title() }}: + {{ check.name|replace("'", "") }} + + {{ lang.words.interval|title() }}: {{ check.interval }} + {{ lang.words.Hostname }}: {{ check.ip }} + VHost: {{ check.vhost }} + {{ lang.words.port|title() }}: {{ check.port }} + + + +
+ {% endfor %} +
+ {% endif %} +
+
\ No newline at end of file diff --git a/app/templates/smon/agent.html b/app/templates/smon/agent.html index 6221dc6..3d11b1c 100644 --- a/app/templates/smon/agent.html +++ b/app/templates/smon/agent.html @@ -92,122 +92,7 @@
-
-
-
{{ lang.words.checks|title() }} {{ lang.words.on }} {{ lang.words.the }} {{ lang.words.agent3 }}
- {% if http_checks %} -
HTTP:
-
- {% for check in http_checks %} -
- {{ lang.words.name|title() }}: - {{ check.name|replace("'", "") }} - - {{ lang.words.interval|title() }}: {{ check.interval }} - URL: {{ check.url }} - {{ lang.words.method|title() }}: {{ check.method|upper() }} - - - -
- {% endfor %} -
- {% endif %} - {% if tcp_checks %} -
TCP:
-
- {% for check in tcp_checks %} -
- {{ lang.words.name|title() }}: - {{ check.name|replace("'", "") }} - - {{ lang.words.interval|title() }}: {{ check.interval }} - {{ lang.words.Hostname }}: {{ check.ip }} - {{ lang.words.port|title() }}: {{ check.port }} - - - -
- {% endfor %} -
- {% endif %} - {% if dns_checks %} -
DNS:
-
- {% for check in dns_checks %} -
- {{ lang.words.name|title() }}: - {{ check.name|replace("'", "") }} - - {{ lang.words.interval|title() }}: {{ check.interval }} - {{ lang.words.record|title() }}: {{ check.ip }} - Resolver:{{ check.resolver }} - {{ lang.words.record_type|title() }}: {{ check.record_type|upper() }} - {{ lang.words.port|title() }}: {{ check.port }} - - - -
- {% endfor %} -
- {% endif %} - {% if ping_checks %} -
Ping:
-
- {% for check in ping_checks %} -
- {{ lang.words.name|title() }}: - {{ check.name|replace("'", "") }} - - {{ lang.words.interval|title() }}: {{ check.interval }} - {{ lang.words.Hostname }}: {{ check.ip }} - {{ lang.smon_page.desc.packet_size }}: {{ check.packet_size }} - - - -
- {% endfor %} -
- {% endif %} - {% if smtp_checks %} -
SMTP:
-
- {% for check in smtp_checks %} -
- {{ lang.words.name|title() }}: - {{ check.name|replace("'", "") }} - - {{ lang.words.interval|title() }}: {{ check.interval }} - {{ lang.words.Hostname }}: {{ check.ip }} - {{ lang.words.port|title() }}: {{ check.port }} - - - -
- {% endfor %} -
- {% endif %} - {% if rabbitmq_checks %} -
RabbitMQ:
-
- {% for check in rabbitmq_checks %} -
- {{ lang.words.name|title() }}: - {{ check.name|replace("'", "") }} - - {{ lang.words.interval|title() }}: {{ check.interval }} - {{ lang.words.Hostname }}: {{ check.ip }} - VHost: {{ check.vhost }} - {{ lang.words.port|title() }}: {{ check.port }} - - - -
- {% endfor %} -
- {% endif %} -
-
+ {% include 'include/smon/checks_for_overview.html' %} diff --git a/app/templates/smon/country.html b/app/templates/smon/country.html new file mode 100644 index 0000000..25d72bf --- /dev/null +++ b/app/templates/smon/country.html @@ -0,0 +1,58 @@ +{% extends "base.html" %} +{% block title %}{{ lang.words.overview|title() }} {{ lang.words.country }}{% endblock %} +{% block h2 %}{{ lang.words.overview|title() }} {{ lang.words.country }}{% endblock %} +{% block content %} +{% from 'include/input_macros.html' import input, select, checking_types %} + + + + + + + + +
+
+ + + {{country.name.replace("'","")}} + + {% if country.description %} ({{country.description.replace("'", "")}}) {% endif %} + + {% if g.user_params['group_id']|string() == country.group_id|string() or g.user_params['role'] == 1 %} + + {% if g.user_params['role'] <= 2 %} + + + {% endif %} + + {% endif %} +
+
+
+ {{ lang.words.country|title() }} ID: {{ country.id }} +
+
+ {{ lang.words.enabled|title() }}: {% if country.enabled %} {{ lang.words.yes|title() }} {% else %} {{ lang.words.no|title() }} {% endif %} + {{ lang.words.shared|title() }}: {% if country.shared %} {{ lang.words.yes|title() }} {% else %} {{ lang.words.no|title() }} {% endif %} +
+
+ {{ lang.words.regions|title() }}: +
+ {% for region in regions %} +
{{region.name.replace("'", "")}}
+ {% endfor %} +
+
+
+
+ {% include 'include/smon/checks_for_overview.html' %} + + {% include 'include/smon/dialogs.html' %} + + {% include 'include/smon/add_form.html' %} +{% endblock %} diff --git a/app/templates/smon/region.html b/app/templates/smon/region.html new file mode 100644 index 0000000..392c651 --- /dev/null +++ b/app/templates/smon/region.html @@ -0,0 +1,53 @@ +{% extends "base.html" %} +{% block title %}{{ lang.words.overview|title() }} {{ lang.words.region }}{% endblock %} +{% block h2 %}{{ lang.words.overview|title() }} {{ lang.words.region }}{% endblock %} +{% block content %} +{% from 'include/input_macros.html' import input, select, checking_types %} + + + + + + + + +
+
+ + + {{region.name.replace("'","")}} + + {% if region.description %} ({{region.description.replace("'", "")}}) {% endif %} + + {% if g.user_params['group_id']|string() == region.group_id|string() or g.user_params['role'] == 1 %} + + {% if g.user_params['role'] <= 2 %} + + + {% endif %} + + {% endif %} +
+
+
+ {{ lang.words.region|title() }} ID: {{ region.id }} +
+
+ {{ lang.words.enabled|title() }}: {% if region.enabled %} {{ lang.words.yes|title() }} {% else %} {{ lang.words.no|title() }} {% endif %} + {{ lang.words.shared|title() }}: {% if region.shared %} {{ lang.words.yes|title() }} {% else %} {{ lang.words.no|title() }} {% endif %} +
+
+ {{ lang.words.agents|title() }}:
+
+
+
+ {% include 'include/smon/checks_for_overview.html' %} + + {% include 'include/smon/dialogs.html' %} + + {% include 'include/smon/add_form.html' %} +{% endblock %}