From 7d25efb93caeff3bf7cb9ef7ba2a762d53b0002f Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Fri, 22 Aug 2014 15:35:02 +0200 Subject: [PATCH 1/6] Remove dashboard.ini related parts refs #6639 --- .vagrant-puppet/manifests/default.pp | 12 --------- config/dashboard/dashboard.ini | 39 ---------------------------- doc/dashboard.md | 26 ------------------- icingaweb2.spec | 2 -- 4 files changed, 79 deletions(-) delete mode 100644 config/dashboard/dashboard.ini diff --git a/.vagrant-puppet/manifests/default.pp b/.vagrant-puppet/manifests/default.pp index 282803a83..13d54bf9f 100644 --- a/.vagrant-puppet/manifests/default.pp +++ b/.vagrant-puppet/manifests/default.pp @@ -740,18 +740,6 @@ file { '/etc/icingaweb/modules/monitoring/instances.ini': group => 'apache', } -file { '/etc/icingaweb/dashboard': - ensure => 'directory', - owner => 'apache', - group => 'apache', -} - -file { '/etc/icingaweb/dashboard/dashboard.ini': - source => 'puppet:////vagrant/config/dashboard/dashboard.ini', - owner => 'apache', - group => 'apache', -} - # pear::package { 'deepend/Mockery': # channel => 'pear.survivethedeepend.com' # } diff --git a/config/dashboard/dashboard.ini b/config/dashboard/dashboard.ini deleted file mode 100644 index 022b34be5..000000000 --- a/config/dashboard/dashboard.ini +++ /dev/null @@ -1,39 +0,0 @@ -[Incidents] -title = "Current incidents" - -[Incidents.Service Problems] -url = "monitoring/list/services" -service_problem = 1 -limit = 10 -sort = service_severity - -[Incidents.Recently Recovered Services] -url = "monitoring/list/services" -sort = "service_last_state_change" -service_state = 0 -limit = 10 -dir = "desc" - -[Incidents.Host Problems] -url = "monitoring/list/hosts" -host_problem = 1 -sort = host_severity - -[Landing] -title = "Landing page" - -[Landing.Hostgroups] -url = "monitoring/chart/hostgroup" - -[Landing.Servicegroups] -url = "monitoring/chart/servicegroup" - -[Landing.Unhandled Problem Services] -url = "monitoring/list/services" -service_handled = 0 -service_problem = 1 - -[Landing.Unhandled Problem Hosts] -url = "monitoring/list/hosts" -host_handled = 0 -host_problem = 1 diff --git a/doc/dashboard.md b/doc/dashboard.md index 89ff52ee1..1b1e7a983 100644 --- a/doc/dashboard.md +++ b/doc/dashboard.md @@ -14,30 +14,4 @@ the objects you're interested in and can add and remove elements. * The dashboard itself is just the view containing the panes -## Configuration files - -By default, the config/dashboard/dashboard.ini is used for storing dashboards in the following format: - - [PaneName] ; Define a new Pane - title = "PaneTitle" ; The title of the pane as displayed in the tabls - - [PaneName.Component1] ; Define a new component 'Component 1' underneat the pane - url = "/url/for/component1" ; the url that will be displayed, with view=compact as URL parameter appended - height = "500px" ; optional height setting - width = "400px" ; optional width setting - - [test.My hosts] ; Another component, here with host - url = "monitoring/list/hosts" ; the url of the component - ; Notice the missing height/width definition - - [test.My services] ; And another pane - url = "monitoring/list/services" ; With service url - - [test2] ; Define a second pane - title = "test2" ; with the title - - [test2.test] ; Add a component to the second pane - url = "/monitoring/show/host/host1" ; ...and define it's url - - [dashboards1]: res/Dashboard.png diff --git a/icingaweb2.spec b/icingaweb2.spec index d7cc53ed9..270e18fff 100644 --- a/icingaweb2.spec +++ b/icingaweb2.spec @@ -185,8 +185,6 @@ install -D -m0644 packages/rpm/etc/httpd/conf.d/icingaweb.conf %{buildroot}/%{ap install -D -m0644 packages/rpm/etc/icingaweb/authentication.ini %{buildroot}/%{_sysconfdir}/icingaweb/authentication.ini # custom resource paths install -D -m0644 packages/rpm/etc/icingaweb/resources.ini %{buildroot}/%{_sysconfdir}/icingaweb/resources.ini -# dashboard -install -D -m0644 config/dashboard/dashboard.ini %{buildroot}/%{_sysconfdir}/icingaweb/dashboard/dashboard.ini # monitoring module (icinga2) install -D -m0644 packages/rpm/etc/icingaweb/modules/monitoring/backends.ini %{buildroot}/%{_sysconfdir}/icingaweb/modules/monitoring/backends.ini install -D -m0644 packages/rpm/etc/icingaweb/modules/monitoring/instances.ini %{buildroot}/%{_sysconfdir}/icingaweb/modules/monitoring/instances.ini From b60c3590b00fe08e90809fde0ba2dd9405b8aeac Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Fri, 22 Aug 2014 15:37:23 +0200 Subject: [PATCH 2/6] Deactivate addUrl to Dashboard refs #6639 --- application/views/scripts/dashboard/addurl.phtml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/application/views/scripts/dashboard/addurl.phtml b/application/views/scripts/dashboard/addurl.phtml index 27ea46f56..c2d3f7e6c 100644 --- a/application/views/scripts/dashboard/addurl.phtml +++ b/application/views/scripts/dashboard/addurl.phtml @@ -2,6 +2,11 @@ tabs ?> -
-form ?> -
+
+

