import os from datetime import datetime, timezone from typing import Dict, List from .utils import load_json, save_json ALERTS_PATH = os.path.join(os.path.dirname(__file__), "..", "..", "infra", "alerts.json") def _timestamp() -> str: return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") def oob_get_alerts(device: str) -> List[Dict]: alerts = load_json(ALERTS_PATH) return alerts.get(device, []) def oob_add_alert(device: str, message: str) -> Dict: alerts = load_json(ALERTS_PATH) entry = alerts.get(device, []) event = {"timestamp": _timestamp(), "message": message} entry.append(event) alerts[device] = entry save_json(ALERTS_PATH, alerts) return event