mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-03 04:09:35 -05:00
Monitoring/DetailViewExtension: Update implementation
This commit is contained in:
parent
fde37a35c6
commit
f62364b772
2 changed files with 20 additions and 28 deletions
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\ProvidedHook;
|
||||
namespace Icinga\Module\Businessprocess\ProvidedHook\Monitoring;
|
||||
|
||||
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\Hook\DetailviewExtensionHook;
|
||||
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
|
||||
class Grapher extends GrapherHook
|
||||
class DetailviewExtension extends DetailviewExtensionHook
|
||||
{
|
||||
|
||||
/**
|
||||
* @var $storage LegacyStorage
|
||||
*/
|
||||
|
|
@ -27,55 +25,49 @@ class Grapher extends GrapherHook
|
|||
{
|
||||
try {
|
||||
$this->storage = new LegacyStorage(
|
||||
Config::module('businessprocess')->getSection('global')
|
||||
$this->getModule()->getConfig()->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)
|
||||
public function getHtmlForObject(MonitoredObject $object)
|
||||
{
|
||||
if (!$this->has($object) || !$this->storage) {
|
||||
if (! isset($this->storage)
|
||||
|| ! $object instanceof Service
|
||||
|| $object->check_command !== 'icingacli-businessprocess'
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$bpName = $object->_service_icingacli_businessprocess_process;
|
||||
if (! $bpName) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$bp = $this->storage->loadProcess($bpName);
|
||||
|
||||
MonitoringState::apply($bp);
|
||||
|
||||
if (filter_var($object->_service_icingacli_businessprocess_grapher_tree, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$renderer = new TreeRenderer($bp);
|
||||
$tag = 'ul';
|
||||
} else {
|
||||
$renderer = new TileRenderer($bp);
|
||||
$tag = 'div';
|
||||
}
|
||||
|
||||
$renderer->setBaseUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $bpName));
|
||||
$renderer->setUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $bpName));
|
||||
$renderer->ensureAssembled()->getFirst($tag)->setAttribute('data-base-target', '_next');
|
||||
|
||||
$html = '<div class="icinga-module module-businessprocess"><h2>Business Process</h2>';
|
||||
$html = $html . $renderer->render() . '</div>';
|
||||
return $html;
|
||||
return '<h2>Business Process</h2>' . $renderer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
run.php
2
run.php
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
$this->provideHook('monitoring/HostActions');
|
||||
$this->provideHook('monitoring/ServiceActions');
|
||||
$this->provideHook('monitoring/DetailviewExtension');
|
||||
$this->provideHook('icingadb/HostActions');
|
||||
$this->provideHook('icingadb/ServiceActions');
|
||||
$this->provideHook('icingadb/icingadbSupport');
|
||||
$this->provideHook('grapher');
|
||||
//$this->provideHook('director/shipConfigFiles');
|
||||
|
|
|
|||
Loading…
Reference in a new issue