diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:15:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:15:40 +0000 |
commit | b7fd908d538ed19fe41f03c0a3f93351d8da64e9 (patch) | |
tree | 46e14f318948cd4f5d7e874f83e7dfcc5d42fc64 /library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-businessprocess-upstream.tar.xz icingaweb2-module-businessprocess-upstream.zip |
Adding upstream version 2.5.0.upstream/2.5.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php')
-rw-r--r-- | library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php b/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php new file mode 100644 index 0000000..691acec --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php @@ -0,0 +1,83 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Monitoring; + +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 DetailviewExtension extends DetailviewExtensionHook +{ + /** @var ?LegacyStorage */ + private $storage; + + /** @var string */ + private $commandName; + + /** + * Initialize storage + */ + public function init() + { + try { + $this->storage = LegacyStorage::getInstance(); + $this->commandName = $this->getModule()->getConfig()->get( + 'DetailviewExtension', + 'checkcommand_name', + 'icingacli-businessprocess' + ); + } catch (\Exception $e) { + // Ignore and don't display anything + } + } + + /** + * Returns the rendered Tree-/TileRenderer HTML + * + * @param MonitoredObject $object + * + * @return string + */ + public function getHtmlForObject(MonitoredObject $object) + { + if (! isset($this->storage) + || ! $object instanceof Service + || $object->check_command !== $this->commandName + ) { + return ''; + } + + $bpName = $object->_service_icingacli_businessprocess_config; + if (! $bpName) { + $bpName = key($this->storage->listProcessNames()); + } + + $nodeName = $object->_service_icingacli_businessprocess_process; + if (! $nodeName) { + return ''; + } + + $bp = $this->storage->loadProcess($bpName); + $node = $bp->getBpNode($nodeName); + + MonitoringState::apply($bp); + + if (filter_var($object->_service_icingaweb_businessprocess_as_tree, FILTER_VALIDATE_BOOLEAN)) { + $renderer = new TreeRenderer($bp, $node); + $tag = 'ul'; + } else { + $renderer = new TileRenderer($bp, $node); + $tag = 'div'; + } + + $renderer->setUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $nodeName)); + $renderer->ensureAssembled()->getFirst($tag)->setAttribute('data-base-target', '_next'); + + return '<h2>Business Process</h2>' . $renderer; + } +} |