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:
bobbanandClaude Sonnet 5.5 committed 2026-10-19 23:16:14 +02:00
1 parent ddd0aa622a
commit be6c5552bd
46 files changed
+7836 -26

No files matched your search

+2 -1
View File
@@ -147,7 +147,8 @@ export default function ComingUp({ user }: { user: CurrentUser }) {
const seen = new Set<string>();
let hidden = 0;
const kept = withinRange.filter((i) => {
const schedule = /^schedule:(\d+):/.exec(i.id)?.[1];
const m = /^(schedule|plan):(\d+):/.exec(i.id);
const schedule = m ? `${m[1]}:${m[2]}` : null;
if (!schedule) return true;
if (seen.has(schedule)) {
hidden++;
+2 -1
View File
@@ -630,7 +630,8 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
const seenSchedules = new Set<string>();
const soon = (agenda?.items ?? []).filter((i) => {
if (i.kind === "updates") return false;
const schedule = /^schedule:(\d+):/.exec(i.id)?.[1];
const m = /^(schedule|plan):(\d+):/.exec(i.id);
const schedule = m ? `${m[1]}:${m[2]}` : null;
if (!schedule) return true;
if (seenSchedules.has(schedule)) return false;
seenSchedules.add(schedule);
+413
View File
@@ -0,0 +1,413 @@
import { useEffect, useState } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { IconPrinter } from "@tabler/icons-react";
import { api, type AvailabilityRow, type CurrentUser, type MonthlyReport as Report } from "../api/client";
import { ErrorNotice } from "../components/Notice";
import { BlockSkeleton } from "../components/Skeleton";
import { CATEGORY_NAMES, incidentPath, SEVERITY_BADGE } from "../components/IncidentHistory";
import { formatDate, formatDateTime } from "../utils/date";
import { readableError } from "../utils/errors";
import { toast } from "../utils/toast";
/** "2 h 40 min", "35 min", "3 d 4 h". */
function span(minutes: number): string {
const m = Math.max(1, Math.round(minutes));
if (m < 60) return `${m} min`;
const h = Math.floor(m / 60);
if (h < 24) return m % 60 && h < 10 ? `${h} h ${m % 60} min` : `${h} h`;
const d = Math.floor(h / 24);
return h % 24 ? `${d} d ${h % 24} h` : `${d} d`;
}
const RESULT_WORDS: Record<string, { label: string; badge: string }> = {
ok: { label: "Passed", badge: "bg-green-lt text-green" },
partial: { label: "Partly worked", badge: "bg-yellow-lt text-yellow" },
failed: { label: "Failed", badge: "bg-red-lt text-red" },
not_needed: { label: "Not needed", badge: "bg-secondary-lt text-secondary" },
};
const average = (rows: { percent: number | null }[]) => {
const known = rows.filter((r) => r.percent !== null);
return known.length === 0 ? null : Math.round((known.reduce((n, r) => n + (r.percent as number), 0) / known.length) * 10) / 10;
};
const percentBadge = (p: number | null) => (p === null ? "text-secondary" : p >= 99.9 ? "text-green" : p >= 99 ? "" : p >= 95 ? "text-yellow" : "text-red");
function Availability({ title, rows, hint }: { title: string; rows: AvailabilityRow[]; hint?: string }) {
if (rows.length === 0) return null;
return (
<div className="mb-3">
<h4 className="mb-1">{title}</h4>
{hint && <div className="text-secondary small mb-2">{hint}</div>}
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Name</th>
<th className="text-end">Up</th>
<th className="text-end">Down for</th>
</tr>
</thead>
<tbody>
{rows.map((r) => (
<tr key={r.id}>
<td>{r.name}</td>
<td className={`text-end ${percentBadge(r.percent)}`}>{r.percent === null ? "—" : `${r.percent}%`}</td>
<td className="text-end text-secondary">{r.downMinutes > 0 ? span(r.downMinutes) : "—"}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
/**
* How a month went, in one page that can be read, printed or sent: how available the servers and endpoints were, the incidents and how long they took, the
* updates applied, restore tests and the state of the backups, and what was renewed. The same report can be sent on a day of the month (Settings →
* Notifications → Monthly report).
*/
export default function MonthlyReport({ user }: { user: CurrentUser }) {
const [params, setParams] = useSearchParams();
const month = params.get("month") ?? undefined;
const [data, setData] = useState<{ report: Report; months: { id: string; label: string }[] } | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let alive = true;
setData(null);
api.reports
.monthly(month)
.then((res) => {
if (!alive) return;
setData(res);
setError(null);
})
.catch((err) => alive && setError(readableError(err)));
return () => {
alive = false;
};
}, [month]);
async function copyText() {
try {
const t = await api.reports.monthlyText(data?.report.month);
await navigator.clipboard.writeText(`${t.title}\n\n${t.message}`);
toast.success("Copied the report as text.");
} catch (err) {
toast.error(readableError(err));
}
}
const r = data?.report;
const serverAvg = r ? average(r.servers) : null;
const endpointAvg = r ? average(r.endpoints) : null;
const cards = r
? [
{ label: "Servers up, on average", value: serverAvg === null ? "—" : `${serverAvg}%`, color: percentBadge(serverAvg) },
{ label: "Endpoints answering", value: endpointAvg === null ? "—" : `${endpointAvg}%`, color: percentBadge(endpointAvg) },
{ label: "Incidents began", value: String(r.incidents.began), color: r.incidents.began > 0 ? "text-yellow" : "text-green" },
{ label: "Update runs", value: String(r.updates.runs), color: r.updates.failed > 0 ? "text-yellow" : "" },
{ label: "Renewed", value: String(r.renewals.length), color: "" },
]
: [];
return (
<div className="report-page">
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
<h2 className="page-title mb-0">Monthly report</h2>
<div className="ms-auto d-flex flex-wrap gap-2 no-print">
{data && (
<select className="form-select w-auto" aria-label="Month" value={r?.month ?? ""} onChange={(e) => setParams(e.target.value === data.months[1]?.id ? {} : { month: e.target.value }, { replace: true })}>
{data.months.map((m) => (
<option key={m.id} value={m.id}>
{m.label}
{m.id === data.months[0].id ? " (so far)" : ""}
</option>
))}
</select>
)}
<button className="btn btn-outline-secondary" onClick={() => void copyText()} disabled={!r}>
Copy as text
</button>
<button className="btn btn-outline-secondary d-inline-flex align-items-center gap-1" onClick={() => window.print()} disabled={!r}>
<IconPrinter size={16} aria-hidden="true" /> Print
</button>
</div>
</div>
<p className="text-secondary no-print">
How the month went, in one page: availability, incidents and how long they took, updates applied, restore tests and backups, and what was renewed.
{user.role === "admin" ? (
<>
{" "}
It can be sent on a day of the month: <Link to="/settings/notifications">Settings → Notifications</Link>.
</>
) : null}
</p>
<ErrorNotice error={error} />
{!data && !error && <BlockSkeleton lines={6} />}
{r && (
<>
<h3 className="mb-1">{r.label}</h3>
<div className="text-secondary mb-3">
{formatDate(new Date(r.from))} – {formatDate(new Date(r.to))}
{r.partial ? " · the month is not over, so this is the month so far" : ""} · time zone {r.timezone}
</div>
<div className="row row-cards mb-3">
{cards.map((c) => (
<div className="col-6 col-md" key={c.label}>
<div className="card card-sm">
<div className="card-body">
<div className={`h2 mb-0 ${c.color}`}>{c.value}</div>
<div className="text-secondary">{c.label}</div>
</div>
</div>
</div>
))}
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Availability</h3>
</div>
<div className="card-body">
{r.servers.length === 0 && r.endpoints.length === 0 && r.integrations.length === 0 ? (
<div className="text-secondary">Nothing was measured for this month. Servers are measured from when their agent first reported, endpoints from when they were first checked.</div>
) : (
<>
<Availability title="Servers" rows={r.servers} hint="From when each stopped reporting and reported again; the worst first." />
{r.endpoints.length > 0 && (
<div className="mb-3">
<h4 className="mb-1">Endpoints</h4>
<div className="text-secondary small mb-2">From every check's answers, day by day (the days are UTC days).</div>
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Check</th>
<th className="text-end">Answered</th>
<th className="text-end">Average answer</th>
<th className="text-end">Times asked</th>
</tr>
</thead>
<tbody>
{r.endpoints.map((e) => (
<tr key={e.id}>
<td>{e.name}</td>
<td className={`text-end ${percentBadge(e.percent)}`}>{e.percent === null ? "—" : `${e.percent}%`}</td>
<td className="text-end text-secondary">{e.avgMs === null ? "—" : `${e.avgMs} ms`}</td>
<td className="text-end text-secondary">{e.checks}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
<Availability title="Integrations" rows={r.integrations} hint="How often the calls to each kind of integration worked." />
</>
)}
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Incidents</h3>
</div>
<div className="card-body">
{r.incidents.began === 0 && r.incidents.resolved === 0 && r.incidents.stillOpen === 0 ? (
<div className="text-secondary">No incident began or ended this month.</div>
) : (
<>
<p>
<strong>{r.incidents.began}</strong> began, <strong>{r.incidents.resolved}</strong> ended{r.incidents.stillOpen > 0 ? <>, <strong>{r.incidents.stillOpen}</strong> {r.partial ? "open" : "still open at the end of the month"}</> : null}.
{r.incidents.averageMinutes !== null && <> One that began and ended in the month took {span(r.incidents.averageMinutes)} on average, {span(r.incidents.totalMinutes)} in all.</>}
</p>
{r.incidents.byCategory.length > 0 && (
<div className="mb-3 d-flex flex-wrap gap-2">
{r.incidents.byCategory.map((c) => (
<span key={c.category} className="badge bg-secondary-lt text-secondary">
{CATEGORY_NAMES[c.category as keyof typeof CATEGORY_NAMES] ?? c.category} · {c.count}
</span>
))}
</div>
)}
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Began</th>
<th>Where</th>
<th>What</th>
<th>Worst</th>
<th className="text-end">Lasted</th>
</tr>
</thead>
<tbody>
{r.incidents.list.map((i) => (
<tr key={i.id}>
<td className="text-nowrap">{formatDateTime(new Date(i.openedAt))}</td>
<td>{i.where}</td>
<td>
<Link to={incidentPath(i.id)}>{i.message}</Link>
</td>
<td>
<span className={`badge ${SEVERITY_BADGE[i.severity] ?? ""}`}>{i.severity}</span>
</td>
<td className="text-end text-nowrap">
{span(i.minutes)}
{!i.resolvedAt && <span className="text-secondary small"> and open</span>}
</td>
</tr>
))}
</tbody>
</table>
</div>
{r.incidents.began > r.incidents.list.length && <div className="text-secondary small">The {r.incidents.list.length} longest of {r.incidents.began}. All are under Alerts → History.</div>}
</>
)}
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Updates</h3>
</div>
<div className="card-body">
{r.updates.runs === 0 && r.updates.planRuns.runs === 0 ? (
<div className="text-secondary">No update run was made from here this month.</div>
) : (
<>
<p>
<strong>{r.updates.runs}</strong> update run{r.updates.runs === 1 ? "" : "s"}: {r.updates.done} done{r.updates.failed > 0 ? `, ${r.updates.failed} failed` : ""}
{r.updates.installed > 0 ? ` — ${r.updates.installed} update${r.updates.installed === 1 ? "" : "s"} installed` : ""}.
{r.updates.planRuns.runs > 0 && (
<>
{" "}
Patch plans ran {r.updates.planRuns.runs} time{r.updates.planRuns.runs === 1 ? "" : "s"}
{r.updates.planRuns.failed > 0 ? `, ${r.updates.planRuns.failed} not cleanly` : ", all cleanly"}.
</>
)}
</p>
{r.updates.byServer.length > 0 && (
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Server</th>
<th className="text-end">Runs</th>
<th className="text-end">Failed</th>
<th className="text-end">Installed</th>
</tr>
</thead>
<tbody>
{r.updates.byServer.map((s) => (
<tr key={s.name}>
<td>{s.name}</td>
<td className="text-end">{s.runs}</td>
<td className={`text-end ${s.failed > 0 ? "text-red" : "text-secondary"}`}>{s.failed || "—"}</td>
<td className="text-end">{s.installed || "—"}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</>
)}
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Backups and restore tests</h3>
</div>
<div className="card-body">
{r.restoreTests.length === 0 ? (
<p className="text-secondary">No restore test was recorded this month.</p>
) : (
<div className="table-responsive mb-2">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Tested</th>
<th>What</th>
<th>Result</th>
<th>Note</th>
</tr>
</thead>
<tbody>
{r.restoreTests.map((t, i) => (
<tr key={`${t.label}-${i}`}>
<td className="text-nowrap">{t.testedAt}</td>
<td>{t.label}</td>
<td>
<span className={`badge ${RESULT_WORDS[t.result]?.badge ?? ""}`}>{RESULT_WORDS[t.result]?.label ?? t.result}</span>
</td>
<td className="text-secondary">{t.note ?? ""}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
{r.backups ? (
<p className="mb-0">
Backups as they are now (<span title={formatDateTime(new Date(r.backups.asOf))}>read {formatDate(new Date(r.backups.asOf))}</span>): <strong>{r.backups.ok}</strong> of {r.backups.total} guest{r.backups.total === 1 ? "" : "s"} have a recent one
{r.backups.failed + r.backups.stale + r.backups.none + r.backups.unknown > 0 && (
<>
; {r.backups.failed} failed, {r.backups.stale} stale, {r.backups.none} without any{r.backups.unknown > 0 ? `, ${r.backups.unknown} unknown` : ""}
</>
)}
. See <Link to="/backups">Backup coverage</Link>.
</p>
) : (
<p className="text-secondary mb-0">The backups have not been read since this app started, so their state is not shown here. Open Backup coverage to read them.</p>
)}
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Renewed</h3>
</div>
<div className="card-body">
{r.renewals.length === 0 ? (
<div className="text-secondary">No certificate or domain was seen to be renewed this month.</div>
) : (
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Seen</th>
<th>What</th>
<th>Was good until</th>
<th>Is good until</th>
</tr>
</thead>
<tbody>
{r.renewals.map((x, i) => (
<tr key={`${x.subject}-${i}`}>
<td className="text-nowrap">{formatDate(new Date(x.at))}</td>
<td>
{x.kind === "domain" ? "Domain" : "Certificate"} {x.subject}
</td>
<td className="text-secondary">{x.fromDate}</td>
<td>{x.toDate}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
<div className="text-secondary small mt-2">Renewals are noticed when the app re-reads an expiry date, so only those since it began watching are here.</div>
</div>
</div>
</>
)}
</div>
);
}
+32 -2
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useState, type ReactNode } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { api, type AgentLatest, type CurrentUser, type DockhandContainer, type UpdatesServer } from "../api/client";
import { agentState, agentVersionWords } from "../utils/agent";
@@ -15,6 +15,8 @@ import { readableError } from "../utils/errors";
import ExportTableButton from "../components/ExportTableButton";
import UpdateRunDrawer from "../components/UpdateRunDrawer";
import UpdateRunsCard from "../components/UpdateRunsCard";
import ViewTabs from "../components/ViewTabs";
import PatchPlans from "../components/PatchPlans";
import { EmptyRow } from "../components/EmptyState";
interface Row {
@@ -56,7 +58,34 @@ const DAY_MS = 86_400_000;
* whether a restart is due, and how long they have been waiting) and the Docker containers that have a newer image. It only looks —
* nothing here installs anything.
*/
const updateTabs = (view: "waiting" | "plans") => (
<ViewTabs
label="Updates view"
tabs={[
{ to: "/updates", label: "Waiting now", active: view === "waiting" },
{ to: "/updates?view=plans", label: "Patch plans", active: view === "plans" },
]}
/>
);
/** What is waiting to be installed, and — as patch plans — updating on a schedule, one server at a time (`?view=plans`). */
export default function Updates({ user }: { user: CurrentUser }) {
const [params] = useSearchParams();
if (params.get("view") === "plans") {
return (
<>
<div className="d-flex align-items-center mb-2">
<h2 className="page-title mb-0">Updates</h2>
</div>
{updateTabs("plans")}
<PatchPlans user={user} />
</>
);
}
return <WaitingNow user={user} tabs={updateTabs("waiting")} />;
}
function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
const canRun = user.role === "admin" || user.role === "operator";
// The server being updated now (its drawer is open), and a counter that makes the runs card look again after one was started.
const [updating, setUpdating] = useState<UpdatesServer | null>(null);
@@ -154,9 +183,10 @@ export default function Updates({ user }: { user: CurrentUser }) {
return (
<>
<div className="d-flex align-items-center mb-3">
<div className="d-flex align-items-center mb-2">
<h2 className="page-title mb-0">Updates</h2>
</div>
{tabs}
<p className="text-secondary">
What the agents say is waiting to be installed on each server, and the Docker containers that have a newer image. {canRun ? "Update… applies a server's updates through a Semaphore playbook: it silences the server, runs the playbook, waits for the server to report again and tells you what is left." : "Operators can apply a server's updates from here."}
</p>
+103 -4
View File
@@ -12,6 +12,7 @@ import {
type EscalationSettings,
type NotificationEvents,
type DigestSettings,
type MonthlyReportSettings,
type QuietHoursSettings,
type HealthCheckSettings,
} from "../../api/client";
@@ -81,7 +82,8 @@ const DIGEST_DAYS: { value: number; label: string }[] = [
{ value: 6, label: "Saturday" },
{ value: 0, label: "Sunday" },
];
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0 };
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true };
const DEFAULT_MONTHLY: MonthlyReportSettings = { enabled: false, day: 1, time: "08:00" };
type TestResult = { ok: boolean; message: string } | null;
type EventKey = { [K in keyof NotificationEvents]: NotificationEvents[K] extends boolean ? K : never }[keyof NotificationEvents];
@@ -240,6 +242,10 @@ export default function NotificationSettings() {
const [digestPreview, setDigestPreview] = useState<{ title: string; message: string } | null>(null);
const [digestBusy, setDigestBusy] = useState<"preview" | "send" | null>(null);
const [digestResult, setDigestResult] = useState<TestResult>(null);
const [monthly, setMonthly] = useState<MonthlyReportSettings>(DEFAULT_MONTHLY);
const [monthlyPreview, setMonthlyPreview] = useState<{ title: string; message: string } | null>(null);
const [monthlyBusy, setMonthlyBusy] = useState<"preview" | "send" | null>(null);
const [monthlyResult, setMonthlyResult] = useState<TestResult>(null);
const [queuedCount, setQueuedCount] = useState<number | null>(null);
const [flushing, setFlushing] = useState(false);
const [flushResult, setFlushResult] = useState<string | null>(null);
@@ -253,7 +259,7 @@ export default function NotificationSettings() {
const [testingWebhook, setTestingWebhook] = useState(false);
const [testWebhookResult, setTestWebhookResult] = useState<TestResult>(null);
const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest });
const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest, monthlyReport: monthly });
const dirty = baseline !== null && snapshot !== baseline;
useEffect(() => {
@@ -277,7 +283,9 @@ export default function NotificationSettings() {
setHealthChecks(s.healthChecks);
const d = s.digest ?? DEFAULT_DIGEST;
setDigest(d);
setBaseline(JSON.stringify({ gotify: s.gotify, ntfy: s.ntfy, smtp: s.smtp, webhook: s.webhook, webPush: wp, routing: rt, escalation: es, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: d }));
const mo = s.monthlyReport ?? DEFAULT_MONTHLY;
setMonthly(mo);
setBaseline(JSON.stringify({ gotify: s.gotify, ntfy: s.ntfy, smtp: s.smtp, webhook: s.webhook, webPush: wp, routing: rt, escalation: es, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: d, monthlyReport: mo }));
})
.catch((err) => setLoadError(err instanceof Error ? err.message : String(err)))
.finally(() => setLoading(false));
@@ -324,7 +332,7 @@ export default function NotificationSettings() {
setSaveError(null);
setSaved(false);
try {
await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest });
await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest, monthlyReport: monthly });
setBaseline(snapshot);
setWebPushSaved(webPush.enabled);
setSaved(true);
@@ -362,6 +370,31 @@ export default function NotificationSettings() {
}
}
async function handleMonthlyPreview() {
setMonthlyBusy("preview");
setMonthlyResult(null);
try {
setMonthlyPreview(await api.reports.monthlyText());
} catch (err) {
setMonthlyResult({ ok: false, message: readableError(err) });
} finally {
setMonthlyBusy(null);
}
}
async function handleMonthlySend() {
setMonthlyBusy("send");
setMonthlyResult(null);
try {
await api.reports.sendMonthly();
setMonthlyResult({ ok: true, message: "Sent through the channels that are on." });
} catch (err) {
setMonthlyResult({ ok: false, message: readableError(err) });
} finally {
setMonthlyBusy(null);
}
}
async function handleFlushNow() {
setFlushing(true);
setFlushResult(null);
@@ -702,6 +735,16 @@ export default function NotificationSettings() {
hint="From each agent server's own history, shown on the Alerts page and dashboard (not sent as a notification). Needs a few days of steady growth to say anything. 0 turns it off."
onChange={(v) => setHealthChecks((h) => ({ ...h, diskForecastDays: v }))}
/>
<label className="form-check mt-3 mb-0">
<input type="checkbox" className="form-check-input" checked={healthChecks.newPortAlerts} onChange={(e) => setHealthChecks((h) => ({ ...h, newPortAlerts: e.target.checked }))} />
<span className="form-check-label">
Warn when a server starts listening on a new port
<span className="form-hint d-block">
The first report from each agent says what is normal; a TCP port that appears later (not UDP, not 49152 and up, not localhost only) is on the Alerts page until it is marked as
expected on the server&rsquo;s Ports card or stops listening. Sent with the server offline and disk messages.
</span>
</span>
</label>
</div>
</div>
</div>
@@ -893,6 +936,62 @@ export default function NotificationSettings() {
</div>
</div>
<div className="col-12">
<div className="card">
<div className="card-header">
<h3 className="card-title">Monthly report</h3>
</div>
<div className="card-body">
<p className="text-secondary">
One message a month with last month in numbers: how available the servers and endpoints were, the incidents and how long they took, updates applied (by hand and by patch plans),
restore tests, and what was renewed. The same report is on the <a href="/reports">Monthly report</a> page, to read and print. Quiet hours hold it like any other notification.
</p>
<label className="form-check mb-3">
<input type="checkbox" className="form-check-input" checked={monthly.enabled} onChange={(e) => setMonthly((m) => ({ ...m, enabled: e.target.checked }))} />
<span className="form-check-label">Send the monthly report</span>
</label>
<div className="row g-2 mb-3" style={{ maxWidth: 420 }}>
<div className="col-6">
<label className="form-label" htmlFor="monthly-day">
Day of the month
</label>
<select id="monthly-day" className="form-select" value={monthly.day} disabled={!monthly.enabled} onChange={(e) => setMonthly((m) => ({ ...m, day: Number(e.target.value) }))}>
{Array.from({ length: 28 }, (_, i) => i + 1).map((d) => (
<option key={d} value={d}>
{d}
</option>
))}
</select>
</div>
<div className="col-6">
<label className="form-label" htmlFor="monthly-time">
Time
</label>
<input id="monthly-time" type="time" className="form-control" value={monthly.time} disabled={!monthly.enabled} onChange={(e) => setMonthly((m) => ({ ...m, time: e.target.value }))} />
</div>
</div>
<div className="btn-list">
<button type="button" className="btn btn-outline-secondary" onClick={handleMonthlyPreview} disabled={monthlyBusy !== null}>
{monthlyBusy === "preview" ? "Gathering…" : "Preview last month"}
</button>
<button type="button" className="btn btn-outline-secondary" onClick={handleMonthlySend} disabled={monthlyBusy !== null}>
{monthlyBusy === "send" ? "Sending…" : "Send last month now"}
</button>
</div>
<div className="form-hint mt-2">The day and time are saved with the Save button; the preview and "send now" don't depend on them. The day is at most the 28th, so every month has it.</div>
<TestBadge result={monthlyResult} />
{monthlyPreview && (
<div className="mt-3">
<div className="fw-bold">{monthlyPreview.title}</div>
<pre className="border rounded p-2 mt-1 mb-0" style={{ whiteSpace: "pre-wrap", fontSize: "0.8125rem" }}>
{monthlyPreview.message}
</pre>
</div>
)}
</div>
</div>
</div>
<div className="col-12">
<div className="card">
<div className="card-header">