From 0af71a82f04df2a88af50cabb3b8aece42c43aa2 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 18 Feb 2016 16:12:38 +0100 Subject: [PATCH] menu: show health summary --- configuration.php | 10 +- .../Renderer/ConfigHealthItemRenderer.php | 101 ++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 library/Director/Web/Navigation/Renderer/ConfigHealthItemRenderer.php diff --git a/configuration.php b/configuration.php index 1eac501f..61645f53 100644 --- a/configuration.php +++ b/configuration.php @@ -24,7 +24,12 @@ $this->provideConfigTab('config', array( $section = $this->menuSection( $this->translate('Icinga Director') -)->setIcon('cubes'); +)->setIcon( + 'cubes' +)->setRenderer(array( + 'SummaryNavigationItemRenderer', + 'state' => 'critical' +)); $section->add($this->translate('Overview'))->setUrl('director')->setPriority(20); $section->add($this->translate('Hosts'))->setUrl('director/hosts')->setPriority(30); @@ -36,5 +41,6 @@ $section->add($this->translate('Import / Sync')) ->setPriority(901); $section->add($this->translate('Config')) ->setUrl('director/list/deploymentlog') - ->setPriority(902); + ->setPriority(902) + ->setRenderer('ConfigHealthItemRenderer'); diff --git a/library/Director/Web/Navigation/Renderer/ConfigHealthItemRenderer.php b/library/Director/Web/Navigation/Renderer/ConfigHealthItemRenderer.php new file mode 100644 index 00000000..230ce7a2 --- /dev/null +++ b/library/Director/Web/Navigation/Renderer/ConfigHealthItemRenderer.php @@ -0,0 +1,101 @@ +checkHealth(); + return $this->count > 0; + } + + public function getState() + { + return $this->directorState; + } + + public function getCount() + { + if ($this->hasProblems()) { + return $this->count; + } else { + return 0; + } + } + + public function getTitle() + { + return $this->message; + } + + protected function checkHealth() + { + $db = $this->db(); + if (! $db) { + $this->directorState = self::STATE_PENDING; + $this->count = 1; + $this->message = $this->translate( + 'No database has been configured for Icinga Director' + ); + + return; + } + + $kickstart = new KickstartHelper($db); + if ($kickstart->isRequired()) { + $this->directorState = self::STATE_PENDING; + $this->count = 1; + $this->message = $this->translate( + 'No API user configured, you might run the kickstart helper' + ); + + return; + } + + $pendingChanges = $db->countActivitiesSinceLastDeployedConfig(); + + if ($pendingChanges > 0) { + $this->directorState = self::STATE_WARNING; + $this->count = $pendingChanges; + $this->message = sprintf( + $this->translate( + '%s config changes happend since the last deployed configuration' + ), + $pendingChanges + ); + + return; + } + } + + protected function translate($message) + { + return mt('director', $message); + } + + protected function db() + { + $resourceName = Config::module('director')->get('db', 'resource'); + if ($resourceName) { + return Db::fromResourceName($resourceName); + } else { + return false; + } + } +}