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;
|
2020-03-04 04:36:42 -05:00
|
|
|
use Icinga\Module\Icingadb\Widget\HostSummaryDonut;
|
|
|
|
|
use Icinga\Module\Icingadb\Widget\ServiceSummaryDonut;
|
2021-08-20 11:23:29 -04:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
2022-08-19 09:47:40 -04:00
|
|
|
use ipl\Orm\Query;
|
|
|
|
|
use ipl\Stdlib\Filter;
|
2021-03-05 07:45:36 -05:00
|
|
|
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()
|
|
|
|
|
{
|
2022-03-16 11:06:00 -04:00
|
|
|
$this->addTitleTab(t('Tactical Overview'));
|
2020-01-16 05:43:51 -05:00
|
|
|
|
|
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
2022-05-19 05:24:20 -04:00
|
|
|
$hoststateSummary = HoststateSummary::on($db);
|
|
|
|
|
$servicestateSummary = ServicestateSummary::on($db);
|
2020-03-03 02:12:08 -05:00
|
|
|
|
2023-05-30 09:26:00 -04:00
|
|
|
$this->handleSearchRequest($servicestateSummary, [
|
|
|
|
|
'host.name_ci',
|
|
|
|
|
'host.display_name',
|
|
|
|
|
'host.address',
|
|
|
|
|
'host.address6'
|
|
|
|
|
]);
|
2020-03-03 02:12:08 -05:00
|
|
|
|
2020-11-02 08:32:47 -05:00
|
|
|
$searchBar = $this->createSearchBar($servicestateSummary);
|
2020-11-06 09:51:00 -05:00
|
|
|
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
|
|
|
|
if ($searchBar->hasBeenSubmitted()) {
|
2020-12-03 11:05:51 -05:00
|
|
|
$filter = $this->getFilter();
|
2020-11-06 09:51:00 -05:00
|
|
|
} 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);
|
2020-03-03 02:12:08 -05:00
|
|
|
|
2020-03-04 04:36:42 -05:00
|
|
|
$this->addContent(
|
|
|
|
|
(new HostSummaryDonut($hoststateSummary->first()))
|
2020-12-03 11:05:51 -05:00
|
|
|
->setBaseFilter($filter)
|
2020-03-04 04:36:42 -05:00
|
|
|
);
|
2020-01-16 05:43:51 -05:00
|
|
|
|
2020-03-04 04:36:42 -05:00
|
|
|
$this->addContent(
|
|
|
|
|
(new ServiceSummaryDonut($servicestateSummary->first()))
|
2020-12-03 11:05:51 -05:00
|
|
|
->setBaseFilter($filter)
|
2020-03-04 04:36:42 -05:00
|
|
|
);
|
2020-03-03 02:12:08 -05:00
|
|
|
|
2020-11-06 09:51:00 -05:00
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
2020-11-02 08:32:47 -05:00
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 02:12:08 -05:00
|
|
|
$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);
|
|
|
|
|
}
|
2021-03-05 07:45:36 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|