icingadb-web/application/controllers/HostsController.php

68 lines
2.1 KiB
PHP
Raw Normal View History

2019-09-09 08:46:56 -04:00
<?php
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2019-09-09 08:46:56 -04:00
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\HoststateSummary;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\HostList;
2019-12-03 05:37:29 -05:00
use Icinga\Module\Icingadb\Widget\HostStatusBar;
2019-09-09 08:46:56 -04:00
class HostsController extends Controller
{
public function indexAction()
{
$this->setTitle($this->translate('Hosts'));
$db = $this->getDb();
$hosts = Host::on($db)->with('state');
$summary = null;
if (! $this->view->compact) {
$summary = HoststateSummary::on($db)->with('state');
}
2019-09-09 08:46:56 -04:00
2019-10-08 18:09:18 -04:00
$limitControl = $this->createLimitControl();
2019-10-15 09:29:36 -04:00
$paginationControl = $this->createPaginationControl($hosts);
2019-12-11 07:55:31 -05:00
$sortControl = $this->createSortControl(
$hosts,
[
'host.display_name' => $this->translate('Name'),
'host.state.severity desc' => $this->translate('Severity'),
'host.state.soft_state' => $this->translate('Current State'),
'host.state.last_state_change desc' => $this->translate('Last State Change')
]
);
2019-10-15 09:29:36 -04:00
$viewModeSwitcher = $this->createViewModeSwitcher();
2019-10-18 02:44:23 -04:00
$filterControl = $this->createFilterControl($hosts);
2019-10-08 17:58:23 -04:00
2019-09-13 04:09:41 -04:00
$hostList = (new HostList($hosts))
2019-10-08 17:58:23 -04:00
->setViewMode($viewModeSwitcher->getViewMode());
2019-10-16 03:22:05 -04:00
$this->filter($hosts);
if (isset($summary)) {
$this->filter($summary);
yield $this->export($hosts, $summary);
} else {
yield $this->export($hosts);
}
2019-10-15 09:29:36 -04:00
$this->addControl($paginationControl);
2019-12-11 07:55:31 -05:00
$this->addControl($sortControl);
2019-10-08 18:09:18 -04:00
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
2019-10-18 02:44:23 -04:00
$this->addControl($filterControl);
2019-09-09 08:46:56 -04:00
$this->addContent($hostList);
if (isset($summary)) {
$this->addFooter(
(new HostStatusBar($summary->first()))->setBaseFilter($this->getFilter())
);
}
2019-12-03 05:37:29 -05:00
$this->setAutorefreshInterval(10);
2019-09-09 08:46:56 -04:00
}
}