Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat(external-status): add support for UptimeRobot (#2183)
Colin Ozanne65492c6918da
diff --git a/packages/db/src/schema/external_services/constants.ts b/packages/db/src/schema/external_services/constants.tsindex 50b9cbea8..95904e7e0 100644--- a/packages/db/src/schema/external_services/constants.ts+++ b/packages/db/src/schema/external_services/constants.ts@@ -5,6 +5,7 @@ export const API_CONFIG_TYPES = ["instatus","betterstack","incidentio",+ "uptimerobot","custom","html-scraper",] as const;@@ -17,6 +18,7 @@ export const STATUS_PAGE_PROVIDERS = ["status.io","custom","better-uptime",+ "uptime-robot","unknown",] as const;diff --git a/packages/db/src/seed/external-services.ts b/packages/db/src/seed/external-services.tsindex 7abd87b63..24448c547 100644--- a/packages/db/src/seed/external-services.ts+++ b/packages/db/src/seed/external-services.ts@@ -189,4 +189,17 @@ export const externalServicesSeed: ExternalServiceSeedEntry[] = [description: "E-commerce platform for online stores",apiConfig: { type: "atlassian" },},+ {+ slug: "bluesky",+ name: "Bluesky",+ url: "https://bsky.app",+ statusPageUrl: "https://status.bsky.app",+ provider: "uptime-robot",+ industry: ["communication"],+ description: "Decentralized social network built on the AT Protocol",+ apiConfig: {+ type: "uptimerobot",+ endpoint: "https://status.bsky.app/api/getMonitorList/2102707-357837",+ },+ },];diff --git a/packages/status-fetcher/__tests__/fetchers/uptimerobot.test.ts b/packages/status-fetcher/__tests__/fetchers/uptimerobot.test.tsnew file mode 100644index 000000000..7a0228998--- /dev/null+++ b/packages/status-fetcher/__tests__/fetchers/uptimerobot.test.ts@@ -0,0 +1,310 @@+import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";+import { UptimeRobotFetcher } from "../../src/fetchers/uptimerobot";+import type { StatusPageEntry } from "../../src/types";++const ENDPOINT = "https://status.example.com/api/getMonitorList/1234567-789012";++function makeEntry(overrides: Partial<StatusPageEntry> = {}): StatusPageEntry {+ return {+ id: "test",+ name: "Test Service",+ url: "https://example.com",+ status_page_url: "https://status.example.com",+ provider: "uptime-robot",+ industry: ["saas"],+ api_config: { type: "uptimerobot", endpoint: ENDPOINT },+ ...overrides,+ };+}++function mockResponse(monitors: Array<Record<string, unknown>>) {+ global.fetch = mock(() =>+ Promise.resolve({+ ok: true,+ json: async () => ({ status: "ok", data: monitors }),+ } as Response),+ );+}++let monitorIdCounter = 0;+function monitor(+ statusClass: string,+ name = `monitor-${statusClass}`,+): Record<string, unknown> {+ monitorIdCounter++;+ return {+ monitorId: monitorIdCounter,+ name,+ statusClass,+ url: null,+ type: "HTTP(s)",+ ratio: { ratio: "99.999", label: "excellent", color: "green" },+ "30dRatio": { ratio: "99.999", label: "excellent", color: "green" },+ "90dRatio": { ratio: "99.999", label: "excellent", color: "green" },+ hasIncidentComments: false,+ lastDowntime: null,+ };+}++describe("UptimeRobotFetcher", () => {+ let fetcher: UptimeRobotFetcher;+ const originalFetch = global.fetch;++ beforeEach(() => {+ fetcher = new UptimeRobotFetcher();+ monitorIdCounter = 0;+ });++ afterEach(() => {+ global.fetch = originalFetch;+ });++ describe("canHandle", () => {+ it("matches api_config.type = uptimerobot", () => {+ expect(+ fetcher.canHandle(+ makeEntry({+ provider: "unknown",+ api_config: { type: "uptimerobot", endpoint: ENDPOINT },+ }),+ ),+ ).toBe(true);+ });++ it("matches provider = uptime-robot", () => {+ expect(+ fetcher.canHandle(+ makeEntry({ provider: "uptime-robot", api_config: undefined }),+ ),+ ).toBe(true);+ });++ it("does not match on hostname alone", () => {+ expect(+ fetcher.canHandle(+ makeEntry({+ provider: "unknown",+ status_page_url: "https://status.uptimerobot.com",+ api_config: undefined,+ }),+ ),+ ).toBe(false);+ });++ it("does not match unrelated providers", () => {+ expect(+ fetcher.canHandle(+ makeEntry({+ provider: "atlassian-statuspage",+ api_config: { type: "atlassian" },+ }),+ ),+ ).toBe(false);+ });+ });++ describe("fetch", () => {+ it("aggregates all success → operational", async () => {+ mockResponse([+ monitor("success"),+ monitor("success"),+ monitor("success"),+ ]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("none");+ expect(result.status).toBe("operational");+ expect(result.description).toBe("0 monitors down (3 total)");+ expect(result.timezone).toBe("UTC");+ expect(typeof result.updated_at).toBe("number");+ expect(global.fetch).toHaveBeenCalledWith(+ ENDPOINT,+ expect.objectContaining({+ headers: expect.objectContaining({+ "User-Agent": "OpenStatus-Directory/1.0",+ }),+ }),+ );+ });++ it("aggregates one warning among success → degraded", async () => {+ mockResponse([+ monitor("success"),+ monitor("warning"),+ monitor("success"),+ ]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("minor");+ expect(result.status).toBe("degraded");+ expect(result.description).toBe("1 monitor degraded (3 total)");+ });++ it("aggregates two warnings among success → degraded (plural)", async () => {+ mockResponse([+ monitor("success"),+ monitor("warning"),+ monitor("warning"),+ monitor("success"),+ ]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.status).toBe("degraded");+ expect(result.description).toBe("2 monitors degraded (4 total)");+ });++ it("aggregates one danger among success → partial_outage", async () => {+ mockResponse([monitor("success"), monitor("danger"), monitor("success")]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("major");+ expect(result.status).toBe("partial_outage");+ expect(result.description).toBe("1 monitor down (3 total)");+ });++ it("aggregates danger + warning mix → partial_outage with separated counts", async () => {+ mockResponse([+ monitor("success"),+ monitor("danger"),+ monitor("warning"),+ monitor("success"),+ ]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("major");+ expect(result.status).toBe("partial_outage");+ expect(result.description).toBe("1 down, 1 degraded (4 total)");+ });++ it("aggregates all danger → major_outage", async () => {+ mockResponse([monitor("danger"), monitor("danger"), monitor("danger")]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("major");+ expect(result.status).toBe("major_outage");+ expect(result.description).toBe("All 3 monitors down");+ });++ it("single monitor all down → major_outage with singular wording", async () => {+ mockResponse([monitor("danger")]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.status).toBe("major_outage");+ expect(result.description).toBe("1 monitor down (1 total)");+ });++ it("single paused alongside healthy stays operational", async () => {+ mockResponse([monitor("success"), monitor("paused"), monitor("success")]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("none");+ expect(result.status).toBe("operational");+ expect(result.description).toBe("0 monitors down (3 total)");+ });++ it("all paused → under_maintenance", async () => {+ mockResponse([monitor("paused"), monitor("paused")]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("none");+ expect(result.status).toBe("under_maintenance");+ expect(result.description).toBe("2 monitors in maintenance (2 total)");+ });++ it("info treated as maintenance", async () => {+ mockResponse([monitor("info"), monitor("info")]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("none");+ expect(result.status).toBe("under_maintenance");+ });++ it("empty data array → operational", async () => {+ mockResponse([]);++ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("none");+ expect(result.status).toBe("operational");+ expect(result.description).toBe("0 monitors down (0 total)");+ });++ it("unknown statusClass folds to operational with a warn", async () => {+ const warnSpy = mock(() => {});+ const originalWarn = console.warn;+ console.warn = warnSpy;++ mockResponse([+ monitor("success"),+ monitor("frobnicate"),+ monitor("success"),+ ]);++ try {+ const result = await fetcher.fetch(makeEntry());++ expect(result.severity).toBe("none");+ expect(result.status).toBe("operational");+ expect(warnSpy).toHaveBeenCalled();+ } finally {+ console.warn = originalWarn;+ }+ });++ it("throws when api_config.endpoint is missing", async () => {+ const entry = makeEntry({+ api_config: { type: "uptimerobot" },+ });++ await expect(fetcher.fetch(entry)).rejects.toThrow(+ "UptimeRobot fetcher requires api_config.endpoint",+ );+ });++ it("throws on HTTP 500", async () => {+ global.fetch = mock(() =>+ Promise.resolve({+ ok: false,+ status: 500,+ statusText: "Internal Server Error",+ } as Response),+ );++ await expect(fetcher.fetch(makeEntry())).rejects.toThrow(+ "HTTP 500: Internal Server Error",+ );+ });++ it("throws on malformed JSON (missing data array)", async () => {+ global.fetch = mock(() =>+ Promise.resolve({+ ok: true,+ json: async () => ({ status: "ok" }),+ } as Response),+ );++ await expect(fetcher.fetch(makeEntry())).rejects.toThrow();+ });++ it("throws on wrong status field", async () => {+ global.fetch = mock(() =>+ Promise.resolve({+ ok: true,+ json: async () => ({ status: "error", data: [] }),+ } as Response),+ );++ await expect(fetcher.fetch(makeEntry())).rejects.toThrow();+ });+ });+});diff --git a/packages/status-fetcher/scripts/test-fetchers.ts b/packages/status-fetcher/scripts/test-fetchers.tsindex b0656f358..900f51584 100644--- a/packages/status-fetcher/scripts/test-fetchers.ts+++ b/packages/status-fetcher/scripts/test-fetchers.ts@@ -33,6 +33,18 @@ const fixtures: StatusPageEntry[] = [parser: "slack",},},+ {+ id: "bluesky",+ name: "Bluesky",+ url: "https://bsky.app",+ status_page_url: "https://status.bsky.app",+ provider: "uptime-robot",+ industry: ["communication"],+ api_config: {+ type: "uptimerobot",+ endpoint: "https://status.bsky.app/api/getMonitorList/2102707-357837",+ },+ },];async function testFetchers() {diff --git a/packages/status-fetcher/src/fetchers/index.ts b/packages/status-fetcher/src/fetchers/index.tsindex 93c7d6147..c3d7d2b77 100644--- a/packages/status-fetcher/src/fetchers/index.ts+++ b/packages/status-fetcher/src/fetchers/index.ts@@ -5,12 +5,14 @@ import { CustomApiFetcher } from "./custom";import { HtmlScraperFetcher } from "./html";import { IncidentioFetcher } from "./incidentio";import { InstatusFetcher } from "./instatus";+import { UptimeRobotFetcher } from "./uptimerobot";export const fetchers: StatusFetcher[] = [new AtlassianFetcher(),new InstatusFetcher(),new BetterStackFetcher(),new IncidentioFetcher(),+ new UptimeRobotFetcher(),new CustomApiFetcher(),new HtmlScraperFetcher(),];@@ -19,5 +21,6 @@ export * from "./atlassian";export * from "./instatus";export * from "./betterstack";export * from "./incidentio";+export * from "./uptimerobot";export * from "./custom";export * from "./html";diff --git a/packages/status-fetcher/src/fetchers/uptimerobot.ts b/packages/status-fetcher/src/fetchers/uptimerobot.tsnew file mode 100644index 000000000..0c5780607--- /dev/null+++ b/packages/status-fetcher/src/fetchers/uptimerobot.ts@@ -0,0 +1,200 @@+import { z } from "zod";+import { FetchError, fetchWithRetry } from "../fetch-utils";+import type {+ SeverityLevel,+ StatusFetcher,+ StatusPageEntry,+ StatusResult,+ StatusType,+} from "../types";++// UptimeRobot public status pages: no official docs.+// Endpoint observed in the wild: `<status_page_url>/api/getMonitorList/<userId>-<pspId>`.+// The page-id is unguessable, so operators must set it via api_config.endpoint.++const monitorRatioSchema = z.object({+ ratio: z.string(),+ label: z.string(),+ color: z.string(),+});++const monitorSchema = z.object({+ monitorId: z.number(),+ name: z.string(),+ statusClass: z.string(),+ url: z.string().nullable().optional(),+ type: z.string().optional(),+ ratio: monitorRatioSchema.optional(),+ "30dRatio": monitorRatioSchema.optional(),+ "90dRatio": monitorRatioSchema.optional(),+ hasIncidentComments: z.boolean().optional(),+ lastDowntime: z+ .object({+ date: z.string(),+ duration: z.number(),+ reason: z.string(),+ })+ .nullable()+ .optional(),+});++const uptimeRobotResponseSchema = z.object({+ status: z.literal("ok"),+ data: z.array(monitorSchema),+});++export class UptimeRobotFetcher implements StatusFetcher {+ name = "uptimerobot";++ canHandle(entry: StatusPageEntry): boolean {+ return (+ entry.api_config?.type === "uptimerobot" ||+ entry.provider === "uptime-robot"+ );+ }++ async fetch(entry: StatusPageEntry): Promise<StatusResult> {+ const apiUrl = entry.api_config?.endpoint;+ if (!apiUrl) {+ throw new FetchError(+ "UptimeRobot fetcher requires api_config.endpoint pointing at /api/getMonitorList/<userId>-<pspId>",+ entry.status_page_url,+ this.name,+ entry.id,+ );+ }++ try {+ const response = await fetchWithRetry(apiUrl, {+ headers: { "User-Agent": "OpenStatus-Directory/1.0" },+ timeout: 30000,+ });++ if (!response.ok) {+ throw new FetchError(+ `HTTP ${response.status}: ${response.statusText}`,+ apiUrl,+ this.name,+ entry.id,+ );+ }++ const json = await response.json();+ const data = uptimeRobotResponseSchema.parse(json);++ const { severity, status, description } = this.aggregate(data.data);++ return {+ severity,+ status,+ description,+ updated_at: Date.now(),+ timezone: "UTC",+ };+ } catch (error) {+ if (error instanceof FetchError) {+ throw error;+ }+ throw new FetchError(+ error instanceof Error ? error.message : "Unknown error",+ apiUrl,+ this.name,+ entry.id,+ error instanceof Error ? error : undefined,+ );+ }+ }++ private aggregate(monitors: z.infer<typeof monitorSchema>[]): {+ severity: SeverityLevel;+ status: StatusType;+ description: string;+ } {+ const total = monitors.length;++ if (total === 0) {+ return {+ severity: "none",+ status: "operational",+ description: "0 monitors down (0 total)",+ };+ }++ let success = 0;+ let danger = 0;+ let warning = 0;+ let maintenance = 0;++ for (const monitor of monitors) {+ switch (monitor.statusClass) {+ case "success":+ success++;+ break;+ case "danger":+ danger++;+ break;+ case "warning":+ warning++;+ break;+ case "paused":+ case "info":+ maintenance++;+ break;+ default:+ console.warn(+ `[uptimerobot] unknown statusClass "${monitor.statusClass}" for monitor "${monitor.name}" — folding to operational`,+ );+ success++;+ }+ }++ if (danger === total) {+ return {+ severity: "major",+ status: "major_outage",+ description:+ total === 1+ ? "1 monitor down (1 total)"+ : `All ${total} monitors down`,+ };+ }++ if (danger > 0) {+ const desc =+ warning > 0+ ? `${danger} down, ${warning} degraded (${total} total)`+ : `${pluralMonitor(danger)} down (${total} total)`;+ return {+ severity: "major",+ status: "partial_outage",+ description: desc,+ };+ }++ if (warning > 0) {+ return {+ severity: "minor",+ status: "degraded",+ description: `${pluralMonitor(warning)} degraded (${total} total)`,+ };+ }++ if (maintenance > 0 && success === 0) {+ return {+ severity: "none",+ status: "under_maintenance",+ description: `${pluralMonitor(maintenance)} in maintenance (${total} total)`,+ };+ }++ return {+ severity: "none",+ status: "operational",+ description: `0 monitors down (${total} total)`,+ };+ }+}++function pluralMonitor(n: number): string {+ return `${n} ${n === 1 ? "monitor" : "monitors"}`;+}diff --git a/packages/status-fetcher/src/types.ts b/packages/status-fetcher/src/types.tsindex 08e962929..f95283311 100644--- a/packages/status-fetcher/src/types.ts+++ b/packages/status-fetcher/src/types.ts@@ -6,6 +6,7 @@ export const API_CONFIG_TYPES = ["instatus","betterstack","incidentio",+ "uptimerobot","custom","html-scraper",] as const;@@ -18,6 +19,7 @@ export const STATUS_PAGE_PROVIDERS = ["status.io","custom","better-uptime",+ "uptime-robot","unknown",] as const;