28 lines
1023 B
Python

import os
import requests
import logging
from health_agent.config import UK_TOKENS
logger = logging.getLogger(__name__)
UK_PUSH_URL_BASE = os.getenv("UK_PUSH_URL_BASE", "https://status.iklim.co/api/push")
def push(monitor_name: str, status: str, msg: str, ping_ms: int):
token = UK_TOKENS.get(monitor_name)
if not token:
logger.warning(f"No token found for monitor {monitor_name}")
return
url = f"{UK_PUSH_URL_BASE}/{token}"
params = {
"status": status,
"msg": msg,
"ping": int(ping_ms)
}
try:
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
logger.info(f"Pushed {monitor_name} status={status}", extra={"check": monitor_name, "status": status, "msg": msg, "ping_ms": ping_ms, "source": "uptime_kuma"})
except Exception as e:
logger.error(f"Failed to push {monitor_name}: {e}", extra={"check": monitor_name, "status": "push_failed", "error": str(e), "source": "uptime_kuma"})