diff --git a/README.md b/README.md index 65f6a53..092d764 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ Content-Type: application/json - **Source**: the API key's name (`gandalf`, `hwmonDaemon`, `thor`) is stored in `tickets.source` and shown as the creator instead of "System"; the dashboard has a Source filter. Comments this endpoint writes (escalation, recurrence) are authored by the key name too. Tickets from before #123: `php scripts/backfill_ticket_source.php --dry-run`, then without - **`dedup_key` (preferred, #123)**: the reporter decides what "the same problem" is by sending `dedup_key` (`scope:subject:kind`, 1-128 of `A-Za-z0-9_.:-`, case-sensitive, e.g. `host:compute-storage-01:oom`, `cluster:ceph:BLUESTORE_SLOW_OP_ALERT`). The hash is then `sha256("key:" + dedup_key)` and the title is not looked at; an invalid key is a 400. When an app starts sending keys, give its existing tickets theirs with `php scripts/backfill_dedup_keys.php --map=file.json [--dry-run]` (the app supplies `{ticket_id: dedup_key}`), or its next reports open duplicates - **Deduplication without a key**: Generates a SHA-256 hash from the issue category, hostname, and device (no time window). A repeat alert matching an existing **open** ticket updates its title/description and escalates the priority if the condition worsened -- **Recurrence (every reporter, keyed or not)**: a report matching a **Closed** ticket that closed less than `AUTO_REOPEN_WINDOW_DAYS` (default 7) ago reopens it, if the Workflow Designer allows an unattended reopen (no admin, no comment); otherwise the recurrence is noted on it and it stays Closed (`recurrence_noted`). A ticket closed longer ago is left alone: a **new ticket** takes over the dedup slot, carries the same `dedup_key`, records the old one in `recurrence_of`, is linked `relates_to` it, and gets a history comment (times seen in the last 7 and 30 days, when it last cleared). Response `action`: `created`, `updated`, `deduplicated`, `reopened`, `recurrence_noted` or `new_recurrence` (with `previous_ticket_id`) +- **Recurrence (every reporter, keyed or not)**: a report matching a **Closed** ticket that closed less than `AUTO_REOPEN_WINDOW_DAYS` (default 7) ago reopens it to Open. Automated reopens skip the Workflow Designer (its Closed → Open rule is for people; prod requires admin + comment there, which no reporter can give); the audit entry says so. A ticket closed longer ago is left alone: a **new ticket** takes over the dedup slot, carries the same `dedup_key`, records the old one in `recurrence_of`, is linked `relates_to` it, and gets a history comment (times seen in the last 7 and 30 days, when it last cleared). Response `action`: `created`, `updated`, `deduplicated`, `reopened` or `new_recurrence` (with `previous_ticket_id`). (`recurrence_noted` is no longer returned.) - Cluster-wide issues (Ceph health, etc.) deduplicate across all nodes (hostname excluded from hash) - Automated network tickets are keyed per problem, not just per host: on the optional `check_code` payload field when sent (it must name the instance, e.g. `iface_down:enp3s0`), otherwise on the title text outside the `[tags]`. After deploying this change (#116), run `php scripts/rehash_network_tickets.php --dry-run`, then without `--dry-run`, so open network tickets keep matching their alerts. The hash logic lives in `helpers/TicketHash.php` - `description` is rendered as markdown on the ticket page, the same as markdown comments (#114). Reporters should send markdown: `##` sections, tables for key/value data and fenced code blocks for raw command output. Fixed-width box layouts lose their alignment. diff --git a/create_ticket_api.php b/create_ticket_api.php index d981194..9fe9be7 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -43,7 +43,6 @@ require_once __DIR__ . '/middleware/ApiKeyAuth.php'; require_once __DIR__ . '/models/AuditLogModel.php'; require_once __DIR__ . '/models/StatsModel.php'; require_once __DIR__ . '/models/TicketModel.php'; -require_once __DIR__ . '/models/WorkflowModel.php'; require_once __DIR__ . '/helpers/UrlHelper.php'; require_once __DIR__ . '/helpers/TicketHash.php'; require_once __DIR__ . '/services/AutoTicketService.php'; @@ -260,52 +259,26 @@ for ($dedupAttempt = 1; $dedupAttempt <= $maxDedupAttempts; $dedupAttempt++) { exit; } - // Ticket closed inside the reopen window: reopen it and add a recurrence comment. Route - // through the Workflow Designer like every other status-write path in - // the app, rather than forcing status='Open' via raw SQL regardless of - // configured transition rules. - $workflowModel = new WorkflowModel($conn); - $reopenStatus = 'Open'; - if (!$workflowModel->isTransitionAllowed('Closed', 'Open', false)) { - // Direct Closed->Open isn't configured — fall back to any transition - // the Workflow Designer does allow from Closed that this unattended, - // non-admin automation can actually satisfy (no comment prompt, no - // admin elevation). If even that doesn't exist, leave the ticket - // Closed rather than force an unconfigured state. - $reopenStatus = null; - foreach ($workflowModel->getAllowedTransitions('Closed') as $transition) { - if (!$transition['requires_comment'] && !$transition['requires_admin']) { - $reopenStatus = $transition['to_status']; - break; - } - } - } - - if ($reopenStatus !== null) { - $ticketModel = new TicketModel($conn); - $ticketModel->updateTicket([ - 'ticket_id' => $existingId, - 'title' => $title, - 'description' => $description, - 'category' => $category, - 'type' => $type, - 'status' => $reopenStatus, - 'priority' => $priority, - ], $userId); - } else { - error_log("create_ticket_api: {$source} recurrence for ticket $existingId: " - . "no admin-free, comment-free transition from Closed is configured; leaving ticket Closed"); - } + // Ticket closed inside the reopen window: reopen it and add a recurrence + // comment. Automated reporters reopen regardless of the Workflow + // Designer (operator decision, 2026-11-28): prod's Closed -> Open needs + // admin + comment, which no unattended reporter can give, so the rule + // only ever produced a "could not be reopened" note on every report + // (2,110 of them before #123). People still go through the workflow. + $ticketModel = new TicketModel($conn); + $ticketModel->updateTicket([ + 'ticket_id' => $existingId, + 'title' => $title, + 'description' => $description, + 'category' => $category, + 'type' => $type, + 'status' => 'Open', + 'priority' => $priority, + ], $userId); $commentText = "**Issue recurred, ticket reopened automatically.**\n\n" . "{$source} detected this condition again. The ticket description reflects the " . "latest report; see this comment's timestamp for when the issue recurred."; - if ($reopenStatus === null) { - $commentText = "**Issue recurred, but the ticket could not be reopened automatically.**\n\n" - . "{$source} detected this condition again. No Workflow Designer transition from " - . "Closed is configured that this automation can perform unattended (no comment/admin " - . "requirement); the ticket remains Closed. Please review and reopen manually if appropriate."; - } $commentStmt = $conn->prepare( "INSERT INTO ticket_comments (ticket_id, user_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, ?, ?, 1)" ); @@ -313,41 +286,31 @@ for ($dedupAttempt = 1; $dedupAttempt <= $maxDedupAttempts; $dedupAttempt++) { $commentStmt->execute(); $commentStmt->close(); - if ($reopenStatus !== null) { - $auditLog->log($userId, 'update', 'ticket', $existingId, [ - 'status' => ['from' => 'Closed', 'to' => $reopenStatus], - 'reason' => "auto-reopened by {$source} (issue recurred)", - ]); + $auditLog->log($userId, 'update', 'ticket', $existingId, [ + 'status' => ['from' => 'Closed', 'to' => 'Open'], + 'reason' => "auto-reopened by {$source} (issue recurred; automated reopen skips the Workflow Designer)", + ]); - // Ticket reopened — refresh dashboard stats. - (new StatsModel($conn))->invalidateCache(); - } else { - $auditLog->log($userId, 'update', 'ticket', $existingId, [ - 'reason' => "{$source} recurrence detected but no valid reopen transition configured; ticket left Closed", - ]); - } + // Ticket reopened: refresh dashboard stats. + (new StatsModel($conn))->invalidateCache(); $conn->commit(); Database::close(); - if ($reopenStatus !== null) { - require_once __DIR__ . '/helpers/NotificationHelper.php'; - NotificationHelper::sendTicketNotification($existingId, [ - 'title' => $title, - 'priority' => $priority, - 'category' => $category, - 'type' => $type, - 'status' => $reopenStatus, - ], 'automated'); - } + require_once __DIR__ . '/helpers/NotificationHelper.php'; + NotificationHelper::sendTicketNotification($existingId, [ + 'title' => $title, + 'priority' => $priority, + 'category' => $category, + 'type' => $type, + 'status' => 'Open', + ], 'automated'); echo json_encode([ 'success' => true, 'ticket_id' => $existingId, - 'message' => $reopenStatus !== null - ? 'Existing closed ticket reopened' - : 'Recurrence noted; ticket left Closed (no valid workflow transition configured)', - 'action' => $reopenStatus !== null ? 'reopened' : 'recurrence_noted', + 'message' => 'Existing closed ticket reopened', + 'action' => 'reopened', ]); exit; } diff --git a/services/AutoTicketService.php b/services/AutoTicketService.php index 782e598..4f80fee 100644 --- a/services/AutoTicketService.php +++ b/services/AutoTicketService.php @@ -9,8 +9,8 @@ * transaction; nothing here commits or rolls back. * * Recurrence rule, the same for every reporter: a report whose dedup hash - * matches a Closed ticket reopens it when it closed less than - * AUTO_REOPEN_WINDOW_DAYS ago. Otherwise a new ticket takes over the hash, is + * matches a Closed ticket reopens it (skipping the Workflow Designer) when it + * closed less than AUTO_REOPEN_WINDOW_DAYS ago. Otherwise a new ticket takes over the hash, is * linked relates_to the old one, records it in recurrence_of, and gets a * history comment. tickets.hash is UNIQUE, so the old ticket gives up its hash * (set to NULL) and keeps its dedup_key.