summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Widget/Detail/HostDetail.php
blob: 875743673a59cc548eb0cb77af7f7f0265e2cc2f (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
<?php

/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Widget\Detail;

use Icinga\Module\Icingadb\Hook\ExtensionHook\ObjectDetailExtensionHook;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\ServicestateSummary;
use Icinga\Module\Icingadb\Widget\EmptyState;
use ipl\Html\Html;
use ipl\Stdlib\Filter;

class HostDetail extends ObjectDetail
{
    protected $serviceSummary;

    public function __construct(Host $object, ServicestateSummary $serviceSummary)
    {
        parent::__construct($object);

        $this->serviceSummary = $serviceSummary;
    }

    protected function createServiceStatistics(): array
    {
        if ($this->serviceSummary->services_total > 0) {
            $services = new ServiceStatistics($this->serviceSummary);
            $services->setBaseFilter(Filter::equal('host.name', $this->object->name));
        } else {
            $services = new EmptyState(t('This host has no services'));
        }

        return [Html::tag('h2', t('Services')), $services];
    }

    protected function assemble()
    {
        if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') {
            $this->add($this->createPrintHeader());
        }

        $this->add(ObjectDetailExtensionHook::injectExtensions([
            0   => $this->createPluginOutput(),
            190 => $this->createServiceStatistics(),
            300 => $this->createActions(),
            301 => $this->createNotes(),
            400 => $this->createComments(),
            401 => $this->createDowntimes(),
            500 => $this->createGroups(),
            501 => $this->createNotifications(),
            600 => $this->createCheckStatistics(),
            601 => $this->createPerformanceData(),
            700 => $this->createCustomVars(),
            701 => $this->createFeatureToggles()
        ], $this->createExtensions()));
    }
}