diff --git a/configuration.php b/configuration.php index 4615bd4f..6ef510e7 100644 --- a/configuration.php +++ b/configuration.php @@ -1,9 +1,11 @@ menuSection(N_('Business Processes'), array( + 'renderer' => 'ProcessesProblemsBadge', 'url' => 'businessprocess', 'icon' => 'sitemap', 'priority' => 46 @@ -30,6 +32,7 @@ } $section->add($meta->getTitle(), array( + 'renderer' => (new ProcessProblemsBadge())->setBpConfigName($name), 'url' => 'businessprocess/process/show', 'urlParameters' => array('config' => $name), 'priority' => $prio diff --git a/library/Businessprocess/Web/Navigation/Renderer/ProcessProblemsBadge.php b/library/Businessprocess/Web/Navigation/Renderer/ProcessProblemsBadge.php new file mode 100644 index 00000000..a31a74b0 --- /dev/null +++ b/library/Businessprocess/Web/Navigation/Renderer/ProcessProblemsBadge.php @@ -0,0 +1,61 @@ +count === null) { + $storage = LegacyStorage::getInstance(); + $count = 0; + $bp = $storage->loadProcess($this->getBpConfigName()); + + + foreach ($bp->getRootNodes() as $rootNode) { + if (! $rootNode->isEmpty() && + $rootNode->getState() !== $rootNode::ICINGA_PENDING + && $rootNode->hasProblems()) { + $count++; + } + } + + $this->count = $count; + $this->setState(self::STATE_CRITICAL); + } + + if ($count) { + $this->setTitle(sprintf( + tp('One unhandled root node critical', '%d unhandled root nodes critical', $count), + $count + )); + } + + return $this->count; + } + + public function setBpConfigName($bpConfigName) + { + $this->bpConfigName = $bpConfigName; + + return $this; + } + + public function getBpConfigName() + { + return $this->bpConfigName; + } +} diff --git a/library/Businessprocess/Web/Navigation/Renderer/ProcessesProblemsBadge.php b/library/Businessprocess/Web/Navigation/Renderer/ProcessesProblemsBadge.php new file mode 100644 index 00000000..dd419a22 --- /dev/null +++ b/library/Businessprocess/Web/Navigation/Renderer/ProcessesProblemsBadge.php @@ -0,0 +1,53 @@ +count === null) { + $storage = LegacyStorage::getInstance(); + $count = 0; + + foreach ($storage->listProcessNames() as $processName) { + $bp = $storage->loadProcess($processName); + if (Module::exists('icingadb') && + (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend()) + ) { + IcingaDbState::apply($bp); + } else { + MonitoringState::apply($bp); + } + + foreach ($bp->getRootNodes() as $rootNode) { + if (! $rootNode->isEmpty() && + $rootNode->getState() !== $rootNode::ICINGA_PENDING + && $rootNode->hasProblems()) { + $count++; + break; + } + } + } + + $this->count = $count; + $this->setState(self::STATE_CRITICAL); + } + + return $this->count; + } +}