wan-uptime-trend
Monitor WAN uptime across sites; flag connections below a threshold and prioritize those with lowest uptime.
Instructions
Aggregate WAN uptime across all sites with severity flagging (default threshold 95%). Returns per-WAN sorted by lowest uptime first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| threshold | No | Uptime % threshold below which WAN is flagged (default: 95) |
Implementation Reference
- src/index.ts:98-100 (registration)Registration of the 'wan-uptime-trend' tool with the MCP server, binding the schema and handler.
tool("wan-uptime-trend", "Aggregate WAN uptime across all sites with severity flagging (default threshold 95%). Returns per-WAN sorted by lowest uptime first.", wanUptimeTrendSchema.shape, wrapToolHandler(wanUptimeTrend)); - src/tools/analytics.ts:136-139 (schema)Input schema for wan-uptime-trend: optional threshold (default 95%).
export const wanUptimeTrendSchema = z.object({ threshold: z.coerce.number().optional().default(95) .describe("Uptime % threshold below which WAN is flagged (default: 95)"), }); - src/tools/analytics.ts:141-193 (handler)Main handler function: aggregates WAN uptime across all sites, flags below threshold, returns sorted results with summary statistics.
export async function wanUptimeTrend(params: z.infer<typeof wanUptimeTrendSchema>) { const sites = await resolveAllSites(); const sitesResp = await unifiClient.get<{ data: Array<{ hostId: string; statistics: SiteStatistics }>; }>("/sites"); const rows: Array<{ site: string; wan: string; uptime: number; externalIp: string; severity: "healthy" | "warning" | "critical"; }> = []; for (const s of sitesResp.data) { const hostName = sites.find((x) => x.hostId === s.hostId)?.hostName ?? "unknown"; const wans = s.statistics.wans ?? {}; for (const [wanName, wan] of Object.entries(wans)) { const uptime = wan.wanUptime ?? 0; let severity: "healthy" | "warning" | "critical" = "healthy"; if (uptime < 90) severity = "critical"; else if (uptime < params.threshold) severity = "warning"; rows.push({ site: hostName, wan: wanName, uptime, externalIp: wan.externalIp ?? "", severity, }); } } rows.sort((a, b) => a.uptime - b.uptime); const flagged = rows.filter((r) => r.severity !== "healthy"); const critical = rows.filter((r) => r.severity === "critical").length; const warning = rows.filter((r) => r.severity === "warning").length; const avgUptime = rows.length === 0 ? null : Math.round((rows.reduce((s, r) => s + r.uptime, 0) / rows.length) * 10) / 10; return { checkedAt: new Date().toISOString(), threshold: params.threshold, totalWans: rows.length, avgUptime, flagged: flagged.length, summary: flagged.length === 0 ? `All ${rows.length} WAN(s) above ${params.threshold}% uptime` : `${flagged.length} WAN(s) below threshold: ${critical} critical, ${warning} warning`, wans: rows, }; } - src/tools/analytics.ts:20-25 (helper)Type interface for SiteStatistics used by the handler to access WAN data.
interface SiteStatistics { counts?: { totalDevice?: number; offlineDevice?: number }; gateway?: { shortname?: string }; percentages?: { wanUptime?: number }; wans?: Record<string, { wanUptime?: number; externalIp?: string }>; }