Skip to content

Zabbix After Close PR Review

Ed Mozley edited this page Dec 5, 2026 · 1 revision

Zabbix alerts after the ticket was closed, merged or deleted - PR review (#516)

PR #516 by @Dr4inder Β· System β†’ Integrations β†’ Zabbix Β· merged 5 December 2026, in 6.0.0

Verdict: merge. A real bug, found by thinking through every state a ticket can be in, with a test for each.

What was wrong

zabbixHandleEvent() found a problem's ticket with zabbixOpenTicketFor(), which looked only for an open one. So:

  • Closed by hand while Zabbix still had the problem - the next alert for it (an acknowledgement, a comment, the action's next escalation step) found nothing and raised a second ticket with the same title.
  • Merged into another ticket - the same, and the recovery was logged as Recovery with no ticket, leaving the surviving ticket open.
  • Deleted - every further alert raised the ticket again.

The fix

A Zabbix event id is one problem, so once a problem has a ticket every later alert for it belongs to that ticket. zabbixTicketFor() takes the latest ticket logged for the problem and follows merges to where it ended up:

$t = $conn->prepare("SELECT t.merged_into_id, t.deleted_datetime, COALESCE(s.is_closed, 0) AS is_closed
                       FROM tickets t LEFT JOIN ticket_statuses s ON s.id = t.status_id WHERE t.id = ?");
// A few hops at most: a merge chain is short, and a loop must not hang the alert.
for ($hop = 0; $hop < 10; $hop++) {
    $t->execute([$tid]);
    $row = $t->fetch(PDO::FETCH_ASSOC);
    if (!$row) return ['id' => $tid, 'closed' => true, 'deleted' => true];   // purged from the trash
    if ($row['merged_into_id'] === null) {
        return ['id' => $tid, 'closed' => (int)$row['is_closed'] === 1, 'deleted' => $row['deleted_datetime'] !== null];
    }
    $tid = (int)$row['merged_into_id'];
}
The problem's ticket is An update The recovery
open on its thread (unchanged) on its thread, resolved (unchanged)
closed on its thread; it stays closed on its thread; status left alone
merged on the ticket it was merged into on that ticket, which is resolved
deleted nothing raised; logged as Not added Recovery with no ticket
never had one a new incident (unchanged) Recovery with no ticket (unchanged)

What was good - copy this

  • Every state a record can be in, not just the one that was reported. Closed, merged, deleted and purged are four different answers, and each has a row in the table and a check in the test.
  • A loop that cannot hang. A merge chain is followed at most ten hops, so a bad loop in the data cannot stall the webhook while it holds its lock.
  • Decisions people made are respected. A closed ticket is not reopened by an acknowledgement - somebody closed it - but the message still goes on its thread, so the record is complete. A deleted ticket is not raised again, because a deletion usually means the alert was noise.
  • Every outcome is logged with its reason (the ticket is closed and was not reopened, the ticket was deleted), and the recent alerts list has a label for the new ignored action.
  • The help changed with the behaviour (A repeat is not a second ticket now says what happens after a close, merge or delete), and nothing needs re-importing in Zabbix.
  • Tested through the real endpoint, api/external/zabbix/alert.php: the 24 existing checks still pass and 11 new ones cover the three cases, with a control (the old handler raised new tickets 13, 16 and 18).
  • Design choices named for the reviewer - "if you would rather an update reopen the ticket, it is one branch" - which made the review quick.

Nothing needed fixing. On a test install tests/zabbix-integration.php passes 44 of 44.

Files

File Change
πŸ”΄ includes/integrations/zabbix.php zabbixTicketFor() replaces zabbixOpenTicketFor(); the handler
🟑 system/integrations/zabbix.php, lang/en/system.php The Not added label
🟑 system/integrations/help_zabbix.php The in-app guide
🟒 tests/zabbix-integration.php 11 new checks

What this means for you

Nothing to change. A problem closed by hand while Zabbix still has it no longer comes back as a second ticket. See Zabbix integration.

Related

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally