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 | |
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')
7 files changed, 261 insertions, 0 deletions
diff --git a/library/Businessprocess/ProvidedHook/Icingadb/HostActions.php b/library/Businessprocess/ProvidedHook/Icingadb/HostActions.php new file mode 100644 index 0000000..ac18959 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Icingadb/HostActions.php @@ -0,0 +1,23 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Icingadb; + +use Icinga\Module\Businessprocess\BpConfig; +use Icinga\Module\Icingadb\Hook\HostActionsHook; +use Icinga\Module\Icingadb\Model\Host; +use ipl\Web\Widget\Link; + +class HostActions extends HostActionsHook +{ + public function getActionsForObject(Host $host): array + { + $label = mt('businessprocess', 'Business Impact'); + return array( + new Link( + $label, + 'businessprocess/node/impact?name=' + . rawurlencode(BpConfig::joinNodeName($host->name, 'Hoststatus')) + ) + ); + } +} diff --git a/library/Businessprocess/ProvidedHook/Icingadb/IcingadbSupport.php b/library/Businessprocess/ProvidedHook/Icingadb/IcingadbSupport.php new file mode 100644 index 0000000..1ff37d3 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Icingadb/IcingadbSupport.php @@ -0,0 +1,10 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Icingadb; + +use Icinga\Module\Icingadb\Hook\IcingadbSupportHook; + +class IcingadbSupport extends IcingadbSupportHook +{ + +} diff --git a/library/Businessprocess/ProvidedHook/Icingadb/ServiceActions.php b/library/Businessprocess/ProvidedHook/Icingadb/ServiceActions.php new file mode 100644 index 0000000..d416d90 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Icingadb/ServiceActions.php @@ -0,0 +1,25 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Icingadb; + +use Icinga\Module\Businessprocess\BpConfig; +use Icinga\Module\Icingadb\Hook\ServiceActionsHook; +use Icinga\Module\Icingadb\Model\Service; +use ipl\Web\Widget\Link; + +class ServiceActions extends ServiceActionsHook +{ + public function getActionsForObject(Service $service): array + { + $label = mt('businessprocess', 'Business Impact'); + return array( + new Link( + $label, + sprintf( + 'businessprocess/node/impact?name=%s', + rawurlencode(BpConfig::joinNodeName($service->host->name, $service->name)) + ) + ) + ); + } +} diff --git a/library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php b/library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php new file mode 100644 index 0000000..6d10af2 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php @@ -0,0 +1,77 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Icingadb; + +use Icinga\Module\Businessprocess\Renderer\TileRenderer; +use Icinga\Module\Businessprocess\Renderer\TreeRenderer; +use Icinga\Module\Businessprocess\State\IcingaDbState; +use Icinga\Module\Businessprocess\Storage\LegacyStorage; +use Icinga\Module\Businessprocess\Web\Url; +use Icinga\Module\Icingadb\Hook\ServiceDetailExtensionHook; +use Icinga\Module\Icingadb\Model\Service; +use ipl\Html\Html; +use ipl\Html\HtmlDocument; +use ipl\Html\HtmlString; +use ipl\Html\ValidHtml; + +class ServiceDetailExtension extends ServiceDetailExtensionHook +{ + /** @var ?LegacyStorage */ + private $storage; + + /** @var string */ + private $commandName; + + protected function init() + { + $this->setSection(self::GRAPH_SECTION); + + 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 + } + } + + public function getHtmlForObject(Service $service): ValidHtml + { + if (! isset($this->storage) + || $service->checkcommand_name !== $this->commandName + ) { + return HtmlString::create(''); + } + + $bpName = $service->customvars['icingacli_businessprocess_config'] ?? null; + if (! $bpName) { + $bpName = key($this->storage->listProcessNames()); + } + + $nodeName = $service->customvars['icingacli_businessprocess_process'] ?? null; + if (! $nodeName) { + return HtmlString::create(''); + } + + $bp = $this->storage->loadProcess($bpName); + $node = $bp->getBpNode($nodeName); + + IcingaDbState::apply($bp); + + if ($service->customvars['icingaweb_businessprocess_as_tree'] ?? false) { + $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 (new HtmlDocument())->addHtml(Html::tag('h2', 'Business Process'), $renderer); + } +} 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; + } +} diff --git a/library/Businessprocess/ProvidedHook/Monitoring/HostActions.php b/library/Businessprocess/ProvidedHook/Monitoring/HostActions.php new file mode 100644 index 0000000..e2b9c59 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Monitoring/HostActions.php @@ -0,0 +1,19 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Monitoring; + +use Icinga\Module\Businessprocess\BpConfig; +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(BpConfig::joinNodeName($host->getName(), 'Hoststatus')) + ); + } +} diff --git a/library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php b/library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php new file mode 100644 index 0000000..ce9fabf --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Monitoring/ServiceActions.php @@ -0,0 +1,24 @@ +<?php + +namespace Icinga\Module\Businessprocess\ProvidedHook\Monitoring; + +use Exception; +use Icinga\Application\Config; +use Icinga\Module\Businessprocess\BpConfig; +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(BpConfig::joinNodeName($service->getHost()->getName(), $service->getName())) + ) + ); + } +} |