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

+14 -2
View File
@@ -5,7 +5,8 @@ import { requireAuth, requireRole } from "../auth/middleware.js";
import { db } from "../db/client.js";
import { integrations } from "../db/schema.js";
import { recordAudit } from "../services/audit.js";
import { getAlertTicketStatus, resetBaseline, runAlertTicketCheck, sendTestTicket } from "../services/alertTickets.js";
import { getAlertTicketStatus, resetBaseline, runAlertTicketCheck, sendTestTicket, testClosing } from "../services/alertTickets.js";
import { hasCloseAccess, type OsTicketCloseConfig } from "../integrations/osticket/closeTicket.js";
import { getSettings, updateSettings } from "../services/settingsStore.js";
import { describeSettingsChanges } from "../services/settingsDiff.js";
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
@@ -34,13 +35,15 @@ async function overview() {
const osticket = [];
for (const row of rows) {
let ready = false;
let closeReady = false;
try {
const loaded = await loadIntegrationConfig(row.id);
ready = loaded ? hasTicketApi(loaded.config as OsTicketApiConfig) : false;
closeReady = loaded ? hasCloseAccess(loaded.config as OsTicketCloseConfig) : false;
} catch {
ready = false;
}
osticket.push({ id: row.id, name: row.name, enabled: row.enabled, ticketApiReady: ready });
osticket.push({ id: row.id, name: row.name, enabled: row.enabled, ticketApiReady: ready, closeReady });
}
return { settings: (await getSettings()).alertTickets, integrations: osticket, categories: CATEGORIES, status: await getAlertTicketStatus() };
}
@@ -113,6 +116,15 @@ alertTicketsRouter.post("/test", asyncHandler(async (req, res) => {
}
}));
// "Test closing": the login, the tables and the writes a close makes, tried inside a transaction that is rolled back. Changes nothing that stays.
alertTicketsRouter.post("/test-close", asyncHandler(async (req, res) => {
const parsed = z.object({ integrationId: z.number().int().positive() }).safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say which osTicket integration." });
const report = await testClosing(parsed.data.integrationId);
await recordAudit({ actor: req.currentUser!, category: "alert_ticket", action: "test_close", targetType: "integration", targetId: parsed.data.integrationId, detail: { ok: report.ok } });
res.json(report);
}));
alertTicketsRouter.post("/run", asyncHandler(async (req, res) => {
const summary = await runAlertTicketCheck({ actor: req.currentUser! });
res.json({ summary, status: await getAlertTicketStatus() });