From 2701e628c3a3fb30dadbe627f5154c31205537ab Mon Sep 17 00:00:00 2001 From: Aidaho Date: Sat, 13 Apr 2024 14:13:03 +0300 Subject: [PATCH] v1.0.1: Add method to retrieve smon group name by id A new function `get_smon_group_name_by_id` was added in the `smon.py` module which retrieves the smon group name given the group id. This function is now utilized in the `check` route in `routes.py` to display group names instead of group ids for improved readability. Additionally, the `smon` module has been imported into `admin/routes.py`. --- app/modules/db/smon.py | 7 +++++++ app/routes/admin/routes.py | 9 ++++++++- app/routes/smon/routes.py | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/modules/db/smon.py b/app/modules/db/smon.py index 29ef416..a930601 100644 --- a/app/modules/db/smon.py +++ b/app/modules/db/smon.py @@ -682,6 +682,13 @@ def get_smon_group_by_name(user_group: int, name: str) -> int: return 0 +def get_smon_group_name_by_id(group_id: int) -> str: + try: + return SmonGroup.get(SmonGroup.id == group_id).name + except Exception as e: + out_error(e) + + def add_smon_group(user_group: int, name: str) -> int: try: return SmonGroup.insert(name=name, user_group=user_group).on_conflict('replace').execute() diff --git a/app/routes/admin/routes.py b/app/routes/admin/routes.py index 12145ae..0dd15b0 100644 --- a/app/routes/admin/routes.py +++ b/app/routes/admin/routes.py @@ -13,6 +13,7 @@ import app.modules.roxywi.roxy as roxy import app.modules.roxywi.auth as roxywi_auth import app.modules.roxywi.common as roxywi_common +import app.modules.tools.smon as smon_mod import app.modules.tools.common as tools_common @@ -99,6 +100,12 @@ def update_settings(param): val = request.form.get('val').replace('92', '/') user_group = roxywi_common.get_user_group(id=1) if sql.update_setting(param, val, user_group): - roxywi_common.logging('Roxy-WI server', f'The {param} setting has been changed to: {val}', roxywi=1, login=1) + roxywi_common.logging('RMON server', f'The {param} setting has been changed to: {val}', roxywi=1, login=1) + + # if param == 'master_port': + # try: + # smon_mod.change_smon_port(val) + # except Exception as e: + # return f'{e}' return 'Ok' diff --git a/app/routes/smon/routes.py b/app/routes/smon/routes.py index bccd54d..17f9890 100644 --- a/app/routes/smon/routes.py +++ b/app/routes/smon/routes.py @@ -174,10 +174,12 @@ def smon_add(): @bp.route('/check/settings//') @login_required +@get_user_params() def check(smon_id, check_type_id): smon = smon_sql.select_one_smon(smon_id, check_type_id) settings = {} for s in smon: + group_name = smon_sql.get_smon_group_name_by_id(s.smon_id.group_id) settings = { 'id': s.smon_id.id, 'name': s.smon_id.name, @@ -191,7 +193,7 @@ def check(smon_id, check_type_id): 'slack': s.smon_id.slack_channel_id, 'pd': s.smon_id.pd_channel_id, 'check_type': s.smon_id.check_type, - 'group': s.smon_id.group, + 'group': group_name, } if check_type_id in (1, 5): settings.setdefault('port', s.port)