Add a notification history

Every notification is written down with how it went through each channel
(or why it was not sent: held for quiet hours, a routing rule said nobody, no
channel on). Records -> Notifications lists them with a filter, a search and
Send again. Errors are cleaned of every secret in the settings; kept 30 days.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-10 19:18:08 +01:00
1 parent 5c6ccc0a4b
commit 9126200295
18 files changed
+9886 -34

No files matched your search

+2
View File
@@ -63,6 +63,7 @@ import Heartbeats from "./pages/Heartbeats";
import ComingUp from "./pages/ComingUp";
import MonthlyReport from "./pages/MonthlyReport";
import ChangeLog from "./pages/ChangeLog";
import NotificationHistory from "./pages/NotificationHistory";
import BackupsHub from "./pages/BackupsHub";
import Consistency from "./pages/Consistency";
import Privacy from "./pages/Privacy";
@@ -220,6 +221,7 @@ function Shelled({ user }: { user: CurrentUser }) {
<Route path="/coming-up" element={<ComingUp user={user} />} />
<Route path="/reports" element={<MonthlyReport user={user} />} />
<Route path="/changes" element={user.role === "viewer" ? <Navigate to="/" replace /> : <ChangeLog />} />
<Route path="/notification-history" element={user.role === "viewer" ? <Navigate to="/" replace /> : <NotificationHistory />} />
<Route path="/backups" element={<BackupsHub user={user} />} />
<Route path="/docker" element={<Docker user={user} />} />
<Route path="/tailscale" element={<Tailscale user={user} />} />
+22
View File
@@ -2235,6 +2235,20 @@ export interface Agenda {
}
export type ChangeKind = "servers" | "maintenance" | "alerts" | "settings" | "integrations" | "dependencies" | "inventory" | "backups" | "endpoints" | "other";
/** One notification as the history lists it: what it said and how each channel took it. */
export interface NotificationEntry {
id: number;
at: string;
title: string;
message: string;
/** sent, partly, failed, none (no channel to send it to), held (quiet hours or away) or muted (a routing rule says nobody). */
status: string;
results: { channel: string; ok: boolean; error: string | null }[];
/** Why it was held or muted. */
note: string | null;
resentOf: number | null;
}
export interface ChangeEntry {
id: string;
at: string;
@@ -3824,6 +3838,14 @@ export const api = {
return request<{ entries: ChangeEntry[]; more: boolean; kinds: { id: ChangeKind; label: string }[] }>(`/api/changes?${q.toString()}`);
},
},
notificationLog: {
list: (params: { status?: string; q?: string; limit?: number }) => {
const q = new URLSearchParams();
for (const [k, v] of Object.entries(params)) if (v !== undefined && v !== "") q.set(k, String(v));
return request<{ entries: NotificationEntry[]; statuses: string[] }>(`/api/notification-log?${q.toString()}`);
},
resend: (id: number) => request<{ ok: boolean; entry: number | null }>(`/api/notification-log/${id}/resend`, { method: "POST" }),
},
push: {
key: () => request<{ publicKey: string }>("/api/push/key"),
mine: () => request<{ enabled: boolean; subscriptions: PushDevice[] }>("/api/push/mine"),
+2
View File
@@ -48,6 +48,7 @@ import {
IconBox,
IconHeartbeat,
IconGitCommit,
IconBellRinging,
IconShieldLock,
IconWorldWww,
IconVersions,
@@ -196,6 +197,7 @@ export const NAV: NavEntry[] = [
{ to: "/reports", label: "Reports", icon: <IconReportAnalytics size={20} /> },
{ to: "/costs", label: "Costs", icon: <IconCoin size={20} /> },
{ to: "/changes", label: "Change log", icon: <IconGitCommit size={20} />, minRole: "operator" },
{ to: "/notification-history", label: "Notifications", icon: <IconBellRinging size={20} />, minRole: "operator" },
],
},
{
+176
View File
@@ -0,0 +1,176 @@
import { useEffect, useState } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { api, type NotificationEntry } from "../api/client";
import EmptyState from "../components/EmptyState";
import { ErrorNotice } from "../components/Notice";
import { BlockSkeleton } from "../components/Skeleton";
import TimeAgo from "../components/TimeAgo";
import { formatDateTime } from "../utils/date";
import { readableError } from "../utils/errors";
import { channelName, isLogStatus, STATUS_BADGE, STATUS_HINT, STATUS_LABEL, STATUS_ORDER, type LogStatus } from "../utils/notificationLog";
import { toast } from "../utils/toast";
/**
* What was sent: every notification, newest first, with how it went through each channel — or why it did not: held for quiet hours, a routing rule said nobody, no channel to send it to.
* "Send again" sends it once more to every channel that is on. Kept 30 days.
*/
export default function NotificationHistory() {
const [params, setParams] = useSearchParams();
const status = isLogStatus(params.get("status") ?? "") ? (params.get("status") as LogStatus) : "";
const q = params.get("q") ?? "";
const [text, setText] = useState(q);
const [entries, setEntries] = useState<NotificationEntry[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [resending, setResending] = useState<number | null>(null);
const [tick, setTick] = useState(0);
const setParam = (key: string, value: string | null) =>
setParams(
(prev) => {
const next = new URLSearchParams(prev);
if (value) next.set(key, value);
else next.delete(key);
return next;
},
{ replace: true },
);
// What is searched for follows what is typed, a moment after it stops.
useEffect(() => {
const t = setTimeout(() => setParam("q", text.trim() || null), 300);
return () => clearTimeout(t);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [text]);
useEffect(() => {
let alive = true;
api.notificationLog
.list({ status, q })
.then((res) => {
if (!alive) return;
setEntries(res.entries);
setError(null);
})
.catch((err) => alive && setError(readableError(err)));
return () => {
alive = false;
};
}, [status, q, tick]);
async function resend(e: NotificationEntry) {
setResending(e.id);
try {
await api.notificationLog.resend(e.id);
toast.success("Sent again to every channel that is on.");
setTick((n) => n + 1);
} catch (err) {
toast.error(readableError(err));
} finally {
setResending(null);
}
}
const failing = entries?.filter((e) => e.status === "failed" || e.status === "partly").length ?? 0;
return (
<>
<div className="d-flex align-items-center mb-1">
<h2 className="page-title mb-0">Notification history</h2>
</div>
<p className="text-secondary">
What was sent, to which channel, and whether it got through — or why it was not sent. Kept 30 days. The channels are set up under <Link to="/settings/notifications">Settings → Notifications</Link>.
</p>
<div className="row g-2 mb-3">
<div className="col-sm-4 col-md-3">
<select className="form-select" aria-label="Show" value={status} onChange={(e) => setParam("status", e.target.value || null)}>
<option value="">Everything</option>
{STATUS_ORDER.map((s) => (
<option key={s} value={s}>
{STATUS_LABEL[s]}
</option>
))}
</select>
</div>
<div className="col-sm-8 col-md-5">
<input className="form-control" type="search" aria-label="Search the history" placeholder="Search the title or the message" value={text} onChange={(e) => setText(e.target.value)} />
</div>
</div>
<ErrorNotice error={error} />
{!entries && !error && <BlockSkeleton lines={5} />}
{entries && entries.length === 0 && (
<div className="card">
<div className="card-body">
<EmptyState title={status || q ? "Nothing matches" : "Nothing has been sent yet"} hint={status || q ? "Try another filter." : "Every notification is listed here from now on, with how each channel took it."} />
</div>
</div>
)}
{entries && entries.length > 0 && (
<div className="card">
<div className="card-header">
<h3 className="card-title">
{entries.length} notification{entries.length === 1 ? "" : "s"}
{failing > 0 && <span className="text-red fw-normal ms-2">{failing} did not get through everywhere</span>}
</h3>
</div>
<div className="table-responsive">
<table className="table table-vcenter card-table">
<thead>
<tr>
<th>When</th>
<th>Notification</th>
<th>How it went</th>
<th className="w-1">Actions</th>
</tr>
</thead>
<tbody>
{entries.map((e) => {
const known = isLogStatus(e.status);
return (
<tr key={e.id}>
<td className="text-nowrap">
<span title={formatDateTime(new Date(e.at))}>
<TimeAgo value={e.at} />
</span>
</td>
<td style={{ maxWidth: 420 }}>
<div className="fw-bold text-break">{e.title}</div>
{e.resentOf !== null && <div className="text-secondary small">sent again from an earlier one</div>}
<details className="small">
<summary className="text-secondary">Show what it said</summary>
<pre className="mb-0 text-break" style={{ whiteSpace: "pre-wrap", maxHeight: 220, overflow: "auto" }}>
{e.message}
</pre>
</details>
</td>
<td>
<span className={`badge ${known ? STATUS_BADGE[e.status as LogStatus] : "bg-secondary-lt"}`} title={known ? STATUS_HINT[e.status as LogStatus] : undefined}>
{known ? STATUS_LABEL[e.status as LogStatus] : e.status}
</span>
{e.note && <div className="text-secondary small">{e.note}</div>}
{e.results.length > 0 && (
<ul className="list-unstyled small mb-0 mt-1">
{e.results.map((r, i) => (
<li key={i} className={r.ok ? "text-secondary" : "text-red"}>
<span aria-hidden="true">{r.ok ? "✓" : "✕"}</span> {channelName(r.channel)}
{!r.ok && r.error ? <span className="text-break"> — {r.error}</span> : null}
</li>
))}
</ul>
)}
</td>
<td>
<button className="btn btn-sm" disabled={resending === e.id} onClick={() => void resend(e)} title="Send it once more to every channel that is on">
{resending === e.id ? "Sending…" : e.status === "held" ? "Send now" : "Send again"}
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
)}
</>
);
}
@@ -1,6 +1,6 @@
import AwayCard from "./AwayCard";
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { useSearchParams } from "react-router-dom";
import { Link, useSearchParams } from "react-router-dom";
import AlertActionsCard from "./AlertActionsCard";
import {
api,
@@ -546,7 +546,12 @@ export default function NotificationSettings() {
<>
<div className="settings-savebar">
<div className="d-flex flex-wrap align-items-center justify-content-between gap-2">
<h3 className="mb-0">Notifications</h3>
<h3 className="mb-0">
Notifications
<Link className="ms-3 fs-5 fw-normal" to="/notification-history">
See what was sent
</Link>
</h3>
<div className="d-flex align-items-center gap-2">
{saveError && <span className="text-danger small">{saveError}</span>}
{saved && <span className="text-success small">✓ Settings saved</span>}
+50
View File
@@ -0,0 +1,50 @@
/** How a notification went, as the history page says it: one label and one colour for each status, and a name for each channel. */
export type LogStatus = "sent" | "partly" | "failed" | "none" | "held" | "muted";
export const STATUS_LABEL: Record<LogStatus, string> = {
sent: "Sent",
partly: "Partly sent",
failed: "Failed",
none: "Nowhere to send it",
held: "Held",
muted: "Not sent (rule)",
};
/** What each status is, in a sentence: for the filter and for a tooltip. */
export const STATUS_HINT: Record<LogStatus, string> = {
sent: "Every channel it went to took it.",
partly: "Some channels took it and some refused or could not be reached.",
failed: "No channel took it.",
none: "No channel was switched on to send it to.",
held: "Held for quiet hours or while you were away; it goes in the digest.",
muted: "A routing rule says nobody should be told about this kind.",
};
export const STATUS_BADGE: Record<LogStatus, string> = {
sent: "bg-green-lt text-green",
partly: "bg-yellow-lt text-yellow",
failed: "bg-red-lt text-red",
none: "bg-secondary-lt",
held: "bg-blue-lt text-blue",
muted: "bg-secondary-lt",
};
/** The order the filter lists them in: what needs a look first. */
export const STATUS_ORDER: LogStatus[] = ["failed", "partly", "none", "held", "muted", "sent"];
const CHANNEL_NAME: Record<string, string> = {
gotify: "Gotify",
ntfy: "ntfy",
telegram: "Telegram",
pushover: "Pushover",
smtp: "Email",
webhook: "Webhook",
webPush: "Push",
email: "Email (escalation)",
};
export const channelName = (channel: string): string => CHANNEL_NAME[channel] ?? channel;
/** Whether a stored status is one this page knows (an unknown one is shown as it is, never hidden). */
export const isLogStatus = (s: string): s is LogStatus => s in STATUS_LABEL;