Start maintenance on everything, all servers or all integrations at once

The Start maintenance list gets a "Many at once" group: Everything, All
servers, All integrations, All DNS providers (enabled ones only). Each target
still gets its own window, existing ones are extended, and the action is one
audit entry. "Everything" asks for confirmation first, and "End all" on the
Active list ends every running window together. The top banner and the wall
display summarise long lists instead of printing every name.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-16 20:58:01 +02:00
1 parent 65263a64e3
commit bff0c2169e
7 files changed
+287 -4

No files matched your search

+61 -1
View File
@@ -1,5 +1,5 @@
import { Router } from "express";
import { and, eq } from "drizzle-orm";
import { and, eq, inArray } from "drizzle-orm";
import { z } from "zod";
import { db } from "../db/client.js";
import { dnsProviders, integrations, maintenanceAliases, maintenanceTargetTypes, maintenanceWindows, servers } from "../db/schema.js";
@@ -208,6 +208,66 @@ maintenanceRouter.delete("/aliases/:id", requireRole("operator"), asyncHandler(a
res.status(204).end();
}));
const bulkSchema = z.object({
scope: z.enum(["everything", "servers", "integrations", "dns_providers"]),
minutes: z.number().int().min(5).max(7 * 24 * 60),
reason: z.string().max(200).optional(),
});
/**
* Starts a window on every server, every integration, every DNS provider, or all of them, in one go — for a power cut, a network move,
* a rack reboot. It is the same window as one started by hand for each target (so each can still be ended on its own); only the
* asking is done once. Disabled integrations and providers are left out: they raise no alerts to silence.
*/
maintenanceRouter.post("/bulk", requireRole("operator"), asyncHandler(async (req, res) => {
const parsed = bulkSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: "invalid_body", message: "Choose what to put in maintenance and for how long.", details: parsed.error.flatten() });
}
const { scope, minutes, reason } = parsed.data;
const targets: { type: "server" | "integration" | "dns_provider"; id: number }[] = [];
if (scope === "everything" || scope === "servers") {
for (const s of await db.select({ id: servers.id }).from(servers)) targets.push({ type: "server", id: s.id });
}
if (scope === "everything" || scope === "integrations") {
for (const i of await db.select({ id: integrations.id }).from(integrations).where(eq(integrations.enabled, true))) targets.push({ type: "integration", id: i.id });
}
if (scope === "everything" || scope === "dns_providers") {
for (const p of await db.select({ id: dnsProviders.id }).from(dnsProviders).where(eq(dnsProviders.enabled, true))) targets.push({ type: "dns_provider", id: p.id });
}
if (targets.length === 0) {
return res.status(400).json({ error: "nothing_to_silence", message: "There is nothing of that kind to put in maintenance yet." });
}
const actor = req.currentUser!;
const createdBy = actor.name ?? actor.email ?? actor.oidcSub;
const why = reason ?? "Everything in maintenance";
let started = 0;
let extended = 0;
for (const t of targets) {
const result = await startOrExtendWindow(t.type, t.id, minutes, why, createdBy);
if (!result) continue; // removed while this ran
if (result.extended) extended++;
else started++;
}
await recordAudit({ actor, category: "maintenance", action: "start_bulk", detail: { scope, minutes, reason: why, started, extended } });
invalidateAlertsCache();
res.status(201).json({ started, extended, total: started + extended });
}));
/** Ends every window that is running now — the way out after starting many. Scheduled ones that haven't begun are left as they are. */
maintenanceRouter.post("/end-all", requireRole("operator"), asyncHandler(async (req, res) => {
const active = await listActiveWindows();
if (active.length > 0) {
await db.update(maintenanceWindows).set({ endsAt: new Date().toISOString() }).where(inArray(maintenanceWindows.id, active.map((w) => w.id)));
}
await recordAudit({ actor: req.currentUser!, category: "maintenance", action: "end_all", detail: { ended: active.length } });
invalidateAlertsCache();
res.json({ ended: active.length });
}));
const syncUptimeKumaSchema = z.object({ integrationId: z.number().int().positive() });
/** Reads Uptime Kuma's maintenance schedule now and brings the mirrored windows in line with it (the same pass that runs every 15 minutes when switched on). */