Skip to content

Commit

Permalink
v1.0.1: Add method to retrieve smon group name by id
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Aidaho12 committed Apr 13, 2024
1 parent 9467f44 commit 2701e62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/modules/db/smon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion app/routes/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'
4 changes: 3 additions & 1 deletion app/routes/smon/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ def smon_add():

@bp.route('/check/settings/<int:smon_id>/<int:check_type_id>')
@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,
Expand All @@ -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)
Expand Down

0 comments on commit 2701e62

Please sign in to comment.