export type Status = "up" | "degraded" | "down" | "maintenance" | "unknown"; export interface Beat { status: number; } // kuma's beat statuses const DOWN = 0; const UP = 1; const PENDING = 2; const MAINTENANCE = 3; export const summarize = (heartbeats: Record): Status => { const latest = Object.values(heartbeats) .map((beats) => beats.at(-1)?.status) .filter((s) => s !== undefined); if (latest.length === 0) return "unknown"; const down = latest.filter((s) => s === DOWN).length; if (down === latest.length) return "down"; if (down > 0 || latest.includes(PENDING)) return "degraded"; if (latest.includes(MAINTENANCE)) return "maintenance"; return latest.every((s) => s === UP) ? "up" : "unknown"; }; export const STATUS_LABEL: Record = { up: "All systems operational", degraded: "Some systems degraded", down: "Major outage", maintenance: "Under maintenance", unknown: "Status unavailable" };