From 9120449acbb0c7c25c7f82e1374726956a71650e Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Tue, 20 Mar 2018 16:31:58 +0100 Subject: [PATCH] BpNode: Use worst state in minimum state calculation Ensure we use the worst state within a minimum condition, previously we did use the Xth best. refs #167 --- library/Businessprocess/BpNode.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index 79d4015..79af272 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -364,13 +364,23 @@ class BpNode extends Node break; default: // MIN: - sort($sort_states); - - // default -> unknown $sort_state = 3 << self::SHIFT_FLAGS; - for ($i = 1; $i <= $this->operator; $i++) { - $sort_state = array_shift($sort_states); + if (count($sort_states) >= $this->operator) { + $actualGood = 0; + foreach ($sort_states as $s) { + if (($s >> self::SHIFT_FLAGS) === self::ICINGA_OK) { + $actualGood++; + } + } + + if ($actualGood >= $this->operator) { + // condition is fulfilled + $sort_state = self::ICINGA_OK; + } else { + // worst state if not fulfilled + $sort_state = max($sort_states); + } } } if ($sort_state & self::FLAG_DOWNTIME) {