Alert rules of your own, storage forecasts for Proxmox and Synology, and snooze
- Monitoring -> Alert rules: CPU, memory, disk use and disk temperature limits with a time, severity and scope (all, one server, a tag); try before saving; findings are ordinary health conditions - Proxmox storages and Synology volumes are written down on each health pass (hourly, 400 days) and forecast like server disks: badge and history chart on the pages, alert, digest line, /metrics gauge - Snooze an alert until a time; held back like maintenance, messages held, announced once again if still there when it ends - Docs updated Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
788b3e073c
commit
24ae8db380
38 files changed
+7847
-8
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { Router } from "express";
|
||||
import { z } from "zod";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { getAlerts } from "../services/alerts.js";
|
||||
import { getAlerts, invalidateAlertsCache } from "../services/alerts.js";
|
||||
import { clearSnooze, setSnooze, SnoozeError } from "../services/alertSnoozes.js";
|
||||
import { keyOfAlertId } from "../services/flapGuard.js";
|
||||
import { AckError, assignableUsers, attentionCounts, clearAck, loadAcks, MAX_HOURS, MAX_NOTE, setAck } from "../services/alertAcks.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { openIncidentIds } from "../services/incidents.js";
|
||||
@@ -95,3 +97,39 @@ alertsRouter.delete("/ack", requireRole("operator"), asyncHandler(async (req, re
|
||||
await recordAudit({ actor: req.currentUser!, category: "alert", action: "unack", ...(alert ? auditTargetOf(alert) : {}), detail: { alertId, message: alert?.message ?? null } });
|
||||
res.status(204).end();
|
||||
}));
|
||||
|
||||
const snoozeSchema = z.object({
|
||||
alertId: z.string().min(1).max(600),
|
||||
/** When it should come back, as a date and time with its zone. */
|
||||
until: z.string().min(1).max(40),
|
||||
});
|
||||
|
||||
// "Remind me then": hide an alert until a time, and announce it again then if it is still there.
|
||||
alertsRouter.put("/snooze", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const parsed = snoozeSchema.safeParse(req.body);
|
||||
const until = parsed.success ? new Date(parsed.data.until) : null;
|
||||
if (!parsed.success || !until || Number.isNaN(until.getTime())) return res.status(400).json({ error: "invalid_body", message: "Say which alert, and when it should come back." });
|
||||
const alert = (await getAlerts(false)).alerts.find((a) => a.id === parsed.data.alertId);
|
||||
if (!alert) return res.status(404).json({ error: "not_found", message: "That alert isn't there any more." });
|
||||
const actor = req.currentUser!;
|
||||
try {
|
||||
const snooze = await setSnooze({ alertId: alert.id, conditionKey: keyOfAlertId(alert.id, alert.category), message: alert.message, until, actor: actor.name ?? actor.email ?? actor.oidcSub });
|
||||
await recordAudit({ actor, category: "alert", action: "snooze", ...auditTargetOf(alert), detail: { alertId: alert.id, message: alert.message, until: snooze.until } });
|
||||
invalidateAlertsCache();
|
||||
res.json({ snooze });
|
||||
} catch (err) {
|
||||
if (err instanceof SnoozeError) return res.status(err.status).json({ error: err.code, message: err.message });
|
||||
throw err;
|
||||
}
|
||||
}));
|
||||
|
||||
alertsRouter.delete("/snooze", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const alertId = typeof req.query.alertId === "string" ? req.query.alertId : "";
|
||||
if (!alertId) return res.status(400).json({ error: "invalid_id" });
|
||||
const removed = await clearSnooze(alertId);
|
||||
if (!removed) return res.status(404).json({ error: "not_found" });
|
||||
const alert = (await getAlerts(false)).alerts.find((a) => a.id === alertId);
|
||||
await recordAudit({ actor: req.currentUser!, category: "alert", action: "unsnooze", ...(alert ? auditTargetOf(alert) : {}), detail: { alertId, message: removed.message } });
|
||||
invalidateAlertsCache();
|
||||
res.status(204).end();
|
||||
}));
|
||||
Reference in new issue
Block a user