2019-11-04 17:30:38 -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:38 -05:00
|
|
|
|
|
|
|
|
use Icinga\Exception\NotFoundError;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\Host;
|
|
|
|
|
use Icinga\Module\Icingadb\Model\Hostgroupsummary;
|
|
|
|
|
use Icinga\Module\Icingadb\Web\Controller;
|
2021-08-20 10:14:00 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\HostList;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\HostgroupList;
|
2020-12-03 11:05:51 -05:00
|
|
|
use ipl\Stdlib\Filter;
|
2019-11-04 17:30:38 -05:00
|
|
|
|
|
|
|
|
class HostgroupController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/** @var Hostgroupsummary The host group object */
|
|
|
|
|
protected $hostgroup;
|
|
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
2021-04-07 06:33:53 -04:00
|
|
|
$this->assertRouteAccess('hostgroups');
|
|
|
|
|
|
2020-04-24 08:36:37 -04:00
|
|
|
$this->setTitle(t('Host Group'));
|
2019-11-04 17:30:38 -05:00
|
|
|
|
|
|
|
|
$name = $this->params->shiftRequired('name');
|
|
|
|
|
|
|
|
|
|
$query = Hostgroupsummary::on($this->getDb());
|
|
|
|
|
|
2021-03-19 10:42:15 -04:00
|
|
|
foreach ($query->getUnions() as $unionPart) {
|
|
|
|
|
$unionPart->filter(Filter::equal('hostgroup.name', $name));
|
|
|
|
|
}
|
2019-11-04 17:30:38 -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:38 -05:00
|
|
|
$hostgroup = $query->first();
|
|
|
|
|
if ($hostgroup === null) {
|
2020-04-24 08:36:37 -04:00
|
|
|
throw new NotFoundError(t('Host group not found'));
|
2019-11-04 17:30:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->hostgroup = $hostgroup;
|
|
|
|
|
}
|
2019-11-22 10:01:27 -05:00
|
|
|
|
2019-11-04 17:30:38 -05:00
|
|
|
public function indexAction()
|
|
|
|
|
{
|
|
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
2020-03-06 08:47:39 -05:00
|
|
|
$hosts = Host::on($db)->with('state')->utilize('hostgroup');
|
2019-11-04 17:30:38 -05:00
|
|
|
|
2020-03-06 08:47:39 -05:00
|
|
|
$hosts->getSelectBase()->where(['host_hostgroup.id = ?' => $this->hostgroup->id]);
|
2021-01-28 06:38:03 -05:00
|
|
|
$this->applyRestrictions($hosts);
|
2019-11-22 10:01:27 -05:00
|
|
|
|
2019-11-04 17:30:38 -05:00
|
|
|
$limitControl = $this->createLimitControl();
|
|
|
|
|
$paginationControl = $this->createPaginationControl($hosts);
|
2021-06-23 09:09:22 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
2019-11-04 17:30:38 -05:00
|
|
|
|
|
|
|
|
$hostList = (new HostList($hosts))
|
|
|
|
|
->setViewMode($viewModeSwitcher->getViewMode());
|
|
|
|
|
|
|
|
|
|
yield $this->export($hosts);
|
|
|
|
|
|
2021-04-29 10:55:19 -04:00
|
|
|
$this->addControl((new HostgroupList([$this->hostgroup]))
|
|
|
|
|
->setViewMode('minimal')
|
|
|
|
|
->setDetailActionsDisabled()
|
|
|
|
|
->setNoSubjectLink());
|
2019-11-04 17:30:38 -05:00
|
|
|
$this->addControl($paginationControl);
|
|
|
|
|
$this->addControl($viewModeSwitcher);
|
|
|
|
|
$this->addControl($limitControl);
|
|
|
|
|
|
|
|
|
|
$this->addContent($hostList);
|
2019-12-11 02:59:30 -05:00
|
|
|
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
2019-11-04 17:30:38 -05:00
|
|
|
}
|
|
|
|
|
}
|