Away mode, and critical alerts through quiet hours
For a one-person homelab, "on call" is when you can be reached. Settings -> Notifications -> When -> Away holds notifications while you are away (a banner on every page says so) and sends one digest when it ends, at its time or when you say you are back. Critical alerts can still come through. Quiet hours get the same "still send critical alerts" option. Escalation steps marked to send in quiet hours are sent while away too. What is held for one reason is not released while the other still holds it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3b31b16796
commit
16b24f5436
21 files changed
+737
-50
No files matched your search
@@ -556,6 +556,15 @@ export interface QuietHoursSettings {
|
||||
enabled: boolean;
|
||||
start: string;
|
||||
end: string;
|
||||
/** A critical alert is sent at once even inside the window. */
|
||||
criticalThrough: boolean;
|
||||
}
|
||||
|
||||
/** Whether somebody is away (notifications held until they are back), and how many are being held. */
|
||||
export interface AwayView {
|
||||
away: { from: string | null; until: string | null; criticalThrough: boolean; note: string; state: "none" | "planned" | "active" };
|
||||
held: number;
|
||||
timezone: string;
|
||||
}
|
||||
|
||||
/** The weekly digest: one message a week through the notification channels. */
|
||||
@@ -2557,6 +2566,11 @@ export const api = {
|
||||
create: (label: string) => request<{ token: MetricsToken; secret: string }>("/api/metrics-tokens", { method: "POST", body: JSON.stringify({ label }) }),
|
||||
remove: (id: number) => request<void>(`/api/metrics-tokens/${id}`, { method: "DELETE" }),
|
||||
},
|
||||
away: {
|
||||
get: () => request<AwayView>("/api/away"),
|
||||
start: (data: { until: string; from?: string | null; criticalThrough: boolean; note?: string }) => request<AwayView>("/api/away", { method: "PUT", body: JSON.stringify(data) }),
|
||||
end: () => request<AwayView & { sent: number }>("/api/away", { method: "DELETE" }),
|
||||
},
|
||||
serviceLevels: {
|
||||
list: () => request<{ levels: ServiceLevel[]; subjects: Record<ServiceLevelSubject, { id: number; name: string }[]> }>("/api/service-levels"),
|
||||
create: (data: ServiceLevelInput) => request<{ id: number }>("/api/service-levels", { method: "POST", body: JSON.stringify(data) }),
|
||||
|
||||
@@ -232,7 +232,7 @@ export default function RoutingEditor({
|
||||
<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>
|
||||
<span className="form-check-label">Send even during quiet hours, and while away</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { Link, NavLink, useLocation } from "react-router-dom";
|
||||
import { IconKey, IconMenu2, IconSun, IconMoon, IconShieldLock, IconTool, IconChevronUp, IconLogout, IconDeviceDesktop, IconChevronsLeft, IconChevronsRight } from "@tabler/icons-react";
|
||||
import { api, type CurrentUser, type MaintenanceWindow } from "../api/client";
|
||||
import { IconPlaneDeparture, IconKey, IconMenu2, IconSun, IconMoon, IconShieldLock, IconTool, IconChevronUp, IconLogout, IconDeviceDesktop, IconChevronsLeft, IconChevronsRight } from "@tabler/icons-react";
|
||||
import { api, type AwayView, type CurrentUser, type MaintenanceWindow } from "../api/client";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { isCurrent, isGroup, visibleNav, type NavGroup } from "./nav";
|
||||
import SidebarNav, { type NavBadge } from "./SidebarNav";
|
||||
import { initFavorites } from "../utils/favorites";
|
||||
@@ -79,6 +80,7 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
return () => window.removeEventListener("toggle-sidebar", toggle);
|
||||
}, []);
|
||||
const [maintenance, setMaintenance] = useState<MaintenanceWindow[]>([]);
|
||||
const [away, setAway] = useState<AwayView | null>(null);
|
||||
const environment = useEnvironment();
|
||||
useStackedTables();
|
||||
useShortcuts(user);
|
||||
@@ -128,6 +130,26 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Everyone sees when notifications are being held because somebody is away, for the same reason.
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const load = () =>
|
||||
api.away
|
||||
.get()
|
||||
.then((res) => {
|
||||
if (!cancelled) setAway(res);
|
||||
})
|
||||
.catch(() => {});
|
||||
load();
|
||||
const poll = setInterval(load, 60_000);
|
||||
window.addEventListener("away-changed", load);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearInterval(poll);
|
||||
window.removeEventListener("away-changed", load);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const nav = visibleNav(user.role);
|
||||
const { pathname } = useLocation();
|
||||
|
||||
@@ -358,6 +380,17 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
<div className="page-wrapper">
|
||||
<main className="page-body" id="main" tabIndex={-1} ref={mainRef}>
|
||||
<div className="container-xl">
|
||||
{away && away.away.state !== "none" && away.away.until && (
|
||||
<div className="alert alert-info d-flex align-items-center gap-2">
|
||||
<IconPlaneDeparture size={18} />
|
||||
<div>
|
||||
{away.away.state === "planned" ? `Away from ${formatDateTime(new Date(away.away.from!))} until ${formatDateTime(new Date(away.away.until))}` : `Away until ${formatDateTime(new Date(away.away.until))}`}
|
||||
{away.away.note ? ` — ${away.away.note}` : ""}.{" "}
|
||||
{away.away.state === "active" ? `Notifications are held${away.away.criticalThrough ? " (critical alerts still come through)" : ""}${away.held > 0 ? ` — ${away.held} so far` : ""}. ` : ""}
|
||||
<Link to="/settings/notifications?tab=when">{user.role === "admin" ? "Manage" : "Details"}</Link>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{maintenance.length > 0 && (
|
||||
<div className="alert alert-warning d-flex align-items-center gap-2">
|
||||
<IconTool size={18} />
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type AwayView } from "../../api/client";
|
||||
import TimeAgo from "../../components/TimeAgo";
|
||||
import { confirmDialog } from "../../utils/dialogs";
|
||||
import { formatDateTime } from "../../utils/date";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
|
||||
/** "2026-10-25T18:00" for a datetime-local input, from a moment. */
|
||||
function wall(ms: number): string {
|
||||
const d = new Date(ms);
|
||||
const p = (n: number) => String(n).padStart(2, "0");
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(d.getHours())}:${p(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
/** Tomorrow, next Sunday, in a week — at 18:00, which is about when most people are home again. */
|
||||
function presets(): { label: string; value: string }[] {
|
||||
const at18 = (offsetDays: number) => {
|
||||
const d = new Date();
|
||||
d.setDate(d.getDate() + offsetDays);
|
||||
d.setHours(18, 0, 0, 0);
|
||||
return wall(d.getTime());
|
||||
};
|
||||
const untilSunday = (7 - new Date().getDay()) % 7 || 7;
|
||||
return [
|
||||
{ label: "Until tomorrow evening", value: at18(1) },
|
||||
{ label: "Until Sunday evening", value: at18(untilSunday) },
|
||||
{ label: "A week", value: at18(7) },
|
||||
{ label: "Two weeks", value: at18(14) },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* "I'm away until Sunday." Notifications are held while it lasts and sent as one digest when it ends (at its time, or when you say you are back); critical alerts can still come
|
||||
* through. Everyone sees that somebody is away; an administrator sets it. The times are the clock of the screen it is set on.
|
||||
*/
|
||||
export default function AwayCard({ canEdit }: { canEdit: boolean }) {
|
||||
const [view, setView] = useState<AwayView | null>(null);
|
||||
const [until, setUntil] = useState("");
|
||||
const [from, setFrom] = useState("");
|
||||
const [critical, setCritical] = useState(true);
|
||||
const [note, setNote] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
function load() {
|
||||
api.away
|
||||
.get()
|
||||
.then((v) => {
|
||||
setView(v);
|
||||
setCritical(v.away.criticalThrough);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
useEffect(load, []);
|
||||
|
||||
async function start(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
// What is typed is the clock on this screen, so it is sent as the exact moment it means.
|
||||
const v = await api.away.start({ until: new Date(until).toISOString(), from: from ? new Date(from).toISOString() : null, criticalThrough: critical, note });
|
||||
setView(v);
|
||||
toast.success(v.away.state === "planned" ? "Away mode planned." : "Away mode is on — notifications are held.");
|
||||
window.dispatchEvent(new Event("away-changed"));
|
||||
setUntil("");
|
||||
setFrom("");
|
||||
setNote("");
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function end() {
|
||||
const planned = view?.away.state === "planned";
|
||||
if (!planned && view && view.held > 0 && !(await confirmDialog({ title: "Back already?", message: `${view.held} notification${view.held === 1 ? " was" : "s were"} held. They are sent now as one digest.`, confirmLabel: "I'm back" }))) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const v = await api.away.end();
|
||||
setView(v);
|
||||
toast.success(planned ? "Cancelled." : v.sent ? `Welcome back — ${v.sent} held notification${v.sent === 1 ? "" : "s"} sent.` : "Welcome back.");
|
||||
window.dispatchEvent(new Event("away-changed"));
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const a = view?.away;
|
||||
const on = a && a.state !== "none";
|
||||
|
||||
return (
|
||||
<div className="card h-100">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Away</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
Going away? Say until when. Notifications are held while you are gone and sent as one digest when it ends, so a week of warnings is one message to read rather than a buzzing phone. Critical alerts can still come
|
||||
through. Quiet hours below are for every night; this is for a stretch.
|
||||
</p>
|
||||
{error && <div className="alert alert-danger py-2">{error}</div>}
|
||||
{on && a ? (
|
||||
<div className="border rounded p-3 mb-2">
|
||||
<div className="fw-bold">{a.state === "planned" ? "Planned" : "Away"} until {formatDateTime(new Date(a.until!))}</div>
|
||||
<div className="text-secondary small">
|
||||
{a.state === "planned" && a.from ? (
|
||||
<>
|
||||
Starts {formatDateTime(new Date(a.from))} (<TimeAgo value={a.from} />).{" "}
|
||||
</>
|
||||
) : null}
|
||||
{a.criticalThrough ? "Critical alerts are still sent." : "Everything is held, critical alerts too."}
|
||||
{a.note ? ` “${a.note}”` : ""} {a.state === "active" ? `${view!.held} held so far.` : ""}
|
||||
</div>
|
||||
{canEdit && (
|
||||
<button className="btn btn-sm btn-primary mt-2" onClick={() => void end()} disabled={busy}>
|
||||
{a.state === "planned" ? "Cancel it" : "I'm back"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
{canEdit && (
|
||||
<form onSubmit={start}>
|
||||
<div className="d-flex flex-wrap gap-2 mb-2">
|
||||
{presets().map((p) => (
|
||||
<button key={p.label} type="button" className={`btn btn-sm ${until === p.value ? "btn-primary" : "btn-outline-secondary"}`} onClick={() => setUntil(p.value)}>
|
||||
{p.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="row g-2 mb-2">
|
||||
<div className="col-sm-6">
|
||||
<label className="form-label" htmlFor="away-until">
|
||||
{on ? "Change to: back at" : "Back at"}
|
||||
</label>
|
||||
<input id="away-until" type="datetime-local" className="form-control" required value={until} onChange={(e) => setUntil(e.target.value)} />
|
||||
</div>
|
||||
<div className="col-sm-6">
|
||||
<label className="form-label" htmlFor="away-from">
|
||||
Starting (blank = now)
|
||||
</label>
|
||||
<input id="away-from" type="datetime-local" className="form-control" value={from} onChange={(e) => setFrom(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
<input className="form-control mb-2" maxLength={200} placeholder="A note to yourself, e.g. Holiday in Spain (optional)" aria-label="Note" value={note} onChange={(e) => setNote(e.target.value)} />
|
||||
<label className="form-check mb-3">
|
||||
<input type="checkbox" className="form-check-input" checked={critical} onChange={(e) => setCritical(e.target.checked)} />
|
||||
<span className="form-check-label">Still send critical alerts (a server down, a disk full, mains power lost)</span>
|
||||
</label>
|
||||
<button className="btn btn-primary" disabled={busy || until === ""}>
|
||||
{busy ? "Saving…" : on ? "Change it" : "Start away mode"}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
{!canEdit && !on && <div className="text-secondary">Nobody is away. An administrator can set it.</div>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import AwayCard from "./AwayCard";
|
||||
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import AlertActionsCard from "./AlertActionsCard";
|
||||
@@ -71,7 +72,7 @@ const DEFAULT_NOTIFICATIONS: NotificationEvents = {
|
||||
integrationFailureAlerts: true,
|
||||
integrationFailureThreshold: 3,
|
||||
};
|
||||
const DEFAULT_QUIET_HOURS: QuietHoursSettings = { enabled: false, start: "22:00", end: "07:00" };
|
||||
const DEFAULT_QUIET_HOURS: QuietHoursSettings = { enabled: false, start: "22:00", end: "07:00", criticalThrough: false };
|
||||
const DEFAULT_DIGEST: DigestSettings = { enabled: false, day: 1, time: "08:00" };
|
||||
// Monday first, as a week reads; the numbers are what the server keeps (0 = Sunday).
|
||||
const DIGEST_DAYS: { value: number; label: string }[] = [
|
||||
@@ -280,7 +281,7 @@ export default function NotificationSettings() {
|
||||
setRouting(rt);
|
||||
setEscalation(es);
|
||||
setNotifications(s.notifications);
|
||||
setQuietHours(s.quietHours);
|
||||
setQuietHours({ ...DEFAULT_QUIET_HOURS, ...s.quietHours });
|
||||
setHealthChecks(s.healthChecks);
|
||||
const d = s.digest ?? DEFAULT_DIGEST;
|
||||
setDigest(d);
|
||||
@@ -963,6 +964,13 @@ export default function NotificationSettings() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-hint mb-3">A start time later than the end time (e.g. 22:00 → 07:00) is treated as spanning midnight.</div>
|
||||
<label className="form-check mb-3">
|
||||
<input type="checkbox" className="form-check-input" checked={quietHours.criticalThrough} disabled={!quietHours.enabled} onChange={(e) => setQuietHours((q) => ({ ...q, criticalThrough: e.target.checked }))} />
|
||||
<span className="form-check-label">
|
||||
Still send critical alerts
|
||||
<span className="form-hint d-block">A server down or a disk full at 03:00 is sent at once; everything else waits for the digest. Off, nothing gets through until the window ends.</span>
|
||||
</span>
|
||||
</label>
|
||||
{queuedCount !== null && queuedCount > 0 && (
|
||||
<div className="alert alert-info d-flex align-items-center justify-content-between mb-0">
|
||||
<span>
|
||||
@@ -978,6 +986,10 @@ export default function NotificationSettings() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-md-6">
|
||||
<AwayCard canEdit />
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
|
||||
@@ -20,6 +20,8 @@ export const SETTINGS_INDEX: SettingsEntry[] = [
|
||||
{ title: "Server offline after (minutes)", where: "Notifications › What to send › Servers and disks", to: `${N}?tab=events`, words: "offline stopped reporting silent agent threshold limit minutes" },
|
||||
{ title: "Disk usage alert at (percent)", where: "Notifications › What to send › Servers and disks", to: `${N}?tab=events`, words: "disk full storage percent threshold space" },
|
||||
{ title: "Warn when a disk will fill within (days)", where: "Notifications › What to send › Servers and disks", to: `${N}?tab=events`, words: "disk forecast fill growth trend days" },
|
||||
{ title: "Away mode: hold notifications while I'm away", where: "Notifications › When", to: `${N}?tab=when`, words: "away holiday vacation travel back hold digest pause mute do not disturb critical" },
|
||||
{ title: "Let critical alerts through quiet hours", where: "Notifications › When", to: `${N}?tab=when`, words: "quiet hours critical night wake sleep through urgent" },
|
||||
{ title: "Quarterly and annual reports", where: "Notifications › When", to: `${N}?tab=when`, words: "report quarterly annual yearly quarter year send message monthly" },
|
||||
{ title: "Warn when CPU or memory is unusually high for the time", where: "Notifications › What to send › Servers and disks", to: `${N}?tab=events`, words: "baseline usual normal unusual unusually busy high cpu memory load weekday hour history anomaly" },
|
||||
{ title: "Warn when a server starts listening on a new port", where: "Notifications › What to send › Servers and disks", to: `${N}?tab=events`, words: "new port baseline listening tcp monitoring" },
|
||||
|
||||
Reference in new issue
Block a user