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;
|
|
|
|
|
use Icinga\Module\Icingadb\Widget\HostList;
|
|
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\HostgroupList;
|
2019-11-04 17:30:38 -05:00
|
|
|
use ipl\Orm\Compat\FilterProcessor;
|
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()
|
|
|
|
|
{
|
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());
|
|
|
|
|
|
|
|
|
|
FilterProcessor::apply(
|
2020-12-03 11:05:51 -05:00
|
|
|
Filter::equal('hostgroup.name', $name),
|
2019-11-04 17:30:38 -05:00
|
|
|
$query
|
|
|
|
|
);
|
|
|
|
|
|
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);
|
|
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher();
|
|
|
|
|
|
|
|
|
|
$hostList = (new HostList($hosts))
|
|
|
|
|
->setViewMode($viewModeSwitcher->getViewMode());
|
|
|
|
|
|
|
|
|
|
yield $this->export($hosts);
|
|
|
|
|
|
2019-12-18 08:32:31 -05:00
|
|
|
$this->addControl((new HostgroupList([$this->hostgroup]))->setViewMode('minimal'));
|
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
|
|
|
}
|
|
|
|
|
}
|