From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../Monitoring/ProvidedHook/ApplicationState.php | 32 +++++++ .../library/Monitoring/ProvidedHook/Health.php | 102 +++++++++++++++++++++ .../library/Monitoring/ProvidedHook/X509/Sni.php | 35 +++++++ 3 files changed, 169 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/ProvidedHook/ApplicationState.php create mode 100644 modules/monitoring/library/Monitoring/ProvidedHook/Health.php create mode 100644 modules/monitoring/library/Monitoring/ProvidedHook/X509/Sni.php (limited to 'modules/monitoring/library/Monitoring/ProvidedHook') diff --git a/modules/monitoring/library/Monitoring/ProvidedHook/ApplicationState.php b/modules/monitoring/library/Monitoring/ProvidedHook/ApplicationState.php new file mode 100644 index 0000000..4e2e61c --- /dev/null +++ b/modules/monitoring/library/Monitoring/ProvidedHook/ApplicationState.php @@ -0,0 +1,32 @@ +select() + ->from( + 'programstatus', + ['is_currently_running', 'status_update_time'] + ) + ->fetchRow(); + + if ($programStatus === false || ! (bool) $programStatus->is_currently_running) { + $message = sprintf( + mt('monitoring', "Monitoring backend '%s' is not running."), + $backend->getName() + ); + + $this->addError('monitoring/backend-down', $programStatus->status_update_time, $message); + } + } +} diff --git a/modules/monitoring/library/Monitoring/ProvidedHook/Health.php b/modules/monitoring/library/Monitoring/ProvidedHook/Health.php new file mode 100644 index 0000000..8f9c893 --- /dev/null +++ b/modules/monitoring/library/Monitoring/ProvidedHook/Health.php @@ -0,0 +1,102 @@ +getName(); + $programStatus = $this->getProgramStatus(); + if ($programStatus === false) { + $this->setState(self::STATE_UNKNOWN); + $this->setMessage(sprintf(t('%s is currently not up and running'), $backendName)); + return; + } + + if ($programStatus->is_currently_running) { + $this->setState(self::STATE_OK); + $this->setMessage(sprintf( + t( + '%1$s has been up and running with PID %2$d %3$s', + 'Last format parameter represents the time running' + ), + $backendName, + $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)); + } + + $this->setMetrics((array) $programStatus); + } + + protected function getProgramStatus() + { + if ($this->programStatus === null) { + $this->programStatus = MonitoringBackend::instance()->select() + ->from('programstatus', [ + 'program_version', + 'status_update_time', + 'program_start_time', + 'program_end_time', + 'endpoint_name', + 'is_currently_running', + 'process_id', + 'last_command_check', + 'last_log_rotation', + 'notifications_enabled', + 'active_service_checks_enabled', + 'active_host_checks_enabled', + 'event_handlers_enabled', + 'flap_detection_enabled', + 'process_performance_data' + ]) + ->fetchRow(); + } + + return $this->programStatus; + } +} diff --git a/modules/monitoring/library/Monitoring/ProvidedHook/X509/Sni.php b/modules/monitoring/library/Monitoring/ProvidedHook/X509/Sni.php new file mode 100644 index 0000000..fd1818f --- /dev/null +++ b/modules/monitoring/library/Monitoring/ProvidedHook/X509/Sni.php @@ -0,0 +1,35 @@ +select() + ->from('hoststatus', [ + 'host_name', + 'host_address', + 'host_address6' + ]); + if ($filter !== null) { + $hosts->applyFilter($filter); + } + + foreach ($hosts as $host) { + if (! empty($host->host_address)) { + yield $host->host_address => $host->host_name; + } + + if (! empty($host->host_address6)) { + yield $host->host_address6 => $host->host_name; + } + } + } +} -- cgit v1.2.3