diff --git a/apps/tgbot/tgbot/config.py b/apps/tgbot/tgbot/config.py index 94b5b3d..aeb33e8 100644 --- a/apps/tgbot/tgbot/config.py +++ b/apps/tgbot/tgbot/config.py @@ -13,6 +13,8 @@ INFLUX_DB = os.getenv("INFLUX_DB", None) # Notifications NOTIFICATION_BOT_TOKEN = os.getenv("NOTIFICATION_BOT_TOKEN") NOTIFICATION_USERS = os.getenv("NOTIFICATION_USERS", "").split(",") +# Send all checks result to NOTIFICATION_USERS +NOTIFY_CHECKS = True # Mysql params MYSQL_HOST = os.getenv("MYSQL_HOST", None) # if none, use sqlite db diff --git a/apps/tgbot/tgbot/handlers/base.py b/apps/tgbot/tgbot/handlers/base.py index 7baa880..dee57b8 100644 --- a/apps/tgbot/tgbot/handlers/base.py +++ b/apps/tgbot/tgbot/handlers/base.py @@ -12,8 +12,9 @@ from loguru import logger from ..middlewares.throttling import rate_limit from ..nodes import nodes as all_nodes from .errors import InvalidPort, LocalhostForbidden, NotEnoughArgs -from .helpers import send_api_requests +from .helpers import send_api_requests, send_message_to_admins from .validators import BaseValidator, LocalhostValidator +from ..config import NOTIFY_CHECKS header = "Отчет о проверке хоста:" \ "\n\n— Хост: {0}"\ @@ -68,6 +69,12 @@ class CheckerBaseHandler(SimpleCommandHandler): node_formatted_response = await self.prepare_message(res) rsp_msg = await rsp_msg.edit_text(rsp_msg.text + f"\n\n{iter_keys}. {node_formatted_response}") iter_keys = iter_keys + 1 + + if NOTIFY_CHECKS: + notify_text = f"**User {chat_id} issued check: {self.api_endpoint} for {data['target_fq']}**\n\n" \ + f"```{rsp_msg.text}```" + await send_message_to_admins(notify_text) + logger.info(f"User {chat_id} ended check {ident}") await rsp_msg.edit_text(rsp_msg.text + f"\n\nПроверка завершена❗") te = time() diff --git a/apps/tgbot/tgbot/handlers/helpers.py b/apps/tgbot/tgbot/handlers/helpers.py index f2620cb..d316364 100644 --- a/apps/tgbot/tgbot/handlers/helpers.py +++ b/apps/tgbot/tgbot/handlers/helpers.py @@ -54,4 +54,4 @@ async def send_message_to_admins(message: str): logger.info(f"Sended notification to {user}") await bot.send_message(user, message, parse_mode='Markdown') else: - logger.warning(f"Notificator bot token not setted. Skipping send notifications to admin") \ No newline at end of file + logger.warning(f"Notificator bot token not setted. Skipping send notifications to admin")