Skip to content

Commit

Permalink
v1.1.4: Refactor alerting and settings update logic
Browse files Browse the repository at this point in the history
Unified receiver fetching in alerting module to use generic methods. Simplified settings update logic and fixed value transformations. Improved UI element handling in SMon. Added missing dependencies to requirements.
  • Loading branch information
Aidaho12 committed Sep 27, 2024
1 parent aef28a6 commit cd3bd39
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/modules/db/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_user_receiver_by_group(receiver: str, group: int):
out_error(e)


def get_receiver_by_ip(receiver:str, ip: str):
def get_receiver_by_ip(receiver: str, ip: str):
model = models[receiver]
try:
return model.select().join(Server, on=(Server.group_id == model.group_id)).where(Server.ip == ip).execute()
Expand Down
20 changes: 10 additions & 10 deletions app/modules/tools/alerting.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def telegram_send_mess(mess, level, **kwargs):
return

if kwargs.get('channel_id'):
telegrams = channel_sql.get_telegram_by_id(kwargs.get('channel_id'))
telegrams = channel_sql.get_receiver_by_id('telegram', kwargs.get('channel_id'))
else:
telegrams = channel_sql.get_telegram_by_ip(kwargs.get('ip'))
telegrams = channel_sql.get_receiver_by_ip('slack', kwargs.get('ip'))

proxy = sql.get_setting('proxy')

Expand Down Expand Up @@ -129,9 +129,9 @@ def slack_send_mess(mess, level, **kwargs):
return

if kwargs.get('channel_id'):
slacks = channel_sql.get_slack_by_id(kwargs.get('channel_id'))
slacks = channel_sql.get_receiver_by_id('slack', kwargs.get('channel_id'))
else:
slacks = channel_sql.get_slack_by_ip(kwargs.get('ip'))
slacks = channel_sql.get_receiver_by_ip('slack', kwargs.get('ip'))

proxy = sql.get_setting('proxy')

Expand Down Expand Up @@ -163,14 +163,14 @@ def pd_send_mess(mess, level, server_ip=None, service_id=None, alert_type=None,

if kwargs.get('channel_id'):
try:
pds = channel_sql.get_pd_by_id(kwargs.get('channel_id'))
pds = channel_sql.get_receiver_by_id('pd', kwargs.get('channel_id'))
except Exception as e:
print(e)
roxywi_common.logging('RMON server', str(e), roxywi=1)
else:
try:
pds = channel_sql.get_pd_by_ip(kwargs.get('ip'))
pds = channel_sql.get_receiver_by_ip('pd', kwargs.get('ip'))
except Exception as e:
print(e)
roxywi_common.logging('RMON server', str(e), roxywi=1)

for pd in pds:
token = pd.token
Expand Down Expand Up @@ -207,12 +207,12 @@ def mm_send_mess(mess, level, server_ip=None, service_id=None, alert_type=None,

if kwargs.get('channel_id'):
try:
mms = channel_sql.get_mm_by_id(kwargs.get('channel_id'))
mms = channel_sql.get_receiver_by_id('mm', kwargs.get('channel_id'))
except Exception as e:
print(e)
else:
try:
mms = channel_sql.get_mm_by_ip(kwargs.get('ip'))
mms = channel_sql.get_receiver_by_ip('mm', kwargs.get('ip'))
except Exception as e:
print(e)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- name: Install Pycurl
ansible.builtin.apt:
name: python3-pycurl
name:
- python3-pip
- python3-pycurl
state: present

- name: Upgrade pip3
Expand Down
5 changes: 1 addition & 4 deletions app/static/js/smon.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ function getCheckSettings(smon_id, check_type) {
$('#new-smon-place').val('agent').change();
$('#new-smon-agent-id').val(data['agent_id']).change();
}
$('#new-smon-place').trigger('selectmenuchange');
$('#new-smon-place').selectmenu("refresh");
$('#new-smon-region-id').selectmenu("refresh");
$('#new-smon-agent-id').selectmenu("refresh");
$('select').selectmenu("refresh");
if (data['smon_id']['enabled']) {
$('#new-smon-enable').prop('checked', true)
} else {
Expand Down
14 changes: 6 additions & 8 deletions app/views/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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
Expand Down Expand Up @@ -124,24 +125,21 @@ def post(self, section: str, body: SettingsRequest, query: GroupQuery):
201:
description: OK
"""
try:
val = body.value.replace('92', '/')
except Exception:
val = body.value

try:
group_id = SupportClass.return_group_id(query)
except Exception as e:
return roxywi_common.handle_json_exceptions(e, 'Cannot get Settings')
try:
sql.update_setting(body.param, val, group_id)
sql.update_setting(body.param, body.value, group_id)
except Exception as e:
roxywi_common.handle_json_exceptions(e, 'Cannot update settings')
roxywi_common.logging('Roxy-WI server', f'The {body.param} setting has been changed to: {val}', roxywi=1, login=1)
roxywi_common.logging('Roxy-WI server', f'The {body.param} setting has been changed to: {body.value}', login=1)

if body.param == 'master_port':
try:
smon_mod.change_smon_port(int(val))
smon_mod.change_smon_port(int(body.value))
except Exception as e:
return f'{e}'
if body.param == 'license':
roxy.update_plan()
return BaseResponse().model_dump(mode='json'), 201
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ python-dateutil~=2.9.0.post0
cryptography~=42.0.5
packaging~=24.0
netaddr>=0.10.1
prometheus_client~=0.21.0
prometheus_flask_exporter~=0.23.1

0 comments on commit cd3bd39

Please sign in to comment.