icingaweb2/application/controllers/HealthController.php
Eric Lippmann 662de28f85 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-26 17:49:26 +01:00

67 lines
2.1 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2021 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Controllers;
use Icinga\Application\Hook\HealthHook;
use Icinga\Web\View\AppHealth;
use Icinga\Web\Widget\Tabextension\OutputFormat;
use ipl\Html\Html;
use ipl\Html\HtmlString;
use ipl\Web\Compat\CompatController;
class HealthController extends CompatController
{
public function indexAction()
{
$query = HealthHook::collectHealthData()
->select();
$this->setupSortControl(
[
'module' => $this->translate('Module'),
'name' => $this->translate('Name'),
'state' => $this->translate('State')
],
$query,
['state' => 'desc']
);
$this->setupLimitControl();
$this->setupPaginationControl($query);
$this->setupFilterControl($query, [
'module' => $this->translate('Module'),
'name' => $this->translate('Name'),
'state' => $this->translate('State'),
'message' => $this->translate('Message')
], ['name'], ['format']);
$this->getTabs()->extend(new OutputFormat(['csv']));
$this->handleFormatRequest($query);
$this->addControl(HtmlString::create((string) $this->view->paginator));
$this->addControl(Html::tag('div', ['class' => 'sort-controls-container'], [
HtmlString::create((string) $this->view->limiter),
HtmlString::create((string) $this->view->sortBox)
]));
$this->addControl(HtmlString::create((string) $this->view->filterEditor));
$this->addTitleTab(t('Health'));
$this->setAutorefreshInterval(10);
$this->addContent(new AppHealth($query));
}
protected function handleFormatRequest($query)
{
$formatJson = $this->params->get('format') === 'json';
if (! $formatJson && ! $this->getRequest()->isApiRequest()) {
return;
}
$this->getResponse()
->json()
->setSuccessData($query->fetchAll())
->sendResponse();
}
}