NodeController: add business impact action

Show all paths to a specific node to visualize it's business impact

fixes #8573
This commit is contained in:
Thomas Gelf 2017-01-10 16:49:53 +01:00
parent 6155bb5e2b
commit b3df39d1b0
6 changed files with 126 additions and 3 deletions

View file

@ -0,0 +1,50 @@
<?php
namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
use Icinga\Module\Businessprocess\Web\Controller;
use Icinga\Module\Businessprocess\Web\Url;
class NodeController extends Controller
{
public function impactAction()
{
$content = $this->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);
}
}
}
}

View file

@ -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)

View file

@ -0,0 +1,18 @@
<?php
namespace Icinga\Module\Businessprocess\ProvidedHook\Monitoring;
use Icinga\Module\Monitoring\Hook\HostActionsHook;
use Icinga\Module\Monitoring\Object\Host;
class HostActions extends HostActionsHook
{
public function getActionsForHost(Host $host)
{
$label = mt('businessprocess', 'Business Impact');
return array(
$label => 'businessprocess/node/impact?name='
. rawurlencode($host->getName() . ';Hoststatus')
);
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Icinga\Module\Businessprocess\ProvidedHook\Monitoring;
use Exception;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Hook\ServiceActionsHook;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Web\Url;
class ServiceActions extends ServiceActionsHook
{
public function getActionsForService(Service $service)
{
$label = mt('businessprocess', 'Business Impact');
return array(
$label => sprintf(
'businessprocess/node/impact?name=%s',
rawurlencode(
sprintf('%s;%s', $service->getHost()->getName(), $service->getName())
)
)
);
}
}

View file

@ -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();

View file

@ -1,3 +1,5 @@
<?php
$this->provideHook('monitoring/HostActions');
$this->provideHook('monitoring/ServiceActions');
//$this->provideHook('director/shipConfigFiles');