mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-25 09:09:34 -05:00
Added Grapher
This commit is contained in:
parent
be0aa5d6f4
commit
bc54d59146
1 changed files with 81 additions and 0 deletions
81
library/Businessprocess/ProvidedHook/Grapher.php
Normal file
81
library/Businessprocess/ProvidedHook/Grapher.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\ProvidedHook;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Hook\GrapherHook;
|
||||
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
||||
use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
use Icinga\Module\Businessprocess\Web\Url;
|
||||
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
|
||||
class Grapher extends GrapherHook
|
||||
{
|
||||
|
||||
/**
|
||||
* @var $storage LegacyStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* Initialize storage
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
try {
|
||||
$this->storage = new LegacyStorage(
|
||||
Config::module('businessprocess')->getSection('global')
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// Ignore and don't display anything
|
||||
}
|
||||
|
||||
$this->hasPreviews = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if the MonitoredObject is not a service or the check_command is not icingacli-businessprocess
|
||||
*
|
||||
* @param MonitoredObject $object
|
||||
* @return bool
|
||||
*/
|
||||
public function has(MonitoredObject $object)
|
||||
{
|
||||
return $object instanceof Service && $object->check_command == 'icingacli-businessprocess';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the rendered Tree-/TileRenderer HTML
|
||||
*
|
||||
* @param MonitoredObject $object
|
||||
* @return string
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*/
|
||||
public function getPreviewHtml(MonitoredObject $object)
|
||||
{
|
||||
if (!$this->has($object) || !$this->storage) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$bpName = $object->_service_icingacli_businessprocess_process;
|
||||
$bp = $this->storage->loadProcess($bpName);
|
||||
|
||||
MonitoringState::apply($bp);
|
||||
|
||||
if (filter_var($object->_service_icingacli_businessprocess_grapher_tree, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$renderer = new TreeRenderer($bp);
|
||||
} else {
|
||||
$renderer = new TileRenderer($bp);
|
||||
}
|
||||
|
||||
$renderer->setBaseUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $bpName));
|
||||
|
||||
$html = '<div class="icinga-module module-businessprocess"><h2>Business Process</h2>';
|
||||
$html = $html . $renderer->render() . '</div>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue