From dbfc7facce10e2d8215c80224c1db9c594f26a6b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 13 Dec 2019 13:54:51 +0100 Subject: [PATCH] Introduce HealthController --- application/controllers/HealthController.php | 104 +++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 application/controllers/HealthController.php diff --git a/application/controllers/HealthController.php b/application/controllers/HealthController.php new file mode 100644 index 00000000..bc3c6ff6 --- /dev/null +++ b/application/controllers/HealthController.php @@ -0,0 +1,104 @@ +setTitle($this->translate('Health')); + + $db = $this->getDb(); + + $instance = Instance::on($db)->with(['endpoint']); + $hoststateSummary = HoststateSummary::on($db)->with('state'); + $servicestateSummary = ServicestateSummary::on($db)->with('state'); + + $this->applyMonitoringRestriction($hoststateSummary); + $this->applyMonitoringRestriction($servicestateSummary); + + yield $this->export($instance, $hoststateSummary, $servicestateSummary); + + $instance = $instance->first(); + + if ($instance === null) { + $this->addContent(Html::tag( + 'p', + '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', 'Host Checks'), + Html::tag('div', ['class' => 'col-content'], [ + new VerticalKeyValue( + 'Active', + $hoststateSummary->hosts_active_checks_enabled + ), + new VerticalKeyValue( + 'Passive', + $hoststateSummary->hosts_passive_checks_enabled + ) + ]) + ]), + Html::tag('div', ['class' => 'col'], [ + Html::tag('h3', 'Service Checks'), + Html::tag('div', ['class' => 'col-content'], [ + new VerticalKeyValue( + 'Active', + $servicestateSummary->services_active_checks_enabled + ), + new VerticalKeyValue( + 'Passive', + $servicestateSummary->services_passive_checks_enabled + ) + ]) + ]) + ] + )); + + $featureCommands = Html::tag( + 'section', ['class' => 'instance-commands'], Html::tag('h2', 'Feature Commands') + ); + $programStatus = (object) [ + 'active_host_checks_enabled' => $instance->icinga2_active_host_checks_enabled, + 'active_service_checks_enabled' => $instance->icinga2_active_service_checks_enabled, + 'event_handlers_enabled' => $instance->icinga2_event_handlers_enabled, + 'flap_detection_enabled' => $instance->icinga2_flap_detection_enabled, + 'notifications_enabled' => $instance->icinga2_notifications_enabled, + 'process_performance_data' => $instance->icinga2_performance_data_enabled, + 'program_version' => $instance->icinga2_version + ]; + $toggleInstanceFeaturesCommandForm = new ToggleInstanceFeaturesCommandForm(); + $toggleInstanceFeaturesCommandForm + ->setBackend(new CompatBackend()) + ->setStatus($programStatus) + ->load($programStatus) + ->handleRequest(); + $featureCommands->add(HtmlString::create($toggleInstanceFeaturesCommandForm->render())); + $this->addContent($featureCommands); + + $this->setAutorefreshInterval(30); + } +}