2017-01-10 10:49:53 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Controllers;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
|
|
|
|
|
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
2017-01-11 10:55:05 -05:00
|
|
|
use Icinga\Module\Businessprocess\Simulation;
|
|
|
|
|
use Icinga\Module\Businessprocess\State\MonitoringState;
|
2017-01-10 10:49:53 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Controller;
|
|
|
|
|
use Icinga\Module\Businessprocess\Web\Url;
|
|
|
|
|
|
|
|
|
|
class NodeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function impactAction()
|
|
|
|
|
{
|
2017-01-11 10:55:05 -05:00
|
|
|
$this->setAutorefreshInterval(10);
|
2017-01-10 10:49:53 -05:00
|
|
|
$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);
|
|
|
|
|
|
2017-01-26 15:37:09 -05:00
|
|
|
$simulation = Simulation::fromSession($this->session());
|
2017-01-10 10:49:53 -05:00
|
|
|
foreach ($this->storage()->listProcessNames() as $configName) {
|
|
|
|
|
$config = $this->storage()->loadProcess($configName);
|
|
|
|
|
|
2019-02-21 06:34:07 -05:00
|
|
|
$parents = [];
|
|
|
|
|
if ($config->hasNode($name)) {
|
|
|
|
|
foreach ($config->getNode($name)->getPaths() as $path) {
|
|
|
|
|
array_pop($path); // Remove the monitored node
|
|
|
|
|
$immediateParentName = array_pop($path); // The directly affected process
|
|
|
|
|
$parents[] = [$config->getNode($immediateParentName), $path];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$askedConfigs = [];
|
|
|
|
|
foreach ($config->getImportedNodes() as $importedNode) {
|
|
|
|
|
$importedConfig = $importedNode->getBpConfig();
|
|
|
|
|
|
|
|
|
|
if (isset($askedConfigs[$importedConfig->getName()])) {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
$askedConfigs[$importedConfig->getName()] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($importedConfig->hasNode($name)) {
|
|
|
|
|
$node = $importedConfig->getNode($name);
|
2019-02-25 07:58:18 -05:00
|
|
|
$nativePaths = $node->getPaths($config);
|
2019-02-21 06:34:07 -05:00
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
$path = array_pop($nativePaths);
|
|
|
|
|
$importedNodePos = array_search($importedNode->getIdentifier(), $path, true);
|
|
|
|
|
if ($importedNodePos !== false) {
|
|
|
|
|
array_pop($path); // Remove the monitored node
|
|
|
|
|
$immediateParentName = array_pop($path); // The directly affected process
|
|
|
|
|
$importedPath = array_slice($path, $importedNodePos + 1);
|
2019-02-25 07:58:18 -05:00
|
|
|
foreach ($importedNode->getPaths($config) as $targetPath) {
|
2019-02-21 06:34:07 -05:00
|
|
|
if ($targetPath[count($targetPath) - 1] === $immediateParentName) {
|
|
|
|
|
array_pop($targetPath);
|
|
|
|
|
$parent = $importedNode;
|
|
|
|
|
} else {
|
|
|
|
|
$parent = $importedConfig->getNode($immediateParentName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$parents[] = [$parent, array_merge($targetPath, $importedPath)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We may get multiple native paths. Though, the right hand of the path is everywhere the
|
|
|
|
|
// same and the left hand not of any interest since that's where the import location is.
|
|
|
|
|
break; // So, once we've found a match, we're done here (Otherwise we'll get duplicates)
|
|
|
|
|
}
|
|
|
|
|
} while (! empty($nativePaths));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($parents)) {
|
2017-01-10 10:49:53 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 10:55:05 -05:00
|
|
|
MonitoringState::apply($config);
|
|
|
|
|
$config->applySimulation($simulation);
|
|
|
|
|
|
2019-02-21 06:34:07 -05:00
|
|
|
foreach ($parents as $parentAndPath) {
|
|
|
|
|
$renderer = (new TileRenderer($config, array_shift($parentAndPath)))
|
|
|
|
|
->setUrl(Url::fromPath('businessprocess/process/show', ['config' => $configName]))
|
|
|
|
|
->setPath(array_shift($parentAndPath));
|
2017-01-10 10:49:53 -05:00
|
|
|
|
|
|
|
|
$bc = Breadcrumb::create($renderer);
|
2019-02-21 08:01:29 -05:00
|
|
|
$bc->getAttributes()
|
|
|
|
|
->set('data-base-target', '_next')
|
|
|
|
|
->add('class', 'with-states');
|
2017-01-10 10:49:53 -05:00
|
|
|
$content->add($bc);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-19 02:45:39 -05:00
|
|
|
|
|
|
|
|
if ($content->isEmpty()) {
|
|
|
|
|
$content->add($this->translate('No impact detected. Is this node part of a business process?'));
|
|
|
|
|
}
|
2017-01-10 10:49:53 -05:00
|
|
|
}
|
|
|
|
|
}
|