2019-11-05 05:52:57 -05:00
|
|
|
<?php
|
|
|
|
|
|
2020-03-13 03:38:01 -04:00
|
|
|
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
|
|
|
|
|
|
2019-11-05 05:52:57 -05:00
|
|
|
namespace Icinga\Module\Icingadb\Controllers;
|
|
|
|
|
|
2020-11-02 08:30:15 -05:00
|
|
|
use GuzzleHttp\Psr7\ServerRequest;
|
2019-11-05 05:52:57 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\History;
|
2020-11-02 08:30:15 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
|
2019-11-05 05:52:57 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Controller;
|
2021-08-20 11:23:29 -04:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
2025-03-24 08:34:08 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\LoadMoreObjectList;
|
2021-08-04 10:30:13 -04:00
|
|
|
use ipl\Stdlib\Filter;
|
2021-03-05 07:45:36 -05:00
|
|
|
use ipl\Web\Control\LimitControl;
|
|
|
|
|
use ipl\Web\Control\SortControl;
|
2019-12-12 03:29:39 -05:00
|
|
|
use ipl\Web\Url;
|
2019-11-05 05:52:57 -05:00
|
|
|
|
|
|
|
|
class HistoryController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function indexAction()
|
|
|
|
|
{
|
2022-03-16 11:06:00 -04:00
|
|
|
$this->addTitleTab(t('History'));
|
2020-01-15 09:50:41 -05:00
|
|
|
$compact = $this->view->compact; // TODO: Find a less-legacy way..
|
2019-11-05 05:52:57 -05:00
|
|
|
|
2022-07-19 10:31:30 -04:00
|
|
|
$preserveParams = [
|
|
|
|
|
LimitControl::DEFAULT_LIMIT_PARAM,
|
|
|
|
|
SortControl::DEFAULT_SORT_PARAM,
|
|
|
|
|
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
|
|
|
|
|
];
|
|
|
|
|
|
2019-11-05 05:52:57 -05:00
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
|
|
|
|
$history = History::on($db)->with([
|
|
|
|
|
'host',
|
|
|
|
|
'host.state',
|
|
|
|
|
'service',
|
|
|
|
|
'service.state',
|
|
|
|
|
'comment',
|
|
|
|
|
'downtime',
|
2020-03-10 08:25:28 -04:00
|
|
|
'flapping',
|
2019-11-05 05:52:57 -05:00
|
|
|
'notification',
|
2020-03-10 03:18:28 -04:00
|
|
|
'acknowledgement',
|
2019-11-05 05:52:57 -05:00
|
|
|
'state'
|
|
|
|
|
]);
|
|
|
|
|
|
2021-08-04 10:30:13 -04:00
|
|
|
$before = $this->params->shift('before', time());
|
2019-12-12 03:29:39 -05:00
|
|
|
|
2019-11-05 05:52:57 -05:00
|
|
|
$limitControl = $this->createLimitControl();
|
2021-08-23 09:23:34 -04:00
|
|
|
$paginationControl = $this->createPaginationControl($history);
|
2019-12-11 07:38:29 -05:00
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$history,
|
|
|
|
|
[
|
2023-05-23 10:25:19 -04:00
|
|
|
'history.event_time desc, history.event_type desc' => t('Event Time')
|
2019-12-11 07:38:29 -05:00
|
|
|
]
|
|
|
|
|
);
|
2021-09-08 05:08:36 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);
|
2022-07-19 10:31:30 -04:00
|
|
|
$searchBar = $this->createSearchBar($history, $preserveParams);
|
2019-11-05 05:52:57 -05:00
|
|
|
|
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-01-31 08:01:01 -05:00
|
|
|
$history->peekAhead();
|
2021-08-23 09:23:34 -04:00
|
|
|
|
|
|
|
|
$page = $paginationControl->getCurrentPageNumber();
|
|
|
|
|
|
|
|
|
|
if ($page > 1 && ! $compact) {
|
2023-03-28 10:34:43 -04:00
|
|
|
$history->resetOffset();
|
2021-08-23 09:23:34 -04:00
|
|
|
$history->limit($page * $limitControl->getLimit());
|
2019-12-13 10:15:58 -05:00
|
|
|
}
|
|
|
|
|
|
2021-08-04 10:30:13 -04:00
|
|
|
$history->filter(Filter::lessThanOrEqual('event_time', $before));
|
2020-11-06 09:51:00 -05:00
|
|
|
$this->filter($history, $filter);
|
2021-11-12 06:58:25 -05:00
|
|
|
|
|
|
|
|
$history->getWith()['history.host']->setJoinType('LEFT');
|
2022-05-20 02:55:57 -04:00
|
|
|
$history->filter(Filter::any(
|
2021-11-12 06:58:25 -05:00
|
|
|
// Because of LEFT JOINs, make sure we'll fetch history entries only for items which still exist:
|
2022-05-20 02:55:57 -04:00
|
|
|
Filter::like('host.id', '*'),
|
|
|
|
|
Filter::like('service.id', '*')
|
|
|
|
|
));
|
2019-11-05 05:52:57 -05:00
|
|
|
|
|
|
|
|
yield $this->export($history);
|
|
|
|
|
|
2019-12-11 07:38:29 -05:00
|
|
|
$this->addControl($sortControl);
|
2019-11-05 05:52:57 -05:00
|
|
|
$this->addControl($limitControl);
|
2021-08-03 11:18:08 -04:00
|
|
|
$this->addControl($viewModeSwitcher);
|
2020-11-02 08:30:15 -05:00
|
|
|
$this->addControl($searchBar);
|
2019-11-05 05:52:57 -05:00
|
|
|
|
2023-09-01 07:53:02 -04:00
|
|
|
$url = Url::fromRequest()
|
|
|
|
|
->onlyWith($preserveParams)
|
|
|
|
|
->setFilter($filter);
|
2022-07-19 10:31:30 -04:00
|
|
|
|
2025-03-24 08:34:08 -04:00
|
|
|
$historyList = (new LoadMoreObjectList($history->execute()))
|
2021-08-03 11:18:08 -04:00
|
|
|
->setPageSize($limitControl->getLimit())
|
2021-08-19 09:14:06 -04:00
|
|
|
->setViewMode($viewModeSwitcher->getViewMode())
|
|
|
|
|
->setLoadMoreUrl($url->setParam('before', $before));
|
2019-12-13 10:15:58 -05:00
|
|
|
if ($compact) {
|
|
|
|
|
$historyList->setPageNumber($page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($compact && $page > 1) {
|
2020-03-10 07:59:19 -04:00
|
|
|
$this->document->addFrom($historyList);
|
2019-12-13 10:15:58 -05:00
|
|
|
} else {
|
|
|
|
|
$this->addContent($historyList);
|
|
|
|
|
}
|
2020-11-02 08:30:15 -05:00
|
|
|
|
2020-11-06 09:51:00 -05:00
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
2020-11-02 08:30:15 -05:00
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function completeAction()
|
|
|
|
|
{
|
|
|
|
|
$suggestions = new ObjectSuggestions();
|
|
|
|
|
$suggestions->setModel(History::class);
|
|
|
|
|
$suggestions->forRequest(ServerRequest::fromGlobals());
|
|
|
|
|
$this->getDocument()->add($suggestions);
|
2019-11-05 05:52:57 -05:00
|
|
|
}
|
2021-03-05 07:45:36 -05:00
|
|
|
|
|
|
|
|
public function searchEditorAction()
|
|
|
|
|
{
|
|
|
|
|
$editor = $this->createSearchEditor(History::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'));
|
|
|
|
|
}
|
2019-11-05 05:52:57 -05:00
|
|
|
}
|