Runbooks per alert kind, high-vulnerability threshold, wall display extras
A "What to do" note (text and/or link) can be written once for a whole kind of alert and shows beside every alert of that kind; alerts now carry their kind and source type. New optional setting: warn when a Docker host has N or more high vulnerabilities (off by default). The wall display gains tiles (Hetzner and game servers running, critical vulnerabilities, stuck downloads) and a summary line for each group of integrations, also in share links. Migration 0074; docs and tests included. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9083adb5b
commit
3d9a2310bb
35 files changed
+9129
-30
No files matched your search
@@ -605,6 +605,7 @@ integrationsRouter.get("/:id/dockhand/vulnerabilities", asyncHandler(async (req,
|
||||
const status = statuses[id] ?? null;
|
||||
res.json({
|
||||
alerts: settings.healthChecks.vulnerabilityAlerts,
|
||||
highThreshold: settings.healthChecks.vulnerabilityHighThreshold ?? 0,
|
||||
status,
|
||||
fresh: isDockerVulnFresh(status ?? undefined, Date.now()),
|
||||
environments: rows
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router } from "express";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
import { dnsProviders, integrations, maintenanceTargetTypes, networkDevices, runbooks, servers } from "../db/schema.js";
|
||||
import { alertKindRunbooks, dnsProviders, integrations, maintenanceTargetTypes, networkDevices, runbooks, servers } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { describeTarget } from "../services/maintenance.js";
|
||||
@@ -25,6 +25,22 @@ const bodySchema = z.object({
|
||||
});
|
||||
const createSchema = bodySchema.extend({ targetType: z.enum(maintenanceTargetTypes), targetId: z.number().int().positive() });
|
||||
|
||||
/** What an alert kind looks like: the first part of a key, letters, digits and dashes. */
|
||||
const KIND = /^[A-Za-z0-9][A-Za-z0-9_-]{0,59}$/;
|
||||
const kindSchema = z.object({
|
||||
title: z.string().trim().min(1).max(120),
|
||||
body: z.string().max(20_000).default(""),
|
||||
/** A page to open; http or https only. */
|
||||
url: z
|
||||
.string()
|
||||
.trim()
|
||||
.max(500)
|
||||
.nullable()
|
||||
.optional()
|
||||
.transform((v) => (v === undefined || v === null || v === "" ? null : v))
|
||||
.refine((v) => v === null || /^https?:\/\/[^\s]+$/i.test(v), "A web address starting with http:// or https://"),
|
||||
});
|
||||
|
||||
const idOf = (v: string) => (/^\d+$/.test(v) ? Number(v) : NaN);
|
||||
|
||||
// What there is for one thing: the full text.
|
||||
@@ -55,6 +71,35 @@ runbooksRouter.get("/summary", asyncHandler(async (_req, res) => {
|
||||
res.json({ runbooks: rows.filter((r) => exists[r.targetType].has(r.targetId)) });
|
||||
}));
|
||||
|
||||
// What there is for kinds of alert (by what they are about, wherever it happens), for everyone: it is what to do first, and is read by the Alerts page.
|
||||
runbooksRouter.get("/kinds", asyncHandler(async (_req, res) => {
|
||||
res.json({ kinds: await db.select().from(alertKindRunbooks).orderBy(alertKindRunbooks.kind) });
|
||||
}));
|
||||
|
||||
runbooksRouter.put("/kinds/:kind", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const kind = String(req.params.kind);
|
||||
const parsed = kindSchema.safeParse(req.body);
|
||||
if (!KIND.test(kind)) return res.status(400).json({ error: "invalid_kind" });
|
||||
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Give it a title, and a web address starting with http:// or https:// if you add one.", details: parsed.error.flatten() });
|
||||
if (parsed.data.body.trim() === "" && parsed.data.url === null) return res.status(400).json({ error: "invalid_body", message: "Write what to do, or give a page to open." });
|
||||
const actor = req.currentUser!;
|
||||
const [before] = await db.select({ kind: alertKindRunbooks.kind }).from(alertKindRunbooks).where(eq(alertKindRunbooks.kind, kind)).limit(1);
|
||||
const values = { title: parsed.data.title, body: parsed.data.body, url: parsed.data.url, updatedBy: actor.name ?? actor.email ?? actor.oidcSub, updatedAt: new Date().toISOString() };
|
||||
const [row] = await db.insert(alertKindRunbooks).values({ kind, ...values }).onConflictDoUpdate({ target: alertKindRunbooks.kind, set: values }).returning();
|
||||
await recordAudit({ actor, category: "runbook", action: before ? "update" : "create", targetType: "alert_kind", targetId: kind, detail: { title: parsed.data.title } });
|
||||
res.json({ runbook: row });
|
||||
}));
|
||||
|
||||
runbooksRouter.delete("/kinds/:kind", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const kind = String(req.params.kind);
|
||||
if (!KIND.test(kind)) return res.status(400).json({ error: "invalid_kind" });
|
||||
const [before] = await db.select().from(alertKindRunbooks).where(eq(alertKindRunbooks.kind, kind)).limit(1);
|
||||
if (!before) return res.status(404).json({ error: "not_found" });
|
||||
await db.delete(alertKindRunbooks).where(eq(alertKindRunbooks.kind, kind));
|
||||
await recordAudit({ actor: req.currentUser!, category: "runbook", action: "delete", targetType: "alert_kind", targetId: kind, detail: { title: before.title } });
|
||||
res.status(204).end();
|
||||
}));
|
||||
|
||||
runbooksRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const parsed = createSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Give it a title and some text, and say what it is for.", details: parsed.error.flatten() });
|
||||
|
||||
@@ -144,7 +144,7 @@ const updateSchema = z.object({
|
||||
.partial()
|
||||
.optional(),
|
||||
healthChecks: z
|
||||
.object({ serverOfflineMinutes: z.number().int().min(15).max(10080), diskUsagePercent: z.number().int().min(50).max(99), domainWarnDays: z.number().int().min(1).max(365), diskForecastDays: z.number().int().min(0).max(90), backupStaleHours: z.number().int().min(0).max(2160), restoreTestDays: z.number().int().min(0).max(730), newPortAlerts: z.boolean(), flapRaises: z.number().int().min(0).max(20), deviceOfflineMinutes: z.number().int().min(5).max(1440), osSupportWarnDays: z.number().int().min(0).max(365), baselineAlerts: z.boolean(), containerAlerts: z.boolean(), vulnerabilityAlerts: z.boolean().default(true), containerIgnore: z.array(z.string().trim().min(1).max(100)).max(200) })
|
||||
.object({ serverOfflineMinutes: z.number().int().min(15).max(10080), diskUsagePercent: z.number().int().min(50).max(99), domainWarnDays: z.number().int().min(1).max(365), diskForecastDays: z.number().int().min(0).max(90), backupStaleHours: z.number().int().min(0).max(2160), restoreTestDays: z.number().int().min(0).max(730), newPortAlerts: z.boolean(), flapRaises: z.number().int().min(0).max(20), deviceOfflineMinutes: z.number().int().min(5).max(1440), osSupportWarnDays: z.number().int().min(0).max(365), baselineAlerts: z.boolean(), containerAlerts: z.boolean(), vulnerabilityAlerts: z.boolean().default(true), vulnerabilityHighThreshold: z.number().int().min(0).max(10000).default(0), containerIgnore: z.array(z.string().trim().min(1).max(100)).max(200) })
|
||||
.partial()
|
||||
.optional(),
|
||||
quietHours: z
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Router } from "express";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { wallExtrasNow } from "../services/wallExtras.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const wallRouter = Router();
|
||||
wallRouter.use(requireAuth);
|
||||
|
||||
/** What the signed-in wall display shows besides the four tiles it works out itself: the extra tiles (Hetzner, game servers, vulnerabilities, stuck downloads) and a summary for each group of integrations. */
|
||||
wallRouter.get("/extras", asyncHandler(async (_req, res) => {
|
||||
res.json(await wallExtrasNow());
|
||||
}));
|
||||
Reference in new issue
Block a user