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;
|
2020-12-03 11:05:51 -05:00
|
|
|
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()
|
|
|
|
|
{
|
2021-04-07 06:34:09 -04:00
|
|
|
$this->assertRouteAccess('servicegroups');
|
|
|
|
|
|
2020-04-24 08:36:37 -04:00
|
|
|
$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
|
|
|
|
2021-03-19 10:42:15 -04:00
|
|
|
foreach ($query->getUnions() as $unionPart) {
|
|
|
|
|
$unionPart->filter(Filter::equal('servicegroup.name', $name));
|
|
|
|
|
}
|
2019-11-04 17:30:56 -05:00
|
|
|
|
2021-01-28 06:38:03 -05:00
|
|
|
$this->applyRestrictions($query);
|
2019-11-22 10:01:27 -05:00
|
|
|
|
2019-11-04 17:30:56 -05:00
|
|
|
$servicegroup = $query->first();
|
|
|
|
|
if ($servicegroup === null) {
|
2020-04-24 08:36:37 -04:00
|
|
|
throw new NotFoundError(t('Service group not found'));
|
2019-11-04 17:30:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->servicegroup = $servicegroup;
|
|
|
|
|
}
|
2019-12-11 02:59:30 -05:00
|
|
|
|
2019-11-04 17:30:56 -05:00
|
|
|
public function indexAction()
|
|
|
|
|
{
|
|
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
|
|
|
|
$services = Service::on($db)->with([
|
|
|
|
|
'state',
|
|
|
|
|
'host',
|
|
|
|
|
'host.state'
|
2020-03-06 08:49:19 -05:00
|
|
|
])->utilize('servicegroup');
|
2019-11-04 17:30:56 -05:00
|
|
|
|
2020-03-06 08:49:19 -05:00
|
|
|
$services->getSelectBase()->where(['service_servicegroup.id = ?' => $this->servicegroup->id]);
|
2021-01-28 06:38:03 -05:00
|
|
|
$this->applyRestrictions($services);
|
2019-11-22 10:01:27 -05:00
|
|
|
|
2019-11-04 17:30:56 -05:00
|
|
|
$limitControl = $this->createLimitControl();
|
|
|
|
|
$paginationControl = $this->createPaginationControl($services);
|
2021-06-23 09:09:22 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
2019-11-04 17:30:56 -05:00
|
|
|
|
|
|
|
|
$serviceList = (new ServiceList($services))
|
|
|
|
|
->setViewMode($viewModeSwitcher->getViewMode());
|
|
|
|
|
|
|
|
|
|
yield $this->export($services);
|
|
|
|
|
|
2021-04-29 10:55:19 -04:00
|
|
|
$this->addControl((new ServicegroupList([$this->servicegroup]))
|
|
|
|
|
->setViewMode('minimal')
|
|
|
|
|
->setDetailActionsDisabled()
|
|
|
|
|
->setNoSubjectLink());
|
2019-11-04 17:30:56 -05:00
|
|
|
$this->addControl($paginationControl);
|
|
|
|
|
$this->addControl($viewModeSwitcher);
|
|
|
|
|
$this->addControl($limitControl);
|
|
|
|
|
|
|
|
|
|
$this->addContent($serviceList);
|
2019-12-11 02:59:30 -05:00
|
|
|
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
2019-11-04 17:30:56 -05:00
|
|
|
}
|
|
|
|
|
}
|