summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/ProvidedHook/Icingadb
diff options
context:
space:
mode:
Diffstat (limited to 'library/Businessprocess/ProvidedHook/Icingadb')
-rw-r--r--library/Businessprocess/ProvidedHook/Icingadb/HostActions.php23
-rw-r--r--library/Businessprocess/ProvidedHook/Icingadb/IcingadbSupport.php10
-rw-r--r--library/Businessprocess/ProvidedHook/Icingadb/ServiceActions.php25
-rw-r--r--library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php77
4 files changed, 135 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);
+ }
+}