mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-05 21:29:33 -05:00
Merge pull request #334 from Icinga/enhance-detail-view-integration
Enhance detail view integration
This commit is contained in:
commit
104e2ab488
4 changed files with 148 additions and 11 deletions
49
doc/10-Monitoring.md
Normal file
49
doc/10-Monitoring.md
Normal file
|
|
@ -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 <process> [options]`
|
||||
|
||||
Options:
|
||||
|
||||
```
|
||||
--config <configname> Name of the config that contains <process>
|
||||
--details Show problem details as a tree
|
||||
--colors Show colored output
|
||||
--state-type <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 `<process>` being checked |
|
||||
| businessprocess\_config | Yes | Name of the config that contains `<process>` |
|
||||
| businessprocess\_as\_tree | No | Whether to show `<process>` as tree or tiles |
|
||||
|
|
@ -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['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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 '<h2>Business Process</h2>' . $renderer;
|
||||
|
|
|
|||
1
run.php
1
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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue