From b2bc6b852e3b924df9b5cf890126e1be2d284b92 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 19 Jul 2022 16:19:07 +0200 Subject: [PATCH 1/3] Enhance DetailViewExtension * The checkcommand name can now be configured * The variable names are shortened * The config and process variables are now separate --- .../Monitoring/DetailviewExtension.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php b/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php index c781504..be7a185 100644 --- a/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php +++ b/library/Businessprocess/ProvidedHook/Monitoring/DetailviewExtension.php @@ -13,19 +13,23 @@ use Icinga\Module\Monitoring\Object\Service; class DetailviewExtension extends DetailviewExtensionHook { - /** - * @var $storage LegacyStorage - */ + /** @var LegacyStorage */ private $storage; + /** @var string */ + private $commandName; + /** * Initialize storage */ public function init() { try { - $this->storage = new LegacyStorage( - $this->getModule()->getConfig()->getSection('global') + $this->storage = LegacyStorage::getInstance(); + $this->commandName = $this->getModule()->getConfig()->get( + 'DetailviewExtension', + 'checkcommand_name', + 'icingacli-businessprocess' ); } catch (\Exception $e) { // Ignore and don't display anything @@ -43,29 +47,35 @@ class DetailviewExtension extends DetailviewExtensionHook { if (! isset($this->storage) || ! $object instanceof Service - || $object->check_command !== 'icingacli-businessprocess' + || $object->check_command !== $this->commandName ) { return ''; } - $bpName = $object->_service_icingacli_businessprocess_process; + $bpName = $object->_service_businessprocess_config; if (! $bpName) { return ''; } + $nodeName = $object->_service_businessprocess_process; + if (! $nodeName) { + return ''; + } + $bp = $this->storage->loadProcess($bpName); + $node = $bp->getBpNode($nodeName); MonitoringState::apply($bp); - if (filter_var($object->_service_icingacli_businessprocess_grapher_tree, FILTER_VALIDATE_BOOLEAN)) { - $renderer = new TreeRenderer($bp); + if (filter_var($object->_service_businessprocess_as_tree, FILTER_VALIDATE_BOOLEAN)) { + $renderer = new TreeRenderer($bp, $node); $tag = 'ul'; } else { - $renderer = new TileRenderer($bp); + $renderer = new TileRenderer($bp, $node); $tag = 'div'; } - $renderer->setUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $bpName)); + $renderer->setUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $nodeName)); $renderer->ensureAssembled()->getFirst($tag)->setAttribute('data-base-target', '_next'); return '

Business Process

' . $renderer; From b8de4580da41201a341b4d112fa30c83469d8ef8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 19 Jul 2022 16:20:56 +0200 Subject: [PATCH 2/3] Add detail integration for Icinga DB Web --- .../Icingadb/ServiceDetailExtension.php | 77 +++++++++++++++++++ run.php | 1 + 2 files changed, 78 insertions(+) create mode 100644 library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php diff --git a/library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php b/library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php new file mode 100644 index 0000000..ca6bc19 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Icingadb/ServiceDetailExtension.php @@ -0,0 +1,77 @@ +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['businessprocess_config'] ?? null; + if (! $bpName) { + return HtmlString::create(''); + } + + $nodeName = $service->customvars['businessprocess_process'] ?? null; + if (! $nodeName) { + return HtmlString::create(''); + } + + $bp = $this->storage->loadProcess($bpName); + $node = $bp->getBpNode($nodeName); + + IcingaDbState::apply($bp); + + if ($service->customvars['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/run.php b/run.php index dbe38fb..6cb81f8 100644 --- a/run.php +++ b/run.php @@ -6,4 +6,5 @@ $this->provideHook('monitoring/DetailviewExtension'); $this->provideHook('icingadb/HostActions'); $this->provideHook('icingadb/ServiceActions'); $this->provideHook('icingadb/icingadbSupport'); +$this->provideHook('icingadb/ServiceDetailExtension'); //$this->provideHook('director/shipConfigFiles'); From 4f1d447faa2e0a539f30effe531fedf3a28d17fc Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 19 Jul 2022 16:21:26 +0200 Subject: [PATCH 3/3] doc: Add monitoring chapter --- doc/10-Monitoring.md | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 doc/10-Monitoring.md diff --git a/doc/10-Monitoring.md b/doc/10-Monitoring.md new file mode 100644 index 0000000..b12a366 --- /dev/null +++ b/doc/10-Monitoring.md @@ -0,0 +1,49 @@ +# Monitoring + +## Process Check Command + +The module provides a CLI command to check a business process. + +### Usage + +General: `icingacli businessprocess process check [options]` + +Options: + +``` + --config Name of the config that contains + --details Show problem details as a tree + --colors Show colored output + --state-type Define which state type to look at. Could be either soft + or hard, overrides an eventually configured default + --blame Show problem details as a tree reduced to the nodes + which have the same state as the business process + --root-cause Used in combination with --blame. Only shows + the path of the nodes which are responsible + for the state of the business process + --downtime-is-ok Treat hosts/services in downtime always as UP/OK. + --ack-is-ok Treat acknowledged hosts/services always as UP/OK. +``` + +### Detail View Integration + +It is possible to show the monitored process in the service detail view. + +For this to work, the name of the checkcommand configured in Icinga 2 must either +be `icingacli-businessprocess` or the name that can be configured in the module +configuration: + +**/etc/icingaweb2/modules/businessprocess/config.ini** +```ini +[DetailviewExtension] +checkcommand_name=businessprocess-check +``` + +A service can define specific custom variables for this. Some are mandatory. +If they are not defined, the detail view integration won't be active. + +| Variable Name | Mandatory | Description | +|---------------------------|-----------|----------------------------------------------| +| businessprocess\_process | Yes | The `` being checked | +| businessprocess\_config | Yes | Name of the config that contains `` | +| businessprocess\_as\_tree | No | Whether to show `` as tree or tiles |