diff --git a/library/Icinga/Web/Menu.php b/library/Icinga/Web/Menu.php index bca1e17d1..476d73879 100644 --- a/library/Icinga/Web/Menu.php +++ b/library/Icinga/Web/Menu.php @@ -234,7 +234,8 @@ class Menu implements RecursiveIterator $section = $this->add(t('System'), array( 'icon' => 'wrench', - 'priority' => 200 + 'priority' => 200, + 'renderer' => 'ProblemMenuItemRenderer' )); $section->add(t('Configuration'), array( 'url' => 'config', @@ -469,6 +470,26 @@ class Menu implements RecursiveIterator return $this->permission; } + /** + * Get parent menu + * + * @return \Icinga\Web\Menu + */ + public function getParent() + { + return $this->parent; + } + + /** + * Get submenus + * + * @return array + */ + public function getSubMenus() + { + return $this->subMenus; + } + /** * Set permission a user is required to have granted to display the menu item * diff --git a/library/Icinga/Web/Menu/ProblemMenuItemRenderer.php b/library/Icinga/Web/Menu/ProblemMenuItemRenderer.php new file mode 100644 index 000000000..010bdc034 --- /dev/null +++ b/library/Icinga/Web/Menu/ProblemMenuItemRenderer.php @@ -0,0 +1,64 @@ +getParent() !== null && $menu->hasSubMenus()) { + /** @var $submenu Menu */ + foreach ($menu->getSubMenus() as $submenu) { + $renderer = $submenu->getRenderer(); + if (method_exists($renderer, 'getSummary')) { + if ($renderer->getSummary() !== null) { + $this->summary[] = $renderer->getSummary(); + } + } + } + } + return $this->getBadge() . $this->createLink($menu); + } + + /** + * Get the problem badge + * + * @return string + */ + protected function getBadge() + { + if (count($this->summary) > 0) { + $problems = 0; + $titles = array(); + + foreach ($this->summary as $summary) { + $problems += $summary['problems']; + $titles[] = $summary['title']; + } + + return sprintf( + '
%s
', + implode(', ', $titles), + $problems + ); + } + return ''; + } +} diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index a7f8047c4..fd3ee334d 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -208,7 +208,8 @@ $section->add($this->translate('Alert Summary'), array( $section = $this->menuSection($this->translate('System')); $section->add($this->translate('Monitoring Health'), array( 'url' => 'monitoring/process/info', - 'priority' => 120 + 'priority' => 120, + 'renderer' => 'Icinga\Module\Monitoring\Web\Menu\BackendAvailabilityMenuItemRenderer' )); /* diff --git a/modules/monitoring/library/Monitoring/Web/Menu/BackendAvailabilityMenuItemRenderer.php b/modules/monitoring/library/Monitoring/Web/Menu/BackendAvailabilityMenuItemRenderer.php new file mode 100644 index 000000000..186351a40 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Web/Menu/BackendAvailabilityMenuItemRenderer.php @@ -0,0 +1,62 @@ +select()->from( + 'programstatus', + array( + 'is_currently_running' + ) + )->getQuery()->fetchRow()->is_currently_running; + } + + /** + * @see MenuItemRenderer::render() + */ + public function render(Menu $menu) + { + return $this->getBadge() . $this->createLink($menu); + } + + protected function getBadge() + { + if (! (bool)$this->isCurrentlyRunning()) { + return sprintf( + '
%s
', + mt('monitoring', 'monitoring backend is not running'), + 1 + ); + } + return ''; + } + + /** + * Get the problem data for the summary + * + * @return array|null + */ + public function getSummary() + { + if (! (bool)$this->isCurrentlyRunning()) { + return array( + 'problems' => 1, + 'title' => mt('monitoring', 'monitoring backend is not running') + ); + } + return null; + } +} diff --git a/modules/monitoring/public/css/module.less b/modules/monitoring/public/css/module.less index 4cc68e18e..881e38f09 100644 --- a/modules/monitoring/public/css/module.less +++ b/modules/monitoring/public/css/module.less @@ -173,19 +173,15 @@ form.instance-features span.description, form.object-features span.description { } } -table.avp form.object-features div.header h4, -table.avp h4.customvar { +table.avp form.object-features div.header h4 { margin: 0; } -table.avp .customvar ul, -table.avp .customvar ul li { +table.avp .customvar ul { list-style-type: none; margin: 0; - margin-top: -0.5em; - margin-bottom: -0.5em; padding: 0; - padding-left: 0.5em; + padding-left: 1.5em; } div.selection-info { @@ -219,3 +215,10 @@ hr.command-separator { border: none; border-bottom: 2px solid @colorPetrol; } + +div.backend-not-running { + background: @colorCritical; + color: white; + text-align: center; + padding: 0.1em; +}