mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-21 21:46:32 +03:00
Send all checks result to NOTIFICATION_USERS if NOTIFY_CHECKS enabled
This commit is contained in:
parent
aff843c867
commit
3ca281627f
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
logger.warning(f"Notificator bot token not setted. Skipping send notifications to admin")
|
||||
|
|
Loading…
Reference in New Issue
Block a user