Open an osTicket ticket for an alert that lasts
With Settings -> Alert tickets switched on (off by default), every 15 minutes the problems on the Alerts page are looked at and one that is new and has lasted gets one ticket in osTicket, through its API (POST api/tickets.json, key in X-API-Key). One problem opens one ticket however many checks see it; the app remembers what it has seen in a new alert_tickets table (migration 0015). - Which: critical and warning by default, every kind; severities and kinds are settings. - A problem must be seen in 2 checks in a row first (1-4, a setting), so a blip that fixes itself, like one failed call to an integration, never opens a ticket. - One ticket per occurrence; a problem that clears and returns within 60 minutes is the same one. - More than 5 new problems in one check become a single summary ticket. - Never for alerts under a maintenance window, nor about osTicket itself or its overdue tickets. - Problems already there when it is switched on are left alone by default (the first check records them as a baseline); can be set to ticket them too. - If osTicket can't be reached nothing is recorded, so the next check retries; if a source couldn't be read, a problem isn't treated as gone. Every ticket is audited. The ticket API address, key (stored encrypted) and self-signed option are optional fields on the osTicket integration, which otherwise still only reads the database. The settings page can send a test ticket and run a check now; the Alerts page shows each alert's ticket number, linked to osTicket. osTicket's API can't close or update a ticket, so a ticket opened here is the end of this app's part in it. Tested against a stand-in osTicket, not a real one. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f71756b119
commit
467d1a1a06
14 files changed
+3455
-2
No files matched your search
+32
-1
@@ -1,5 +1,5 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { sqliteTable, text, integer, real, uniqueIndex } from "drizzle-orm/sqlite-core";
|
||||
import { sqliteTable, text, integer, real, uniqueIndex, index } from "drizzle-orm/sqlite-core";
|
||||
|
||||
// ─── Users & roles ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -410,3 +410,34 @@ export const tagDefinitions = sqliteTable("tag_definitions", {
|
||||
.notNull()
|
||||
.default(sql`(current_timestamp)`),
|
||||
});
|
||||
|
||||
// ─── Tickets opened for alerts ──────────────────────────────────────────────
|
||||
|
||||
export const alertTicketStatuses = ["pending", "open", "baseline"] as const;
|
||||
export type AlertTicketStatus = (typeof alertTicketStatuses)[number];
|
||||
|
||||
// What the ticket feature remembers about each problem it has seen, so one problem opens one ticket however many checks see it.
|
||||
// A row is one *occurrence*: when the alert clears and later returns, that is a new row. Alert ids (e.g. "disk:server:3:/") are the
|
||||
// stable keys the Alerts page already uses, so they aren't a foreign key to anything.
|
||||
export const alertTickets = sqliteTable(
|
||||
"alert_tickets",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
alertKey: text("alert_key").notNull(),
|
||||
// pending = seen, but not yet in enough checks in a row to open a ticket (so a blip that fixes itself never does)
|
||||
// open = a ticket was opened for it (ticket_number says which)
|
||||
// baseline = it was already there when the feature was switched on and "existing problems" is set to be left alone
|
||||
status: text("status").$type<AlertTicketStatus>().notNull(),
|
||||
seenCount: integer("seen_count").notNull().default(1),
|
||||
integrationId: integer("integration_id").references(() => integrations.id, { onDelete: "set null" }),
|
||||
ticketNumber: text("ticket_number"), // osTicket's own ticket number; null unless status is "open"
|
||||
grouped: integer("grouped", { mode: "boolean" }).notNull().default(false), // part of a summary ticket covering several alerts
|
||||
severity: text("severity").notNull(),
|
||||
message: text("message").notNull(), // what the alert said when it was first recorded
|
||||
firstSeenAt: text("first_seen_at").notNull(), // ISO
|
||||
lastSeenAt: text("last_seen_at").notNull(), // ISO
|
||||
ticketedAt: text("ticketed_at"), // ISO; when the ticket was opened
|
||||
clearedAt: text("cleared_at"), // ISO; null while the alert is still active
|
||||
},
|
||||
(t) => [index("alert_tickets_key_idx").on(t.alertKey)],
|
||||
);
|
||||
Reference in new issue
Block a user