diff --git a/application/clicommands/ProcessCommand.php b/application/clicommands/ProcessCommand.php index 33c8936..7b6fb4e 100644 --- a/application/clicommands/ProcessCommand.php +++ b/application/clicommands/ProcessCommand.php @@ -60,6 +60,17 @@ class ProcessCommand extends Command } } + protected function listConfigNames($withTitle) + { + foreach ($this->storage->listProcesses() as $key => $title) { + if ($withTitle) { + echo $title . "\n"; + } else { + echo $key . "\n"; + } + } + } + /** * Check a specific process * @@ -81,6 +92,10 @@ class ProcessCommand extends Command * --root-cause Used in combination with --blame. Only shows * the path of the nodes which are responsible for * the state of the business process + * --downtime-is-ok Treat hosts/services in downtime always as + * UP/OK. + * --ack-is-ok Treat acknowledged hosts/services always as + * UP/OK. */ public function checkAction() { @@ -112,6 +127,14 @@ class ProcessCommand extends Command exit(3); } + if ($this->params->shift('ack-is-ok')) { + Node::setAckIsOk(); + } + + if ($this->params->shift('downtime-is-ok')) { + Node::setDowntimeIsOk(); + } + printf("Business Process %s: %s\n", $node->getStateName(), $node->getAlias()); if ($this->params->shift('details')) { echo $this->renderProblemTree($node->getProblemTree(), $this->params->shift('colors')); @@ -126,17 +149,6 @@ class ProcessCommand extends Command exit($node->getState()); } - protected function listConfigNames($withTitle) - { - foreach ($this->storage->listProcesses() as $key => $title) { - if ($withTitle) { - echo $title . "\n"; - } else { - echo $key . "\n"; - } - } - } - protected function listBpNames(BpConfig $config) { foreach ($config->listBpNodes() as $title) { diff --git a/library/Businessprocess/Node.php b/library/Businessprocess/Node.php index 2c9e7a8..21c8708 100644 --- a/library/Businessprocess/Node.php +++ b/library/Businessprocess/Node.php @@ -22,6 +22,12 @@ abstract class Node const ICINGA_UNREACHABLE = 2; const ICINGA_PENDING = 99; + /** @var bool Whether to treat acknowledged hosts/services always as UP/OK */ + protected static $ackIsOk = false; + + /** @var bool Whether to treat hosts/services in downtime always as UP/OK */ + protected static $downtimeIsOk = false; + protected $sortStateToStateMap = array( 4 => self::ICINGA_CRITICAL, 3 => self::ICINGA_UNKNOWN, @@ -111,6 +117,26 @@ abstract class Node abstract public function __construct($object); + /** + * Set whether to treat acknowledged hosts/services always as UP/OK + * + * @param bool $ackIsOk + */ + public static function setAckIsOk($ackIsOk = true) + { + self::$ackIsOk = $ackIsOk; + } + + /** + * Set whether to treat hosts/services in downtime always as UP/OK + * + * @param bool $downtimeIsOk + */ + public static function setDowntimeIsOk($downtimeIsOk = true) + { + self::$downtimeIsOk = $downtimeIsOk; + } + public function setBpConfig(BpConfig $bp) { $this->bp = $bp; @@ -219,13 +245,24 @@ abstract class Node public function getSortingState() { - $sort = $this->stateToSortState($this->getState()); + $state = $this->getState(); + + if (self::$ackIsOk && $this->isAcknowledged()) { + $state = self::ICINGA_OK; + } + + if (self::$downtimeIsOk && $this->isInDowntime()) { + $state = self::ICINGA_OK; + } + + $sort = $this->stateToSortState($state); $sort = ($sort << self::SHIFT_FLAGS) + ($this->isInDowntime() ? self::FLAG_DOWNTIME : 0) + ($this->isAcknowledged() ? self::FLAG_ACK : 0); if (! ($sort & (self::FLAG_DOWNTIME | self::FLAG_ACK))) { $sort |= self::FLAG_NONE; } + return $sort; }