Browse Source

v6.3.8.0

Changelog: https://roxy-wi.org/changelog#6_3_8
pull/364/head
Aidaho 2 years ago
parent
commit
d0484a7a81
  1. 24
      app/modules/alerting/alerting.py
  2. 9
      app/users.py

24
app/modules/alerting/alerting.py

@ -50,37 +50,37 @@ def alert_routing(
json_for_sending = {"user_group": group_id, "message": subject}
send_message_to_rabbit(json.dumps(json_for_sending))
except Exception as e:
roxywi_common.logging('Roxy-WI server', 'error: unable to send message: ' + str(e), roxywi=1)
roxywi_common.logging('Roxy-WI server', f'error: unable to send message: {e}', roxywi=1)
for setting in checker_settings:
if alert_type == 'service' and setting.service_alert:
telegram_send_mess(mes, telegram_channel_id=setting.telegram_id)
slack_send_mess(mes, slack_channel_id=setting.slack_id)
telegram_send_mess(mes, level, telegram_channel_id=setting.telegram_id)
slack_send_mess(mes, level, slack_channel_id=setting.slack_id)
if setting.email:
send_email_to_server_group(subject, mes, group_id)
if alert_type == 'backend' and setting.backend_alert:
telegram_send_mess(mes, telegram_channel_id=setting.telegram_id)
slack_send_mess(mes, slack_channel_id=setting.slack_id)
telegram_send_mess(mes, level, telegram_channel_id=setting.telegram_id)
slack_send_mess(mes, level, slack_channel_id=setting.slack_id)
if setting.email:
send_email_to_server_group(subject, mes, group_id)
if alert_type == 'maxconn' and setting.maxconn_alert:
telegram_send_mess(mes, telegram_channel_id=setting.telegram_id)
slack_send_mess(mes, slack_channel_id=setting.slack_id)
telegram_send_mess(mes, level, telegram_channel_id=setting.telegram_id)
slack_send_mess(mes, level, slack_channel_id=setting.slack_id)
if setting.email:
send_email_to_server_group(subject, mes, group_id)
def send_email_to_server_group(subject: str, mes: str, group_id: int) -> None:
def send_email_to_server_group(subject: str, mes: str, level: str, group_id: int) -> None:
try:
users_email = sql.select_users_emails_by_group_id(group_id)
for user_email in users_email:
send_email(user_email.email, subject, mes)
send_email(user_email.email, subject, f'{level}: {mes}')
except Exception as e:
roxywi_common.logging('Roxy-WI server', f'error: unable to send email: {e}', roxywi=1)
@ -116,7 +116,7 @@ def send_email(email_to: str, subject: str, message: str) -> None:
roxywi_common.logging('Roxy-WI server', f'error: unable to send email: {e}', roxywi=1)
def telegram_send_mess(mess, **kwargs):
def telegram_send_mess(mess, level, **kwargs):
import telebot
from telebot import apihelper
token_bot = ''
@ -144,7 +144,7 @@ def telegram_send_mess(mess, **kwargs):
apihelper.proxy = {'https': proxy}
try:
bot = telebot.TeleBot(token=token_bot)
bot.send_message(chat_id=channel_name, text=mess)
bot.send_message(chat_id=channel_name, text=f'{level}: {mess}')
except Exception as e:
roxywi_common.logging('Roxy-WI server', str(e), roxywi=1)
@ -176,7 +176,7 @@ def slack_send_mess(mess, **kwargs):
client = WebClient(token=slack_token)
try:
client.chat_postMessage(channel=f'#{channel_name}', text=mess)
client.chat_postMessage(channel=f'#{channel_name}', text=f'{level}: {mess}')
except SlackApiError as e:
roxywi_common.logging('Roxy-WI server', str(e), roxywi=1)

9
app/users.py

@ -7,6 +7,7 @@ import pytz
import modules.db.sql as sql
import modules.common.common as common
import modules.server.server as server_mod
import modules.roxywi.roxy as roxywi
import modules.roxywi.auth as roxywi_auth
import modules.roxywi.common as roxywi_common
@ -35,7 +36,11 @@ services = sql.select_services()
gits = sql.select_gits()
masters = sql.select_servers(get_master_servers=1)
is_needed_tool = common.is_tool('ansible')
grafana, stderr = server_mod.subprocess_execute("systemctl is-active grafana-server")
grafana = 0
if not roxywi.is_docker():
grafana, stderr = server_mod.subprocess_execute("systemctl is-active grafana-server")
grafana = grafana[0]
try:
user_subscription = roxywi_common.return_user_status()
@ -49,6 +54,6 @@ rendered_template = template.render(
settings=settings, backups=sql.select_backups(), services=services, timezones=pytz.all_timezones,
page="users.py", user_services=user_params['user_services'], ldap_enable=ldap_enable, gits=gits, guide_me=1,
user_status=user_subscription['user_status'], user_plan=user_subscription['user_plan'], token=user_params['token'],
is_needed_tool=is_needed_tool, lang=user_params['lang'], grafana=grafana[0]
is_needed_tool=is_needed_tool, lang=user_params['lang'], grafana=grafana
)
print(rendered_template)

Loading…
Cancel
Save