mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
send start and stop healthchecks signals correctly
This commit is contained in:
parent
13fd4b05d9
commit
878a4fc092
8 changed files with 54 additions and 38 deletions
|
|
@ -1,7 +1,11 @@
|
|||
import logging
|
||||
from socket import gethostname
|
||||
|
||||
from telethon import TelegramClient
|
||||
from telethon.sessions import MemorySession
|
||||
from uplink import AiohttpClient
|
||||
|
||||
from ..checks.utils import format_for_healthchecks_slug
|
||||
from ..core import cvars
|
||||
from .alert import Alert
|
||||
from .clients.healthchecks import HealthchecksClient
|
||||
|
|
@ -37,6 +41,7 @@ def format_message(alert: Alert, note: str) -> str:
|
|||
|
||||
|
||||
async def send_alert(alert: Alert, note: str = "") -> None:
|
||||
logging.debug(f"Sending {alert.alert_type} alert to Telegram")
|
||||
try:
|
||||
tg_client = cvars.tg_client.get()
|
||||
except LookupError: # being called standalone
|
||||
|
|
@ -62,6 +67,8 @@ async def send_healthchecks_status(alert: Alert) -> None:
|
|||
else:
|
||||
return keys["default"]
|
||||
|
||||
logging.debug(f"Sending {alert.alert_type} to Healthchecks")
|
||||
|
||||
if alert.healthchecks_slug is None:
|
||||
return
|
||||
try:
|
||||
|
|
@ -76,26 +83,3 @@ async def send_healthchecks_status(alert: Alert) -> None:
|
|||
await hc_client.success(key, alert.healthchecks_slug, create=True, log=alert.plain_message)
|
||||
else:
|
||||
await hc_client.failure(key, alert.healthchecks_slug, create=True, log=alert.plain_message)
|
||||
|
||||
|
||||
# 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(
|
||||
Alert(
|
||||
alert_type=AlertType.BOOT,
|
||||
message=f"Service running with enabled checks: {', '.join(config.enabled_check_sets)}",
|
||||
severity=Severity.INFO,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def send_stop_alert() -> None:
|
||||
await send_alert(
|
||||
Alert(
|
||||
alert_type=AlertType.BOOT,
|
||||
message="Service stopping.",
|
||||
severity=Severity.INFO,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue