From bff47213eef4f610a844c46af172986f2ac4dc60 Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Fri, 19 Aug 2022 10:10:45 +0200 Subject: [PATCH] Show warning health state badges The warning state badges should be shown when notifications or active host/service checks are disabled. --- .../Monitoring/ProvidedHook/Health.php | 21 ++++ ...kendAvailabilityNavigationItemRenderer.php | 96 ------------------- 2 files changed, 21 insertions(+), 96 deletions(-) delete mode 100644 modules/monitoring/library/Monitoring/Web/Navigation/Renderer/BackendAvailabilityNavigationItemRenderer.php diff --git a/modules/monitoring/library/Monitoring/ProvidedHook/Health.php b/modules/monitoring/library/Monitoring/ProvidedHook/Health.php index c2de3131c..8f9c89354 100644 --- a/modules/monitoring/library/Monitoring/ProvidedHook/Health.php +++ b/modules/monitoring/library/Monitoring/ProvidedHook/Health.php @@ -44,6 +44,27 @@ class Health extends HealthHook $programStatus->process_id, DateFormatter::timeSince($programStatus->program_start_time) )); + + $warningMessages = []; + + if (! $programStatus->active_host_checks_enabled) { + $this->setState(self::STATE_WARNING); + $warningMessages[] = t('Active host checks are disabled'); + } + + if (! $programStatus->active_service_checks_enabled) { + $this->setState(self::STATE_WARNING); + $warningMessages[] = t('Active service checks are disabled'); + } + + if (! $programStatus->notifications_enabled) { + $this->setState(self::STATE_WARNING); + $warningMessages[] = t('Notifications are disabled'); + } + + if ($this->getState() === self::STATE_WARNING) { + $this->setMessage(implode("; ", $warningMessages)); + } } else { $this->setState(self::STATE_CRITICAL); $this->setMessage(sprintf(t('Backend %s is not running'), $backendName)); diff --git a/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/BackendAvailabilityNavigationItemRenderer.php b/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/BackendAvailabilityNavigationItemRenderer.php deleted file mode 100644 index e8ed2cab3..000000000 --- a/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/BackendAvailabilityNavigationItemRenderer.php +++ /dev/null @@ -1,96 +0,0 @@ -select() - ->from( - 'programstatus', - array( - 'active_host_checks_enabled', - 'active_service_checks_enabled', - 'is_currently_running', - 'notifications_enabled' - ) - ) - ->fetchRow(); - - if ($programStatus === false) { - throw new Exception(sprintf( - mt('monitoring', '%s is currently not up and running'), - MonitoringBackend::instance()->getName() - )); - } - - return $programStatus; - } - - /** - * {@inheritdoc} - */ - public function getCount() - { - if ($this->count === null) { - try { - $programStatus = $this->isCurrentlyRunning(); - } catch (Exception $e) { - Logger::debug($e); - $this->count = 1; - $this->state = static::STATE_UNKNOWN; - $this->title = $e->getMessage(); - return $this->count; - } - $count = 0; - $titles = array(); - if (! (bool) $programStatus->active_host_checks_enabled) { - $count++; - $this->state = static::STATE_WARNING; - $titles[] = mt('monitoring', 'Active host checks are disabled'); - } - if (! (bool) $programStatus->active_service_checks_enabled) { - $count++; - $this->state = static::STATE_WARNING; - $titles[] = mt('monitoring', 'Active service checks are disabled'); - } - if (! (bool) $programStatus->notifications_enabled) { - $count++; - $this->state = static::STATE_WARNING; - $titles[] = mt('monitoring', 'Notifications are disabled'); - } - if (! (bool) $programStatus->is_currently_running) { - $count++; - $this->state = static::STATE_CRITICAL; - array_unshift($titles, sprintf( - mt('monitoring', 'Monitoring backend %s is not running'), - MonitoringBackend::instance()->getName() - )); - } - $this->count = $count; - $this->title = implode('. ', $titles); - } - - return $this->count; - } -}