From 9750e132349bf9232a66af27ebe7b1fa1a814b70 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 20 Feb 2017 14:41:15 +0100 Subject: [PATCH] BpNode, process/show: error for missing children... ...and unknown as state fixes #105 --- application/controllers/ProcessController.php | 19 +++++++++++++++++++ library/Businessprocess/BpConfig.php | 10 ++++++++++ library/Businessprocess/BpNode.php | 3 +++ 3 files changed, 32 insertions(+) diff --git a/application/controllers/ProcessController.php b/application/controllers/ProcessController.php index be8b7db..7d8357d 100644 --- a/application/controllers/ProcessController.php +++ b/application/controllers/ProcessController.php @@ -96,8 +96,13 @@ class ProcessController extends Controller } $this->prepareControls($bp, $renderer); + $missing = $bp->getMissingChildren(); + if (! empty($missing)) { + $bp->addError(sprintf('There are missing nodes: %s', implode(', ', $missing))); + } $this->content()->addContent($this->showHints($bp)); $this->content()->addContent($this->showWarnings($bp)); + $this->content()->addContent($this->showErrors($bp)); $this->content()->add($renderer); $this->loadActionForm($bp, $node); $this->setDynamicAutorefresh(); @@ -264,6 +269,20 @@ class ProcessController extends Controller } } + protected function showErrors(BpConfig $bp) + { + if ($bp->hasWarnings()) { + $ul = Element::create('ul', array('class' => 'error')); + foreach ($bp->getErrors() as $msg) { + $ul->createElement('li')->addContent($msg); + } + + return $ul; + } else { + return null; + } + } + protected function showHints(BpConfig $bp) { $ul = Element::create('ul', array('class' => 'error')); diff --git a/library/Businessprocess/BpConfig.php b/library/Businessprocess/BpConfig.php index ba33934..6584523 100644 --- a/library/Businessprocess/BpConfig.php +++ b/library/Businessprocess/BpConfig.php @@ -464,6 +464,16 @@ class BpConfig return $this->createBp($name)->setMissing(); } + public function getMissingChildren() + { + $missing = array(); + foreach ($this->getRootNodes() as $root) { + $missing += $root->getMissingChildren(); + } + + return $missing; + } + public function createImportedNode($config, $name = null) { $params = (object) array('configName' => $config); diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index d83aa9d..61888c0 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -336,6 +336,9 @@ class BpNode extends Node $sort_states[] = $child->getSortingState(); $lastStateChange = max($lastStateChange, $child->getLastStateChange()); $bp->endLoopDetection($this->name); + if ($child instanceof MonitoredNode && $child->isMissing()) { + $child->setState(self::ICINGA_UNKNOWN); + } } $this->setLastStateChange($lastStateChange);