Speedtest Tracker, Costs, "Having trouble" on status pages, grouped Integrations and Dashboard
- Speedtest Tracker integration: charts, alerts for a slow line (median of the last three tests under a share of what is paid for) and for failing tests. - Costs page (Records): things paid for by hand plus Hetzner's estimate, totals per currency, bills rolled forward into Coming up as Renewals. - Status pages: a "Having trouble" state for things that answer but have an open alert; Speedtest reads as the internet. - Integrations page and kind picker grouped like the sidebar (one shared types file); Notifications "What to send" shown one group at a time; Dashboard integration sections follow the menu groups, with tiles for integrations that have no widget. - Docs, tests, and ROLES.md menu table brought up to date. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
78822346b1
commit
f86661f6c9
49 files changed
+18156
-238
No files matched your search
@@ -4,22 +4,27 @@
|
||||
* ("Movies", "Photos") instead of what the machine is called. Each is a server (reporting, or not), an integration (its latest calls work,
|
||||
* or don't) or an Uptime Kuma monitor (up, down, or in maintenance).
|
||||
*
|
||||
* What the public gets back is only: the page's title and message, and for each item its name, whether it is up, down, being worked on
|
||||
* or can't be told, and — where known — how it has done over 30 days. No addresses, no ids, no alert text.
|
||||
* What the public gets back is only: the page's title and message, and for each item its name, whether it is up, having trouble, down, being
|
||||
* worked on or can't be told, and — where known — how it has done over 30 days. No addresses, no ids, no alert text.
|
||||
*
|
||||
* "Having trouble" is a thing that answers but has an alert open that nobody has silenced, snoozed or closed — a disk filling up, a queue that
|
||||
* is stuck, an internet line slower than it is sold at. The alert itself is never shown; the family is only told that it is not quite right.
|
||||
*/
|
||||
import { and, asc, eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, servers, statusItems, type StatusItemKind } from "../db/schema.js";
|
||||
import { createUptimeKumaAdapter, type UptimeKumaMonitor } from "../integrations/uptimekuma/adapter.js";
|
||||
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
|
||||
import { getAlerts } from "./alerts.js";
|
||||
import type { Alert } from "./alertTypes.js";
|
||||
import { getSourceStatus } from "./integrationHealthMonitor.js";
|
||||
import { activeSubjects } from "./maintenance.js";
|
||||
import { effectiveThresholds, parseThresholds } from "./serverThresholds.js";
|
||||
import { getSettings } from "./settingsStore.js";
|
||||
import { getUptime } from "./uptimeHistory.js";
|
||||
|
||||
export type ItemState = "up" | "down" | "maintenance" | "unknown";
|
||||
export type PageLevel = "ok" | "issue" | "maintenance" | "unknown";
|
||||
export type ItemState = "up" | "trouble" | "down" | "maintenance" | "unknown";
|
||||
export type PageLevel = "ok" | "trouble" | "issue" | "maintenance" | "unknown";
|
||||
|
||||
export const MAX_ITEMS = 30;
|
||||
export const MAX_LABEL = 60;
|
||||
@@ -111,14 +116,22 @@ export interface PublicStatus {
|
||||
display: { dateFormat: string; timeFormat: string };
|
||||
}
|
||||
|
||||
/** How the whole page reads: anything down is an issue; otherwise anything being worked on says so; otherwise fine — unless nothing could be told at all. */
|
||||
/** How the whole page reads: anything down is an issue; then anything having trouble; then anything being worked on; otherwise fine — unless nothing could be told at all. */
|
||||
export function pageLevel(counts: Record<ItemState, number>): PageLevel {
|
||||
if (counts.down > 0) return "issue";
|
||||
if (counts.trouble > 0) return "trouble";
|
||||
if (counts.maintenance > 0) return "maintenance";
|
||||
if (counts.up === 0 && counts.unknown > 0) return "unknown";
|
||||
return "ok";
|
||||
}
|
||||
|
||||
let alertsLoader: (() => Promise<Pick<Alert, "id" | "severity" | "silenced" | "target">[]>) | null = null;
|
||||
|
||||
/** For tests: use these alerts instead of collecting the real ones (which asks every integration). */
|
||||
export function setAlertsLoaderForTests(loader: typeof alertsLoader): void {
|
||||
alertsLoader = loader;
|
||||
}
|
||||
|
||||
// Uptime Kuma is asked at most this often per instance, however many people have the page open.
|
||||
const KUMA_CACHE_MS = 30_000;
|
||||
const kumaCache = new Map<number, { at: number; monitors: Map<string, UptimeKumaMonitor> | null }>();
|
||||
@@ -157,6 +170,23 @@ export async function buildPublicStatus(link: { id: number; label: string; title
|
||||
const integrationRows = new Map((await db.select({ id: integrations.id, type: integrations.type, enabled: integrations.enabled }).from(integrations)).map((i) => [i.id, i]));
|
||||
const uptime = items.some((i) => i.kind !== "monitor") ? await getUptime(now, 30).catch(() => null) : null;
|
||||
|
||||
// What has an alert open that nobody has put aside: a server or an integration that answers but is not quite right. If the alerts cannot be read nothing is said to be in trouble.
|
||||
const trouble = { server: new Set<number>(), integration: new Set<number>() };
|
||||
const failingTests = new Set<number>();
|
||||
try {
|
||||
for (const a of alertsLoader ? await alertsLoader() : (await getAlerts(false)).alerts) {
|
||||
if (a.silenced || a.severity === "info" || !a.target) continue;
|
||||
if (a.target.type === "server") trouble.server.add(a.target.id);
|
||||
else if (a.target.type === "integration") {
|
||||
trouble.integration.add(a.target.id);
|
||||
// Speed tests that keep failing mean the internet is down, not slow.
|
||||
if (a.id.includes(`speedtest-failing:${a.target.id}`)) failingTests.add(a.target.id);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// no alerts, no "trouble"
|
||||
}
|
||||
|
||||
const out: PublicStatusItem[] = [];
|
||||
for (const item of items) {
|
||||
let state: ItemState = "unknown";
|
||||
@@ -167,14 +197,14 @@ export async function buildPublicStatus(link: { id: number; label: string; title
|
||||
if (s?.lastSeenAt) {
|
||||
const limit = effectiveThresholds({ ...settings.healthChecks }, parseThresholds(s.thresholds)).serverOfflineMinutes * 60_000;
|
||||
const quiet = now.getTime() - Date.parse(s.lastSeenAt) > limit;
|
||||
state = subjects.has(`server:${s.id}`) ? "maintenance" : quiet ? "down" : "up";
|
||||
state = subjects.has(`server:${s.id}`) ? "maintenance" : quiet ? "down" : trouble.server.has(s.id) ? "trouble" : "up";
|
||||
}
|
||||
uptime30d = uptime?.servers[item.targetId]?.percent ?? null;
|
||||
} else if (item.kind === "integration") {
|
||||
const i = integrationRows.get(item.targetId);
|
||||
if (i?.enabled) {
|
||||
const status = getSourceStatus(i.type).status;
|
||||
state = subjects.has(`integration:${i.id}`) ? "maintenance" : status === "ok" ? "up" : status === "failing" ? "down" : "unknown";
|
||||
state = subjects.has(`integration:${i.id}`) ? "maintenance" : status === "failing" || failingTests.has(i.id) ? "down" : status === "ok" ? (trouble.integration.has(i.id) ? "trouble" : "up") : "unknown";
|
||||
}
|
||||
uptime30d = uptime?.integrations[item.targetId]?.percent ?? null;
|
||||
} else {
|
||||
@@ -187,7 +217,7 @@ export async function buildPublicStatus(link: { id: number; label: string; title
|
||||
out.push({ id: item.id, label: item.label, state, uptime30d: uptime30d === null ? null : Math.round(uptime30d * 10) / 10 });
|
||||
}
|
||||
|
||||
const counts: Record<ItemState, number> = { up: 0, down: 0, maintenance: 0, unknown: 0 };
|
||||
const counts: Record<ItemState, number> = { up: 0, trouble: 0, down: 0, maintenance: 0, unknown: 0 };
|
||||
for (const o of out) counts[o.state]++;
|
||||
return {
|
||||
title: link.title?.trim() || link.label,
|
||||
|
||||
Reference in new issue
Block a user