add healthchecks client

This commit is contained in:
Alex Tau 2025-08-15 02:56:27 +03:00
parent c01ab8303c
commit d59d5ac4e2
11 changed files with 630 additions and 5 deletions

View file

@ -1,12 +1,14 @@
from telethon import TelegramClient
from telethon.sessions import MemorySession
from uplink import AiohttpClient
from ..core import cvars
from .alert import Alert
from .clients.healthchecks import HealthchecksClient
from .enum import SEVERITY_TO_EMOJI, AlertType, Severity
async def get_client() -> TelegramClient:
async def get_tg_client() -> TelegramClient:
config = cvars.config.get()
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)
@ -14,6 +16,15 @@ async def get_client() -> TelegramClient:
return client
def get_healthchecks_client() -> HealthchecksClient:
config = cvars.config.get()
base_url = config.alert_channels.healthchecks.pinging_api_endpoint
client = HealthchecksClient(
base_url=config.alert_channels.healthchecks.pinging_api_endpoint, client=AiohttpClient()
)
return client
def format_message(alert: Alert, note: str) -> str:
severity_emoji = SEVERITY_TO_EMOJI[alert.severity]
note_formatted = f"{note}, " if note else ""
@ -31,7 +42,7 @@ async def send_alert(alert: Alert, note: str = "") -> None:
except LookupError: # being called standalone
# cvars.config.set(get_config())
# temp_client = True
# client = await get_client()
# client = await get_tg_client()
# cvars.matrix_client.set(client)
raise NotImplementedError # TODO
else:
@ -42,7 +53,10 @@ async def send_alert(alert: Alert, note: str = "") -> None:
await client.send_message(entity=room_id, message=message)
# if temp_client:
# await client.close()
# TODO ping healthchecks if enabled
if alert.healthchecks_slug is not None:
raise NotImplementedError
# TODO service itself has to be monitored like everything else - with regular pinging - if we're