34 lines
1.3 KiB
Python

import os
import requests
import logging
from health_agent.config import load_uk_tokens
logger = logging.getLogger(__name__)
UK_PUSH_URL_BASE = os.getenv("UK_PUSH_URL_BASE", "https://uptime.tarla.io/api/push")
DRY_RUN = False
def push(monitor_name: str, status: str, msg: str, ping_ms: int):
token = load_uk_tokens().get(monitor_name)
if not token:
logger.warning(f"No token found for monitor {monitor_name}")
return
if DRY_RUN:
logger.info(f"[DRY-RUN] Would push {monitor_name} status={status} msg={msg} ping={ping_ms}ms", extra={"check": monitor_name, "status": status, "push_msg": msg, "ping_ms": ping_ms, "source": "uptime_kuma"})
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, "push_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"})