Close the osTicket ticket along with an alert

The Close drawer can also close the alert's osTicket ticket. osTicket's API
cannot, so this writes to its database with a separate, optional login: the
ticket is set to Closed, a note in its thread says who closed it and why, and
the closed event is recorded, in one transaction. Tables and columns are
checked first, only an open ticket is closed, and a ticket closed by somebody
else at the same moment is left alone. Summary tickets are not closed from here.

"Test closing" (Alert tickets settings) tries every write and rolls it back.
If the ticket cannot be closed the alert is still closed and the reason is
said, noted on the incident and audited.

Not run against a real osTicket: tested against a pretend database only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-25 21:27:38 +01:00
1 parent a94899865e
commit 5ae61a1ece
21 files changed
+8405 -23

No files matched your search

+5 -3
View File
@@ -1905,7 +1905,7 @@ export interface AlertItem {
/** On a host's alert: the servers on it whose own alerts are folded under this one. */
affects?: string[];
/** The osTicket ticket opened for it, if one was. */
ticket?: { number: string | null; url: string | null; grouped: boolean; openedAt: string | null } | null;
ticket?: { number: string | null; url: string | null; grouped: boolean; openedAt: string | null; closedAt: string | null; canClose: boolean } | null;
/** Somebody has said they are on it. */
ack?: AlertAck | null;
/** The incident record this alert is part of, while it lasts. */
@@ -2121,7 +2121,7 @@ export interface AlertTicketRunSummary {
export interface AlertTicketOverview {
settings: AlertTicketSettings;
integrations: { id: number; name: string; enabled: boolean; ticketApiReady: boolean }[];
integrations: { id: number; name: string; enabled: boolean; ticketApiReady: boolean; /** A login for closing tickets is set. */ closeReady: boolean }[];
categories: { value: string; label: string }[];
status: { lastRun: AlertTicketRunSummary | null; open: number; pending: number; baseline: number; baselinePending: boolean };
}
@@ -3187,7 +3187,8 @@ export const api = {
ack: (data: AckInput) => request<{ ack: AlertAck }>("/api/alerts/ack", { method: "PUT", body: JSON.stringify(data) }),
unack: (alertId: string) => request<void>(`/api/alerts/ack?alertId=${encodeURIComponent(alertId)}`, { method: "DELETE" }),
snooze: (alertId: string, until: string) => request<{ snooze: { until: string; snoozedBy: string } }>("/api/alerts/snooze", { method: "PUT", body: JSON.stringify({ alertId, until }) }),
close: (alertId: string, note: string | null) => request<{ closed: { by: string; at: string; note: string | null } }>("/api/alerts/close", { method: "PUT", body: JSON.stringify({ alertId, note }) }),
close: (alertId: string, note: string | null, closeTicket = false) =>
request<{ closed: { by: string; at: string; note: string | null }; ticket: { number: string | null; result: "closed" | "already_closed" | "failed"; message: string | null } | null }>("/api/alerts/close", { method: "PUT", body: JSON.stringify({ alertId, note, closeTicket }) }),
reopen: (alertId: string) => request<void>(`/api/alerts/close?alertId=${encodeURIComponent(alertId)}`, { method: "DELETE" }),
unsnooze: (alertId: string) => request<void>(`/api/alerts/snooze?alertId=${encodeURIComponent(alertId)}`, { method: "DELETE" }),
noise: (days: number) => request<NoiseReport>(`/api/alerts/noise?days=${days}`),
@@ -3220,6 +3221,7 @@ export const api = {
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" }),
testClose: (integrationId: number) => request<{ ok: boolean; problems: string[]; notes: string[] }>("/api/alert-tickets/test-close", { method: "POST", body: JSON.stringify({ integrationId }) }),
run: () => request<{ summary: AlertTicketRunSummary; status: AlertTicketOverview["status"] }>("/api/alert-tickets/run", { method: "POST" }),
},
ports: {