icingadb-web/application/controllers/ServicegroupController.php

76 lines
2.2 KiB
PHP
Raw Normal View History

2019-11-04 17:30:56 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2019-11-04 17:30:56 -05:00
use Icinga\Exception\NotFoundError;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\Service;
2019-11-05 03:22:58 -05:00
use Icinga\Module\Icingadb\Model\ServicegroupSummary;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ServiceList;
use Icinga\Module\Icingadb\Widget\ItemList\ServicegroupList;
2019-11-04 17:30:56 -05:00
use ipl\Orm\Compat\FilterProcessor;
use ipl\Stdlib\Filter;
2019-11-04 17:30:56 -05:00
class ServicegroupController extends Controller
{
2019-11-05 03:22:58 -05:00
/** @var ServicegroupSummary The service group object */
2019-11-04 17:30:56 -05:00
protected $servicegroup;
public function init()
{
$this->setTitle(t('Service Group'));
2019-11-04 17:30:56 -05:00
$name = $this->params->shiftRequired('name');
2019-11-05 03:22:58 -05:00
$query = ServicegroupSummary::on($this->getDb());
2019-11-04 17:30:56 -05:00
FilterProcessor::apply(
Filter::equal('servicegroup.name', $name),
2019-11-04 17:30:56 -05:00
$query
);
$this->applyMonitoringRestriction($query);
2019-11-04 17:30:56 -05:00
$servicegroup = $query->first();
if ($servicegroup === null) {
throw new NotFoundError(t('Service group not found'));
2019-11-04 17:30:56 -05:00
}
$this->servicegroup = $servicegroup;
}
2019-11-04 17:30:56 -05:00
public function indexAction()
{
$db = $this->getDb();
$services = Service::on($db)->with([
'state',
'host',
'host.state'
])->utilize('servicegroup');
2019-11-04 17:30:56 -05:00
$services->getSelectBase()->where(['service_servicegroup.id = ?' => $this->servicegroup->id]);
$this->applyMonitoringRestriction($services);
2019-11-04 17:30:56 -05:00
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($services);
$viewModeSwitcher = $this->createViewModeSwitcher();
$serviceList = (new ServiceList($services))
->setViewMode($viewModeSwitcher->getViewMode());
yield $this->export($services);
2019-12-18 08:32:14 -05:00
$this->addControl((new ServicegroupList([$this->servicegroup]))->setViewMode('minimal'));
2019-11-04 17:30:56 -05:00
$this->addControl($paginationControl);
$this->addControl($viewModeSwitcher);
$this->addControl($limitControl);
$this->addContent($serviceList);
$this->setAutorefreshInterval(10);
2019-11-04 17:30:56 -05:00
}
}