From 7f28c0a2372694b0a55df4f107dfe3933ce290b6 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Thu, 30 Apr 2015 16:06:05 +0200 Subject: [PATCH 1/4] Implement ProblemMenuItemRenderer refs # 4139 --- library/Icinga/Web/Menu.php | 23 ++++++- .../Web/Menu/ProblemMenuItemRenderer.php | 64 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 library/Icinga/Web/Menu/ProblemMenuItemRenderer.php diff --git a/library/Icinga/Web/Menu.php b/library/Icinga/Web/Menu.php index bca1e17d10..476d73879a 100644 --- a/library/Icinga/Web/Menu.php +++ b/library/Icinga/Web/Menu.php @@ -234,7 +234,8 @@ protected function addMainMenuItems() $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 @@ public function getPermission() 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 0000000000..010bdc0346 --- /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 ''; + } +} From 5075ccdf38698d03fb11b8f02cd4ae77fdd14826 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Thu, 30 Apr 2015 16:08:10 +0200 Subject: [PATCH 2/4] Add ProblemMenuItemRenderer to system menu as renderer refs #4139 --- modules/monitoring/configuration.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index a7f8047c4f..fd3ee334d5 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -208,7 +208,8 @@ $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' )); /* From 880b1eb21a2740aac5a0ea6df1eabefb1ddcfc6a Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Thu, 30 Apr 2015 16:12:36 +0200 Subject: [PATCH 3/4] Add better styling for backend-not-running class refs #4139 --- modules/monitoring/public/css/module.less | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/public/css/module.less b/modules/monitoring/public/css/module.less index 4cc68e18e7..881e38f098 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; +} From 8484a27b5685f22ab209808c453893b04186c548 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Thu, 30 Apr 2015 16:13:10 +0200 Subject: [PATCH 4/4] Add a backend problem menu item renderer to system menu refs #4139 --- .../BackendAvailabilityMenuItemRenderer.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Web/Menu/BackendAvailabilityMenuItemRenderer.php 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 0000000000..186351a405 --- /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; + } +}