Menu: Integrate health endpoint
This commit is contained in:
parent
5e382dcfa9
commit
0d2bf1ae33
|
@ -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
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2021 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Navigation\Renderer;
|
||||
|
||||
use Icinga\Application\Hook\HealthHook;
|
||||
|
||||
class HealthNavigationRenderer extends BadgeNavigationItemRenderer
|
||||
{
|
||||
public function getCount()
|
||||
{
|
||||
$count = 0;
|
||||
$title = null;
|
||||
$worstState = null;
|
||||
foreach (HealthHook::collectHealthData()->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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue