From 0d2bf1ae33ccd1204a63b5bda0d48c5c4594fcc1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 20 Apr 2021 13:04:55 +0200 Subject: [PATCH] Menu: Integrate health endpoint --- library/Icinga/Web/Menu.php | 10 ++++- .../Renderer/HealthNavigationRenderer.php | 44 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 library/Icinga/Web/Navigation/Renderer/HealthNavigationRenderer.php diff --git a/library/Icinga/Web/Menu.php b/library/Icinga/Web/Menu.php index 5f822fa2b..7a8b39c90 100644 --- a/library/Icinga/Web/Menu.php +++ b/library/Icinga/Web/Menu.php @@ -48,12 +48,20 @@ class Menu extends Navigation 'url' => 'about', 'priority' => 700 ], + 'health' => [ + 'icon' => 'eye', + 'description' => t('Open health overview'), + 'label' => t('Health'), + 'url' => 'health', + 'priority' => 710, + 'renderer' => 'HealthNavigationRenderer' + ], 'announcements' => [ 'icon' => 'megaphone', 'description' => t('List announcements'), 'label' => t('Announcements'), 'url' => 'announcements', - 'priority' => 710 + 'priority' => 720 ] ] ]); diff --git a/library/Icinga/Web/Navigation/Renderer/HealthNavigationRenderer.php b/library/Icinga/Web/Navigation/Renderer/HealthNavigationRenderer.php new file mode 100644 index 000000000..577895bf2 --- /dev/null +++ b/library/Icinga/Web/Navigation/Renderer/HealthNavigationRenderer.php @@ -0,0 +1,44 @@ +select() as $result) { + if ($worstState === null || $result->state > $worstState) { + $worstState = $result->state; + $title = $result->message; + $count = 1; + } elseif ($worstState === $result->state) { + $count++; + } + } + + switch ($worstState) { + case HealthHook::STATE_OK: + $count = 0; + break; + case HealthHook::STATE_WARNING: + $this->state = self::STATE_WARNING; + break; + case HealthHook::STATE_CRITICAL: + $this->state = self::STATE_CRITICAL; + break; + case HealthHook::STATE_UNKNOWN: + $this->state = self::STATE_UNKNOWN; + break; + } + + $this->title = $title; + + return $count; + } +}