From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- application/controllers/HealthController.php | 115 +++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 application/controllers/HealthController.php (limited to 'application/controllers/HealthController.php') diff --git a/application/controllers/HealthController.php b/application/controllers/HealthController.php new file mode 100644 index 0000000..52ba220 --- /dev/null +++ b/application/controllers/HealthController.php @@ -0,0 +1,115 @@ +addTitleTab(t('Health')); + + $db = $this->getDb(); + + $instance = Instance::on($db)->with(['endpoint']); + $hoststateSummary = HoststateSummary::on($db); + $servicestateSummary = ServicestateSummary::on($db); + + $this->applyRestrictions($hoststateSummary); + $this->applyRestrictions($servicestateSummary); + + yield $this->export($instance, $hoststateSummary, $servicestateSummary); + + $instance = $instance->first(); + + if ($instance === null) { + $this->addContent(Html::tag('p', t( + 'It seems that Icinga DB is not running.' + . ' Make sure Icinga DB is running and writing into the database.' + ))); + + 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')), + Html::tag('div', ['class' => 'col-content'], [ + new VerticalKeyValue( + t('Active'), + $hoststateSummary->hosts_active_checks_enabled + ), + new VerticalKeyValue( + t('Passive'), + $hoststateSummary->hosts_passive_checks_enabled + ) + ]) + ]), + Html::tag('div', ['class' => 'col'], [ + Html::tag('h3', t('Service Checks')), + Html::tag('div', ['class' => 'col-content'], [ + new VerticalKeyValue( + t('Active'), + $servicestateSummary->services_active_checks_enabled + ), + new VerticalKeyValue( + t('Passive'), + $servicestateSummary->services_passive_checks_enabled + ) + ]) + ]) + ])); + + $featureCommands = Html::tag( + 'section', + ['class' => 'instance-commands'], + Html::tag('h2', t('Feature Commands')) + ); + $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); + $this->addContent($featureCommands); + + $this->setAutorefreshInterval(30); + } +} -- cgit v1.2.3