mirror of
https://github.com/Icinga/icingaweb2-module-graphite.git
synced 2026-04-15 21:49:43 -04:00
99 lines
3.2 KiB
PHP
99 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Icinga\Module\Graphite\Controllers;
|
|
|
|
use GuzzleHttp\Psr7\ServerRequest;
|
|
use Icinga\Module\Graphite\Util\TimeRangePickerTools;
|
|
use Icinga\Module\Graphite\Web\Controller\IcingadbGraphiteController;
|
|
use Icinga\Module\Graphite\Web\Controller\TimeRangePickerTrait;
|
|
use Icinga\Module\Graphite\Web\Widget\IcingadbGraphs;
|
|
use Icinga\Module\Icingadb\Model\Host;
|
|
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
|
|
use ipl\Html\HtmlString;
|
|
use ipl\Stdlib\Filter;
|
|
use ipl\Web\Control\LimitControl;
|
|
use ipl\Web\Control\SortControl;
|
|
use ipl\Web\Url;
|
|
|
|
class HostsController extends IcingadbGraphiteController
|
|
{
|
|
use TimeRangePickerTrait;
|
|
|
|
public function indexAction()
|
|
{
|
|
// shift graph params to avoid exception
|
|
foreach (['graphs_limit', 'graph_range', 'graph_start', 'graph_end'] as $param) {
|
|
$this->params->shift($param);
|
|
}
|
|
|
|
$this->setTitle(t('Hosts'));
|
|
|
|
$db = $this->getDb();
|
|
|
|
$hosts = Host::on($db)->with(['state']);
|
|
$hosts->filter(Filter::equal('state.performance_data', '*'));
|
|
|
|
$this->applyRestrictions($hosts);
|
|
|
|
$baseUrl = Url::fromPath('icingadb/host');
|
|
TimeRangePickerTools::copyAllRangeParameters(
|
|
$baseUrl->getParams(),
|
|
$this->getRequest()->getUrl()->getParams()
|
|
);
|
|
|
|
$limitControl = $this->createLimitControl();
|
|
$paginationControl = $this->createPaginationControl($hosts);
|
|
$sortControl = $this->createSortControl($hosts, ['host.display_name' => t('Hostname')]);
|
|
|
|
$searchBar = $this->createSearchBar($hosts, [
|
|
$limitControl->getLimitParam(),
|
|
$sortControl->getSortParam()
|
|
]);
|
|
|
|
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
|
if ($searchBar->hasBeenSubmitted()) {
|
|
$filter = $this->getFilter();
|
|
} else {
|
|
$this->addControl($searchBar);
|
|
$this->sendMultipartUpdate();
|
|
return;
|
|
}
|
|
} else {
|
|
$filter = $searchBar->getFilter();
|
|
}
|
|
|
|
$this->filter($hosts, $filter);
|
|
|
|
$this->addControl($paginationControl);
|
|
$this->addControl($sortControl);
|
|
$this->addControl($limitControl);
|
|
$this->addControl($searchBar);
|
|
$this->handleTimeRangePickerRequest();
|
|
$this->addControl(HtmlString::create($this->renderTimeRangePicker($this->view)));
|
|
|
|
$this->addContent(new IcingadbGraphs($hosts->execute(), $baseUrl));
|
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
|
$this->sendMultipartUpdate();
|
|
}
|
|
}
|
|
|
|
public function completeAction()
|
|
{
|
|
$suggestions = new ObjectSuggestions();
|
|
$suggestions->setModel(Host::class);
|
|
$suggestions->forRequest(ServerRequest::fromGlobals());
|
|
$this->getDocument()->add($suggestions);
|
|
}
|
|
|
|
public function searchEditorAction()
|
|
{
|
|
$editor = $this->createSearchEditor(
|
|
Host::on($this->getDb()),
|
|
[LimitControl::DEFAULT_LIMIT_PARAM, SortControl::DEFAULT_SORT_PARAM]
|
|
);
|
|
|
|
$this->getDocument()->add($editor);
|
|
$this->setTitle(t('Adjust Filter'));
|
|
}
|
|
}
|