summaryrefslogtreecommitdiffstats
path: root/application/controllers/DowntimeController.php
blob: a0a7fa07098ad09c6f582e6ff4e81dea7b4c8470 (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
78
79
80
81
82
83
84
<?php

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

namespace Icinga\Module\Icingadb\Controllers;

use Icinga\Exception\NotFoundError;
use Icinga\Module\Icingadb\Common\CommandActions;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\Downtime;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\DowntimeDetail;
use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList;
use ipl\Stdlib\Filter;
use ipl\Web\Url;

class DowntimeController extends Controller
{
    use CommandActions;

    /** @var Downtime */
    protected $downtime;

    public function init()
    {
        $this->addTitleTab(t('Downtime'));

        $name = $this->params->getRequired('name');

        $query = Downtime::on($this->getDb())->with([
            'host',
            'host.state',
            'service',
            'service.state',
            'service.host',
            'service.host.state',
            'parent',
            'parent.host',
            'parent.host.state',
            'parent.service',
            'parent.service.state',
            'triggered_by',
            'triggered_by.host',
            'triggered_by.host.state',
            'triggered_by.service',
            'triggered_by.service.state'
        ]);
        $query->filter(Filter::equal('downtime.name', $name));

        $this->applyRestrictions($query);

        $downtime = $query->first();
        if ($downtime === null) {
            throw new NotFoundError(t('Downtime not found'));
        }

        $this->downtime = $downtime;
    }

    public function indexAction()
    {
        $detail = new DowntimeDetail($this->downtime);

        $this->addControl((new DowntimeList([$this->downtime]))
            ->setViewMode('minimal')
            ->setDetailActionsDisabled()
            ->setCaptionDisabled()
            ->setNoSubjectLink());

        $this->addContent($detail);

        $this->setAutorefreshInterval(10);
    }

    protected function fetchCommandTargets(): array
    {
        return [$this->downtime];
    }

    protected function getCommandTargetsUrl(): Url
    {
        return Links::downtime($this->downtime);
    }
}