icingadb-web/application/controllers/HealthController.php

116 lines
4.5 KiB
PHP
Raw Permalink Normal View History

2019-12-13 07:54:51 -05:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-12-13 07:54:51 -05:00
namespace Icinga\Module\Icingadb\Controllers;
use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Icingadb\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Forms\Command\Instance\ToggleInstanceFeaturesForm;
2019-12-13 07:54:51 -05:00
use Icinga\Module\Icingadb\Model\HoststateSummary;
use Icinga\Module\Icingadb\Model\Instance;
use Icinga\Module\Icingadb\Model\ServicestateSummary;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Health;
use ipl\Web\Widget\VerticalKeyValue;
2019-12-13 07:54:51 -05:00
use ipl\Html\Html;
use ipl\Web\Url;
2019-12-13 07:54:51 -05:00
class HealthController extends Controller
{
public function indexAction()
{
$this->addTitleTab(t('Health'));
2019-12-13 07:54:51 -05:00
$db = $this->getDb();
$instance = Instance::on($db)->with(['endpoint']);
$hoststateSummary = HoststateSummary::on($db);
$servicestateSummary = ServicestateSummary::on($db);
2019-12-13 07:54:51 -05:00
$this->applyRestrictions($hoststateSummary);
$this->applyRestrictions($servicestateSummary);
2019-12-13 07:54:51 -05:00
yield $this->export($instance, $hoststateSummary, $servicestateSummary);
$instance = $instance->first();
if ($instance === null) {
$this->addContent(Html::tag('p', t(
2019-12-13 07:54:51 -05:00
'It seems that Icinga DB is not running.'
. ' Make sure Icinga DB is running and writing into the database.'
)));
2019-12-13 07:54:51 -05:00
return;
}
$hoststateSummary = $hoststateSummary->first();
$servicestateSummary = $servicestateSummary->first();
$this->content->addAttributes(['class' => 'monitoring-health']);
$this->addContent(new Health($instance));
$this->addContent(Html::tag('section', ['class' => 'check-summary'], [
Html::tag('div', ['class' => 'col'], [
Html::tag('h3', t('Host Checks')),
2019-12-13 07:54:51 -05:00
Html::tag('div', ['class' => 'col-content'], [
new VerticalKeyValue(
t('Active'),
2019-12-13 07:54:51 -05:00
$hoststateSummary->hosts_active_checks_enabled
),
new VerticalKeyValue(
t('Passive'),
2019-12-13 07:54:51 -05:00
$hoststateSummary->hosts_passive_checks_enabled
)
])
]),
Html::tag('div', ['class' => 'col'], [
Html::tag('h3', t('Service Checks')),
2019-12-13 07:54:51 -05:00
Html::tag('div', ['class' => 'col-content'], [
new VerticalKeyValue(
t('Active'),
2019-12-13 07:54:51 -05:00
$servicestateSummary->services_active_checks_enabled
),
new VerticalKeyValue(
t('Passive'),
2019-12-13 07:54:51 -05:00
$servicestateSummary->services_passive_checks_enabled
)
])
])
]));
2019-12-13 07:54:51 -05:00
$featureCommands = Html::tag(
'section',
['class' => 'instance-commands'],
Html::tag('h2', t('Feature Commands'))
2019-12-13 07:54:51 -05:00
);
$toggleInstanceFeaturesCommandForm = new ToggleInstanceFeaturesForm([
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS =>
$instance->icinga2_active_host_checks_enabled,
ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS =>
$instance->icinga2_active_service_checks_enabled,
ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS =>
$instance->icinga2_event_handlers_enabled,
ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION =>
$instance->icinga2_flap_detection_enabled,
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS =>
$instance->icinga2_notifications_enabled,
ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA =>
$instance->icinga2_performance_data_enabled
]);
$toggleInstanceFeaturesCommandForm->setObjects([$instance]);
$toggleInstanceFeaturesCommandForm->on(ToggleInstanceFeaturesForm::ON_SUCCESS, function () {
$this->getResponse()->setAutoRefreshInterval(1);
$this->redirectNow(Url::fromPath('icingadb/health')->getAbsoluteUrl());
});
$toggleInstanceFeaturesCommandForm->handleRequest(ServerRequest::fromGlobals());
$featureCommands->add($toggleInstanceFeaturesCommandForm);
2019-12-13 07:54:51 -05:00
$this->addContent($featureCommands);
$this->setAutorefreshInterval(30);
}
}