From b3df39d1b076721f6ea5e6da84915ff1b4b1a18c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 10 Jan 2017 16:49:53 +0100 Subject: [PATCH] NodeController: add business impact action Show all paths to a specific node to visualize it's business impact fixes #8573 --- application/controllers/NodeController.php | 50 +++++++++++++++++++ library/Businessprocess/Node.php | 20 +++++++- .../ProvidedHook/Monitoring/HostActions.php | 18 +++++++ .../Monitoring/ServiceActions.php | 25 ++++++++++ library/Businessprocess/Web/Controller.php | 14 +++++- run.php | 2 + 6 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 application/controllers/NodeController.php create mode 100644 library/Businessprocess/ProvidedHook/Monitoring/HostActions.php create mode 100644 library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php diff --git a/application/controllers/NodeController.php b/application/controllers/NodeController.php new file mode 100644 index 0000000..d2dc8b6 --- /dev/null +++ b/application/controllers/NodeController.php @@ -0,0 +1,50 @@ +content(); + $this->controls()->add( + $this->singleTab($this->translate('Node Impact')) + ); + $name = $this->params->get('name'); + $this->addTitle($this->translate('Business Impact (%s)'), $name); + + foreach ($this->storage()->listProcessNames() as $configName) { + $config = $this->storage()->loadProcess($configName); + + // TODO: Fix issues with children, they do not exist unless resolved :-/ + // This is a workaround: + foreach ($config->getRootNodes() as $node) { + $node->getState(); + } + + if (! $config->hasNode($name)) { + continue; + } + + foreach ($config->getNode($name)->getPaths() as $path) { + $node = array_pop($path); + $renderer = new TileRenderer($config, $config->getNode($node)); + $renderer->setUrl( + Url::fromPath( + 'businessprocess/process/show', + array('config' => $configName) + ) + )->setPath($path); + + $bc = Breadcrumb::create($renderer); + $bc->attributes()->set('data-base-target', '_next'); + $content->add($bc); + } + } + } +} diff --git a/library/Businessprocess/Node.php b/library/Businessprocess/Node.php index 0d3794d..7062c97 100644 --- a/library/Businessprocess/Node.php +++ b/library/Businessprocess/Node.php @@ -309,15 +309,33 @@ abstract class Node ); } + /** + * @return Node[] + */ public function getParents() { return $this->parents; } + /** + * @return array + */ public function getPaths() { + if ($this->bp->hasRootNode($this->getName())) { + return array(array($this->getName())); + } + + $paths = array(); + foreach ($this->parents as $parent) { + foreach ($parent->getPaths() as $path) { + // $path[] = $this->getName(); + $paths[] = $path; + } + + } // TODO! -> for delete etc - return $this->parents; + return $paths; } protected function stateToSortState($state) diff --git a/library/Businessprocess/ProvidedHook/Monitoring/HostActions.php b/library/Businessprocess/ProvidedHook/Monitoring/HostActions.php new file mode 100644 index 0000000..57ce8f5 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Monitoring/HostActions.php @@ -0,0 +1,18 @@ + 'businessprocess/node/impact?name=' + . rawurlencode($host->getName() . ';Hoststatus') + ); + } +} diff --git a/library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php b/library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php new file mode 100644 index 0000000..69a93ae --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php @@ -0,0 +1,25 @@ + sprintf( + 'businessprocess/node/impact?name=%s', + rawurlencode( + sprintf('%s;%s', $service->getHost()->getName(), $service->getName()) + ) + ) + ); + } +} diff --git a/library/Businessprocess/Web/Controller.php b/library/Businessprocess/Web/Controller.php index abb2ab9..7748d7f 100644 --- a/library/Businessprocess/Web/Controller.php +++ b/library/Businessprocess/Web/Controller.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Businessprocess\Web; use Icinga\Application\Icinga; use Icinga\Module\Businessprocess\BusinessProcess; +use Icinga\Module\Businessprocess\Html\HtmlTag; use Icinga\Module\Businessprocess\Modification\ProcessChanges; use Icinga\Module\Businessprocess\Storage\LegacyStorage; use Icinga\Module\Businessprocess\Storage\Storage; @@ -42,8 +43,8 @@ class Controller extends ModuleController if (! $m->hasLoaded('monitoring') && $m->hasInstalled('monitoring')) { $m->loadModule('monitoring'); } - $this->view->errors = array(); - + $this->controls(); + $this->content(); $this->url(); $this->view->showFullscreen = $this->showFullscreen @@ -175,6 +176,15 @@ class Controller extends ModuleController return $this; } + protected function addTitle($title) + { + $args = func_get_args(); + array_shift($args); + $this->view->title = vsprintf($title, $args); + $this->controls()->add(HtmlTag::h1($this->view->title)); + return $this; + } + protected function loadModifiedBpConfig() { $bp = $this->loadBpConfig(); diff --git a/run.php b/run.php index 0daf506..2cde2ee 100644 --- a/run.php +++ b/run.php @@ -1,3 +1,5 @@ provideHook('monitoring/HostActions'); +$this->provideHook('monitoring/ServiceActions'); //$this->provideHook('director/shipConfigFiles');