Dependency map, impact preview in maintenance, and a calmer Alerts page

- Map: a Dependencies view showing what would go down with a picked box and what it relies on
- Maintenance: lists what depends on a target and can silence those too (same time, audited); the recurring form and update drawer show the same note
- Alerts: a headline on where things stand, held-back alerts nested under their cause, severity edge on rows; caused-by now carries the explaining alert's id

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-18 19:17:09 +02:00
1 parent ec9c2f73f0
commit 9caa414829
19 files changed
+944 -40

No files matched your search

+55 -2
View File
@@ -2,11 +2,14 @@ import { Router } from "express";
import { eq } from "drizzle-orm";
import { z } from "zod";
import { db } from "../db/client.js";
import { dependencies } from "../db/schema.js";
import { dependencies, servers } from "../db/schema.js";
import { requireAuth, requireRole } from "../auth/middleware.js";
import { recordAudit } from "../services/audit.js";
import { invalidateAlertsCache } from "../services/alerts.js";
import { loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js";
import { dependentsOf, impactOf, loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js";
import { getSettings } from "../services/settingsStore.js";
import { getSourceStatus } from "../services/integrationHealthMonitor.js";
import { serverStatus, type MapStatus } from "../services/topology.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const dependenciesRouter = Router();
@@ -41,6 +44,56 @@ dependenciesRouter.get("/", asyncHandler(async (_req, res) => {
});
}));
// What a thing would take with it, and what it needs itself: for the maintenance and update pages, which say so before it is done.
dependenciesRouter.get("/impact", asyncHandler(async (req, res) => {
const type = nodeTypes.find((t) => t === req.query.type);
const id = typeof req.query.id === "string" && /^\d+$/.test(req.query.id) ? Number(req.query.id) : NaN;
if (!type || !Number.isInteger(id)) return res.status(400).json({ error: "invalid_query", message: "Say which server or integration." });
const impact = await impactOf(type, id);
if (!impact) return res.status(404).json({ error: "not_found" });
res.json(impact);
}));
// The graph for the Map page: the servers and integrations that take part in any dependency, how each is doing, and who needs whom. An edge runs
// from the thing that is needed to the thing that needs it, so the foundations come first.
dependenciesRouter.get("/graph", asyncHandler(async (_req, res) => {
const graph = await loadGraph();
const written = new Set(graph.rows.map((r) => `${nodeKey(r.fromType, r.fromId)}>${nodeKey(r.toType, r.toId)}`));
const edges: { from: string; to: string; kind: "written" | "runs-on" }[] = [];
const taking = new Set<string>();
for (const [needing, needed] of graph.edges) {
for (const n of needed) {
edges.push({ from: n, to: needing, kind: written.has(`${needing}>${n}`) ? "written" : "runs-on" });
taking.add(needing);
taking.add(n);
}
}
const { healthChecks } = await getSettings();
const now = new Date();
const serverRows = await db.select({ id: servers.id, lastSeenAt: servers.lastSeenAt, thresholds: servers.thresholds }).from(servers);
const serverById = new Map(serverRows.map((s) => [s.id, s]));
const intById = new Map(graph.intRows.map((i) => [i.id, i]));
const nodes = [...taking]
.map((key) => {
const [type, rawId] = key.split(":");
const id = Number(rawId);
let status: MapStatus = "unknown";
if (type === "server") {
const s = serverById.get(id);
if (s) status = serverStatus(s, healthChecks.serverOfflineMinutes, now);
} else {
const i = intById.get(id);
if (i?.enabled) {
const st = getSourceStatus(i.type).status;
status = st === "failing" ? "bad" : st === "ok" ? "ok" : "unknown";
}
}
return { key, type: type as "server" | "integration", id, name: graph.names.get(key) ?? key, status, href: type === "server" ? `/servers/${id}` : "/integrations" };
})
.sort((a, b) => a.name.localeCompare(b.name));
res.json({ nodes, edges });
}));
dependenciesRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
const parsed = edgeSchema.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say what needs what: a server or an integration each.", details: parsed.error.flatten() });
+18 -2
View File
@@ -9,6 +9,7 @@ import { invalidateAlertsCache } from "../services/alerts.js";
import { requireAuth, requireRole } from "../auth/middleware.js";
import { recordAudit } from "../services/audit.js";
import { describeTarget, listActiveWindows, listUpcomingWindows, startOrExtendWindow } from "../services/maintenance.js";
import { impactOf } from "../services/dependencies.js";
import { KumaSyncError, syncKumaMaintenance } from "../services/kumaMaintenanceSync.js";
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
import { createUptimeKumaAdapter } from "../integrations/uptimekuma/adapter.js";
@@ -56,6 +57,8 @@ const startSchema = z.object({
// Required and capped: an open-ended window is the way this feature could quietly hide a real outage.
minutes: z.number().int().min(5).max(7 * 24 * 60),
reason: z.string().max(200).optional(),
// Also put what depends on the target under maintenance, for the same time: it will look down while the target is.
withDependents: z.boolean().optional(),
});
maintenanceRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
@@ -63,7 +66,7 @@ maintenanceRouter.post("/", requireRole("operator"), asyncHandler(async (req, re
if (!parsed.success) {
return res.status(400).json({ error: "invalid_body", details: parsed.error.flatten() });
}
const { targetType, targetId, minutes, reason } = parsed.data;
const { targetType, targetId, minutes, reason, withDependents } = parsed.data;
const actor = req.currentUser!;
const createdBy = actor.name ?? actor.email ?? actor.oidcSub;
@@ -73,6 +76,19 @@ maintenanceRouter.post("/", requireRole("operator"), asyncHandler(async (req, re
return res.status(404).json({ error: "not_found", message: "That target doesn't exist." });
}
// What depends on it goes down with it, so it is silenced for the same time (and says why).
const alsoSilenced: { type: "server" | "integration"; id: number; name: string }[] = [];
if (withDependents && (targetType === "server" || targetType === "integration")) {
const impact = await impactOf(targetType, targetId);
for (const d of impact?.dependents ?? []) {
const also = await startOrExtendWindow(d.type, d.id, minutes, `Depends on ${result.target.name}${reason ? ` — ${reason}` : ""}`.slice(0, 200), createdBy);
if (also) {
alsoSilenced.push({ type: d.type, id: d.id, name: also.target.name });
await recordAudit({ actor, category: "maintenance", action: also.extended ? "extend" : "start", targetType: d.type, targetId: d.id, detail: { name: also.target.name, minutes, reason: `depends on ${result.target.name}`, dependsOn: result.target.name } });
}
}
}
await recordAudit({
actor,
category: "maintenance",
@@ -83,7 +99,7 @@ maintenanceRouter.post("/", requireRole("operator"), asyncHandler(async (req, re
});
invalidateAlertsCache();
res.status(201).json({ window: { ...result.window, targetName: result.target.name, targetKind: result.target.kind } });
res.status(201).json({ window: { ...result.window, targetName: result.target.name, targetKind: result.target.kind }, alsoSilenced });
}));
const importUptimeKumaSchema = z.object({
+2 -1
View File
@@ -19,7 +19,8 @@ export interface Alert {
/** Under an active maintenance window: still a real problem, but notifications for it are held back. */
silenced: boolean;
/** Set when this problem is explained by another one (a guest down because its host is): it is held back like a silenced one, but the reason is this, not maintenance. */
causedBy?: { name: string };
/** What explains it: the name of the thing that is down, and the id of the alert about that when there is one. */
causedBy?: { name: string; alertId?: string };
/** On a host's alert: the servers on it whose own alerts are folded under this one. */
affects?: string[];
/** What a maintenance window would have to be on to silence it, when there is such a thing — which is what "Silence" acts on. */
+3 -3
View File
@@ -33,7 +33,7 @@ import { computeSecretStatus } from "./secretStatus.js";
import { getFailingSources } from "./integrationHealthMonitor.js";
import { getSettings } from "./settingsStore.js";
import { sourceLabel } from "./notify.js";
import { dependencyCover, integrationTypeCause, takenByType } from "./dependencies.js";
import { alertIdOfNode, dependencyCover, integrationTypeCause, takenByType } from "./dependencies.js";
import type { Alert, AlertCategory, AlertSeverity, SourceFailure } from "./alertTypes.js";
export interface AlertsReport {
@@ -189,7 +189,7 @@ export async function collectAlerts(): Promise<AlertsReport> {
const offlineId = /^offline:server:(\d+)$/.exec(c.key)?.[1];
const parentOf = offlineId ? cover.cause.get(`server:${offlineId}`) : undefined;
push({
causedBy: parentOf !== undefined ? { name: cover.graph.names.get(parentOf) ?? parentOf } : undefined,
causedBy: parentOf !== undefined ? { name: cover.graph.names.get(parentOf) ?? parentOf, alertId: alertIdOfNode(parentOf, cover.graph) ?? undefined } : undefined,
affects: offlineId ? cover.taken.get(`server:${offlineId}`)?.sort((a, b) => a.localeCompare(b)) : undefined,
category: origin.category,
severity: c.severity ?? "warning",
@@ -458,7 +458,7 @@ export async function collectAlerts(): Promise<AlertsReport> {
const cause = cover ? integrationTypeCause(f.source, cover) : null;
const affects = cover ? takenByType(f.source, cover) : [];
push({
causedBy: cause ? { name: cause.name } : undefined,
causedBy: cause ? { name: cause.name, alertId: (cover && alertIdOfNode(cause.key, cover.graph)) || undefined } : undefined,
affects: affects.length > 0 ? affects.sort((a, b) => a.localeCompare(b)) : undefined,
category: "integration",
severity: f.alerted ? "critical" : "warning",
+67
View File
@@ -12,6 +12,7 @@ import { eq } from "drizzle-orm";
import { db } from "../db/client.js";
import { dependencies, integrations, servers } from "../db/schema.js";
import { getInternalFlag } from "./settingsStore.js";
import { listActiveWindows } from "./maintenance.js";
import { loadParentRows, resolveParents, type ParentLink } from "./serverParents.js";
/** Where the health monitor keeps the problems it is announcing; read here so a service's alert can tell a server it needs is down. */
@@ -89,6 +90,33 @@ export function wouldLoop(edges: Edges, from: string, to: string): boolean {
return from === to || ancestorsOf(to, edges).order.includes(from) || ancestorsOf(to, edges).looped;
}
/** Everything that needs `key`, directly or through others, nearest first. */
export function dependentsOf(edges: Edges, key: string): { key: string; distance: number }[] {
const reverse = new Map<string, string[]>();
for (const [from, tos] of edges) for (const to of tos) reverse.set(to, [...(reverse.get(to) ?? []), from]);
const out: { key: string; distance: number }[] = [];
const seen = new Set<string>([key]);
let layer = [key];
for (let distance = 1; layer.length > 0; distance++) {
const next: string[] = [];
for (const k of layer) {
for (const d of (reverse.get(k) ?? []).sort()) {
if (seen.has(d)) continue;
seen.add(d);
out.push({ key: d, distance });
next.push(d);
}
}
layer = next;
}
return out;
}
/** Everything `key` needs, directly or through others, nearest first. */
export function needsOfNode(edges: Edges, key: string): string[] {
return ancestorsOf(key, edges).order;
}
export interface Graph {
edges: Edges;
/** node → its name, for every node that exists. */
@@ -115,6 +143,45 @@ export async function loadGraph(): Promise<Graph> {
return { edges: buildEdges(resolveParents(parentRows), rows, (k) => names.has(k)), names, rows, instances, intRows };
}
/** The id of the alert about a node being down, when it has one (a server's "offline", a kind of service's "failing"). */
export function alertIdOfNode(key: string, graph: Graph): string | null {
const m = /^(server|integration):(\d+)$/.exec(key);
if (!m) return null;
if (m[1] === "server") return `offline:offline:server:${m[2]}`;
const row = graph.intRows.find((r) => r.id === Number(m[2]));
return row ? `integration:failing:${row.type}` : null;
}
export interface ImpactItem {
key: string;
type: NodeType;
id: number;
name: string;
/** 1 = needs it directly, 2 = through one other, … */
distance: number;
/** Already under a maintenance window. */
silenced: boolean;
}
/** What would be affected if `type`/`id` went down (everything that needs it) and what it needs itself. Null if it doesn't exist. */
export async function impactOf(type: NodeType, id: number, now: Date = new Date()): Promise<{ target: { key: string; type: NodeType; id: number; name: string }; dependents: ImpactItem[]; needs: ImpactItem[] } | null> {
const graph = await loadGraph();
const key = nodeKey(type, id);
const name = graph.names.get(key);
if (name === undefined) return null;
const windows = await listActiveWindows(now);
const silenced = new Set(windows.map((w) => `${w.targetType}:${w.targetId}`));
const item = (k: string, distance: number): ImpactItem => {
const [t, i] = k.split(":");
return { key: k, type: t as NodeType, id: Number(i), name: graph.names.get(k) ?? k, distance, silenced: silenced.has(k) };
};
return {
target: { key, type, id, name },
dependents: dependentsOf(graph.edges, key).map((d) => item(d.key, d.distance)),
needs: needsOfNode(graph.edges, key).map((k, i) => item(k, i + 1)),
};
}
export interface Cover {
/** Each node that is down because of another → the root cause. */
cause: Map<string, string>;
+8 -3
View File
@@ -59,6 +59,13 @@ function parseIps(stored: string | null): string[] {
}
}
/** Whether a server is reporting: "ok", "bad" once it has been silent longer than its limit, "unknown" if it has never reported. */
export function serverStatus(row: { lastSeenAt: string | null; thresholds: string | null }, offlineMinutes: number, now: Date): MapStatus {
const lastSeen = row.lastSeenAt ? Date.parse(row.lastSeenAt) : null;
const offlineAfterMs = (parseThresholds(row.thresholds)?.serverOfflineMinutes ?? offlineMinutes) * 60_000;
return lastSeen === null ? "unknown" : now.getTime() - lastSeen > offlineAfterMs ? "bad" : "ok";
}
export async function buildTopology(now: Date = new Date()): Promise<MapData> {
const nodes: MapNode[] = [];
const edges: MapEdge[] = [];
@@ -72,9 +79,7 @@ export async function buildTopology(now: Date = new Date()): Promise<MapData> {
// Servers, and the Proxmox hosts they run on.
const hostIds = new Set<string>();
for (const s of serverRows) {
const lastSeen = s.lastSeenAt ? Date.parse(s.lastSeenAt) : null;
const offlineAfterMs = (parseThresholds(s.thresholds)?.serverOfflineMinutes ?? healthChecks.serverOfflineMinutes) * 60_000;
const status: MapStatus = lastSeen === null ? "unknown" : now.getTime() - lastSeen > offlineAfterMs ? "bad" : "ok";
const status = serverStatus(s, healthChecks.serverOfflineMinutes, now);
nodes.push({ id: `server:${s.id}`, kind: "server", label: s.name, sub: s.hostname, status, href: `/servers/${s.id}` });
if (s.proxmoxIntegrationId && s.proxmoxNode) {
const hostId = `host:${s.proxmoxIntegrationId}:${s.proxmoxNode}`;