Add the Alert tickets settings page, and show each alert's ticket on the Alerts page

Settings -> Alert tickets: switch it on, choose the osTicket integration (only ones with a ticket API
set up can be chosen), who the tickets come from, help topic and priority, which severities and kinds,
how long a problem must last, when many become one summary ticket, how long a return counts as the
same problem, and what to do about problems already there. Buttons to send a test ticket and to check
now, and a line saying what the last check did. Server messages (a missing integration, a refused key)
are shown as they are.

The Alerts page shows "Ticket #123" on an alert that has one, linking to it in osTicket, and a Ticket
column in the CSV export.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-07 23:41:46 +02:00
1 parent 467d1a1a06
commit 96c93ef924
6 files changed
+372 -2

No files matched your search

+2
View File
@@ -39,6 +39,7 @@ import CacheSettings from "./pages/settings/CacheSettings";
import LogSettings from "./pages/settings/LogSettings"; import LogSettings from "./pages/settings/LogSettings";
import BackupSettings from "./pages/settings/BackupSettings"; import BackupSettings from "./pages/settings/BackupSettings";
import NameSettings from "./pages/settings/NameSettings"; import NameSettings from "./pages/settings/NameSettings";
import AlertTicketSettings from "./pages/settings/AlertTicketSettings";
import AppShell from "./layout/AppShell"; import AppShell from "./layout/AppShell";
import DialogHost from "./components/DialogHost"; import DialogHost from "./components/DialogHost";
import { setDateTimeSettings } from "./utils/date"; import { setDateTimeSettings } from "./utils/date";
@@ -163,6 +164,7 @@ export default function App() {
<Route path="display" element={<DisplaySettings />} /> <Route path="display" element={<DisplaySettings />} />
<Route path="tags" element={<TagSettings />} /> <Route path="tags" element={<TagSettings />} />
<Route path="names" element={<NameSettings />} /> <Route path="names" element={<NameSettings />} />
<Route path="alert-tickets" element={<AlertTicketSettings />} />
<Route path="cache" element={<CacheSettings />} /> <Route path="cache" element={<CacheSettings />} />
<Route path="logs" element={<LogSettings />} /> <Route path="logs" element={<LogSettings />} />
<Route path="backup" element={<BackupSettings />} /> <Route path="backup" element={<BackupSettings />} />
+45
View File
@@ -409,6 +409,45 @@ export interface AlertItem {
link: string | null; link: string | null;
/** Under a maintenance window: still a real problem, but its notifications are held back. */ /** Under a maintenance window: still a real problem, but its notifications are held back. */
silenced: boolean; silenced: boolean;
/** The osTicket ticket opened for it, if one was. */
ticket?: { number: string | null; url: string | null; grouped: boolean; openedAt: string | null } | null;
}
export type AlertTicketSeverity = "critical" | "warning" | "info";
export interface AlertTicketSettings {
enabled: boolean;
integrationId: number | null;
severities: AlertTicketSeverity[];
categories: string[];
requesterName: string;
requesterEmail: string;
topicId: number | null;
priorityId: number | null;
notifyStaff: boolean;
existingProblems: "ignore" | "ticket";
confirmChecks: number;
summaryAbove: number;
reopenAfterMinutes: number;
}
export interface AlertTicketRunSummary {
at: string;
skipped?: "disabled" | "busy";
error?: string;
ticketsOpened: number;
alertsCovered: number;
baseline: number;
pending: number;
cleared: number;
failed: number;
}
export interface AlertTicketOverview {
settings: AlertTicketSettings;
integrations: { id: number; name: string; enabled: boolean; ticketApiReady: boolean }[];
categories: { value: string; label: string }[];
status: { lastRun: AlertTicketRunSummary | null; open: number; pending: number; baseline: number; baselinePending: boolean };
} }
export interface AlertsReport { export interface AlertsReport {
@@ -1062,6 +1101,12 @@ export const api = {
alerts: { alerts: {
list: (refresh = false) => request<AlertsReport>(`/api/alerts${refresh ? "?refresh=1" : ""}`), list: (refresh = false) => request<AlertsReport>(`/api/alerts${refresh ? "?refresh=1" : ""}`),
}, },
alertTickets: {
get: () => request<AlertTicketOverview>("/api/alert-tickets"),
update: (patch: Partial<AlertTicketSettings>) => request<AlertTicketOverview>("/api/alert-tickets", { method: "PUT", body: JSON.stringify(patch) }),
test: () => request<{ ok: boolean; ticketNumber: string | null }>("/api/alert-tickets/test", { method: "POST" }),
run: () => request<{ summary: AlertTicketRunSummary; status: AlertTicketOverview["status"] }>("/api/alert-tickets/run", { method: "POST" }),
},
ports: { ports: {
agent: () => request<AgentPortsResponse>("/api/ports/agent"), agent: () => request<AgentPortsResponse>("/api/ports/agent"),
forwards: { forwards: {
+16 -2
View File
@@ -73,8 +73,8 @@ export default function Alerts(_props: { user: CurrentUser }) {
function exportCsv() { function exportCsv() {
downloadCsv( downloadCsv(
"alerts.csv", "alerts.csv",
["Severity", "Category", "Source", "Alert", "Silenced"], ["Severity", "Category", "Source", "Alert", "Silenced", "Ticket"],
(sorted ?? []).map((a) => [SEVERITY[a.severity].label, CATEGORY_LABELS[a.category], a.source, a.message, a.silenced ? "yes" : "no"]), (sorted ?? []).map((a) => [SEVERITY[a.severity].label, CATEGORY_LABELS[a.category], a.source, a.message, a.silenced ? "yes" : "no", a.ticket ? (a.ticket.number ?? "opened") : ""]),
); );
} }
@@ -222,6 +222,20 @@ export default function Alerts(_props: { user: CurrentUser }) {
silenced silenced
</span> </span>
)} )}
{a.ticket &&
(() => {
const label = a.ticket.number ? `Ticket #${a.ticket.number}` : "Ticket opened";
const title = a.ticket.grouped ? "Part of one ticket that covers several problems that appeared together" : "A ticket was opened for this in osTicket";
return a.ticket.url ? (
<a className="badge bg-blue-lt text-blue ms-2" href={a.ticket.url} target="_blank" rel="noopener noreferrer" title={title}>
{label}
</a>
) : (
<span className="badge bg-blue-lt text-blue ms-2" title={title}>
{label}
</span>
);
})()}
</td> </td>
</tr> </tr>
))} ))}
+4
View File
@@ -226,6 +226,10 @@ export default function Privacy() {
{outbound && outbound.integrationTypes.length > 0 ? ` (${outbound.integrationTypes.join(", ")})` : ""} — API calls to systems {outbound && outbound.integrationTypes.length > 0 ? ` (${outbound.integrationTypes.join(", ")})` : ""} — API calls to systems
you configured, to read status and, when someone with permission asks, to act (start a VM, run a template…). you configured, to read status and, when someone with permission asks, to act (start a VM, run a template…).
</li> </li>
<li className="mb-2">
<strong>osTicket tickets</strong> — only if an admin has switched on Settings → Alert tickets: for a problem that has lasted, the text of the alert
(which server or integration, what is wrong), a link back to this app, and the requester name and email set there go to your osTicket's API.
</li>
<li className="mb-2"> <li className="mb-2">
<strong>DNS providers</strong> <strong>DNS providers</strong>
{outbound && outbound.dnsProviderTypes.length > 0 ? ` (${outbound.dnsProviderTypes.join(", ")})` : ""} — zones and records are read {outbound && outbound.dnsProviderTypes.length > 0 ? ` (${outbound.dnsProviderTypes.join(", ")})` : ""} — zones and records are read
+1
View File
@@ -6,6 +6,7 @@ const SUB_NAV = [
{ to: "/settings/badges", label: "Badges" }, { to: "/settings/badges", label: "Badges" },
{ to: "/settings/display", label: "Display" }, { to: "/settings/display", label: "Display" },
{ to: "/settings/tags", label: "Tags" }, { to: "/settings/tags", label: "Tags" },
{ to: "/settings/alert-tickets", label: "Alert tickets" },
{ to: "/settings/names", label: "Names" }, { to: "/settings/names", label: "Names" },
{ to: "/settings/cache", label: "Cache" }, { to: "/settings/cache", label: "Cache" },
{ to: "/settings/logs", label: "Logs" }, { to: "/settings/logs", label: "Logs" },
@@ -0,0 +1,304 @@
import { useEffect, useMemo, useState } from "react";
import { Link } from "react-router-dom";
import { api, type AlertTicketOverview, type AlertTicketRunSummary, type AlertTicketSettings as Settings, type AlertTicketSeverity } from "../../api/client";
import { formatDateTime } from "../../utils/date";
import { formatAgo } from "../../utils/duration";
import { readableError } from "../../utils/errors";
const SEVERITIES: { value: AlertTicketSeverity; label: string; hint: string }[] = [
{ value: "critical", label: "Critical", hint: "A server down, a disk nearly full, a failed backup, something expired" },
{ value: "warning", label: "Warning", hint: "Something about to expire, an integration failing" },
{ value: "info", label: "Info", hint: "Updates waiting, monitors that can't be matched — rarely worth a ticket" },
];
/** Blank means "not set"; anything else must be a whole number. */
function optionalNumber(text: string): number | null {
const n = Number(text);
return text.trim() === "" || !Number.isInteger(n) || n < 1 ? null : n;
}
function describeRun(run: AlertTicketRunSummary): string {
if (run.skipped === "disabled") return "Switched off.";
if (run.skipped === "busy") return "A check was already running.";
const parts = [`${run.ticketsOpened} ticket${run.ticketsOpened === 1 ? "" : "s"} opened${run.ticketsOpened > 0 ? ` for ${run.alertsCovered} alert${run.alertsCovered === 1 ? "" : "s"}` : ""}`];
if (run.pending > 0) parts.push(`${run.pending} waiting to last long enough`);
if (run.baseline > 0) parts.push(`${run.baseline} already there, left alone`);
if (run.cleared > 0) parts.push(`${run.cleared} cleared`);
if (run.failed > 0) parts.push(`${run.failed} couldn't be opened`);
return `${parts.join(", ")}.`;
}
export default function AlertTicketSettings() {
const [overview, setOverview] = useState<AlertTicketOverview | null>(null);
const [draft, setDraft] = useState<Settings | null>(null);
const [error, setError] = useState<string | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const [busy, setBusy] = useState<"save" | "test" | "run" | null>(null);
function show(next: AlertTicketOverview) {
setOverview(next);
setDraft(next.settings);
}
useEffect(() => {
api.alertTickets
.get()
.then(show)
.catch((err) => setError(readableError(err)));
}, []);
const dirty = useMemo(() => overview !== null && draft !== null && JSON.stringify(overview.settings) !== JSON.stringify(draft), [overview, draft]);
if (!overview || !draft) {
return error ? <div className="alert alert-danger">{error}</div> : <div className="text-secondary">Loading…</div>;
}
const set = (patch: Partial<Settings>) => {
setDraft({ ...draft, ...patch });
setNotice(null);
};
const toggle = <T extends string>(list: T[], value: T) => (list.includes(value) ? list.filter((v) => v !== value) : [...list, value]);
async function save() {
setBusy("save");
setError(null);
setNotice(null);
try {
show(await api.alertTickets.update(draft!));
setNotice("Saved.");
} catch (err) {
setError(readableError(err));
} finally {
setBusy(null);
}
}
async function sendTest() {
setBusy("test");
setError(null);
setNotice(null);
try {
const res = await api.alertTickets.test();
setNotice(`A test ticket was opened in osTicket${res.ticketNumber ? ` (#${res.ticketNumber})` : ""}. You can close it there.`);
} catch (err) {
setError(readableError(err));
} finally {
setBusy(null);
}
}
async function checkNow() {
setBusy("run");
setError(null);
setNotice(null);
try {
const res = await api.alertTickets.run();
setOverview({ ...overview!, status: res.status });
if (res.summary.error) setError(res.summary.error);
setNotice(describeRun(res.summary));
} catch (err) {
setError(readableError(err));
} finally {
setBusy(null);
}
}
const chosen = overview.integrations.find((i) => i.id === draft.integrationId);
const { status } = overview;
return (
<>
{error && <div className="alert alert-danger">{error}</div>}
{notice && <div className="alert alert-success">{notice}</div>}
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Open a ticket in osTicket when something goes wrong</h3>
<div className="card-actions">
<label className="form-check form-switch mb-0">
<input type="checkbox" className="form-check-input" checked={draft.enabled} onChange={(e) => set({ enabled: e.target.checked })} />
<span className="form-check-label">{draft.enabled ? "On" : "Off"}</span>
</label>
</div>
</div>
<div className="card-body">
<p className="text-secondary">
Every 15 minutes the problems on the <Link to="/alerts">Alerts page</Link> are checked, and one that is new and has lasted gets a ticket. One problem opens
one ticket, however many checks see it. Problems under a <Link to="/maintenance">maintenance window</Link> never do. osTicket's API can't close or update a
ticket, so the ticket is yours from then on: close it in osTicket when it is dealt with. The Alerts page shows which alerts have one.
</p>
<div className="alert alert-info">
<div>
<strong>Set this up in osTicket first.</strong> Under <em>Admin Panel → Manage → API Keys</em> add a key, tie it to this server's IP address (the one osTicket
sees requests come from), and tick <em>Can create tickets</em>. Then enter the address and the key on the osTicket integration under{" "}
<Link to="/integrations">Integrations</Link>.
</div>
</div>
<div className="row g-3">
<div className="col-md-6">
<label className="form-label">osTicket integration</label>
<select className="form-select" value={draft.integrationId ?? ""} onChange={(e) => set({ integrationId: e.target.value === "" ? null : Number(e.target.value) })}>
<option value="">Choose…</option>
{overview.integrations.map((i) => (
<option key={i.id} value={i.id} disabled={!i.ticketApiReady}>
{i.name}
{!i.ticketApiReady ? " — no ticket API address and key yet" : ""}
</option>
))}
</select>
{overview.integrations.length === 0 && <div className="form-hint text-warning">There is no osTicket integration yet. Add one under Integrations.</div>}
{chosen && !chosen.enabled && <div className="form-hint text-warning">That integration is switched off.</div>}
</div>
<div className="col-md-6 d-flex align-items-end">
<button className="btn btn-outline-secondary" onClick={() => void sendTest()} disabled={busy !== null || dirty || !overview.settings.integrationId} title={dirty ? "Save first — the test uses the saved settings" : undefined}>
{busy === "test" ? "Sending…" : "Send a test ticket"}
</button>
</div>
<div className="col-md-4">
<label className="form-label">Tickets come from (name)</label>
<input className="form-control" maxLength={100} value={draft.requesterName} onChange={(e) => set({ requesterName: e.target.value })} />
</div>
<div className="col-md-4">
<label className="form-label">…and this email</label>
<input className="form-control" type="email" maxLength={200} placeholder="homelab@example.com" value={draft.requesterEmail} onChange={(e) => set({ requesterEmail: e.target.value })} />
<div className="form-hint">osTicket needs one for every ticket. Replies from staff would go here.</div>
</div>
<div className="col-md-2">
<label className="form-label">Help topic id</label>
<input className="form-control" inputMode="numeric" placeholder="default" value={draft.topicId ?? ""} onChange={(e) => set({ topicId: optionalNumber(e.target.value) })} />
</div>
<div className="col-md-2">
<label className="form-label">Priority id</label>
<input className="form-control" inputMode="numeric" placeholder="default" value={draft.priorityId ?? ""} onChange={(e) => set({ priorityId: optionalNumber(e.target.value) })} />
</div>
<div className="col-12">
<label className="form-check mb-0">
<input type="checkbox" className="form-check-input" checked={draft.notifyStaff} onChange={(e) => set({ notifyStaff: e.target.checked })} />
<span className="form-check-label">Let osTicket send its own "new ticket" alert to staff (as set up in osTicket)</span>
</label>
</div>
</div>
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Which problems</h3>
</div>
<div className="card-body">
<div className="row g-4">
<div className="col-md-6">
<div className="form-label">Severity</div>
{SEVERITIES.map((s) => (
<label className="form-check" key={s.value}>
<input type="checkbox" className="form-check-input" checked={draft.severities.includes(s.value)} onChange={() => set({ severities: toggle(draft.severities, s.value) })} />
<span className="form-check-label">
{s.label} <span className="text-secondary small">— {s.hint}</span>
</span>
</label>
))}
</div>
<div className="col-md-6">
<div className="form-label">Kind</div>
<label className="form-check">
<input type="checkbox" className="form-check-input" checked={draft.categories.length === 0} onChange={(e) => set({ categories: e.target.checked ? [] : overview.categories.map((c) => c.value) })} />
<span className="form-check-label">All kinds</span>
</label>
{draft.categories.length > 0 && (
<div className="ms-3">
{overview.categories.map((c) => (
<label className="form-check mb-1" key={c.value}>
<input type="checkbox" className="form-check-input" checked={draft.categories.includes(c.value)} onChange={() => set({ categories: toggle(draft.categories, c.value) })} />
<span className="form-check-label">{c.label}</span>
</label>
))}
</div>
)}
<div className="form-hint">Problems with osTicket itself never open a ticket — it would go to the thing that is down.</div>
</div>
<div className="col-md-4">
<label className="form-label">Must last</label>
<select className="form-select" value={draft.confirmChecks} onChange={(e) => set({ confirmChecks: Number(e.target.value) })}>
<option value={1}>Open a ticket straight away</option>
<option value={2}>2 checks in a row (15–30 minutes)</option>
<option value={3}>3 checks in a row (30–45 minutes)</option>
<option value={4}>4 checks in a row (about an hour)</option>
</select>
<div className="form-hint">So a blip that fixes itself, like one failed call to an integration, never opens a ticket.</div>
</div>
<div className="col-md-4">
<label className="form-label">Many at once</label>
<div className="input-group">
<span className="input-group-text">More than</span>
<input className="form-control" type="number" min={1} max={50} value={draft.summaryAbove} onChange={(e) => set({ summaryAbove: Math.min(50, Math.max(1, Number(e.target.value) || 1)) })} />
<span className="input-group-text">new</span>
</div>
<div className="form-hint">…in one check become a single ticket listing them all, so one outage doesn't fill the queue.</div>
</div>
<div className="col-md-4">
<label className="form-label">Comes back within</label>
<div className="input-group">
<input className="form-control" type="number" min={0} max={1440} value={draft.reopenAfterMinutes} onChange={(e) => set({ reopenAfterMinutes: Math.min(1440, Math.max(0, Number(e.target.value) || 0)) })} />
<span className="input-group-text">minutes</span>
</div>
<div className="form-hint">A problem that clears and returns this fast is the same one, not a new ticket. After that, it is.</div>
</div>
<div className="col-12">
<div className="form-label">Problems already there when this is switched on</div>
<label className="form-check">
<input type="radio" className="form-check-input" name="existing" checked={draft.existingProblems === "ignore"} onChange={() => set({ existingProblems: "ignore" })} />
<span className="form-check-label">
Leave them alone <span className="text-secondary small">— only problems that start after this is switched on get a ticket. Recommended.</span>
</span>
</label>
<label className="form-check">
<input type="radio" className="form-check-input" name="existing" checked={draft.existingProblems === "ticket"} onChange={() => set({ existingProblems: "ticket" })} />
<span className="form-check-label">
Open tickets for them too <span className="text-secondary small">— several at once become one summary ticket.</span>
</span>
</label>
</div>
</div>
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">What it has done</h3>
<div className="card-actions">
<button className="btn btn-outline-secondary btn-sm" onClick={() => void checkNow()} disabled={busy !== null || dirty || !overview.settings.enabled} title={dirty ? "Save first — the check uses the saved settings" : !overview.settings.enabled ? "Switched off" : undefined}>
{busy === "run" ? "Checking…" : "Check now"}
</button>
</div>
</div>
<div className="card-body">
{status.lastRun ? (
<div className="mb-2">
<span title={formatDateTime(new Date(status.lastRun.at))}>Last check {formatAgo(status.lastRun.at)}</span>: {describeRun(status.lastRun)}
{status.lastRun.error && <div className="text-danger small mt-1">{status.lastRun.error}</div>}
</div>
) : (
<div className="text-secondary mb-2">No check has run yet.</div>
)}
<div className="text-secondary small">
Right now: {status.open} problem{status.open === 1 ? "" : "s"} with a ticket, {status.pending} waiting to last long enough, {status.baseline} already there and left alone.
{status.baselinePending && " The next check records what is wrong at that point as the starting line, without opening tickets for it."}
</div>
</div>
</div>
<div className="d-flex flex-wrap align-items-center gap-2">
<button className="btn btn-primary" onClick={() => void save()} disabled={busy !== null || !dirty}>
{busy === "save" ? "Saving…" : "Save changes"}
</button>
<button className="btn btn-outline-secondary" onClick={() => { setDraft(overview.settings); setError(null); setNotice(null); }} disabled={busy !== null || !dirty}>
Discard changes
</button>
{dirty && <span className="text-secondary small">You have unsaved changes.</span>}
</div>
</>
);
}