From ccf2ba4c66708e078f7da48ee354049972cdac9f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 30 Jun 2025 12:26:27 +0200 Subject: [PATCH] IcingaDbState: Correctly determine ack and downtime flags fixes #469 --- .../Businessprocess/State/IcingaDbState.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/library/Businessprocess/State/IcingaDbState.php b/library/Businessprocess/State/IcingaDbState.php index 1a66900..6de8caa 100644 --- a/library/Businessprocess/State/IcingaDbState.php +++ b/library/Businessprocess/State/IcingaDbState.php @@ -180,12 +180,38 @@ class IcingaDbState $node->setLastStateChange($row->last_state_change / 1000.0); } - $node->setDowntime($row->in_downtime === 'y'); - $node->setAck($row->is_acknowledged === 'y'); + $node->setDowntime($this->toBoolean($row->in_downtime)); + $node->setAck($this->toBoolean($row->is_acknowledged)); $node->setAlias($row->display_name); if ($node instanceof ServiceNode) { $node->setHostAlias($row->host_display_name); } } + + private function toBoolean($value): bool + { + switch (true) { + // Icinga Redis >= 6 (is_acknowledged, in_downtime) + case $value === true: + case $value === false: + return $value; + // Icinga Redis < 6 (is_acknowledged) + case $value === 1: + case $value === 2: + return true; + case $value === 0: + return false; + // Icinga DB < 1.4 (is_acknowledged) + case $value === 'sticky': + return true; + // Icinga DB >= * (is_acknowledged, in_downtime) + case $value === 'y': + return true; + case $value === 'n': + return false; + } + + return false; + } }