Patch plans, a monthly report and new-port alerts
Patch plans (Updates -> Patch plans): updates on a schedule, one server at a time, each by an ordinary update run, stopping at the first failure by default, silencing what depends on a server while it is updated, with one message at the end. Monthly report (Operations -> Monthly report, and optionally a message on a day of the month): availability, incidents, updates, restore tests, backups and renewals for a calendar month, printable. Backed by daily endpoint figures and a record of renewals. New ports: the first report with ports is the baseline; a TCP port that begins listening later and is not noted on the server's Ports card is a warning, cleared by Mark as expected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddd0aa622a
commit
be6c5552bd
46 files changed
+7836
-26
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { Router } from "express";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { buildMonthlyReport, isMonthId, lastFullMonth, monthlyReportText, recentMonths } from "../services/monthlyReport.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { notifyNow } from "../services/notify.js";
|
||||
import { getSettings } from "../services/settingsStore.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const reportsRouter = Router();
|
||||
|
||||
reportsRouter.use(requireAuth);
|
||||
|
||||
/** The month asked for, or the last whole one; null when what was asked is not a month. */
|
||||
async function monthFrom(query: unknown): Promise<{ id: string; months: { id: string; label: string }[] } | null> {
|
||||
const tz = (await getSettings()).notifications.timezone || "UTC";
|
||||
const months = recentMonths(new Date(), tz);
|
||||
if (query === undefined || query === "") return { id: lastFullMonth(new Date(), tz), months };
|
||||
if (!isMonthId(query) || !months.some((m) => m.id === query)) return null;
|
||||
return { id: query, months };
|
||||
}
|
||||
|
||||
// How a month went, for everyone signed in: it is only what the pages it comes from already show them. ?month=2026-09, the last whole month by default;
|
||||
// ?format=text is the plain-text version a notification carries.
|
||||
reportsRouter.get("/monthly", asyncHandler(async (req, res) => {
|
||||
const picked = await monthFrom(req.query.month);
|
||||
if (!picked) return res.status(400).json({ error: "invalid_month", message: "Ask for one of the last twelve months, like 2026-09." });
|
||||
const report = await buildMonthlyReport(picked.id);
|
||||
if (req.query.format === "text") return res.json(monthlyReportText(report));
|
||||
res.json({ report, months: picked.months });
|
||||
}));
|
||||
|
||||
// Send it now to the notification channels, as if it were the day. Administrators.
|
||||
reportsRouter.post("/monthly/send", requireRole("admin"), asyncHandler(async (req, res) => {
|
||||
const picked = await monthFrom((req.body as { month?: unknown } | undefined)?.month);
|
||||
if (!picked) return res.status(400).json({ error: "invalid_month", message: "Ask for one of the last twelve months, like 2026-09." });
|
||||
const { title, message } = monthlyReportText(await buildMonthlyReport(picked.id));
|
||||
await notifyNow(title, message);
|
||||
await recordAudit({ actor: req.currentUser!, category: "report", action: "send_monthly", targetType: "report", detail: { month: picked.id } });
|
||||
res.json({ sent: true });
|
||||
}));
|
||||
Reference in new issue
Block a user