prepare config for healthchecks integration

This commit is contained in:
Alex Tau 2025-08-13 16:59:23 +03:00
parent 4558cf9e6f
commit c01ab8303c
8 changed files with 89 additions and 34 deletions

View file

@ -1,5 +1,3 @@
from dataclasses import dataclass
from telethon import TelegramClient
from telethon.sessions import MemorySession
@ -10,7 +8,7 @@ from .enum import SEVERITY_TO_EMOJI, AlertType, Severity
async def get_client() -> TelegramClient:
config = cvars.config.get()
api_id, api_hash, bot_token = config.telegram.creds.split(",")
api_id, api_hash, bot_token = config.alert_channels.telegram.creds.split(",")
client = await TelegramClient(MemorySession(), api_id, api_hash, connection_retries=None).start(bot_token=bot_token)
client.parse_mode = "html"
return client
@ -38,13 +36,17 @@ async def send_alert(alert: Alert, note: str = "") -> None:
raise NotImplementedError # TODO
else:
... # temp_client = False
room_id = cvars.config.get().telegram.room_id
message = format_message(alert, note)
await client.send_message(entity=room_id, message=message)
# if temp_client:
# await client.close()
if client is not None:
room_id = cvars.config.get().alert_channels.telegram.room_id
message = format_message(alert, note)
await client.send_message(entity=room_id, message=message)
# if temp_client:
# await client.close()
# TODO ping healthchecks if enabled
# TODO service itself has to be monitored like everything else - with regular pinging - if we're
# using healthchecks
async def send_start_alert() -> None:
config = cvars.config.get()
await send_alert(