icingadb-web/application/controllers/DowntimeController.php

85 lines
2.1 KiB
PHP
Raw Normal View History

2019-11-05 07:06:57 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-11-05 07:06:57 -05:00
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\Web\Url;
2019-11-05 07:06:57 -05:00
class DowntimeController extends Controller
{
use CommandActions;
/** @var Downtime */
protected $downtime;
public function init()
{
$this->setTitle(t('Downtime'));
2019-11-05 07:06:57 -05:00
$name = $this->params->getRequired('name');
2019-11-05 07:06:57 -05:00
$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'
]);
2019-11-05 07:06:57 -05:00
$query->getSelectBase()
->where(['downtime.name = ?' => $name]);
2019-11-05 07:06:57 -05:00
$this->applyRestrictions($query);
2019-11-05 07:06:57 -05:00
$downtime = $query->first();
if ($downtime === null) {
throw new NotFoundError(t('Downtime not found'));
2019-11-05 07:06:57 -05:00
}
$this->downtime = $downtime;
}
public function indexAction()
{
2019-12-16 08:29:32 -05:00
$detail = new DowntimeDetail($this->downtime);
2019-11-05 07:06:57 -05:00
$this->addControl((new DowntimeList([$this->downtime]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setCaptionDisabled()
->setNoSubjectLink());
2019-11-05 07:06:57 -05:00
2019-12-16 08:29:32 -05:00
$this->addContent($detail);
$this->setAutorefreshInterval(10);
2019-11-05 07:06:57 -05:00
}
protected function fetchCommandTargets(): array
2019-11-05 07:06:57 -05:00
{
return [$this->downtime];
}
protected function getCommandTargetsUrl(): Url
2019-11-05 07:06:57 -05:00
{
return Links::downtime($this->downtime);
}
}