icingadb-web/application/controllers/TacticalController.php

95 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2020-01-16 05:43:51 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2020-01-16 05:43:51 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2020-11-02 08:32:47 -05:00
use GuzzleHttp\Psr7\ServerRequest;
2020-01-16 05:43:51 -05:00
use Icinga\Module\Icingadb\Model\HoststateSummary;
use Icinga\Module\Icingadb\Model\ServicestateSummary;
2020-11-02 08:32:47 -05:00
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
2020-01-16 05:43:51 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\HostSummaryDonut;
use Icinga\Module\Icingadb\Widget\ServiceSummaryDonut;
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
use ipl\Orm\Query;
use ipl\Stdlib\Filter;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
2020-01-16 05:43:51 -05:00
class TacticalController extends Controller
{
public function indexAction()
{
$this->addTitleTab(t('Tactical Overview'));
2020-01-16 05:43:51 -05:00
$db = $this->getDb();
$hoststateSummary = HoststateSummary::on($db);
$servicestateSummary = ServicestateSummary::on($db);
$this->handleSearchRequest($servicestateSummary, [
'host.name_ci',
'host.display_name',
'host.address',
'host.address6'
]);
2020-11-02 08:32:47 -05:00
$searchBar = $this->createSearchBar($servicestateSummary);
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}
2020-11-02 08:32:47 -05:00
$this->filter($hoststateSummary, $filter);
$this->filter($servicestateSummary, $filter);
2020-01-16 05:43:51 -05:00
yield $this->export($hoststateSummary, $servicestateSummary);
2020-11-02 08:32:47 -05:00
$this->addControl($searchBar);
$this->addContent(
(new HostSummaryDonut($hoststateSummary->first()))
->setBaseFilter($filter)
);
2020-01-16 05:43:51 -05:00
$this->addContent(
(new ServiceSummaryDonut($servicestateSummary->first()))
->setBaseFilter($filter)
);
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
2020-11-02 08:32:47 -05:00
$this->sendMultipartUpdate();
}
$this->setAutorefreshInterval(10);
2020-01-16 05:43:51 -05:00
}
2020-11-02 08:32:47 -05:00
public function completeAction()
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(ServicestateSummary::class);
$suggestions->forRequest(ServerRequest::fromGlobals());
$this->getDocument()->add($suggestions);
}
public function searchEditorAction()
{
$editor = $this->createSearchEditor(ServicestateSummary::on($this->getDb()), [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
]);
$this->getDocument()->add($editor);
$this->setTitle(t('Adjust Filter'));
}
2020-01-16 05:43:51 -05:00
}