Bulk close can close the osTicket tickets; Alerts top-level, Records group

Closing several alerts together can now also close their osTicket tickets
(one by one, each written on its incident and in the audit log; one that
fails does not stop the rest; Undo does not reopen tickets). The single
and bulk close share one helper. Alerts moves to the top of the sidebar,
and Monthly report and Change log move to a new Records group. Docs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-26 20:20:28 +01:00
1 parent 215c0de8bf
commit 78822346b1
13 files changed
+234 -37

No files matched your search

+4 -14
View File
@@ -8,8 +8,8 @@ import { AckError, assignableUsers, attentionCounts, clearAck, loadAcks, MAX_HOU
import { recordAudit } from "../services/audit.js";
import { addNote, openIncidentIds } from "../services/incidents.js";
import { buildNoiseReport, NOISE_DAYS } from "../services/alertNoise.js";
import { closeTicketForAlert, ticketsForAlerts, type AlertTicketInfo, type TicketCloseOutcome } from "../services/alertTickets.js";
import { CloseError } from "../integrations/osticket/closeTicket.js";
import { ticketsForAlerts, type AlertTicketInfo } from "../services/alertTickets.js";
import { closeTicketAndRecord, type TicketResult } from "../services/closeAlertTicket.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const alertsRouter = Router();
@@ -159,20 +159,10 @@ alertsRouter.put("/close", requireRole("operator"), asyncHandler(async (req, res
await recordAudit({ actor, category: "alert", action: "close", ...auditTargetOf(alert), detail: { alertId: alert.id, message: alert.message, note: closed.note } });
invalidateAlertsCache();
// The ticket, if asked for. The alert is closed either way: a ticket that could not be closed is said, not hidden, and does not undo the closing.
let ticket: { number: string | null; result: TicketCloseOutcome["result"] | "failed"; message: string | null } | null = null;
let ticket: TicketResult | null = null;
if (parsed.data.closeTicket) {
const number = (await ticketsForAlerts([alert.id])).get(alert.id)?.number ?? null;
try {
const outcome = await closeTicketForAlert(alert.id, { closedBy: who, reason: closed.note });
ticket = { number: outcome.number, result: outcome.result, message: null };
await recordAudit({ actor, category: "alert_ticket", action: "close_ticket", ...auditTargetOf(alert), detail: { alertId: alert.id, number: outcome.number, result: outcome.result } });
if (incidentId) await addNote(incidentId, who, outcome.result === "closed" ? "osTicket ticket " + outcome.number + " closed." : "osTicket ticket " + outcome.number + " was already closed.");
} catch (err) {
const message = err instanceof CloseError ? err.message : "Closing the ticket failed: " + (err instanceof Error ? err.message : String(err));
ticket = { number, result: "failed", message };
await recordAudit({ actor, category: "alert_ticket", action: "close_ticket_failed", ...auditTargetOf(alert), detail: { alertId: alert.id, number, message } });
if (incidentId) await addNote(incidentId, who, "osTicket ticket" + (number ? " " + number : "") + " could not be closed: " + message);
}
ticket = await closeTicketAndRecord({ alert, number, actor, who, reason: closed.note, incidentId });
}
res.json({ closed: { by: closed.snoozedBy, at: closed.snoozedAt, note: closed.note }, ticket });
} catch (err) {
+12 -3
View File
@@ -6,6 +6,8 @@ import { SnoozeError } from "../services/alertSnoozes.js";
import { recordAudit } from "../services/audit.js";
import { acknowledgeAlerts, BulkInputError, changeAssets, closeAlerts, reopenAlerts, changeServerTag, MAX_BULK, restoreAcks, restoreAssets, restoreServerParents, restoreSnoozes, setServerParents, setServerTags, silenceTargets, snoozeAlerts, targetsOfAlerts, undoSilence, unacknowledgeAlerts, unsnoozeAlerts } from "../services/bulkActions.js";
import { addNote, openIncidentIds } from "../services/incidents.js";
import { closeTicketsOfAlerts, type BulkTicketResult } from "../services/closeAlertTicket.js";
import { getAlerts } from "../services/alerts.js";
import { InvalidTagError } from "../services/serverTags.js";
import { asyncHandler } from "../utils/asyncHandler.js";
@@ -111,7 +113,7 @@ const alertsBody = z.discriminatedUnion("action", [
z.object({ action: z.literal("snooze"), alertIds: stringIds, until: z.string().min(1).max(40) }),
z.object({ action: z.literal("unsnooze"), alertIds: stringIds }),
/** "Dealt with, or accepted": hidden with no end, until each gets worse. The note is written on each one's incident. */
z.object({ action: z.literal("close"), alertIds: stringIds, note: z.string().max(500).nullable().optional() }),
z.object({ action: z.literal("close"), alertIds: stringIds, note: z.string().max(500).nullable().optional(), /** Also close the osTicket tickets of those that have one that can be closed from here. Not undone by Undo. */ closeTickets: z.boolean().optional() }),
z.object({ action: z.literal("reopen"), alertIds: stringIds }),
z.object({ action: z.literal("restore_snoozes"), items: z.array(z.object({ alertId: z.string().min(1).max(600), previous: snoozeRecord.nullable() })).min(1).max(MAX_BULK), closed: z.boolean().optional() }),
z.object({ action: z.literal("acknowledge"), alertIds: stringIds, note: z.string().max(MAX_NOTE).default(""), assigneeId: z.number().int().positive().nullable().default(null), hours: z.number().int().min(1).max(MAX_HOURS).nullable().default(null) }),
@@ -166,8 +168,15 @@ alertsBulkRouter.post("/", asyncHandler(async (req, res) => {
const incidentId = open.get(item.alertId);
if (incidentId) await addNote(incidentId, who, (note ? "Closed: " + note : "Closed without a note.") + together);
}
await recordAudit({ actor, category: "alert", action: "bulk_close", detail: { changed: r.changed, note, alerts: detailIds(body.alertIds) } });
return res.json(r);
// The tickets, if asked for. The alerts are closed either way; what could not be closed is said, with why.
let tickets: BulkTicketResult | null = null;
if (body.closeTickets && r.undo) {
const closedIds = new Set(r.undo.items.map((i) => i.alertId));
const here = (await getAlerts(false)).alerts.filter((a) => closedIds.has(a.id));
tickets = await closeTicketsOfAlerts(here, { actor, who, reason: note, incidentIds: open });
}
await recordAudit({ actor, category: "alert", action: "bulk_close", detail: { changed: r.changed, note, alerts: detailIds(body.alertIds), ...(tickets ? { tickets: { closed: tickets.closed, alreadyClosed: tickets.alreadyClosed, failed: tickets.failed.length, notClosable: tickets.notClosable } } : {}) } });
return res.json({ ...r, tickets });
}
case "reopen": {
const who = nameOf(req);