Notification routing rules, per-browser push wishes, escalation of unacknowledged alerts
- Routing: rules pick channels by kind, severity and server tags (first match wins, none = nobody); mixed batches split per route; recoveries follow their alert; quiet-hours digest keeps each notification's audience - Push: each subscribed browser can ask for a minimum severity and some kinds - Escalation: up to three timed steps re-notify alerts nobody has acknowledged, through chosen channels and an optional extra email; an acknowledgement stops them - Fix ntfy: titles with an em dash made every ntfy send fail (header not Latin-1); now RFC 2047 encoded Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9caa414829
commit
43fc5e0272
21 files changed
+4769
-55
No files matched your search
@@ -409,6 +409,32 @@ export interface WebhookSettings {
|
||||
secret: string;
|
||||
}
|
||||
|
||||
export type NotifyChannelId = "gotify" | "ntfy" | "smtp" | "webhook" | "webPush";
|
||||
|
||||
export interface RoutingRule {
|
||||
id: string;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
categories: AlertCategory[];
|
||||
minSeverity: "warning" | "critical" | null;
|
||||
tags: string[];
|
||||
channels: NotifyChannelId[];
|
||||
}
|
||||
export interface RoutingSettings {
|
||||
rules: RoutingRule[];
|
||||
}
|
||||
export interface EscalationStep {
|
||||
afterMinutes: number;
|
||||
minSeverity: "warning" | "critical";
|
||||
channels: NotifyChannelId[];
|
||||
extraEmail: string;
|
||||
evenInQuietHours: boolean;
|
||||
}
|
||||
export interface EscalationSettings {
|
||||
enabled: boolean;
|
||||
steps: EscalationStep[];
|
||||
}
|
||||
|
||||
export interface WebPushSettings {
|
||||
enabled: boolean;
|
||||
/** An email address or https address a push service can reach whoever runs this on. Blank is fine. */
|
||||
@@ -423,6 +449,10 @@ export interface PushDevice {
|
||||
endpoint: string;
|
||||
createdAt: string;
|
||||
lastSuccessAt: string | null;
|
||||
/** This browser only wants alerts at least this bad; null = every severity. */
|
||||
minSeverity: "warning" | "critical" | null;
|
||||
/** Only these kinds of alert; null = every kind. */
|
||||
categories: AlertCategory[] | null;
|
||||
}
|
||||
|
||||
export interface NotificationEvents {
|
||||
@@ -490,6 +520,8 @@ export interface AppSettings {
|
||||
smtp: SmtpSettings;
|
||||
webhook: WebhookSettings;
|
||||
webPush: WebPushSettings;
|
||||
routing: RoutingSettings;
|
||||
escalation: EscalationSettings;
|
||||
notifications: NotificationEvents;
|
||||
providerColors: Record<string, string>;
|
||||
integrationColors: Record<string, string>;
|
||||
@@ -1718,6 +1750,8 @@ export const api = {
|
||||
mine: () => request<{ enabled: boolean; subscriptions: PushDevice[] }>("/api/push/mine"),
|
||||
subscribe: (data: { endpoint: string; keys: { p256dh: string; auth: string }; label?: string }) => request<{ id: number }>("/api/push/subscribe", { method: "POST", body: JSON.stringify(data) }),
|
||||
remove: (id: number) => request<void>(`/api/push/${id}`, { method: "DELETE" }),
|
||||
setPrefs: (id: number, data: { minSeverity: "warning" | "critical" | null; categories: AlertCategory[] | null }) =>
|
||||
request<{ minSeverity: string | null; categories: AlertCategory[] | null }>(`/api/push/${id}`, { method: "PATCH", body: JSON.stringify(data) }),
|
||||
test: () => request<{ sent: number; removed: number; failed: number }>("/api/push/test", { method: "POST" }),
|
||||
},
|
||||
dependencies: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { api, type PushDevice } from "../api/client";
|
||||
import { api, type AlertCategory, type PushDevice } from "../api/client";
|
||||
import { CATEGORY_LABELS } from "./RoutingEditor";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { toast } from "../utils/toast";
|
||||
@@ -15,6 +16,62 @@ function keyBytes(base64url: string): Uint8Array<ArrayBuffer> {
|
||||
return out;
|
||||
}
|
||||
|
||||
const KINDS = Object.keys(CATEGORY_LABELS) as AlertCategory[];
|
||||
|
||||
/** What one browser wants to be told: how bad, and which kinds. Saved when asked. */
|
||||
function Wishes({ device, onSaved, onError }: { device: PushDevice; onSaved: () => void; onError: (message: string) => void }) {
|
||||
const [severity, setSeverity] = useState<"" | "warning" | "critical">(device.minSeverity ?? "");
|
||||
const [kinds, setKinds] = useState<AlertCategory[]>(device.categories ?? []);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const dirty = severity !== (device.minSeverity ?? "") || JSON.stringify([...kinds].sort()) !== JSON.stringify([...(device.categories ?? [])].sort());
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.push.setPrefs(device.id, { minSeverity: severity === "" ? null : severity, categories: kinds.length > 0 && kinds.length < KINDS.length ? kinds : null });
|
||||
toast.success("Saved.");
|
||||
onSaved();
|
||||
} catch (err) {
|
||||
onError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="ms-3 mb-2 small">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
<label htmlFor={`push-sev-${device.id}`} className="text-secondary">
|
||||
Only alerts that are
|
||||
</label>
|
||||
<select id={`push-sev-${device.id}`} className="form-select form-select-sm w-auto" value={severity} onChange={(e) => setSeverity(e.target.value as "" | "warning" | "critical")}>
|
||||
<option value="">of any severity</option>
|
||||
<option value="warning">warnings or worse</option>
|
||||
<option value="critical">critical</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="d-flex flex-wrap gap-3 mb-1">
|
||||
{KINDS.map((k) => (
|
||||
<label key={k} className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={kinds.length === 0 || kinds.includes(k)} onChange={(e) => setKinds((prev) => {
|
||||
const base = prev.length === 0 ? KINDS : prev;
|
||||
const next = e.target.checked ? [...base.filter((x) => x !== k), k] : base.filter((x) => x !== k);
|
||||
// At least one kind stays ticked: a browser that wants nothing is better removed.
|
||||
return next.length === 0 ? prev : next;
|
||||
})} />
|
||||
<span className="form-check-label">{CATEGORY_LABELS[k]}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
{dirty && (
|
||||
<button type="button" className="btn btn-sm btn-primary" onClick={() => void save()} disabled={busy}>
|
||||
Save what this browser gets
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** A short name for this browser, to tell the devices apart in the list. */
|
||||
function browserLabel(): string {
|
||||
const ua = navigator.userAgent;
|
||||
@@ -142,13 +199,17 @@ export default function PushDevices({ serverEnabled }: { serverEnabled: boolean
|
||||
{devices && devices.length > 0 && (
|
||||
<ul className="list-unstyled mb-0">
|
||||
{devices.map((d) => (
|
||||
<li key={d.id} className="d-flex align-items-center gap-2 py-1">
|
||||
<li key={d.id} className="d-flex flex-wrap align-items-center gap-2 py-2 border-bottom">
|
||||
<span>{d.label || d.host}</span>
|
||||
{d.endpoint === thisEndpoint && <span className="badge bg-blue-lt text-blue">this browser</span>}
|
||||
<span className="text-secondary small">via {d.host}</span>
|
||||
<button type="button" className="btn btn-sm btn-outline-danger ms-auto" onClick={() => void remove(d)}>
|
||||
Remove
|
||||
</button>
|
||||
<div className="w-100 text-secondary small">
|
||||
{d.minSeverity || d.categories ? `Gets ${d.minSeverity === "critical" ? "critical alerts" : d.minSeverity === "warning" ? "warnings and worse" : "alerts of any severity"}${d.categories ? (d.categories.length > KINDS.length / 2 ? ` about everything except ${KINDS.filter((k) => !d.categories!.includes(k)).map((c) => CATEGORY_LABELS[c].toLowerCase()).join(", ")}` : ` about ${d.categories.map((c) => CATEGORY_LABELS[c].toLowerCase()).join(", ")}`) : ""}.` : "Gets every alert."}
|
||||
</div>
|
||||
<Wishes device={d} onSaved={() => void load()} onError={setError} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
import { useState } from "react";
|
||||
import type { AlertCategory, EscalationSettings, EscalationStep, NotifyChannelId, RoutingRule, RoutingSettings } from "../api/client";
|
||||
|
||||
export const CHANNEL_LABELS: Record<NotifyChannelId, string> = { gotify: "Gotify", ntfy: "ntfy", smtp: "Email", webhook: "Webhook", webPush: "Phone and browser" };
|
||||
const CHANNELS = Object.keys(CHANNEL_LABELS) as NotifyChannelId[];
|
||||
|
||||
export const CATEGORY_LABELS: Record<AlertCategory, string> = {
|
||||
offline: "Server down",
|
||||
disk: "Disk & storage",
|
||||
services: "Failing services",
|
||||
backup: "Backups",
|
||||
updates: "Updates",
|
||||
expiry: "Expiry",
|
||||
automation: "Automation",
|
||||
integration: "Integration failing",
|
||||
monitoring: "Monitoring",
|
||||
tickets: "Tickets",
|
||||
};
|
||||
const CATEGORIES = Object.keys(CATEGORY_LABELS) as AlertCategory[];
|
||||
|
||||
const newId = () => Math.random().toString(36).slice(2, 10);
|
||||
|
||||
/** Tags typed as "prod, db servers": kept as typed while editing, split when it leaves the box. */
|
||||
function TagsInput({ value, onChange, id }: { value: string[]; onChange: (tags: string[]) => void; id: string }) {
|
||||
const [text, setText] = useState(value.join(", "));
|
||||
return (
|
||||
<input
|
||||
id={id}
|
||||
className="form-control"
|
||||
placeholder="any server"
|
||||
value={text}
|
||||
onChange={(e) => {
|
||||
setText(e.target.value);
|
||||
onChange(e.target.value.split(",").map((t) => t.trim()).filter(Boolean));
|
||||
}}
|
||||
onBlur={() => setText(value.join(", "))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ChannelChecks({ value, onChange, enabled, idPrefix }: { value: NotifyChannelId[]; onChange: (v: NotifyChannelId[]) => void; enabled: Record<NotifyChannelId, boolean>; idPrefix: string }) {
|
||||
return (
|
||||
<div className="d-flex flex-wrap gap-3">
|
||||
{CHANNELS.map((c) => (
|
||||
<label key={c} className="form-check mb-0">
|
||||
<input
|
||||
id={`${idPrefix}-${c}`}
|
||||
type="checkbox"
|
||||
className="form-check-input"
|
||||
checked={value.includes(c)}
|
||||
onChange={(e) => onChange(e.target.checked ? [...value, c] : value.filter((x) => x !== c))}
|
||||
/>
|
||||
<span className="form-check-label">
|
||||
{CHANNEL_LABELS[c]}
|
||||
{!enabled[c] && <span className="text-secondary small"> (not switched on)</span>}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Who hears what. Routing rules decide which channels get a notification (the first rule that matches wins; no rule matching means every channel
|
||||
* that is on), and escalation tells people again about alerts nobody has acknowledged.
|
||||
*/
|
||||
export default function RoutingEditor({
|
||||
routing,
|
||||
onRouting,
|
||||
escalation,
|
||||
onEscalation,
|
||||
channelsOn,
|
||||
}: {
|
||||
routing: RoutingSettings;
|
||||
onRouting: (r: RoutingSettings) => void;
|
||||
escalation: EscalationSettings;
|
||||
onEscalation: (e: EscalationSettings) => void;
|
||||
channelsOn: Record<NotifyChannelId, boolean>;
|
||||
}) {
|
||||
const setRule = (i: number, patch: Partial<RoutingRule>) => onRouting({ rules: routing.rules.map((r, j) => (j === i ? { ...r, ...patch } : r)) });
|
||||
const move = (i: number, by: -1 | 1) => {
|
||||
const to = i + by;
|
||||
if (to < 0 || to >= routing.rules.length) return;
|
||||
const rules = [...routing.rules];
|
||||
[rules[i], rules[to]] = [rules[to], rules[i]];
|
||||
onRouting({ rules });
|
||||
};
|
||||
const setStep = (i: number, patch: Partial<EscalationStep>) => onEscalation({ ...escalation, steps: escalation.steps.map((s, j) => (j === i ? { ...s, ...patch } : s)) });
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Routing rules</h3>
|
||||
<div className="card-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-primary"
|
||||
disabled={routing.rules.length >= 30}
|
||||
onClick={() => onRouting({ rules: [...routing.rules, { id: newId(), name: `Rule ${routing.rules.length + 1}`, enabled: true, categories: [], minSeverity: null, tags: [], channels: [] }] })}
|
||||
>
|
||||
Add a rule
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
By default every notification goes to every channel that is switched on. A rule narrows that for what it matches: <strong>the first rule that matches decides</strong> which channels get it, so put the specific rules first. A
|
||||
rule with no channels tells nobody — the Alerts page still shows the problem. Only problems and recoveries about servers, services and the like carry a kind and a severity; a rule that asks about
|
||||
something a notification doesn’t say doesn’t match it.
|
||||
</p>
|
||||
{routing.rules.length === 0 && <div className="text-secondary">No rules: everything goes everywhere.</div>}
|
||||
{routing.rules.map((r, i) => (
|
||||
<div key={r.id} className="border rounded p-3 mb-3">
|
||||
<div className="d-flex align-items-center gap-2 mb-3">
|
||||
<label className="form-check form-switch mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={r.enabled} onChange={(e) => setRule(i, { enabled: e.target.checked })} />
|
||||
<span className="visually-hidden">Rule {r.name} is on</span>
|
||||
</label>
|
||||
<input className="form-control" style={{ maxWidth: "20rem" }} aria-label="Name of the rule" maxLength={60} value={r.name} onChange={(e) => setRule(i, { name: e.target.value })} />
|
||||
<span className="text-secondary small">#{i + 1}</span>
|
||||
<div className="btn-list ms-auto flex-nowrap">
|
||||
<button type="button" className="btn btn-sm" aria-label={`Move ${r.name} up`} disabled={i === 0} onClick={() => move(i, -1)}>
|
||||
↑
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm" aria-label={`Move ${r.name} down`} disabled={i === routing.rules.length - 1} onClick={() => move(i, 1)}>
|
||||
↓
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-outline-danger" onClick={() => onRouting({ rules: routing.rules.filter((_, j) => j !== i) })}>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row g-3">
|
||||
<div className="col-12">
|
||||
<div className="form-label">When it is about (none ticked: anything)</div>
|
||||
<div className="d-flex flex-wrap gap-3">
|
||||
{CATEGORIES.map((c) => (
|
||||
<label key={c} className="form-check mb-0">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input"
|
||||
checked={r.categories.includes(c)}
|
||||
onChange={(e) => setRule(i, { categories: e.target.checked ? [...r.categories, c] : r.categories.filter((x) => x !== c) })}
|
||||
/>
|
||||
<span className="form-check-label">{CATEGORY_LABELS[c]}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`rule-sev-${r.id}`}>
|
||||
At least this bad
|
||||
</label>
|
||||
<select id={`rule-sev-${r.id}`} className="form-select" value={r.minSeverity ?? ""} onChange={(e) => setRule(i, { minSeverity: e.target.value === "" ? null : (e.target.value as "warning" | "critical") })}>
|
||||
<option value="">Any severity</option>
|
||||
<option value="warning">Warning or worse</option>
|
||||
<option value="critical">Critical only</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-8">
|
||||
<label className="form-label" htmlFor={`rule-tags-${r.id}`}>
|
||||
On a server with one of these tags
|
||||
</label>
|
||||
<TagsInput id={`rule-tags-${r.id}`} value={r.tags} onChange={(tags) => setRule(i, { tags })} />
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className="form-label">Tell</div>
|
||||
<ChannelChecks value={r.channels} onChange={(channels) => setRule(i, { channels })} enabled={channelsOn} idPrefix={`rule-${r.id}`} />
|
||||
{r.channels.length === 0 && <div className="text-warning small mt-1">No channel ticked: nobody is told. The Alerts page still shows it.</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{routing.rules.length > 0 && <div className="text-secondary small">Anything no rule matches goes to every channel that is on. A phone or browser can also turn down what it doesn’t want, under Phone and browser.</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Escalation</h3>
|
||||
<div className="card-actions">
|
||||
<label className="form-check form-switch mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={escalation.enabled} onChange={(e) => onEscalation({ ...escalation, enabled: e.target.checked })} />
|
||||
<span className="form-check-label">On</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
When an alert has been raised for a while and nobody has acknowledged it, tell again — through a louder channel, and perhaps someone else. Each step is sent once per alert, in order, and an acknowledgement stops the
|
||||
rest. Problems under maintenance, or held back because something they depend on is down, never escalate.
|
||||
</p>
|
||||
{escalation.steps.length === 0 && <div className="text-secondary mb-2">No steps yet.</div>}
|
||||
{escalation.steps.map((s, i) => (
|
||||
<div key={i} className="border rounded p-3 mb-3">
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<strong>Step {i + 1}</strong>
|
||||
<button type="button" className="btn btn-sm btn-outline-danger ms-auto" onClick={() => onEscalation({ ...escalation, steps: escalation.steps.filter((_, j) => j !== i) })}>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
<div className="row g-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`esc-after-${i}`}>
|
||||
After it has been up for
|
||||
</label>
|
||||
<div className="input-group">
|
||||
<input id={`esc-after-${i}`} type="number" min={5} max={10080} className="form-control" value={s.afterMinutes} onChange={(e) => setStep(i, { afterMinutes: Number(e.target.value) })} />
|
||||
<span className="input-group-text">min</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`esc-sev-${i}`}>
|
||||
For alerts that are
|
||||
</label>
|
||||
<select id={`esc-sev-${i}`} className="form-select" value={s.minSeverity} onChange={(e) => setStep(i, { minSeverity: e.target.value as "warning" | "critical" })}>
|
||||
<option value="warning">Warning or worse</option>
|
||||
<option value="critical">Critical only</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`esc-mail-${i}`}>
|
||||
Also email (someone else)
|
||||
</label>
|
||||
<input id={`esc-mail-${i}`} type="email" className="form-control" placeholder="neighbour@example.com" value={s.extraEmail} onChange={(e) => setStep(i, { extraEmail: e.target.value })} />
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className="form-label">Tell</div>
|
||||
<ChannelChecks value={s.channels} onChange={(channels) => setStep(i, { channels })} enabled={channelsOn} idPrefix={`esc-${i}`} />
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={s.evenInQuietHours} onChange={(e) => setStep(i, { evenInQuietHours: e.target.checked })} />
|
||||
<span className="form-check-label">Send even during quiet hours</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-outline-primary"
|
||||
disabled={escalation.steps.length >= 3}
|
||||
onClick={() => {
|
||||
const last = escalation.steps[escalation.steps.length - 1];
|
||||
onEscalation({
|
||||
...escalation,
|
||||
steps: [...escalation.steps, { afterMinutes: last ? last.afterMinutes + 60 : 30, minSeverity: "critical", channels: [], extraEmail: "", evenInQuietHours: false }],
|
||||
});
|
||||
}}
|
||||
>
|
||||
Add a step
|
||||
</button>
|
||||
<div className="text-secondary small mt-2">Looked at every five minutes, so a step can come up to five minutes after its time.</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
type SmtpSettings,
|
||||
type WebhookSettings,
|
||||
type WebPushSettings,
|
||||
type RoutingSettings,
|
||||
type EscalationSettings,
|
||||
type NotificationEvents,
|
||||
type DigestSettings,
|
||||
type QuietHoursSettings,
|
||||
@@ -17,6 +19,7 @@ import { readableError } from "../../utils/errors";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import { PageSkeleton } from "../../components/Skeleton";
|
||||
import PushDevices from "../../components/PushDevices";
|
||||
import RoutingEditor from "../../components/RoutingEditor";
|
||||
|
||||
const TIMEZONES = [
|
||||
"UTC",
|
||||
@@ -46,6 +49,8 @@ const DEFAULT_NTFY: NtfySettings = { enabled: false, url: "https://ntfy.sh", top
|
||||
const DEFAULT_SMTP: SmtpSettings = { enabled: false, host: "", port: 587, secure: false, username: "", password: "", from: "", to: "" };
|
||||
const DEFAULT_WEBHOOK: WebhookSettings = { enabled: false, url: "", secret: "" };
|
||||
const DEFAULT_WEBPUSH: WebPushSettings = { enabled: false, contact: "" };
|
||||
const DEFAULT_ROUTING: RoutingSettings = { rules: [] };
|
||||
const DEFAULT_ESCALATION: EscalationSettings = { enabled: false, steps: [] };
|
||||
const DEFAULT_NOTIFICATIONS: NotificationEvents = {
|
||||
dnsAdd: true,
|
||||
dnsUpdate: true,
|
||||
@@ -84,6 +89,7 @@ type EventKey = { [K in keyof NotificationEvents]: NotificationEvents[K] extends
|
||||
const TABS = [
|
||||
{ id: "channels", label: "Channels" },
|
||||
{ id: "events", label: "What to send" },
|
||||
{ id: "routing", label: "Who hears what" },
|
||||
{ id: "when", label: "When" },
|
||||
] as const;
|
||||
type TabId = (typeof TABS)[number]["id"];
|
||||
@@ -225,6 +231,8 @@ export default function NotificationSettings() {
|
||||
const [webPush, setWebPush] = useState<WebPushSettings>(DEFAULT_WEBPUSH);
|
||||
// Whether push is on as saved: people can only add their browsers once the server knows it is on.
|
||||
const [webPushSaved, setWebPushSaved] = useState(false);
|
||||
const [routing, setRouting] = useState<RoutingSettings>(DEFAULT_ROUTING);
|
||||
const [escalation, setEscalation] = useState<EscalationSettings>(DEFAULT_ESCALATION);
|
||||
const [notifications, setNotifications] = useState<NotificationEvents>(DEFAULT_NOTIFICATIONS);
|
||||
const [quietHours, setQuietHours] = useState<QuietHoursSettings>(DEFAULT_QUIET_HOURS);
|
||||
const [healthChecks, setHealthChecks] = useState<HealthCheckSettings>(DEFAULT_HEALTH_CHECKS);
|
||||
@@ -245,7 +253,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, notifications, quietHours, healthChecks, digest });
|
||||
const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest });
|
||||
const dirty = baseline !== null && snapshot !== baseline;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -260,12 +268,16 @@ export default function NotificationSettings() {
|
||||
const wp = s.webPush ?? DEFAULT_WEBPUSH;
|
||||
setWebPush(wp);
|
||||
setWebPushSaved(wp.enabled);
|
||||
const rt = s.routing ?? DEFAULT_ROUTING;
|
||||
const es = s.escalation ?? DEFAULT_ESCALATION;
|
||||
setRouting(rt);
|
||||
setEscalation(es);
|
||||
setNotifications(s.notifications);
|
||||
setQuietHours(s.quietHours);
|
||||
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, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: 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 }));
|
||||
})
|
||||
.catch((err) => setLoadError(err instanceof Error ? err.message : String(err)))
|
||||
.finally(() => setLoading(false));
|
||||
@@ -312,7 +324,7 @@ export default function NotificationSettings() {
|
||||
setSaveError(null);
|
||||
setSaved(false);
|
||||
try {
|
||||
await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, notifications, quietHours, healthChecks, digest });
|
||||
await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest });
|
||||
setBaseline(snapshot);
|
||||
setWebPushSaved(webPush.enabled);
|
||||
setSaved(true);
|
||||
@@ -777,6 +789,17 @@ export default function NotificationSettings() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Who hears what ── */}
|
||||
<div role="tabpanel" id="panel-routing" aria-labelledby="tab-routing" hidden={tab !== "routing"} className="pt-3">
|
||||
<RoutingEditor
|
||||
routing={routing}
|
||||
onRouting={setRouting}
|
||||
escalation={escalation}
|
||||
onEscalation={setEscalation}
|
||||
channelsOn={{ gotify: gotify.enabled && gotifyComplete, ntfy: ntfy.enabled && ntfyComplete, smtp: smtp.enabled && smtpComplete, webhook: webhook.enabled && webhookComplete, webPush: webPush.enabled }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* ── When ── */}
|
||||
<div role="tabpanel" id="panel-when" aria-labelledby="tab-when" hidden={tab !== "when"} className="pt-3">
|
||||
<p className="text-secondary">When notifications are sent: the time zone everything here runs in, the daily reminders, hours to keep quiet, and the weekly digest.</p>
|
||||
|
||||
Reference in new issue
Block a user