escape($this->translate('This feature is deactivated at the moment.')); ?>

+

+ escape($this->translate('Please have a little patience, we are hard working on it, take a look at icingaweb2 issues.')); + ?> +

+
\ No newline at end of file From 11127446e07e7fe8fb083c59210cbc95ac19812d Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Fri, 22 Aug 2014 15:39:35 +0200 Subject: [PATCH 3/6] Update description if no dashlets available refs #6639 --- .../views/scripts/dashboard/index.phtml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/application/views/scripts/dashboard/index.phtml b/application/views/scripts/dashboard/index.phtml index 3e721dc68..4adad7b66 100644 --- a/application/views/scripts/dashboard/index.phtml +++ b/application/views/scripts/dashboard/index.phtml @@ -7,16 +7,10 @@
-

No dashboard configuration found!

-

- translate('We tried to load a dashboard configuration with no success.' - . ' Please have look that the configuration does exist:'); - ?> - - - escape($this->configPath) ?>.ini - -

+

escape($this->translate('Welcome to Icinga Web!')) ?>

+

escape($this->translate('Currently there is no dashlet available. This might change once you enabled some of the available %s.')), + $this->qlink($this->translate('modules'), 'config/modules') + ) ?>

- \ No newline at end of file + \ No newline at end of file From af0cf48197c9ffccddbfcec619037a33503acb78 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 26 Aug 2014 10:08:33 +0200 Subject: [PATCH 4/6] Add self provided configuration for dashlets refs #6639 --- .../controllers/DashboardController.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 1f45eacde..108117959 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -111,19 +111,23 @@ class DashboardController extends ActionController */ public function indexAction() { - $dashboard = $this->getDashboard(); - if ($this->_getParam('pane')) { - $pane = $this->_getParam('pane'); - $dashboard->activate($pane); - } + $dashboard = Dashboard::load(); - $this->view->configPath = IcingaConfig::resolvePath(self::DEFAULT_CONFIG); - - if ($dashboard === null) { + if (! $dashboard->hasPanes()) { $this->view->title = 'Dashboard'; } else { - $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard'; - $this->view->tabs = $dashboard->getTabs(); + if ($this->_getParam('pane')) { + $pane = $this->_getParam('pane'); + $dashboard->activate($pane); + } + + $this->view->configPath = IcingaConfig::resolvePath(self::DEFAULT_CONFIG); + + if ($dashboard === null) { + $this->view->title = 'Dashboard'; + } else { + $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard'; + $this->view->tabs = $dashboard->getTabs(); /* Temporarily removed $this->view->tabs->add( @@ -135,8 +139,8 @@ class DashboardController extends ActionController ); */ - $this->view->dashboard = $dashboard; - + $this->view->dashboard = $dashboard; + } } } From bae5ba23524ffc24453a3189233b6d01c45249fc Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 26 Aug 2014 10:12:19 +0200 Subject: [PATCH 5/6] Add self provided configuration for dashlets in monitoring module refs #6639 --- modules/monitoring/configuration.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index d4431e6e1..412581d24 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -125,10 +125,18 @@ $section->add($this->translate('Performance Info'), array( )); /* - -$dashboard = $this->dashboard('Current Incidents'); // Web\Widget\Dashboard\Pane -$dashboard->add('Service Problems', array( - -)); - -*/ + * Dashboard + */ +$dashboard = $this->dashboard($this->translate('Current Incidents')); +$dashboard->add( + $this->translate('Service Problems'), + 'monitoring/list/services?service_problem=1&limit=10&sort=service_severity' +); +$dashboard->add( + $this->translate('Recently Recovered Services'), + 'monitoring/list/services?service_state=0&limit=10&sort=service_last_state_change&dir=desc' +); +$dashboard->add( + $this->translate('Host Problems'), + 'monitoring/list/hosts?host_problem=1&sort=host_severity' +); From 42e2b3435699e7f6452304a0679b4954bdc7a6b0 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 26 Aug 2014 10:13:49 +0200 Subject: [PATCH 6/6] Implement self provided configuration for dashboard/dashlets in modules refs #6639 --- library/Icinga/Application/Modules/Module.php | 31 ++++++++++++ library/Icinga/Web/Widget/Dashboard.php | 50 +++++++++++++++++++ library/Icinga/Web/Widget/Dashboard/Pane.php | 41 +++++++++++++++ 3 files changed, 122 insertions(+) diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index a4b87be08..a325dfef0 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -16,6 +16,7 @@ use Icinga\Util\Translator; use Icinga\Web\Hook; use Icinga\Web\Menu; use Icinga\Web\Widget; +use Icinga\Web\Widget\Dashboard\Pane; use Icinga\Util\File; use Icinga\Exception\ProgrammingError; @@ -154,6 +155,36 @@ class Module */ protected $menuItems = array(); + /** + * A set of Pane elements + * + * @var array + */ + protected $paneItems = array(); + + /** + * Get all Menu Items + * + * @return array + */ + public function getPaneItems() + { + $this->launchConfigScript(); + return $this->paneItems; + } + + /** + * Add a pane to dashboard + * + * @param $name + * @return Pane + */ + protected function dashboard($name) + { + $this->paneItems[$name] = new Pane($name); + return $this->paneItems[$name]; + } + /** * Get all Menu Items * diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index c87afa1ab..f565c0fca 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -63,6 +63,46 @@ class Dashboard extends AbstractWidget $this->getTabs()->activate($name); } + /** + * Load Pane items provided by all enabled modules + * + * @return self + */ + public static function load() + { + /** @var $dashboard Dashboard */ + $dashboard = new static('dashboard'); + $manager = Icinga::app()->getModuleManager(); + foreach ($manager->getLoadedModules() as $module) { + /** @var $module \Icinga\Application\Modules\Module */ + $dashboard->mergePanes($module->getPaneItems()); + + } + return $dashboard; + } + + /** + * Merge panes with existing panes + * + * @param array $panes + * @return $this + */ + public function mergePanes(array $panes) + { + /** @var $pane Pane */ + foreach ($panes as $pane) { + if (array_key_exists($pane->getName(), $this->panes)) { + /** @var $current Pane */ + $current = $this->panes[$pane->getName()]; + $current->addComponents($pane->getComponents()); + } else { + $this->panes = array_filter(array_merge($this->panes, $panes)); + } + } + + return $this; + } + /** * Return the tab object used to navigate through this dashboard * @@ -147,6 +187,16 @@ class Dashboard extends AbstractWidget return $this; } + /** + * Checks if the current dashboard has any panes + * + * @return bool + */ + public function hasPanes() + { + return ! empty($this->panes); + } + /** * Return true if a pane doesn't exist or doesn't have any components in it * diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php index 5e3e8ffea..15cf56524 100644 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ b/library/Icinga/Web/Widget/Dashboard/Pane.php @@ -162,6 +162,47 @@ class Pane extends AbstractWidget return $this; } + /** + * Add new components to existing components + * + * @param array $components + * @return $this + */ + public function addComponents(array $components) + { + /* @var $component Component */ + foreach ($components as $component) { + if (array_key_exists($component->getTitle(), $this->components)) { + if (preg_match('/_(\d+)$/', $component->getTitle(), $m)) { + $name = preg_replace('/_\d+$/', $m[1]++, $component->getTitle()); + } else { + $name = $component->getTitle() . '_2'; + } + $this->components[$name] = $component; + } else { + $this->components[$component->getTitle()] = $component; + } + } + + return $this; + } + + /** + * Add a component to the current pane + * + * @param $title + * @param $url + * @return Component + * + * @see addComponent() + */ + public function add($title, $url = null) + { + $this->addComponent($title, $url); + + return $this->components[$title]; + } + /** * Return the this pane's structure as array *