blob: 6d10af27c83938cc807b16bdaec3ddd0aa617606 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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);
}
}
|