From ceb32679d8247a4eec3afaf2240023da529907d3 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Mon, 3 Aug 2015 16:52:50 +0200 Subject: [PATCH 1/8] RemoteInstanceForm: Fix the unhandled exception if no ... ..resources are available * Now we only can use the ssh identity, if there is at least one ssh identity resource exists fixes #9517 --- .../Config/Instance/RemoteInstanceForm.php | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php index 244bf66d1..e290866cc 100644 --- a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php +++ b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php @@ -52,24 +52,46 @@ class RemoteInstanceForm extends Form return $this; } + /** + * Check whether ssh identity resources exists or not + * + * @return boolean + */ + public function hasResources() + { + $resourceConfig = ResourceFactory::getResourceConfigs(); + + foreach ($resourceConfig as $name => $resource) { + if ($resource->type === 'ssh') { + return true; + } + } + return false; + } + /** * (non-PHPDoc) * @see Form::createElements() For the method documentation. */ public function createElements(array $formData = array()) { - $useResource = isset($formData['use_resource']) ? $formData['use_resource'] : $this->getValue('use_resource'); + $useResource = false; - $this->addElement( - 'checkbox', - 'use_resource', - array( - 'label' => $this->translate('Use SSH Identity'), - 'description' => $this->translate('Make use of the ssh identity resource'), - 'autosubmit' => true, - 'ignore' => true - ) - ); + if ($this->hasResources()) { + $useResource = isset($formData['use_resource']) + ? $formData['use_resource'] : $this->getValue('use_resource'); + + $this->addElement( + 'checkbox', + 'use_resource', + array( + 'label' => $this->translate('Use SSH Identity'), + 'description' => $this->translate('Make use of the ssh identity resource'), + 'autosubmit' => true, + 'ignore' => true + ) + ); + } if ($useResource) { From 5ae21fd1965cb43b63f81d1c1ac7b7ff9dd9ac78 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 4 Aug 2015 12:48:53 +0200 Subject: [PATCH 2/8] doc: Set parameters from route explicitly refs #9817 --- modules/doc/library/Doc/DocController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/doc/library/Doc/DocController.php b/modules/doc/library/Doc/DocController.php index 36abe6b10..10a9b1d40 100644 --- a/modules/doc/library/Doc/DocController.php +++ b/modules/doc/library/Doc/DocController.php @@ -9,6 +9,21 @@ use Icinga\Web\Controller; class DocController extends Controller { + /** + * {@inheritdoc} + */ + protected function moduleInit() + { + // Our UrlParams object does not take parameters from custom routes into account which is why we have to set + // them explicitly + if ($this->hasParam('chapter')) { + $this->params->set('chapter', $this->getParam('chapter')); + } + if ($this->hasParam('moduleName')) { + $this->params->set('moduleName', $this->getParam('moduleName')); + } + } + /** * Render a chapter * From 1c5bf36538fe359b49857163a727f32d45fb6deb Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 4 Aug 2015 13:25:17 +0200 Subject: [PATCH 3/8] Host(s)-/Service(s)Controller: Set the form backend refs #9672 --- modules/monitoring/application/controllers/HostController.php | 1 + modules/monitoring/application/controllers/HostsController.php | 1 + modules/monitoring/application/controllers/ServiceController.php | 1 + .../monitoring/application/controllers/ServicesController.php | 1 + 4 files changed, 4 insertions(+) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index a7659726e..ffc7fcdd3 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -167,6 +167,7 @@ class Monitoring_HostController extends MonitoredObjectController $this->assertPermission('monitoring/command/process-check-result'); $form = new ProcessCheckResultCommandForm(); + $form->setBackend($this->backend); $form->setTitle($this->translate('Submit Passive Host Check Result')); $this->handleCommandForm($form); } diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 740b5cb5c..9a753adec 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -226,6 +226,7 @@ class Monitoring_HostsController extends Controller $this->assertPermission('monitoring/command/process-check-result'); $form = new ProcessCheckResultCommandForm(); + $form->setBackend($this->backend); $form->setTitle($this->translate('Submit Passive Host Check Results')); $this->handleCommandForm($form); } diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index d9ed0d36b..cf7c4807c 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -122,6 +122,7 @@ class Monitoring_ServiceController extends MonitoredObjectController $this->assertPermission('monitoring/command/process-check-result'); $form = new ProcessCheckResultCommandForm(); + $form->setBackend($this->backend); $form->setTitle($this->translate('Submit Passive Service Check Result')); $this->handleCommandForm($form); } diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index faebcd11c..18c427f86 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -242,6 +242,7 @@ class Monitoring_ServicesController extends Controller $this->assertPermission('monitoring/command/process-check-result'); $form = new ProcessCheckResultCommandForm(); + $form->setBackend($this->backend); $form->setTitle($this->translate('Submit Passive Service Check Results')); $this->handleCommandForm($form); } From dfbcc066a7157dda58427787aa577282c7b2417e Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 4 Aug 2015 13:28:32 +0200 Subject: [PATCH 4/8] MonitoringBackend: Implement the getProgramVersion method refs #9672 --- .../library/Monitoring/Backend/MonitoringBackend.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php b/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php index 012b7c110..6ee534b17 100644 --- a/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php +++ b/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php @@ -331,4 +331,14 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface array_push($parts, 'Query', ucfirst(strtolower($query)) . 'Query'); return implode('\\', $parts); } + + /** + * Fetch and return the program version of the current instance + * + * @return string + */ + public function getProgramVersion() + { + return $this->select()->from('programstatus', array('program_version'))->fetchOne(); + } } From 18f382e85e51e54cc9506a4e9d6fc94685216085 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 4 Aug 2015 13:30:46 +0200 Subject: [PATCH 5/8] ProcessCheckResultCommandForm: Use getHostMultiOptions method refs #9672 --- .../Object/ProcessCheckResultCommandForm.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php index ec80a539f..6b566bbd6 100644 --- a/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php @@ -52,11 +52,7 @@ class ProcessCheckResultCommandForm extends ObjectsCommandForm 'required' => true, 'label' => $this->translate('Status'), 'description' => $this->translate('The state this check result should report'), - 'multiOptions' => $object->getType() === $object::TYPE_HOST ? array( - ProcessCheckResultCommand::HOST_UP => $this->translate('UP', 'icinga.state'), - ProcessCheckResultCommand::HOST_DOWN => $this->translate('DOWN', 'icinga.state'), - ProcessCheckResultCommand::HOST_UNREACHABLE => $this->translate('UNREACHABLE', 'icinga.state') - ) : array( + 'multiOptions' => $object->getType() === $object::TYPE_HOST ? $this->getHostMultiOptions() : array( ProcessCheckResultCommand::SERVICE_OK => $this->translate('OK', 'icinga.state'), ProcessCheckResultCommand::SERVICE_WARNING => $this->translate('WARNING', 'icinga.state'), ProcessCheckResultCommand::SERVICE_CRITICAL => $this->translate('CRITICAL', 'icinga.state'), @@ -115,4 +111,23 @@ class ProcessCheckResultCommandForm extends ObjectsCommandForm return true; } + + /** + * Returns the available host options based on the program version + * + * @return array + */ + protected function getHostMultiOptions() + { + $options = array( + ProcessCheckResultCommand::HOST_UP => $this->translate('UP', 'icinga.state'), + ProcessCheckResultCommand::HOST_DOWN => $this->translate('DOWN', 'icinga.state') + ); + + if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->getBackend()->getProgramVersion())) { + $options[ProcessCheckResultCommand::HOST_UNREACHABLE] = $this->translate('UNREACHABLE', 'icinga.state'); + } + + return $options; + } } From b5ae4599fd790eba178edcba644c3513501e2e0c Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 4 Aug 2015 13:54:30 +0200 Subject: [PATCH 6/8] ProcessCheckResultCommandForm: Use substr instead of pregmatch refs #9672 --- .../forms/Command/Object/ProcessCheckResultCommandForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php index 6b566bbd6..0239ab657 100644 --- a/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/ProcessCheckResultCommandForm.php @@ -124,7 +124,7 @@ class ProcessCheckResultCommandForm extends ObjectsCommandForm ProcessCheckResultCommand::HOST_DOWN => $this->translate('DOWN', 'icinga.state') ); - if (! preg_match('~^v2\.\d+\.\d+.*$~', $this->getBackend()->getProgramVersion())) { + if (substr($this->getBackend()->getProgramVersion(), 0, 2) !== 'v2') { $options[ProcessCheckResultCommand::HOST_UNREACHABLE] = $this->translate('UNREACHABLE', 'icinga.state'); } From c3fe14a205d5e4ecf91fc006a8744f38a965fa4f Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 4 Aug 2015 14:34:30 +0200 Subject: [PATCH 7/8] Modules/Manager: Fix that non-existent modules can be disabled fixes #9374 --- library/Icinga/Application/Modules/Manager.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 8a3970841..f3bf4e016 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -281,7 +281,10 @@ class Manager public function disableModule($name) { if (! $this->hasEnabled($name)) { - return $this; + throw new ConfigurationError( + 'Cannot disable module "%s". Module is not installed.', + $name + ); } if (! is_writable($this->enableDir)) { From ac31fb00c9a2b7261171e82575856900004d6af6 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 4 Aug 2015 15:08:30 +0200 Subject: [PATCH 8/8] dashboard/index: Fix the suggestion to enable modules fixes #9790 --- application/views/scripts/dashboard/index.phtml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/application/views/scripts/dashboard/index.phtml b/application/views/scripts/dashboard/index.phtml index 8550d8a6b..1d561146f 100644 --- a/application/views/scripts/dashboard/index.phtml +++ b/application/views/scripts/dashboard/index.phtml @@ -11,10 +11,16 @@

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

- hasPermission('config/modules')) { + echo $this->escape($this->translate( + 'Currently there is no dashlet available. Please contact the administrator.' + )); + } else { + printf( $this->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') - ) ?> + ); + } ?>