From 1a1263d9d866eb2b84b5ba7d24a3129325cc3572 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Thu, 10 Jul 2014 11:09:48 +0200
Subject: [PATCH 001/277] Rename Icinga\Web\Form\Decorator\BootstrapForm
We do not use bootstrap anymore but do not want the default Zend
decorators either so this decorator got a more common name.
refs #5525
---
.../Web/Form/Decorator/BootstrapForm.php | 105 ------------------
.../Web/Form/Decorator/ElementWrapper.php | 70 ++++++++++++
public/css/icinga/forms.less | 6 +-
3 files changed, 71 insertions(+), 110 deletions(-)
delete mode 100644 library/Icinga/Web/Form/Decorator/BootstrapForm.php
create mode 100644 library/Icinga/Web/Form/Decorator/ElementWrapper.php
diff --git a/library/Icinga/Web/Form/Decorator/BootstrapForm.php b/library/Icinga/Web/Form/Decorator/BootstrapForm.php
deleted file mode 100644
index 89ad82780..000000000
--- a/library/Icinga/Web/Form/Decorator/BootstrapForm.php
+++ /dev/null
@@ -1,105 +0,0 @@
-
- * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
- * @author Icinga Development Team
- *
- */
-// {{{ICINGA_LICENSE_HEADER}}}
-
-namespace Icinga\Web\Form\Decorator;
-
-use Zend_Form_Decorator_Abstract;
-
-/**
- * Decorator that styles forms in the DOM Bootstrap wants for it's forms
- *
- * This component replaces the dt/dd wrapping of elements with the approach used by bootstrap.
- *
- * Labels are drawn for all elements, except hidden, button and submit elements. If you want a
- * placeholder for this elements, set the 'addLabelPlaceholder' property. This can be useful in
- * cases where you want to put inputs with and inputs without labels on the same line and don't
- * want buttons to 'jump'
- */
-class BootstrapForm extends Zend_Form_Decorator_Abstract
-{
- /**
- * An array of elements that won't get a
-
\ No newline at end of file
+
From c3731fa79ec140ab739a7083e975d5000a522792 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Thu, 24 Jul 2014 16:17:30 +0200
Subject: [PATCH 035/277] Adjust removeresource-action to suit the new resource
form interface
refs #5525
---
application/controllers/ConfigController.php | 54 ++++++++++---------
.../scripts/config/resource/remove.phtml | 13 ++---
.../Web/Controller/BaseConfigController.php | 14 +++++
3 files changed, 47 insertions(+), 34 deletions(-)
diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index 4e6bc9bd7..ee91f729f 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -447,44 +447,50 @@ class ConfigController extends BaseConfigController
$this->render('resource/modify');
}
+ /**
+ * Display a confirmation form to remove a resource
+ */
public function removeresourceAction()
{
$this->view->messageBox = new AlertMessageBox(true);
- $resources = ResourceFactory::getResourceConfigs()->toArray();
- $name = $this->getParam('resource');
- if (!isset($resources[$name])) {
- $this->addSuccessMessage('Can\'t remove: Unknown resource provided');
- $this->render('resource/remove');
- return;
+ // Fetch the resource to be removed
+ $resources = IcingaConfig::app('resources')->toArray();
+ $name = $this->getParam('resource');
+ if (false === array_key_exists($name, $resources)) {
+ $this->addErrorMessage(sprintf($this->translate('Cannot remove "%s". Resource not found.'), $name));
+ $this->redirectNow('config/configurationerror');
+ }
+
+ // Check if selected resource is currently used for authentication
+ $authConfig = IcingaConfig::app('authentication')->toArray();
+ foreach ($authConfig as $backendName => $config) {
+ if (array_key_exists('resource', $config) && $config['resource'] === $name) {
+ $this->addWarningMessage(
+ sprintf(
+ $this->translate(
+ 'The resource "%s" is currently in use by the authentication backend "%s". ' .
+ 'Removing the resource can result in noone being able to log in any longer.'
+ ),
+ $name,
+ $backendName
+ )
+ );
+ }
}
$form = new ConfirmRemovalForm();
- $form->setRequest($this->getRequest());
- $form->setRemoveTarget('resource', $name);
-
- // Check if selected resource is currently used for authentication
- $authConfig = IcingaConfig::app('authentication', true)->toArray();
- foreach ($authConfig as $backendName => $config) {
- if (array_key_exists('resource', $config) && $config['resource'] === $name) {
- $this->addErrorMessage(
- 'Warning: The resource "' . $name . '" is currently used for user authentication by "' . $backendName . '". ' .
- ' Deleting it could eventally make login impossible.'
- );
- }
- }
-
- if ($form->isSubmittedAndValid()) {
+ $request = $this->getRequest();
+ if ($request->isPost() && $form->isValid($request->getPost())) {
unset($resources[$name]);
if ($this->writeConfigFile($resources, 'resources')) {
- $this->addSuccessMessage('Resource "' . $name . '" removed.');
+ $this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully removed.'), $name));
$this->redirectNow('config/resource');
}
- return;
}
- $this->view->name = $name;
$this->view->form = $form;
+ $this->view->messageBox->addForm($form);
$this->render('resource/remove');
}
diff --git a/application/views/scripts/config/resource/remove.phtml b/application/views/scripts/config/resource/remove.phtml
index 3b5ffbfc1..fba6b081b 100644
--- a/application/views/scripts/config/resource/remove.phtml
+++ b/application/views/scripts/config/resource/remove.phtml
@@ -1,10 +1,3 @@
-
+= $messageBox; ?>
+= $form; ?>
\ No newline at end of file
diff --git a/library/Icinga/Web/Controller/BaseConfigController.php b/library/Icinga/Web/Controller/BaseConfigController.php
index 98941686e..b4c90f3e2 100644
--- a/library/Icinga/Web/Controller/BaseConfigController.php
+++ b/library/Icinga/Web/Controller/BaseConfigController.php
@@ -47,6 +47,20 @@ class BaseConfigController extends ActionController
Session::getSession()->write();
}
+ /**
+ * Send a message with the logging level Zend_Log::WARN to the current user and
+ * commit the changes to the underlying session.
+ *
+ * @param $msg The message content
+ */
+ protected function addWarningMessage($msg)
+ {
+ AuthenticationManager::getInstance()->getUser()->addMessage(
+ new Message($msg, Zend_Log::WARN)
+ );
+ Session::getSession()->write();
+ }
+
/*
* Return an array of tabs provided by this configuration controller.
*
From 26a78dc387e19ad95e1386adff20c6fab7c84b8a Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Thu, 24 Jul 2014 16:20:01 +0200
Subject: [PATCH 036/277] Remove properties from ConfirmRemovalForm and update
it
Which object should be removed needs not to be a part of a form but is
accessible from the url's query string which should be in the action of the
form.
refs #5525
---
.../forms/Config/ConfirmRemovalForm.php | 48 +++----------------
1 file changed, 7 insertions(+), 41 deletions(-)
diff --git a/application/forms/Config/ConfirmRemovalForm.php b/application/forms/Config/ConfirmRemovalForm.php
index 65624c7b5..96dea6056 100644
--- a/application/forms/Config/ConfirmRemovalForm.php
+++ b/application/forms/Config/ConfirmRemovalForm.php
@@ -12,57 +12,23 @@ use Icinga\Web\Form;
class ConfirmRemovalForm extends Form
{
/**
- * The value of the target to remove
- *
- * @var string
+ * Initalize this form
*/
- private $removeTarget;
-
- /**
- * The name of the target parameter to remove
- *
- * @var string
- */
- private $targetName;
-
- /**
- * Set the remove target in this field to be a hidden field with $name and value $target
- *
- * @param string $name The name to be set in the hidden field
- * @param string $target The value to be set in the hidden field
- */
- public function setRemoveTarget($name, $target)
+ public function init()
{
- $this->targetName = $name;
- $this->removeTarget = $target;
+ $this->setName('form_confirm_removal');
}
/**
- * Create the confirmation form
- *
- * @see Form::create()
+ * @see Form::addSubmitButton()
*/
- public function create()
+ public function addSubmitButton()
{
- $this->setName('form_confirm_removal');
$this->addElement(
- 'hidden',
- $this->targetName,
- array(
- 'value' => $this->removeTarget,
- 'required' => true
- )
- );
-
- $this->addElement(
- 'button',
+ 'submit',
'btn_submit',
array(
- 'type' => 'submit',
- 'escape' => false,
- 'value' => '1',
- 'class' => 'btn btn-cta btn-common',
- 'label' => ' Confirm Removal'
+ 'label' => t('Confirm Removal')
)
);
}
From af898cc2b3267217e96071192e4b6bef9e7c164a Mon Sep 17 00:00:00 2001
From: Alexander Klimov
Date: Thu, 24 Jul 2014 17:35:26 +0200
Subject: [PATCH 037/277] Prefer switch rather than if - elseif
---
application/controllers/ConfigController.php | 40 +++++++++++---------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index 210a4af68..a693599a9 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -233,25 +233,29 @@ class ConfigController extends BaseConfigController
$backendType = $this->getRequest()->getParam('type');
$authenticationConfig = IcingaConfig::app('authentication')->toArray();
- if ($backendType === 'ldap') {
- $form = new LdapBackendForm();
- } else if ($backendType === 'db') {
- $form = new DbBackendForm();
- } else if ($backendType === 'autologin') {
- $existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; });
- if (false === empty($existing)) {
- $this->addErrorMessage(
- $this->translate('An autologin backend already exists')
- );
+ switch ($backendType) {
+ case 'ldap':
+ $form = new LdapBackendForm();
+ break;
+ case 'db':
+ $form = new DbBackendForm();
+ break;
+ case 'autologin':
+ $existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; });
+ if (false === empty($existing)) {
+ $this->addErrorMessage(
+ $this->translate('An autologin backend already exists')
+ );
+ $this->redirectNow('config/configurationerror');
+ }
+ $form = new AutologinBackendForm();
+ break;
+ default:
+ $this->addErrorMessage(sprintf(
+ $this->translate('There is no backend type `%s\''),
+ $backendType
+ ));
$this->redirectNow('config/configurationerror');
- }
- $form = new AutologinBackendForm();
- } else {
- $this->addErrorMessage(sprintf(
- $this->translate('There is no backend type `%s\''),
- $backendType
- ));
- $this->redirectNow('config/configurationerror');
}
$request = $this->getRequest();
From 5f7652133e4479405294ca1d9ba1ab209d39aff7 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Fri, 25 Jul 2014 08:39:27 +0200
Subject: [PATCH 038/277] Fix code-style and documentation
---
.../controllers/ConfigController.php | 36 +++++++++----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php
index c06ded57f..a6b3ab6d4 100644
--- a/modules/monitoring/application/controllers/ConfigController.php
+++ b/modules/monitoring/application/controllers/ConfigController.php
@@ -2,19 +2,15 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
-use \Exception;
-
+use Exception;
use Icinga\Config\PreservingIniWriter;
use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Notification;
-use Icinga\Web\Url;
-
use Icinga\Module\Monitoring\Form\Config\ConfirmRemovalForm;
use Icinga\Module\Monitoring\Form\Config\Backend\EditBackendForm;
use Icinga\Module\Monitoring\Form\Config\Backend\CreateBackendForm;
use Icinga\Module\Monitoring\Form\Config\Instance\EditInstanceForm;
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
-
use Icinga\Exception\NotReadableError;
/**
@@ -22,7 +18,6 @@ use Icinga\Exception\NotReadableError;
*/
class Monitoring_ConfigController extends ModuleActionController
{
-
/**
* Display a list of available backends and instances
*/
@@ -74,7 +69,7 @@ class Monitoring_ConfigController extends ModuleActionController
}
/**
- * Display a form to create a new backends
+ * Display a form to create a new backend
*/
public function createbackendAction()
{
@@ -128,7 +123,7 @@ class Monitoring_ConfigController extends ModuleActionController
}
/**
- * Display a form to remove the instance identified by the 'instance' parameter
+ * Display a confirmation form to remove the instance identified by the 'instance' parameter
*/
public function removeinstanceAction()
{
@@ -214,9 +209,14 @@ class Monitoring_ConfigController extends ModuleActionController
}
/**
- * Display a form to remove the instance identified by the 'instance' parameter
+ * Write configuration to an ini file
+ *
+ * @param Zend_Config $config The configuration to write
+ * @param string $file The config file to write to
+ *
+ * @return bool Whether the configuration was written or not
*/
- private function writeConfiguration($config, $file)
+ protected function writeConfiguration($config, $file)
{
$target = $this->Config($file)->getConfigFile();
$writer = new PreservingIniWriter(array('filename' => $target, 'config' => $config));
@@ -234,26 +234,26 @@ class Monitoring_ConfigController extends ModuleActionController
}
/**
- * Return true if the backend exists in the current configuration
+ * Return whether the given backend exists in the current configuration
*
- * @param string $backend The name of the backend to check for existence
+ * @param string $backend The name of the backend to check
*
- * @return bool True if the backend name exists, otherwise false
+ * @return bool Whether the backend exists or not
*/
- private function isExistingBackend($backend)
+ protected function isExistingBackend($backend)
{
$backendCfg = $this->Config('backends');
return $backend && $backendCfg->get($backend);
}
/**
- * Return true if the instance exists in the current configuration
+ * Return whether the given instance exists in the current configuration
*
- * @param string $instance The name of the instance to check for existence
+ * @param string $instance The name of the instance to check
*
- * @return bool True if the instance name exists, otherwise false
+ * @return bool Whether the instance exists or not
*/
- private function isExistingInstance($instance)
+ protected function isExistingInstance($instance)
{
$instanceCfg = $this->Config('instances');
return $instanceCfg && $instanceCfg->get($instance);
From a6bd802e3e565b2b9f873c12ebeb5eacbe08f8a4 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Fri, 25 Jul 2014 08:58:11 +0200
Subject: [PATCH 039/277] Remove unnecessary properties and its getters/setters
refs #5525
---
.../forms/Config/Backend/EditBackendForm.php | 66 -------------------
1 file changed, 66 deletions(-)
diff --git a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
index 52e420a76..93d306d72 100644
--- a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
+++ b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
@@ -14,72 +14,6 @@ use Icinga\Data\ResourceFactory;
*/
class EditBackendForm extends Form
{
- /**
- * Database resources to use instead of the one's from ResourceFactory (used for testing)
- *
- * @var array
- */
- protected $resources;
-
- /**
- * The Backend configuration to use for populating the form
- *
- * @var Zend_Config
- */
- protected $backend;
-
- /**
- * Set the configuration to be used for initial population of the form
- *
- * @param Zend_Form $config
- */
- public function setBackendConfiguration($config)
- {
- $this->backend = $config;
- }
-
- /**
- * Set a custom array of resources to be used in this form instead of the ones from ResourceFactory
- * (used for testing)
- */
- public function setResources($resources)
- {
- $this->resources = $resources;
- }
-
- /**
- * Return content of the resources.ini or previously set resources for displaying in the database selection field
- *
- * @return array
- */
- public function getResources()
- {
- if ($this->resources === null) {
- return ResourceFactory::getResourceConfigs()->toArray();
- } else {
- return $this->resources;
- }
- }
-
- /**
- * Return a list of all resources of the given type ready to be used as content for a select input
- *
- * @param string $type The type of resources to return
- *
- * @return array
- */
- protected function getResourcesByType($type)
- {
- $backends = array();
- foreach ($this->getResources() as $name => $resource) {
- if ($resource['type'] === $type) {
- $backends[$name] = $name;
- }
- }
-
- return $backends;
- }
-
/**
* Create this form
*
From 26d42da6352f750c0753780ef13b3473333179b1 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Fri, 25 Jul 2014 08:58:50 +0200
Subject: [PATCH 040/277] Re-add getResourcesByType as simplified version
refs #5525
---
.../forms/Config/Backend/EditBackendForm.php | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
index 93d306d72..b66383f73 100644
--- a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
+++ b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
@@ -79,4 +79,21 @@ class EditBackendForm extends Form
)
);
}
+
+ /**
+ * Return a list of all resources of the given type ready to be used as content for a select input
+ *
+ * @param string $type The type of resources to return
+ *
+ * @return array
+ */
+ protected function getResourcesByType($type)
+ {
+ $backends = array();
+ foreach (array_keys(ResourceFactory::getResourceConfigs($type)->toArray()) as $name) {
+ $backends[$name] = $name;
+ }
+
+ return $backends;
+ }
}
From af5a3262be89a58dfd3fba0a4f2a24bc7977bd5f Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Fri, 25 Jul 2014 09:12:12 +0200
Subject: [PATCH 041/277] Revert backslash removal in front of namespace-less
use statement
---
modules/monitoring/application/controllers/ConfigController.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php
index a6b3ab6d4..9e74943f3 100644
--- a/modules/monitoring/application/controllers/ConfigController.php
+++ b/modules/monitoring/application/controllers/ConfigController.php
@@ -2,7 +2,7 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
-use Exception;
+use \Exception;
use Icinga\Config\PreservingIniWriter;
use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Notification;
From 50de21e43786e79ddd020f20e0d7e360ea47eac7 Mon Sep 17 00:00:00 2001
From: Alexander Klimov
Date: Fri, 25 Jul 2014 10:29:33 +0200
Subject: [PATCH 042/277] Make it possible to edit an authentication backend
refs #6434
---
application/controllers/ConfigController.php | 68 +++++++++++--------
.../config/authentication/modify.phtml | 22 ++----
2 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index a693599a9..fd0e391fa 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -294,18 +294,21 @@ class ConfigController extends BaseConfigController
$configArray = IcingaConfig::app('authentication', true)->toArray();
$authBackend = $this->getParam('auth_backend');
- if (!isset($configArray[$authBackend])) {
- $this->addErrorMessage('Can\'t edit: Unknown Authentication Backend Provided');
- $this->configurationerrorAction();
- return;
- }
- if (!array_key_exists('resource', $configArray[$authBackend])) {
- $this->addErrorMessage('Configuration error: Backend "' . $authBackend . '" has no Resource');
- $this->configurationerrorAction();
- return;
+ if (false === isset($configArray[$authBackend])) {
+ $this->addErrorMessage(
+ $this->translate('Can\'t edit: Unknown Authentication Backend Provided')
+ );
+ $this->redirectNow('config/configurationerror');
}
- $type = ResourceFactory::getResourceConfig($configArray[$authBackend]['resource'])->type;
+ if (false === array_key_exists('backend', $configArray[$authBackend])) {
+ $this->addErrorMessage(sprintf(
+ $this->translate('Backend "%s" has no `backend\' setting'),
+ $authBackend
+ ));
+ $this->redirectNow('config/configurationerror');
+ }
+ $type = $configArray[$authBackend]['backend'];
switch ($type) {
case 'ldap':
$form = new LdapBackendForm();
@@ -313,32 +316,37 @@ class ConfigController extends BaseConfigController
case 'db':
$form = new DbBackendForm();
break;
+ case 'autologin':
+ $form = new AutologinBackendForm();
+ break;
default:
- $this->addErrorMessage('Can\'t edit: backend type "' . $type . '" of given resource not supported.');
- $this->configurationerrorAction();
- return;
+ $this->addErrorMessage(sprintf(
+ $this->translate('Can\'t edit: backend type "%s" of given resource not supported.'),
+ $type
+ ));
+ $this->redirectNow('config/configurationerror');
}
- $form->setBackendName($this->getParam('auth_backend'));
- $form->setBackend(IcingaConfig::app('authentication', true)->$authBackend);
- $form->setRequest($this->getRequest());
-
- if ($form->isSubmittedAndValid()) {
- $backendCfg = IcingaConfig::app('authentication')->toArray();
- foreach ($form->getConfig() as $backendName => $settings) {
- $backendCfg[$backendName] = $settings;
- // Remove the old section if the backend is renamed
+ $request = $this->getRequest();
+ if ($request->isPost()) {
+ if ($form->isValid($request->getPost())) {
+ list($backendName, $backendConfig) = $form->getBackendConfig();
+ $configArray[$backendName] = $backendConfig;
if ($backendName != $authBackend) {
- unset($backendCfg[$authBackend]);
+ unset($configArray[$authBackend]);
}
- unset($settings['name']);
+ if ($this->writeAuthenticationFile($configArray)) {
+ // redirect to overview with success message
+ Notification::success(sprintf(
+ $this->translate('Backend "%s" saved'),
+ $backendName
+ ));
+ $this->redirectNow('config/authentication');
+ }
+ return;
}
- if ($this->writeAuthenticationFile($backendCfg)) {
- // redirect to overview with success message
- Notification::success('Backend "' . $authBackend . '" created');
- $this->redirectNow("config/authentication");
- }
- return;
+ } else {
+ $form->setBackendConfig($authBackend, $configArray[$authBackend]);
}
$this->view->messageBox->addForm($form);
diff --git a/application/views/scripts/config/authentication/modify.phtml b/application/views/scripts/config/authentication/modify.phtml
index ca2cef6f9..4666ce686 100644
--- a/application/views/scripts/config/authentication/modify.phtml
+++ b/application/views/scripts/config/authentication/modify.phtml
@@ -1,18 +1,8 @@
+ = sprintf(
+ $this->translate('The file %s couldn\'t be stored. (Error: "%s")'),
+ $this->escape($filePath),
+ $this->escape($errorMessage)
+ ); ?>
+
+ = $this->translate('This could have one or more of the following reasons:'); ?>
+
+
+
= $this->translate('You don\'t have file-system permissions to write to the file'); ?>
+
= $this->translate('Something went wrong while writing the file'); ?>
+
= $this->translate('There\'s an application error preventing you from persisting the configuration'); ?>
+
+
+
+ = $this->translate('Details can be found in the application log. (If you don\'t have access to this log, call your administrator in this case)'); ?>
+
+ = $this->translate('In case you can access the file by yourself, you can open it and insert the config manually:'); ?>
+
+
+
+ = $this->escape($configString); ?>
+
+
\ No newline at end of file
From 0e2e1bc0056ea5f1b59597312b0f1eeeb0cfd6fa Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 29 Aug 2014 14:34:16 +0200
Subject: [PATCH 092/277] monitoring/commands: Add `CommandTransportInterface'
All concrete Icinga command transport classes should implement the `CommandTransportInterface' .
refs #6593
---
.../Transport/CommandTransportInterface.php | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php
new file mode 100644
index 000000000..bb0da2716
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php
@@ -0,0 +1,22 @@
+
Date: Fri, 29 Aug 2014 14:38:52 +0200
Subject: [PATCH 093/277] monitoring/commands: Replace `Command' with
`IcingaCommand'
Since there's already a `Cli\Command', `Command' is now named `IcingaCommand'.
All concrete Icinga commands should extend `IcingaCommand' which handles
command encoding. All other "features" of the `Command' object have been removed
because theses "features" should be handled by upcoming concrete command classes.
refs #6593
---
.../library/Monitoring/Command/Command.php | 177 ------------------
.../Monitoring/Command/IcingaCommand.php | 44 +++++
2 files changed, 44 insertions(+), 177 deletions(-)
delete mode 100644 modules/monitoring/library/Monitoring/Command/Command.php
create mode 100644 modules/monitoring/library/Monitoring/Command/IcingaCommand.php
diff --git a/modules/monitoring/library/Monitoring/Command/Command.php b/modules/monitoring/library/Monitoring/Command/Command.php
deleted file mode 100644
index e89169f35..000000000
--- a/modules/monitoring/library/Monitoring/Command/Command.php
+++ /dev/null
@@ -1,177 +0,0 @@
-withoutHosts = (bool) $state;
- return $this;
- }
-
- /**
- * Set whether this command should only affect the hosts of a host- or servicegroup
- *
- * @param bool $state
- * @return self
- */
- public function excludeServices($state = true)
- {
- $this->withoutServices = (bool) $state;
- return $this;
- }
-
- /**
- * Set whether this command should also affect all children hosts of a host
- *
- * @param bool $state
- * @return self
- */
- public function includeChildren($state = true)
- {
- $this->withChildren = (bool) $state;
- return $this;
- }
-
- /**
- * Set whether this command only affects the services associated with a particular host
- *
- * @param bool $state
- * @return self
- */
- public function excludeHost($state = true)
- {
- $this->onlyServices = (bool) $state;
- return $this;
- }
-
- /**
- * Getter for flag whether a command is global
- * @return bool
- */
- public function provideGlobalCommand()
- {
- return (bool) $this->globalCommand;
- }
-
- /**
- * Return this command's arguments in the order expected by the actual command definition
- *
- * @return array
- */
- abstract public function getArguments();
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- */
- abstract public function getHostCommand($hostname);
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- */
- abstract public function getServiceCommand($hostname, $servicename);
-
- /**
- * Return the command as a string with the given hostgroup being inserted
- *
- * @param string $hostgroup The name of the hostgroup to insert
- *
- * @return string The string representation of the command
- */
- public function getHostgroupCommand($hostgroup)
- {
- throw new ProgrammingError(
- '%s does not provide a hostgroup command',
- get_class($this)
- );
- }
-
- /**
- * Return the command as a string with the given servicegroup being inserted
- *
- * @param string $servicegroup The name of the servicegroup to insert
- *
- * @return string The string representation of the command
- */
- public function getServicegroupCommand($servicegroup)
- {
- throw new ProgrammingError(
- '%s does not provide a servicegroup command',
- get_class($this)
- );
- }
-
- /**
- * Return the command as a string for the whole instance
- *
- * @param string $instance
- *
- * @return string
- * @throws ProgrammingError
- */
- public function getGlobalCommand($instance = null)
- {
- throw new ProgrammingError(
- '%s does not provide a global command',
- getclass($this)
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/IcingaCommand.php b/modules/monitoring/library/Monitoring/Command/IcingaCommand.php
new file mode 100644
index 000000000..dd8dd97fe
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/IcingaCommand.php
@@ -0,0 +1,44 @@
+escape($this->getCommandString())
+ );
+ }
+}
From 2ac4a8503c5dd3e1f0815c1d5a7fefc6d0ae2059 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 29 Aug 2014 14:43:44 +0200
Subject: [PATCH 094/277] monitoring/commands: Remove the `Transport' interface
The `Transport' interface is superseded by the `CommandTransportInterface'.
refs #6593
---
.../Command/Transport/Transport.php | 27 -------------------
1 file changed, 27 deletions(-)
delete mode 100644 modules/monitoring/library/Monitoring/Command/Transport/Transport.php
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/Transport.php b/modules/monitoring/library/Monitoring/Command/Transport/Transport.php
deleted file mode 100644
index c5a5b3883..000000000
--- a/modules/monitoring/library/Monitoring/Command/Transport/Transport.php
+++ /dev/null
@@ -1,27 +0,0 @@
-
Date: Fri, 29 Aug 2014 15:04:48 +0200
Subject: [PATCH 095/277] monitoring/commands: Replace `LocalPipe' with
`LocalCommandFile'
`LocalCommandFile' is configured via property setters instead of the too general `setEndpoint' function.
refs #6593
---
.../Command/Transport/LocalCommandFile.php | 115 ++++++++++++++++++
.../Command/Transport/LocalPipe.php | 70 -----------
2 files changed, 115 insertions(+), 70 deletions(-)
create mode 100644 modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Transport/LocalPipe.php
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php b/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php
new file mode 100644
index 000000000..8278b79b0
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php
@@ -0,0 +1,115 @@
+path = (string) $path;
+ return $this;
+ }
+
+ /**
+ * Get the path to the local Icinga command file
+ *
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ /**
+ * Set the mode used to open the icinga command file
+ *
+ * @param string $openMode
+ *
+ * @return self
+ */
+ public function setOpenMode($openMode)
+ {
+ $this->openMode = (string) $openMode;
+ return $this;
+ }
+
+ /**
+ * Get the mode used to open the icinga command file
+ *
+ * @return string
+ */
+ public function getOpenMode()
+ {
+ return $this->openMode;
+ }
+
+ /**
+ * Write the command to the local Icinga command file
+ *
+ * @param IcingaCommand $command
+ *
+ * @throws LogicException
+ * @throws TransportException
+ */
+ public function send(IcingaCommand $command)
+ {
+ if (! isset($this->path)) {
+ throw new LogicException;
+ }
+ Logger::debug(
+ sprintf(
+ mt('monitoring', 'Sending external Icinga command "%s" to the local command file "%s"'),
+ $command,
+ $this->path
+ )
+ );
+ try {
+ $file = new File($this->path, $this->openMode);
+ $file->fwrite($command . "\n");
+ $file->fflush();
+ } catch (Exception $e) {
+ throw new TransportException(
+ mt(
+ 'monitoring',
+ 'Can\'t send external Icinga command "%s" to the local command file "%s": %s'
+ ),
+ $command,
+ $this->path,
+ $e
+ );
+ }
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/LocalPipe.php b/modules/monitoring/library/Monitoring/Command/Transport/LocalPipe.php
deleted file mode 100644
index 32f745565..000000000
--- a/modules/monitoring/library/Monitoring/Command/Transport/LocalPipe.php
+++ /dev/null
@@ -1,70 +0,0 @@
-path = isset($config->path) ? $config->path : '/usr/local/icinga/var/rw/icinga.cmd';
- }
-
- /**
- * @see Transport::send()
- */
- public function send($message)
- {
- Logger::debug('Attempting to send external icinga command %s to local command file ', $message, $this->path);
-
- try {
- $file = new File($this->path, $this->openMode);
- $file->fwrite('[' . time() . '] ' . $message . PHP_EOL);
- $file->fflush();
- } catch (Exception $e) {
- throw new ConfigurationError(
- 'Could not open icinga command pipe at "%s" (%s)',
- $this->path,
- $e->getMessage()
- );
- }
-
- Logger::debug('Command sent: [' . time() . '] ' . $message . PHP_EOL);
- }
-
- /**
- * Overwrite the open mode (useful for testing)
- *
- * @param string $mode The mode to use to access the pipe
- */
- public function setOpenMode($mode)
- {
- $this->openMode = $mode;
- }
-}
From 249099348e87d966e9d1c4dd39ebb19b216c7dac Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 29 Aug 2014 15:08:58 +0200
Subject: [PATCH 096/277] monitoring/commands: Replace `SecureShell' with
`RemoteCommandFile'
`RemoteCommandFile' is configured via property setters instead of the too general `setEndpoint' function.
The ssh command to be executed only has the option 'BatchMode' set to 'yes' as this is enough to disable
interactive authentication methods. Further, all arguments become espaced.
refs #6593
---
.../Command/Transport/RemoteCommandFile.php | 188 ++++++++++++++++++
.../Command/Transport/SecureShell.php | 102 ----------
2 files changed, 188 insertions(+), 102 deletions(-)
create mode 100644 modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Transport/SecureShell.php
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php b/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php
new file mode 100644
index 000000000..fe1ae92c2
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php
@@ -0,0 +1,188 @@
+host = (string) $host;
+ return $this;
+ }
+
+ /**
+ * Get the remote host
+ *
+ * @return string
+ */
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ /**
+ * Set the port to connect to on the remote host
+ *
+ * @param int $port
+ *
+ * @return self
+ */
+ public function setPort($port)
+ {
+ $this->port = (int) $port;
+ return $this;
+ }
+
+ /**
+ * Get the port to connect on the remote host
+ *
+ * @return int
+ */
+ public function getPort()
+ {
+ return $this->port;
+ }
+
+ /**
+ * Set the user to log in as on the remote host
+ *
+ * @param string $user
+ *
+ * @return self
+ */
+ public function setUser($user)
+ {
+ $this->user = (string) $user;
+ return $this;
+ }
+
+ /**
+ * Get the user to log in as on the remote host
+ *
+ * Defaults to current PHP process' user
+ *
+ * @return string|null
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+
+ /**
+ * Set the path to the Icinga command file on the remote host
+ *
+ * @param string $path
+ *
+ * @return self
+ */
+ public function setPath($path)
+ {
+ $this->path = (string) $path;
+ return $this;
+ }
+
+ /**
+ * Get the path to the Icinga command file on the remote host
+ *
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ /**
+ * Write the command to the Icinga command file on the remote host
+ *
+ * @param IcingaCommand $command
+ *
+ * @throws LogicException
+ * @throws TransportException
+ */
+ public function send(IcingaCommand $command)
+ {
+ if (! isset($this->path)) {
+ throw new LogicException;
+ }
+ Logger::debug(
+ sprintf(
+ mt('monitoring', 'Sending external Icinga command "%s" to the remote command file "%s:%u%s"'),
+ $command,
+ $this->host,
+ $this->port,
+ $this->path
+ )
+ );
+ $ssh = sprintf('ssh -o BatchMode=yes -p %u', $this->port); // -o BatchMode=yes for disabling interactive
+ // authentication methods
+ if (isset($this->user)) {
+ $ssh .= sprintf(' -l %s', escapeshellarg($this->user));
+ }
+ $ssh .= sprintf(
+ ' %s "echo %s > %s" 2>&1', // Redirect stderr to stdout
+ escapeshellarg($this->host),
+ escapeshellarg($command),
+ escapeshellarg($this->path)
+ );
+ exec($ssh, $output, $status);
+ if ($status !== 0) {
+ throw new TransportException(
+ mt(
+ 'monitoring',
+ 'Can\'t send external Icinga command "%s": %s'
+ ),
+ $ssh,
+ implode(' ', $output)
+ );
+ }
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/SecureShell.php b/modules/monitoring/library/Monitoring/Command/Transport/SecureShell.php
deleted file mode 100644
index f1505c2ef..000000000
--- a/modules/monitoring/library/Monitoring/Command/Transport/SecureShell.php
+++ /dev/null
@@ -1,102 +0,0 @@
-host = isset($config->host) ? $config->host : 'localhost';
- $this->port = isset($config->port) ? $config->port : 22;
- $this->user = isset($config->user) ? $config->user : null;
- $this->path = isset($config->path) ? $config->path : '/usr/local/icinga/var/rw/icinga.cmd';
- }
-
- /**
- * Write the given external command to the command pipe
- *
- * @param string $command
- *
- * @throws RuntimeException When the command could not be sent to the remote Icinga host
- * @see Transport::send()
- */
- public function send($command)
- {
- $retCode = 0;
- $output = array();
- Logger::debug(
- 'Icinga instance is on different host, attempting to send command %s via ssh to %s:%s/%s',
- $command,
- $this->host,
- $this->port,
- $this->path
- );
- $hostConnector = $this->user ? $this->user . "@" . $this->host : $this->host;
- $command = escapeshellarg('['. time() .'] ' . $command);
- $sshCommand = sprintf(
- 'ssh -o BatchMode=yes -o KbdInteractiveAuthentication=no %s -p %d'
- . ' "echo %s > %s" 2>&1',
- $hostConnector,
- $this->port,
- $command,
- $this->path
- );
-
- exec($sshCommand, $output, $retCode);
- Logger::debug("Command '%s' exited with %d: %s", $sshCommand, $retCode, $output);
-
- if ($retCode != 0) {
- $msg = 'Could not send command to remote Icinga host: '
- . implode(PHP_EOL, $output)
- . " (returncode $retCode)";
- Logger::error($msg);
- throw new RuntimeException($msg);
- }
- }
-}
From 6fdc436f653984ec61031268038e7563cc164dae Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 29 Aug 2014 15:14:53 +0200
Subject: [PATCH 097/277] monitoring/commands: Add `TransportException'
`TransportException' should be thrown if a command was not sent.
refs #6593
---
.../Command/Exception/TransportException.php | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Exception/TransportException.php
diff --git a/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php b/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php
new file mode 100644
index 000000000..db06e67ba
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php
@@ -0,0 +1,12 @@
+
Date: Fri, 29 Aug 2014 15:16:13 +0200
Subject: [PATCH 098/277] Adjust authentication backend forms to suit.. some
form implementation
refs #5525
---
application/controllers/ConfigController.php | 233 +++----------
.../Authentication/AutologinBackendForm.php | 18 +-
.../Config/Authentication/BaseBackendForm.php | 94 ------
.../Config/Authentication/DbBackendForm.php | 76 +++--
.../Config/Authentication/LdapBackendForm.php | 87 ++---
.../AuthenticationBackendConfigForm.php | 318 ++++++++++++++++++
.../AuthenticationBackendReorderForm.php | 68 ++++
.../views/scripts/config/authentication.phtml | 57 ----
.../config/authentication/create.phtml | 18 +-
.../config/authentication/modify.phtml | 10 +-
.../config/authentication/remove.phtml | 10 +-
.../config/authentication/reorder.phtml | 11 +
.../scripts/form/reorder-authbackend.phtml | 40 +++
13 files changed, 591 insertions(+), 449 deletions(-)
delete mode 100644 application/forms/Config/Authentication/BaseBackendForm.php
create mode 100644 application/forms/Config/AuthenticationBackendConfigForm.php
create mode 100644 application/forms/Config/AuthenticationBackendReorderForm.php
delete mode 100644 application/views/scripts/config/authentication.phtml
create mode 100644 application/views/scripts/config/authentication/reorder.phtml
create mode 100644 application/views/scripts/form/reorder-authbackend.phtml
diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index 423a59902..f5da2952a 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -6,19 +6,16 @@ use Icinga\Web\Controller\BaseConfigController;
use Icinga\Web\Widget\AlertMessageBox;
use Icinga\Web\Notification;
use Icinga\Application\Modules\Module;
-use Icinga\Web\Form;
use Icinga\Web\Widget;
use Icinga\Application\Icinga;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Form\Config\GeneralForm;
-use Icinga\Form\Config\Authentication\LdapBackendForm;
-use Icinga\Form\Config\Authentication\DbBackendForm;
-use Icinga\Form\Config\Authentication\AutologinBackendForm;
+use Icinga\Form\Config\AuthenticationBackendReorderForm;
+use Icinga\Form\Config\AuthenticationBackendConfigForm;
use Icinga\Form\Config\ResourceForm;
-use Icinga\Form\Config\LoggingForm;
use Icinga\Form\Config\ConfirmRemovalForm;
use Icinga\Config\PreservingIniWriter;
-use Icinga\Exception\ConfigurationError;
+use Icinga\Data\ResourceFactory;
/**
@@ -142,47 +139,17 @@ class ConfigController extends BaseConfigController
}
/**
- * Action for reordering authentication backends
+ * Action for listing and reordering authentication backends
*/
public function authenticationAction()
{
- $this->view->messageBox = new AlertMessageBox(true);
+ $form = new AuthenticationBackendReorderForm();
+ $form->setConfig(IcingaConfig::app('authentication'));
+ $form->handleRequest();
+
+ $this->view->form = $form;
$this->view->tabs->activate('authentication');
-
- $config = IcingaConfig::app('authentication');
- $backendOrder = array_keys($config->toArray());
- $form = new Form();
- $form->setName('form_reorder_authbackend');
- $request = $this->getRequest();
- if ($request->isPost()) {
- $requestData = $request->getPost();
- if ($form->isValid($requestData)) { // Validate the CSRF token
- $reordered = false;
- foreach ($backendOrder as $backendName) {
- if (isset($requestData[$backendName])) {
- array_splice($backendOrder, array_search($backendName, $backendOrder), 1);
- array_splice($backendOrder, $requestData[$backendName], 0, $backendName);
- $reordered = true;
- break;
- }
- }
-
- if ($reordered) {
- $reorderedConfig = array();
- foreach ($backendOrder as $backendName) {
- $reorderedConfig[$backendName] = $config->{$backendName};
- }
-
- if ($this->writeAuthenticationFile($reorderedConfig)) {
- Notification::success($this->translate('Authentication order updated!'));
- $this->redirectNow('config/authentication');
- }
- }
- }
- }
-
- $this->view->form = $form->create(); // Necessary in case its a GET request
- $this->view->backendNames = $backendOrder;
+ $this->render('authentication/reorder');
}
/**
@@ -190,172 +157,66 @@ class ConfigController extends BaseConfigController
*/
public function createauthenticationbackendAction()
{
- $this->view->messageBox = new AlertMessageBox(true);
- $this->view->tabs->activate('authentication');
+ $form = new AuthenticationBackendConfigForm();
+ $form->setConfig(IcingaConfig::app('authentication'));
+ $form->setResourceConfig(ResourceFactory::getResourceConfigs());
+ $form->setRedirectUrl('config/authentication');
+ $form->handleRequest();
- $backendType = $this->getRequest()->getParam('type');
- $authenticationConfig = IcingaConfig::app('authentication')->toArray();
- try {
- switch ($backendType) {
- case 'ldap':
- $form = new LdapBackendForm();
- break;
- case 'db':
- $form = new DbBackendForm();
- break;
- case 'autologin':
- foreach ($authenticationConfig as $ac) {
- if (array_key_exists('backend', $ac) && $ac['backend'] === 'autologin') {
- throw new ConfigurationError(
- $this->translate('An autologin backend already exists')
- );
- }
- }
- $form = new AutologinBackendForm();
- break;
- default:
- $this->addErrorMessage(sprintf(
- $this->translate('There is no backend type `%s\''),
- $backendType
- ));
- $this->redirectNow('config/configurationerror');
- }
- } catch (ConfigurationError $e) {
- $this->addErrorMessage($e->getMessage());
- $this->redirectNow('config/configurationerror');
- }
-
- $request = $this->getRequest();
- if ($request->isPost() && $form->isValid($request->getPost())) {
- list($backendName, $backendConfig) = $form->getBackendConfig();
- if (isset($authenticationConfig[$backendName])) {
- $this->addErrorMessage(
- $this->translate('Backend name already exists')
- );
- } else {
- $authenticationConfig[$backendName] = $backendConfig;
- if ($this->writeConfigFile($authenticationConfig, 'authentication')) {
- $this->addSuccessMessage(
- $this->translate('Backend Modification Written.')
- );
- $this->redirectNow('config/authentication');
- }
- }
- }
-
- $this->view->messageBox->addForm($form);
$this->view->form = $form;
+ $this->view->tabs->activate('authentication');
$this->render('authentication/create');
}
-
/**
- * Form for editing backends
- *
- * Mostly the same like the createAuthenticationBackendAction, but with additional checks for backend existence
- * and form population
+ * Action for editing authentication backends
*/
public function editauthenticationbackendAction()
{
- $this->view->messageBox = new AlertMessageBox(true);
+ $form = new AuthenticationBackendConfigForm();
+ $form->setConfig(IcingaConfig::app('authentication'));
+ $form->setResourceConfig(ResourceFactory::getResourceConfigs());
+ $form->setRedirectUrl('config/authentication');
+ $form->handleRequest();
- $configArray = IcingaConfig::app('authentication', true)->toArray();
- $authBackend = $this->getParam('auth_backend');
- if (false === isset($configArray[$authBackend])) {
- $this->addErrorMessage(
- $this->translate('Can\'t edit: Unknown Authentication Backend Provided')
- );
- $this->redirectNow('config/configurationerror');
- }
-
- if (false === array_key_exists('backend', $configArray[$authBackend])) {
- $this->addErrorMessage(sprintf(
- $this->translate('Backend "%s" has no `backend\' setting'),
- $authBackend
- ));
- $this->redirectNow('config/configurationerror');
- }
- $type = $configArray[$authBackend]['backend'];
- switch ($type) {
- case 'ldap':
- $form = new LdapBackendForm();
- break;
- case 'db':
- $form = new DbBackendForm();
- break;
- case 'autologin':
- $form = new AutologinBackendForm();
- break;
- default:
- $this->addErrorMessage(sprintf(
- $this->translate('Can\'t edit: backend type "%s" of given resource not supported.'),
- $type
- ));
- $this->redirectNow('config/configurationerror');
- }
-
- $request = $this->getRequest();
- if ($request->isPost()) {
- if ($form->isValid($request->getPost())) {
- list($backendName, $backendConfig) = $form->getBackendConfig();
- $configArray[$backendName] = $backendConfig;
- if ($backendName != $authBackend) {
- unset($configArray[$authBackend]);
- }
- if ($this->writeAuthenticationFile($configArray)) {
- // redirect to overview with success message
- Notification::success(sprintf(
- $this->translate('Backend "%s" saved'),
- $backendName
- ));
- $this->redirectNow('config/authentication');
- }
- return;
- }
- } else {
- $form->setBackendConfig($authBackend, $configArray[$authBackend]);
- }
-
- $this->view->messageBox->addForm($form);
- $this->view->name = $authBackend;
$this->view->form = $form;
+ $this->view->tabs->activate('authentication');
$this->render('authentication/modify');
}
/**
- * Action for removing a backend from the authentication list.
- *
- * Redirects to the overview after removal is finished
+ * Action for removing a backend from the authentication list
*/
public function removeauthenticationbackendAction()
{
- $this->view->messageBox = new AlertMessageBox(true);
+ $form = new ConfirmRemovalForm(array(
+ 'onSuccess' => function ($request) {
+ $configForm = new AuthenticationBackendConfigForm();
+ $configForm->setConfig(IcingaConfig::app('authentication'));
+ $authBackend = $request->getQuery('auth_backend');
- $configArray = IcingaConfig::app('authentication', true)->toArray();
- $authBackend = $this->getParam('auth_backend');
- if (false === array_key_exists($authBackend, $configArray)) {
- $this->addErrorMessage(
- $this->translate('Can\'t perform removal: Unknown authentication backend provided')
- );
- $this->redirectNow('config/configurationerror');
- }
+ try {
+ $configForm->remove($authBackend);
+ } catch (InvalidArgumentException $e) {
+ Notification::error($e->getMessage());
+ return;
+ }
- $form = new ConfirmRemovalForm();
- $request = $this->getRequest();
-
- if ($request->isPost() && $form->isValid($request->getPost())) {
- unset($configArray[$authBackend]);
- if ($this->writeAuthenticationFile($configArray)) {
- Notification::success(sprintf(
- $this->translate('Authentication Backend "%s" Removed'),
- $authBackend
- ));
- $this->redirectNow('config/authentication');
+ if ($configForm->save()) {
+ Notification::success(sprintf(
+ t('Authentication backend "%s" has been successfully removed'),
+ $authBackend
+ ));
+ } else {
+ return false;
+ }
}
- }
+ ));
+ $form->setRedirectUrl('config/authentication');
+ $form->handleRequest();
$this->view->form = $form;
- $this->view->name = $authBackend;
+ $this->view->tabs->activate('authentication');
$this->render('authentication/remove');
}
diff --git a/application/forms/Config/Authentication/AutologinBackendForm.php b/application/forms/Config/Authentication/AutologinBackendForm.php
index c3cf56fa7..662106bcd 100644
--- a/application/forms/Config/Authentication/AutologinBackendForm.php
+++ b/application/forms/Config/Authentication/AutologinBackendForm.php
@@ -5,19 +5,19 @@
namespace Icinga\Form\Config\Authentication;
use Zend_Validate_Callback;
+use Icinga\Web\Form;
/**
* Form class for adding/modifying autologin authentication backends
*/
-class AutologinBackendForm extends BaseBackendForm
+class AutologinBackendForm extends Form
{
/**
* Initialize this form
*/
public function init()
{
- $this->setName('form_config_authentication_autologin');
- $this->setSubmitLabel(t('Save Changes'));
+ $this->setName('form_config_authbackend_autologin');
}
/**
@@ -31,7 +31,6 @@ class AutologinBackendForm extends BaseBackendForm
'name',
array(
'required' => true,
- 'allowEmpty' => false,
'label' => t('Backend Name'),
'helptext' => t('The name of this authentication backend'),
'validators' => array(
@@ -53,7 +52,6 @@ class AutologinBackendForm extends BaseBackendForm
'strip_username_regexp',
array(
'required' => true,
- 'allowEmpty' => false,
'label' => t('Backend Domain Pattern'),
'helptext' => t('The domain pattern of this authentication backend'),
'value' => '/\@[^$]+$/',
@@ -76,13 +74,15 @@ class AutologinBackendForm extends BaseBackendForm
}
/**
- * Validate the configuration state of this backend
+ * Validate the configuration by creating a backend and requesting the user count
*
- * Returns just true as autologins are being handled externally by the webserver.
+ * Returns always true as autologin backends are just "passive" backends. (The webserver authenticates users.)
*
- * @return true
+ * @param Form $form The form to fetch the configuration values from
+ *
+ * @return bool Whether validation succeeded or not
*/
- public function isValidAuthenticationBackend()
+ public function isValidAuthenticationBackend(Form $form)
{
return true;
}
diff --git a/application/forms/Config/Authentication/BaseBackendForm.php b/application/forms/Config/Authentication/BaseBackendForm.php
deleted file mode 100644
index 840b5f34c..000000000
--- a/application/forms/Config/Authentication/BaseBackendForm.php
+++ /dev/null
@@ -1,94 +0,0 @@
-isValidAuthenticationBackend()
- ) {
- $this->addForceCreationCheckbox();
- return false;
- }
-
- return true;
- }
-
- /**
- * Validate the configuration state of this backend with the concrete authentication backend.
- *
- * An implementation should not throw any exception, but use the add/setErrorMessages method
- * of Zend_Form. If the 'force_creation' checkbox is set, this method won't be called.
- *
- * @return bool Whether validation succeeded or not
- */
- abstract public function isValidAuthenticationBackend();
-
- /**
- * Return the backend's configuration values and its name
- *
- * The first value is the name and the second one the values as array.
- *
- * @return array
- */
- public function getBackendConfig()
- {
- $values = $this->getValues();
- $name = $values['name'];
- unset($values['name']);
- return array($name, $values);
- }
-
- /**
- * Populate the form with the given configuration values
- *
- * @param string $name The name of the backend
- * @param array $config The configuration values
- */
- public function setBackendConfig($name, array $config)
- {
- $config['name'] = $name;
- $this->populate($config);
- }
-
- /**
- * Add a checkbox to be displayed at the beginning of the form
- * which allows the user to skip the connection validation
- */
- protected function addForceCreationCheckbox()
- {
- $this->addElement(
- 'checkbox',
- 'force_creation',
- array(
- 'order' => 0,
- 'ignore' => true,
- 'label' => t('Force Changes'),
- 'helptext' => t('Check this box to enforce changes without connectivity validation')
- )
- );
- }
-}
diff --git a/application/forms/Config/Authentication/DbBackendForm.php b/application/forms/Config/Authentication/DbBackendForm.php
index 521414094..7ec9c3c26 100644
--- a/application/forms/Config/Authentication/DbBackendForm.php
+++ b/application/forms/Config/Authentication/DbBackendForm.php
@@ -5,17 +5,18 @@
namespace Icinga\Form\Config\Authentication;
use Exception;
+use Icinga\Web\Form;
+use Icinga\Web\Request;
use Icinga\Data\ResourceFactory;
-use Icinga\Exception\ConfigurationError;
use Icinga\Authentication\Backend\DbUserBackend;
/**
* Form class for adding/modifying database authentication backends
*/
-class DbBackendForm extends BaseBackendForm
+class DbBackendForm extends Form
{
/**
- * The available database resources prepared to be used as select input data
+ * The database resource names the user can choose from
*
* @var array
*/
@@ -23,28 +24,23 @@ class DbBackendForm extends BaseBackendForm
/**
* Initialize this form
- *
- * Populates $this->resources.
- *
- * @throws ConfigurationError In case no database resources can be found
*/
public function init()
{
- $this->setName('form_config_authentication_db');
- $this->setSubmitLabel(t('Save Changes'));
+ $this->setName('form_config_authbackend_db');
+ }
- $dbResources = array_keys(
- ResourceFactory::getResourceConfigs('db')->toArray()
- );
-
- if (empty($dbResources)) {
- throw new ConfigurationError(
- t('There are no database resources')
- );
- }
-
- // array_combine() is necessary in order to use the array as select input data
- $this->resources = array_combine($dbResources, $dbResources);
+ /**
+ * Set the resource names the user can choose from
+ *
+ * @param array $resources The resources to choose from
+ *
+ * @return self
+ */
+ public function setResources(array $resources)
+ {
+ $this->resources = $resources;
+ return $this;
}
/**
@@ -69,7 +65,9 @@ class DbBackendForm extends BaseBackendForm
'required' => true,
'label' => t('Database Connection'),
'helptext' => t('The database connection to use for authenticating with this provider'),
- 'multiOptions' => $this->resources
+ 'multiOptions' => false === empty($this->resources)
+ ? array_combine($this->resources, $this->resources)
+ : array()
)
),
$this->createElement(
@@ -84,25 +82,39 @@ class DbBackendForm extends BaseBackendForm
}
/**
- * Validate the current configuration by creating a backend and requesting the user count
+ * Validate that the selected resource is a valid database authentication backend
*
- * @return bool Whether validation succeeded or not
- *
- * @see BaseBackendForm::isValidAuthenticationBackend()
+ * @see Form::onSuccess()
*/
- public function isValidAuthenticationBackend()
+ public function onSuccess(Request $request)
{
+ if (false === $this->isValidAuthenticationBackend($this)) {
+ return false;
+ }
+ }
+
+ /**
+ * Validate the configuration by creating a backend and requesting the user count
+ *
+ * @param Form $form The form to fetch the configuration values from
+ *
+ * @return bool Whether validation succeeded or not
+ */
+ public function isValidAuthenticationBackend(Form $form)
+ {
+ $element = $form->getElement('resource');
+
try {
- $testConnection = ResourceFactory::createResource(ResourceFactory::getResourceConfig(
- $this->getValue('resource')
- ));
+ $testConnection = ResourceFactory::createResource(
+ ResourceFactory::getResourceConfig($element->getValue())
+ );
$dbUserBackend = new DbUserBackend($testConnection);
if ($dbUserBackend->count() < 1) {
- $this->addErrorMessage(t('No users found under the specified database backend'));
+ $element->addError(t('No users found under the specified database backend'));
return false;
}
} catch (Exception $e) {
- $this->addErrorMessage(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
+ $element->addError(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
return false;
}
diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php
index ed261c1f9..af627df48 100644
--- a/application/forms/Config/Authentication/LdapBackendForm.php
+++ b/application/forms/Config/Authentication/LdapBackendForm.php
@@ -5,17 +5,17 @@
namespace Icinga\Form\Config\Authentication;
use Exception;
+use Icinga\Web\Form;
use Icinga\Data\ResourceFactory;
-use Icinga\Exception\ConfigurationError;
use Icinga\Authentication\Backend\LdapUserBackend;
/**
- * Form for adding or modifying LDAP authentication backends
+ * Form class for adding/modifying LDAP authentication backends
*/
-class LdapBackendForm extends BaseBackendForm
+class LdapBackendForm extends Form
{
/**
- * The available ldap resources prepared to be used as select input data
+ * The ldap resource names the user can choose from
*
* @var array
*/
@@ -23,28 +23,23 @@ class LdapBackendForm extends BaseBackendForm
/**
* Initialize this form
- *
- * Populates $this->resources.
- *
- * @throws ConfigurationError In case no database resources can be found
*/
public function init()
{
- $this->setName('form_config_authentication_ldap');
- $this->setSubmitLabel(t('Save Changes'));
+ $this->setName('form_config_authbackend_ldap');
+ }
- $ldapResources = array_keys(
- ResourceFactory::getResourceConfigs('ldap')->toArray()
- );
-
- if (empty($ldapResources)) {
- throw new ConfigurationError(
- t('There are no LDAP resources')
- );
- }
-
- // array_combine() is necessary in order to use the array as select input data
- $this->resources = array_combine($ldapResources, $ldapResources);
+ /**
+ * Set the resource names the user can choose from
+ *
+ * @param array $resources The resources to choose from
+ *
+ * @return self
+ */
+ public function setResources(array $resources)
+ {
+ $this->resources = $resources;
+ return $this;
}
/**
@@ -69,7 +64,9 @@ class LdapBackendForm extends BaseBackendForm
'required' => true,
'label' => t('LDAP Resource'),
'helptext' => t('The resource to use for authenticating with this provider'),
- 'multiOptions' => $this->resources
+ 'multiOptions' => false === empty($this->resources)
+ ? array_combine($this->resources, $this->resources)
+ : array()
)
),
$this->createElement(
@@ -104,33 +101,39 @@ class LdapBackendForm extends BaseBackendForm
}
/**
- * Validate the current configuration by connecting to a backend and requesting the user count
+ * Validate that the selected resource is a valid ldap authentication backend
*
- * @return bool Whether validation succeeded or not
- *
- * @see BaseBackendForm::isValidAuthenticationBacken()
+ * @see Form::onSuccess()
*/
- public function isValidAuthenticationBackend()
+ public function onSuccess(Request $request)
{
- if (false === ResourceFactory::ldapAvailable()) {
- // It should be possible to run icingaweb without the php ldap extension. When the user
- // tries to create an ldap backend without ldap being installed we display an error.
- $this->addErrorMessage(t('Using ldap is not possible, the php extension "ldap" is not installed.'));
+ if (false === $this->isValidAuthenticationBackend($this)) {
return false;
}
+ }
+
+ /**
+ * Validate the configuration by creating a backend and requesting the user count
+ *
+ * @param Form $form The form to fetch the configuration values from
+ *
+ * @return bool Whether validation succeeded or not
+ */
+ public function isValidAuthenticationBackend(Form $form)
+ {
+ $element = $form->getElement('resource');
try {
- $backend = ResourceFactory::createResource(
- ResourceFactory::getResourceConfig($this->getValue('resource'))
+ $ldapUserBackend = new LdapUserBackend(
+ ResourceFactory::createResource(
+ ResourceFactory::getResourceConfig($element->getValue())
+ ),
+ $form->getElement('user_class')->getValue(),
+ $form->getElement('user_name_attribute')->getValue()
);
- $testConn = new LdapUserBackend(
- $backend,
- $this->getValue('user_class'),
- $this->getValue('user_name_attribute')
- );
- $testConn->assertAuthenticationPossible();
- } catch (Exception $exc) {
- $this->addErrorMessage(sprintf(t('Connection validation failed: %s'), $exc->getMessage()));
+ $ldapUserBackend->assertAuthenticationPossible();
+ } catch (Exception $e) {
+ $element->addError(sprintf(t('Connection validation failed: %s'), $e->getMessage()));
return false;
}
diff --git a/application/forms/Config/AuthenticationBackendConfigForm.php b/application/forms/Config/AuthenticationBackendConfigForm.php
new file mode 100644
index 000000000..6aeccdd20
--- /dev/null
+++ b/application/forms/Config/AuthenticationBackendConfigForm.php
@@ -0,0 +1,318 @@
+setName('form_config_authbackend');
+ $this->setSubmitLabel(t('Save Changes'));
+ }
+
+ /**
+ * Set the resource configuration to use
+ *
+ * @param Config $resources The resource configuration
+ *
+ * @return self
+ *
+ * @throws ConfigurationError In case no resources are available for authentication
+ */
+ public function setResourceConfig(Config $resourceConfig)
+ {
+ $resources = array();
+ foreach ($resourceConfig as $name => $resource) {
+ $resources[strtolower($resource->type)][] = $name;
+ }
+
+ if (empty($resources)) {
+ throw new ConfigurationError(t('Could not find any resources for authentication'));
+ }
+
+ $this->resources = $resources;
+ return $this;
+ }
+
+ /**
+ * Return a form object for the given backend type
+ *
+ * @param string $type The backend type for which to return a form
+ *
+ * @return Form
+ */
+ public function getBackendForm($type)
+ {
+ if ($type === 'db') {
+ $form = new DbBackendForm();
+ $form->setResources(isset($this->resources['db']) ? $this->resources['db'] : array());
+ } elseif ($type === 'ldap') {
+ $form = new LdapBackendForm();
+ $form->setResources(isset($this->resources['ldap']) ? $this->resources['ldap'] : array());
+ } elseif ($type === 'autologin') {
+ $form = new AutologinBackendForm();
+ } else {
+ throw new InvalidArgumentException(sprintf(t('Invalid backend type "%s" provided'), $type));
+ }
+
+ return $form;
+ }
+
+ /**
+ * Add a particular authentication backend
+ *
+ * The backend to add is identified by the array-key `name'.
+ *
+ * @param array $values The values to extend the configuration with
+ *
+ * @return self
+ *
+ * @throws InvalidArgumentException In case the backend does already exist
+ */
+ public function add(array $values)
+ {
+ $name = isset($values['name']) ? $values['name'] : '';
+ if (! $name) {
+ throw new InvalidArgumentException(t('Authentication backend name missing'));
+ } elseif ($this->config->get($name) !== null) {
+ throw new InvalidArgumentException(t('Authentication backend already exists'));
+ }
+
+ unset($values['name']);
+ $this->config->{$name} = $values;
+ return $this;
+ }
+
+ /**
+ * Edit a particular authentication backend
+ *
+ * @param string $name The name of the backend to edit
+ * @param array $values The values to edit the configuration with
+ *
+ * @return array The edited backend configuration
+ *
+ * @throws InvalidArgumentException In case the backend does not exist
+ */
+ public function edit($name, array $values)
+ {
+ if (! $name) {
+ throw new InvalidArgumentException(t('Old authentication backend name missing'));
+ } elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
+ throw new InvalidArgumentException(t('New authentication backend name missing'));
+ } elseif (($backendConfig = $this->config->get($name)) === null) {
+ throw new InvalidArgumentException(t('Unknown authentication backend provided'));
+ }
+
+ if ($newName !== $name) {
+ // Only remove the old entry if it has changed as the order gets screwed when editing backend names
+ unset($this->config->{$name});
+ }
+
+ unset($values['name']);
+ $this->config->{$newName} = array_merge($backendConfig->toArray(), $values);
+ return $this->config->{$newName};
+ }
+
+ /**
+ * Remove the given authentication backend
+ *
+ * @param string $name The name of the backend to remove
+ *
+ * @return array The removed backend configuration
+ *
+ * @throws InvalidArgumentException In case the backend does not exist
+ */
+ public function remove($name)
+ {
+ if (! $name) {
+ throw new InvalidArgumentException(t('Authentication backend name missing'));
+ } elseif (($backendConfig = $this->config->get($name)) === null) {
+ throw new InvalidArgumentException(t('Unknown authentication backend provided'));
+ }
+
+ unset($this->config->{$name});
+ return $backendConfig;
+ }
+
+ /**
+ * Move the given authentication backend up or down in order
+ *
+ * @param string $name The name of the backend to be moved
+ * @param int $position The new (absolute) position of the backend
+ *
+ * @return self
+ *
+ * @throws InvalidArgumentException In case the backend does not exist
+ */
+ public function move($name, $position)
+ {
+ if (! $name) {
+ throw new InvalidArgumentException(t('Authentication backend name missing'));
+ } elseif ($this->config->get($name) === null) {
+ throw new InvalidArgumentException(t('Unknown authentication backend provided'));
+ }
+
+ $backendOrder = $this->config->keys();
+ array_splice($backendOrder, array_search($name, $backendOrder), 1);
+ array_splice($backendOrder, $position, 0, $name);
+
+ $newConfig = array();
+ foreach ($backendOrder as $backendName) {
+ $newConfig[$backendName] = $this->config->get($backendName);
+ }
+
+ $config = new Config($newConfig);
+ $this->config = $config->setConfigFile($this->config->getConfigFile());
+ return $this;
+ }
+
+ /**
+ * Add or edit an authentication backend and save the configuration
+ *
+ * Performs a connectivity validation using the submitted values. A checkbox is
+ * added to the form to skip the check if it fails and redirection is aborted.
+ *
+ * @see Form::onSuccess()
+ */
+ public function onSuccess(Request $request)
+ {
+ if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
+ $backendForm = $this->getBackendForm($this->getElement('type')->getValue());
+ if (false === $backendForm->isValidAuthenticationBackend($this)) {
+ $this->addForceCreationCheckbox();
+ return false;
+ }
+ }
+
+ $authBackend = $request->getQuery('auth_backend');
+ try {
+ if ($authBackend === null) { // create new backend
+ $this->add($this->getValues());
+ $message = t('Authentication backend "%s" has been successfully created');
+ } else { // edit existing backend
+ $this->edit($authBackend, $this->getValues());
+ $message = t('Authentication backend "%s" has been successfully changed');
+ }
+ } catch (InvalidArgumentException $e) {
+ Notification::error($e->getMessage());
+ return;
+ }
+
+ if ($this->save()) {
+ Notification::success(sprintf($message, $this->getElement('name')->getValue()));
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Populate the form in case an authentication backend is being edited
+ *
+ * @see Form::onShow()
+ *
+ * @throws ConfigurationError In case the backend name is missing in the request or is invalid
+ */
+ public function onShow(Request $request)
+ {
+ $authBackend = $request->getQuery('auth_backend');
+ if ($authBackend !== null) {
+ if ($authBackend === '') {
+ throw new ConfigurationError(t('Authentication backend name missing'));
+ } elseif (false === isset($this->config->{$authBackend})) {
+ throw new ConfigurationError(t('Unknown authentication backend provided'));
+ } elseif (false === isset($this->config->{$authBackend}->backend)) {
+ throw new ConfigurationError(sprintf(t('Backend "%s" has no `backend\' setting'), $authBackend));
+ }
+
+ $configValues = $this->config->{$authBackend}->toArray();
+ $configValues['type'] = $configValues['backend'];
+ $configValues['name'] = $authBackend;
+ $this->populate($configValues);
+ }
+ }
+
+ /**
+ * Add a checkbox to be displayed at the beginning of the form
+ * which allows the user to skip the connection validation
+ */
+ protected function addForceCreationCheckbox()
+ {
+ $this->addElement(
+ 'checkbox',
+ 'force_creation',
+ array(
+ 'order' => 0,
+ 'ignore' => true,
+ 'label' => t('Force Changes'),
+ 'helptext' => t('Check this box to enforce changes without connectivity validation')
+ )
+ );
+ }
+
+ /**
+ * @see Form::createElements()
+ */
+ public function createElements(array $formData)
+ {
+ $backendTypes = array();
+ $backendType = isset($formData['type']) ? $formData['type'] : 'db';
+
+ if (isset($this->resources['db'])) {
+ $backendTypes['db'] = t('Database');
+ }
+ if (isset($this->resources['ldap']) && ($backendType === 'ldap' || ResourceFactory::ldapAvailable())) {
+ $backendTypes['ldap'] = 'LDAP';
+ }
+
+ $autologinBackends = array_filter(
+ $this->config->toArray(),
+ function ($authBackendCfg) {
+ return isset($authBackendCfg['backend']) && $authBackendCfg['backend'] === 'autologin';
+ }
+ );
+ if ($backendType === 'autologin' || empty($autologinBackends)) {
+ $backendTypes['autologin'] = t('Autologin');
+ }
+
+ $typeSelection = $this->createElement(
+ 'select',
+ 'type',
+ array(
+ 'ignore' => true,
+ 'required' => true,
+ 'autosubmit' => true,
+ 'label' => t('Backend Type'),
+ 'helptext' => t('The type of the resource to use for this authenticaton backend'),
+ 'multiOptions' => $backendTypes
+ )
+ );
+
+ return array_merge(
+ array($typeSelection),
+ $this->getBackendForm($backendType)->createElements($formData)
+ );
+ }
+}
diff --git a/application/forms/Config/AuthenticationBackendReorderForm.php b/application/forms/Config/AuthenticationBackendReorderForm.php
new file mode 100644
index 000000000..d4be16c30
--- /dev/null
+++ b/application/forms/Config/AuthenticationBackendReorderForm.php
@@ -0,0 +1,68 @@
+setName('form_reorder_authbackend');
+ $this->setViewScript('form/reorder-authbackend.phtml');
+ }
+
+ /**
+ * Return the ordered backend names
+ *
+ * @return array
+ */
+ public function getBackendOrder()
+ {
+ return $this->config->keys();
+ }
+
+ /**
+ * Update the authentication backend order and save the configuration
+ *
+ * @see Form::onSuccess()
+ */
+ public function onSuccess(Request $request)
+ {
+ $formData = $this->getRequestData($request);
+ if (isset($formData['backend_newpos'])) {
+ $configForm = $this->getConfigForm();
+ list($backendName, $position) = explode('|', $formData['backend_newpos'], 2);
+
+ try {
+ if ($configForm->move($backendName, $position)->save()) {
+ Notification::success(t('Authentication order updated!'));
+ } else {
+ return false;
+ }
+ } catch (InvalidArgumentException $e) {
+ Notification::error($e->getMessage());
+ }
+ }
+ }
+
+ /**
+ * Return the config form for authentication backends
+ *
+ * @return ConfigForm
+ */
+ protected function getConfigForm()
+ {
+ $form = new AuthenticationBackendConfigForm();
+ $form->setConfig($this->config);
+ return $form;
+ }
+}
diff --git a/application/views/scripts/config/authentication.phtml b/application/views/scripts/config/authentication.phtml
deleted file mode 100644
index 5f1be17bd..000000000
--- a/application/views/scripts/config/authentication.phtml
+++ /dev/null
@@ -1,57 +0,0 @@
-
= $this->translate('Create New Authentication Backend'); ?>
- Create a new backend for authenticating your users. This backend will be added at the end of your authentication order.
+ = $this->translate(
+ 'Create a new backend for authenticating your users. This backend will be added at the end of your authentication order.'
+ ); ?>
-
-= $this->form ?>
\ No newline at end of file
+= $form; ?>
\ No newline at end of file
diff --git a/application/views/scripts/config/authentication/modify.phtml b/application/views/scripts/config/authentication/modify.phtml
index 4666ce686..19901ae5b 100644
--- a/application/views/scripts/config/authentication/modify.phtml
+++ b/application/views/scripts/config/authentication/modify.phtml
@@ -1,8 +1,2 @@
-
+= $form; ?>
\ No newline at end of file
diff --git a/application/views/scripts/config/authentication/reorder.phtml b/application/views/scripts/config/authentication/reorder.phtml
new file mode 100644
index 000000000..0ae7850eb
--- /dev/null
+++ b/application/views/scripts/config/authentication/reorder.phtml
@@ -0,0 +1,11 @@
+
= $this->translate('Resources are entities that provide data to Icingaweb.'); ?>
+
= $this->translate('Create A New Resource'); ?>
+
= $this->translate('Resources are entities that provide data to Icinga Web 2.'); ?>
= $form; ?>
\ No newline at end of file
diff --git a/application/views/scripts/config/resource/modify.phtml b/application/views/scripts/config/resource/modify.phtml
index 7f549d537..5fa2536bd 100644
--- a/application/views/scripts/config/resource/modify.phtml
+++ b/application/views/scripts/config/resource/modify.phtml
@@ -1,3 +1,2 @@
= $this->translate('Edit Existing Resource'); ?>
-= $messageBox; ?>
= $form; ?>
\ No newline at end of file
diff --git a/application/views/scripts/config/resource/remove.phtml b/application/views/scripts/config/resource/remove.phtml
index fba6b081b..a43bcd74c 100644
--- a/application/views/scripts/config/resource/remove.phtml
+++ b/application/views/scripts/config/resource/remove.phtml
@@ -1,3 +1,2 @@
Are you sure you want to remove the instance = $this->escape($name); ?>?
-
If you have still any environments or views referring to this instance, you won't be able to send commands anymore after deletion.
+
= $this->translate('Are you sure you want to remove this instance?'); ?>
+
= $this->translate('If you have still any environments or views referring to this instance, you won\'t be able to send commands anymore after deletion.'); ?>
= $form; ?>
\ No newline at end of file
From 439d1895a7c16dd5bbb35699858a14706ac38231 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Thu, 4 Sep 2014 11:25:47 +0200
Subject: [PATCH 157/277] Adjust Monitoring\BackendForm to use handleRequest()
& Co.
refs #5525
---
.../controllers/ConfigController.php | 144 +++--------
.../forms/Config/BackendConfigForm.php | 244 ++++++++++++++++++
.../application/forms/Config/BackendForm.php | 125 ---------
.../views/scripts/config/index.phtml | 161 +++++-------
4 files changed, 346 insertions(+), 328 deletions(-)
create mode 100644 modules/monitoring/application/forms/Config/BackendConfigForm.php
delete mode 100644 modules/monitoring/application/forms/Config/BackendForm.php
diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php
index 5636b5b17..c2de49be1 100644
--- a/modules/monitoring/application/controllers/ConfigController.php
+++ b/modules/monitoring/application/controllers/ConfigController.php
@@ -2,14 +2,13 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
-use Icinga\Config\PreservingIniWriter;
-use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Notification;
+use Icinga\Data\ResourceFactory;
use Icinga\Form\ConfirmRemovalForm;
-use Icinga\Module\Monitoring\Form\Config\BackendForm;
+use Icinga\Web\Controller\ModuleActionController;
+use Icinga\Module\Monitoring\Form\Config\BackendConfigForm;
use Icinga\Module\Monitoring\Form\Config\InstanceConfigForm;
use Icinga\Module\Monitoring\Form\Config\SecurityConfigForm;
-use Icinga\Exception\NotReadableError;
/**
* Configuration controller for editing monitoring resources
@@ -21,19 +20,9 @@ class Monitoring_ConfigController extends ModuleActionController
*/
public function indexAction()
{
+ $this->view->backendsConfig = $this->Config('backends');
+ $this->view->instancesConfig = $this->Config('instances');
$this->view->tabs = $this->Module()->getConfigTabs()->activate('backends');
- foreach (array('backends', 'instances') as $element) {
- try {
- $elementConfig = $this->Config($element);
- if ($elementConfig === null) {
- $this->view->{$element} = array();
- } else {
- $this->view->{$element} = $elementConfig->toArray();
- }
- } catch (NotReadableError $e) {
- $this->view->{$element} = $e;
- }
- }
}
/**
@@ -41,38 +30,11 @@ class Monitoring_ConfigController extends ModuleActionController
*/
public function editbackendAction()
{
- // Fetch the backend to be edited
- $backend = $this->getParam('backend');
- $backendsConfig = $this->Config('backends')->toArray();
- if (false === array_key_exists($backend, $backendsConfig)) {
- // TODO: Should behave as in the app's config controller (Specific redirect to an error action)
- Notification::error(sprintf($this->translate('Cannot edit "%s". Backend not found.'), $backend));
- $this->redirectNow('monitoring/config');
- }
-
- $form = new BackendForm();
- $request = $this->getRequest();
- if ($request->isPost()) {
- if ($form->isValid($request->getPost())) {
- list($newName, $config) = $form->getBackendConfig();
-
- if ($newName !== $backend) {
- // Backend name has changed
- unset($backendsConfig[$backend]); // We can safely use unset as all values are part of the form
- }
-
- $backendsConfig[$newName] = $config;
- if ($this->writeConfiguration($backendsConfig, 'backends')) {
- Notification::success(sprintf($this->translate('Backend "%s" successfully modified.'), $backend));
- $this->redirectNow('monitoring/config');
- } else {
- $this->render('show-configuration');
- return;
- }
- }
- } else {
- $form->setBackendConfig($backend, $backendsConfig[$backend]);
- }
+ $form = new BackendConfigForm();
+ $form->setConfig($this->Config('backends'));
+ $form->setResourceConfig(ResourceFactory::getResourceConfigs());
+ $form->setRedirectUrl('monitoring/config');
+ $form->handleRequest();
$this->view->form = $form;
}
@@ -82,20 +44,11 @@ class Monitoring_ConfigController extends ModuleActionController
*/
public function createbackendAction()
{
- $form = new BackendForm();
- $request = $this->getRequest();
- if ($request->isPost() && $form->isValid($request->getPost())) {
- list($name, $config) = $form->getBackendConfig();
- $backendsConfig = $this->Config('backends')->toArray();
- $backendsConfig[$name] = $config;
- if ($this->writeConfiguration($backendsConfig, 'backends')) {
- Notification::success(sprintf($this->translate('Backend "%s" created successfully.'), $name));
- $this->redirectNow('monitoring/config');
- } else {
- $this->render('show-configuration');
- return;
- }
- }
+ $form = new BackendConfigForm();
+ $form->setConfig($this->Config('backends'));
+ $form->setResourceConfig(ResourceFactory::getResourceConfigs());
+ $form->setRedirectUrl('monitoring/config');
+ $form->handleRequest();
$this->view->form = $form;
}
@@ -105,26 +58,29 @@ class Monitoring_ConfigController extends ModuleActionController
*/
public function removebackendAction()
{
- $backend = $this->getParam('backend');
- $backendsConfig = $this->Config('backends')->toArray();
- if (false === array_key_exists($backend, $backendsConfig)) {
- // TODO: Should behave as in the app's config controller (Specific redirect to an error action)
- Notification::error(sprintf($this->translate('Cannot remove "%s". Backend not found.'), $backend));
- $this->redirectNow('monitoring/config');
- }
+ $config = $this->Config('backends');
+ $form = new ConfirmRemovalForm(array(
+ 'onSuccess' => function ($request) use ($config) {
+ $backendName = $request->getQuery('backend');
+ $configForm = new BackendConfigForm();
+ $configForm->setConfig($config);
- $form = new ConfirmRemovalForm();
- $request = $this->getRequest();
- if ($request->isPost() && $form->isValid($request->getPost())) {
- unset($backendsConfig[$backend]);
- if ($this->writeConfiguration($backendsConfig, 'backends')) {
- Notification::success(sprintf($this->translate('Backend "%s" successfully removed.'), $backend));
- $this->redirectNow('monitoring/config');
- } else {
- $this->render('show-configuration');
- return;
+ try {
+ $configForm->remove($backendName);
+ } catch (InvalidArgumentException $e) {
+ Notification::error($e->getMessage());
+ return;
+ }
+
+ if ($configForm->save()) {
+ Notification::success(sprintf(t('Backend "%s" successfully removed.'), $backendName));
+ } else {
+ return false;
+ }
}
- }
+ ));
+ $form->setRedirectUrl('monitoring/config');
+ $form->handleRequest();
$this->view->form = $form;
}
@@ -187,34 +143,6 @@ class Monitoring_ConfigController extends ModuleActionController
$this->view->form = $form;
}
- /**
- * Write configuration to an ini file
- *
- * @param Zend_Config $config The configuration to write
- * @param string $file The config file to write to
- *
- * @return bool Whether the configuration was written or not
- */
- protected function writeConfiguration($config, $file = null)
- {
- if (is_array($config)) {
- $config = new Zend_Config($config);
- }
- $target = $this->Config($file)->getConfigFile();
- $writer = new PreservingIniWriter(array('filename' => $target, 'config' => $config));
-
- try {
- $writer->write();
- } catch (Exception $exc) {
- $this->view->exceptionMessage = $exc->getMessage();
- $this->view->iniConfigurationString = $writer->render();
- $this->view->file = $target;
- return false;
- }
-
- return true;
- }
-
/**
* Display a form to adjust security relevant settings
*/
diff --git a/modules/monitoring/application/forms/Config/BackendConfigForm.php b/modules/monitoring/application/forms/Config/BackendConfigForm.php
new file mode 100644
index 000000000..84f68b57e
--- /dev/null
+++ b/modules/monitoring/application/forms/Config/BackendConfigForm.php
@@ -0,0 +1,244 @@
+setName('form_config_monitoring_backends');
+ $this->setSubmitLabel(t('Save Changes'));
+ }
+
+ /**
+ * Set the resource configuration to use
+ *
+ * @param Config $resources The resource configuration
+ *
+ * @return self
+ *
+ * @throws ConfigurationError In case there are no valid monitoring backend resources
+ */
+ public function setResourceConfig(Config $resourceConfig)
+ {
+ $resources = array();
+ foreach ($resourceConfig as $name => $resource) {
+ if ($resource->type === 'db' || $resource->type === 'statusdat' || $resource->type === 'livestatus') {
+ $resources[$resource->type === 'db' ? 'ido' : strtolower($resource->type)][] = $name;
+ }
+ }
+
+ if (empty($resources)) {
+ throw new ConfigurationError(t('Could not find any valid monitoring backend resources'));
+ }
+
+ $this->resources = $resources;
+ return $this;
+ }
+
+ /**
+ * Add a particular monitoring backend
+ *
+ * The backend to add is identified by the array-key `name'.
+ *
+ * @param array $values The values to extend the configuration with
+ *
+ * @return self
+ *
+ * @throws InvalidArgumentException In case the backend does already exist
+ */
+ public function add(array $values)
+ {
+ $name = isset($values['name']) ? $values['name'] : '';
+ if (! $name) {
+ throw new InvalidArgumentException(t('Monitoring backend name missing'));
+ } elseif ($this->config->get($name) !== null) {
+ throw new InvalidArgumentException(t('Monitoring backend already exists'));
+ }
+
+ unset($values['name']);
+ $this->config->{$name} = $values;
+ return $this;
+ }
+
+ /**
+ * Edit a particular monitoring backend
+ *
+ * @param string $name The name of the backend to edit
+ * @param array $values The values to edit the configuration with
+ *
+ * @return array The edited backend configuration
+ *
+ * @throws InvalidArgumentException In case the backend does not exist
+ */
+ public function edit($name, array $values)
+ {
+ if (! $name) {
+ throw new InvalidArgumentException(t('Old monitoring backend name missing'));
+ } elseif (! ($newName = isset($values['name']) ? $values['name'] : '')) {
+ throw new InvalidArgumentException(t('New monitoring backend name missing'));
+ } elseif (($backendConfig = $this->config->get($name)) === null) {
+ throw new InvalidArgumentException(t('Unknown monitoring backend provided'));
+ }
+
+ unset($values['name']);
+ unset($this->config->{$name});
+ $this->config->{$newName} = $values;
+ return $this->config->{$newName};
+ }
+
+ /**
+ * Remove the given monitoring backend
+ *
+ * @param string $name The name of the backend to remove
+ *
+ * @return array The removed backend configuration
+ *
+ * @throws InvalidArgumentException In case the backend does not exist
+ */
+ public function remove($name)
+ {
+ if (! $name) {
+ throw new InvalidArgumentException(t('Monitoring backend name missing'));
+ } elseif (($backendConfig = $this->config->get($name)) === null) {
+ throw new InvalidArgumentException(t('Unknown monitoring backend provided'));
+ }
+
+ unset($this->config->{$name});
+ return $backendConfig;
+ }
+
+ /**
+ * Add or edit a monitoring backend and save the configuration
+ *
+ * @see Form::onSuccess()
+ */
+ public function onSuccess(Request $request)
+ {
+ $monitoringBackend = $request->getQuery('backend');
+ try {
+ if ($monitoringBackend === null) { // create new backend
+ $this->add($this->getValues());
+ $message = t('Monitoring backend "%s" has been successfully created');
+ } else { // edit existing backend
+ $this->edit($monitoringBackend, $this->getValues());
+ $message = t('Monitoring backend "%s" has been successfully changed');
+ }
+ } catch (InvalidArgumentException $e) {
+ Notification::error($e->getMessage());
+ return;
+ }
+
+ if ($this->save()) {
+ Notification::success(sprintf($message, $this->getElement('name')->getValue()));
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Populate the form in case a monitoring backend is being edited
+ *
+ * @see Form::onRequest()
+ *
+ * @throws ConfigurationError In case the backend name is missing in the request or is invalid
+ */
+ public function onRequest(Request $request)
+ {
+ $monitoringBackend = $request->getQuery('backend');
+ if ($monitoringBackend !== null) {
+ if ($monitoringBackend === '') {
+ throw new ConfigurationError(t('Monitoring backend name missing'));
+ } elseif (false === isset($this->config->{$monitoringBackend})) {
+ throw new ConfigurationError(t('Unknown monitoring backend provided'));
+ }
+
+ $backendConfig = $this->config->{$monitoringBackend}->toArray();
+ $backendConfig['name'] = $monitoringBackend;
+ $this->populate($backendConfig);
+ }
+ }
+
+ /**
+ * @see Form::createElements()
+ */
+ public function createElements(array $formData)
+ {
+ $resourceType = isset($formData['type']) ? $formData['type'] : key($this->resources);
+
+ $resourceTypes = array();
+ if ($resourceType === 'ido' || array_key_exists('ido', $this->resources)) {
+ $resourceTypes['ido'] = 'IDO Backend';
+ }
+ if ($resourceType === 'statusdat' || array_key_exists('statusdat', $this->resources)) {
+ $resourceTypes['statusdat'] = 'Status.dat';
+ }
+ if ($resourceType === 'livestatus' || array_key_exists('livestatus', $this->resources)) {
+ $resourceTypes['livestatus'] = 'Livestatus';
+ }
+
+ $this->addElement(
+ 'checkbox',
+ 'disabled',
+ array(
+ 'required' => true,
+ 'label' => t('Disable This Backend')
+ )
+ );
+ $this->addElement(
+ 'text',
+ 'name',
+ array(
+ 'required' => true,
+ 'label' => t('Backend Name'),
+ 'description' => t('The identifier of this backend')
+ )
+ );
+ $this->addElement(
+ 'select',
+ 'type',
+ array(
+ 'required' => true,
+ 'autosubmit' => true,
+ 'label' => t('Backend Type'),
+ 'description' => t('The data source used for retrieving monitoring information'),
+ 'multiOptions' => $resourceTypes,
+ 'value' => $resourceType
+ )
+ );
+ $this->addElement(
+ 'select',
+ 'resource',
+ array(
+ 'required' => true,
+ 'label' => t('Resource'),
+ 'description' => t('The resource to use'),
+ 'multiOptions' => $this->resources[$resourceType]
+ )
+ );
+
+ return $this;
+ }
+}
diff --git a/modules/monitoring/application/forms/Config/BackendForm.php b/modules/monitoring/application/forms/Config/BackendForm.php
deleted file mode 100644
index f74c9bbaf..000000000
--- a/modules/monitoring/application/forms/Config/BackendForm.php
+++ /dev/null
@@ -1,125 +0,0 @@
-setName('form_config_monitoring_backends');
- $this->setSubmitLabel(t('Save Changes'));
- }
-
- /**
- * @see Form::createElements()
- */
- public function createElements(array $formData)
- {
- return array(
- $this->createElement(
- 'text',
- 'name',
- array(
- 'required' => true,
- 'label' => t('Backend Name'),
- 'helptext' => t('The identifier of this backend')
- )
- ),
- $this->createElement(
- 'select',
- 'type',
- array(
- 'required' => true,
- 'class' => 'autosubmit',
- 'label' => t('Backend Type'),
- 'helptext' => t('The data source used for retrieving monitoring information'),
- 'multiOptions' => array(
- 'ido' => 'IDO Backend',
- 'statusdat' => 'Status.dat',
- 'livestatus' => 'Livestatus'
- )
- )
- ),
- $this->createElement(
- 'select',
- 'resource',
- array(
- 'required' => true,
- 'label' => t('Resource'),
- 'helptext' => t('The resource to use'),
- 'multiOptions' => $this->getResourcesByType(
- false === isset($formData['type']) || $formData['type'] === 'ido' ? 'db' : $formData['type']
- )
- )
- ),
- $this->createElement(
- 'checkbox',
- 'disabled',
- array(
- 'required' => true,
- 'label' => t('Disable This Backend')
- )
- )
- );
- }
-
- /**
- * Return the backend configuration values and its name
- *
- * The first value is the name and the second one the values as array.
- *
- * @return array
- */
- public function getBackendConfig()
- {
- $values = $this->getValues();
- $name = $values['name'];
-
- if ($values['disabled'] == '0') {
- unset($values['disabled']);
- }
-
- unset($values['name']);
- return array($name, $values);
- }
-
- /**
- * Populate the form with the given configuration values
- *
- * @param string $name The name of the backend
- * @param array $config The configuration values
- */
- public function setBackendConfig($name, array $config)
- {
- $config['name'] = $name;
- $this->populate($config);
- }
-
- /**
- * Return a list of all resources of the given type ready to be used as content for a select input
- *
- * @param string $type The type of resources to return
- *
- * @return array
- */
- protected function getResourcesByType($type)
- {
- $backends = array();
- foreach (array_keys(ResourceFactory::getResourceConfigs($type)->toArray()) as $name) {
- $backends[$name] = $name;
- }
-
- return $backends;
- }
-}
diff --git a/modules/monitoring/application/views/scripts/config/index.phtml b/modules/monitoring/application/views/scripts/config/index.phtml
index 41d2748d5..34f47a0b4 100644
--- a/modules/monitoring/application/views/scripts/config/index.phtml
+++ b/modules/monitoring/application/views/scripts/config/index.phtml
@@ -1,99 +1,70 @@
-{$element}) &&
- get_class($this->{$element}) === 'Icinga\Exception\NotReadableError') {
- $fileNotReadable[$element] = $this->{$element}->getMessage();
- } else {
- $fileNotReadable[$element] = false;
- }
-}
-?>
-
- Your = $this->escape($this->file); ?> configuration couldn't be stored (error: "= $this->exceptionMessage; ?>").
- This could have one or more of the following reasons:
-
-
-
You don't have file-system permissions to write to the = $this->escape($this->file); ?>.ini file
-
Something went wrong while writing the file
-
There's an application error preventing you from persisting the configuration
-
-
-
-
- Details can be seen in your application log (if you don't have access to this file, call your administrator in this case).
-
- In case you can access the configuration file (config/= $this->escape($this->file); ?>.ini) by yourself, you can open it and
- insert the config manually:
-
-
\ No newline at end of file
From d6377ca00c8620379276f93bd0bc3c08c663d9e4 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 10:19:51 +0200
Subject: [PATCH 187/277] Return bootstrap mock when calling
BaseTestCase::setupIcingaMock()
---
library/Icinga/Test/BaseTestCase.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php
index f836e2725..4ff58c521 100644
--- a/library/Icinga/Test/BaseTestCase.php
+++ b/library/Icinga/Test/BaseTestCase.php
@@ -145,6 +145,8 @@ namespace Icinga\Test {
/**
* Setup mock object for the application's bootstrap
+ *
+ * @return Mockery\Mock
*/
protected function setupIcingaMock()
{
@@ -163,6 +165,7 @@ namespace Icinga\Test {
->shouldReceive('getResponse')->andReturn($responseMock);
Icinga::setApp($bootstrapMock, true);
+ return $bootstrapMock;
}
/**
From a5c027b77c606c2be94d5d2c40c7d8400fd31eb8 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 10:21:09 +0200
Subject: [PATCH 188/277] Fix UrlTest utilizing BaseTestCase::setupIcingaMock()
---
test/php/library/Icinga/Web/UrlTest.php | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/test/php/library/Icinga/Web/UrlTest.php b/test/php/library/Icinga/Web/UrlTest.php
index 5da50c3f8..68206beee 100644
--- a/test/php/library/Icinga/Web/UrlTest.php
+++ b/test/php/library/Icinga/Web/UrlTest.php
@@ -12,11 +12,9 @@ class UrlTest extends BaseTestCase
{
public function testWhetherFromRequestWorksWithoutARequest()
{
- $request = Mockery::mock('Icinga\Web\Request');
- $request->shouldReceive('getPathInfo')->andReturn('my/test/url.html')
- ->shouldReceive('getBaseUrl')->andReturn('/path/to')
+ $this->getRequestMock()->shouldReceive('getBaseUrl')->andReturn('/path/to')
+ ->shouldReceive('getPathInfo')->andReturn('my/test/url.html')
->shouldReceive('getQuery')->andReturn(array('param1' => 'value1', 'param2' => 'value2'));
- $this->setupIcingaMock($request);
$url = Url::fromRequest();
$this->assertEquals(
From cee3c32fa513273fe291f7d1196d3a94498a2aa9 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 10:21:37 +0200
Subject: [PATCH 189/277] Fix dashboard tests utilizing
BaseTestCase::setupIcingaMock()
---
.../Icinga/Web/Widget/DashboardTest.php | 10 ++--------
.../Icinga/Web/Widget/SearchDashboardTest.php | 19 +++----------------
2 files changed, 5 insertions(+), 24 deletions(-)
diff --git a/test/php/library/Icinga/Web/Widget/DashboardTest.php b/test/php/library/Icinga/Web/Widget/DashboardTest.php
index 9114a8f90..be11c42fe 100644
--- a/test/php/library/Icinga/Web/Widget/DashboardTest.php
+++ b/test/php/library/Icinga/Web/Widget/DashboardTest.php
@@ -47,7 +47,7 @@ class DashboardTest extends BaseTestCase
Mockery::close(); // Necessary because some tests run in a separate process
}
- protected function setupIcingaMock(\Zend_Controller_Request_Abstract $request)
+ public function setUp()
{
$moduleMock = Mockery::mock('Icinga\Application\Modules\Module');
$moduleMock->shouldReceive('getPaneItems')->andReturn(array(
@@ -59,14 +59,8 @@ class DashboardTest extends BaseTestCase
'test-module' => $moduleMock
));
- $bootstrapMock = Mockery::mock('Icinga\Application\ApplicationBootstrap')->shouldDeferMissing();
- $bootstrapMock->shouldReceive('getFrontController->getRequest')->andReturnUsing(
- function () use ($request) { return $request; }
- )->shouldReceive('getApplicationDir')->andReturn(self::$appDir);
-
+ $bootstrapMock = $this->setupIcingaMock();
$bootstrapMock->shouldReceive('getModuleManager')->andReturn($moduleManagerMock);
-
- Icinga::setApp($bootstrapMock, true);
}
public function testWhetherCreatePaneCreatesAPane()
diff --git a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php
index d42862ff6..d9323c00a 100644
--- a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php
+++ b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php
@@ -5,19 +5,12 @@
namespace Tests\Icinga\Web;
use Mockery;
-use Icinga\Application\Icinga;
-use Icinga\Web\Widget\SearchDashboard;
use Icinga\Test\BaseTestCase;
+use Icinga\Web\Widget\SearchDashboard;
class SearchDashboardTest extends BaseTestCase
{
- public function tearDown()
- {
- parent::tearDown();
- Mockery::close();
- }
-
- protected function setupIcingaMock(\Zend_Controller_Request_Abstract $request)
+ public function setUp()
{
$moduleMock = Mockery::mock('Icinga\Application\Modules\Module');
$searchUrl = (object) array(
@@ -33,14 +26,8 @@ class SearchDashboardTest extends BaseTestCase
'test-module' => $moduleMock
));
- $bootstrapMock = Mockery::mock('Icinga\Application\ApplicationBootstrap')->shouldDeferMissing();
- $bootstrapMock->shouldReceive('getFrontController->getRequest')->andReturnUsing(
- function () use ($request) { return $request; }
- )->shouldReceive('getApplicationDir')->andReturn(self::$appDir);
-
+ $bootstrapMock = $this->setupIcingaMock();
$bootstrapMock->shouldReceive('getModuleManager')->andReturn($moduleManagerMock);
-
- Icinga::setApp($bootstrapMock, true);
}
/**
From 31978e12360afac8eed56180147f4eb55a5c7f82 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 10:36:42 +0200
Subject: [PATCH 190/277] Fix LdapBackendFormTest
refs #5525
---
.../Config/Authentication/LdapBackendForm.php | 1 +
.../Authentication/LdapBackendFormTest.php | 20 +++++++++----------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php
index 4e3172ad2..a0c20b949 100644
--- a/application/forms/Config/Authentication/LdapBackendForm.php
+++ b/application/forms/Config/Authentication/LdapBackendForm.php
@@ -6,6 +6,7 @@ namespace Icinga\Form\Config\Authentication;
use Exception;
use Icinga\Web\Form;
+use Icinga\Web\Request;
use Icinga\Data\ResourceFactory;
use Icinga\Authentication\Backend\LdapUserBackend;
diff --git a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php
index 209b7a675..0335d1f82 100644
--- a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php
+++ b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php
@@ -29,16 +29,15 @@ class LdapBackendFormTest extends BaseTestCase
{
$this->setUpResourceFactoryMock();
Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend')
- ->shouldReceive('assertAuthenticationPossible')->andReturn(null);
+ ->shouldReceive('assertAuthenticationPossible')->andReturnNull();
$form = new LdapBackendForm();
- $form->setBackendName('test');
- $form->setResources(array('test_ldap_backend' => null));
- $form->create();
- $form->populate(array('backend_test_resource' => 'test_ldap_backend'));
+ $form->setTokenDisabled();
+ $form->setResources(array('test_ldap_backend'));
+ $form->populate(array('resource' => 'test_ldap_backend'));
$this->assertTrue(
- $form->isValidAuthenticationBackend(),
+ $form->isValidAuthenticationBackend($form),
'LdapBackendForm claims that a valid authentication backend with users is not valid'
);
}
@@ -54,13 +53,12 @@ class LdapBackendFormTest extends BaseTestCase
->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
$form = new LdapBackendForm();
- $form->setBackendName('test');
- $form->setResources(array('test_ldap_backend' => null));
- $form->create();
- $form->populate(array('backend_test_resource' => 'test_ldap_backend'));
+ $form->setTokenDisabled();
+ $form->setResources(array('test_ldap_backend'));
+ $form->populate(array('resource' => 'test_ldap_backend'));
$this->assertFalse(
- $form->isValidAuthenticationBackend(),
+ $form->isValidAuthenticationBackend($form),
'LdapBackendForm claims that an invalid authentication backend without users is valid'
);
}
From e4fccdd15019676eaaa0bd8a47e2923f27b21562 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 10:39:49 +0200
Subject: [PATCH 191/277] Fix DbBackendFormTest
refs #5525
---
.../Authentication/DbBackendFormTest.php | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/test/php/application/forms/Config/Authentication/DbBackendFormTest.php b/test/php/application/forms/Config/Authentication/DbBackendFormTest.php
index 51bec896f..3364dff60 100644
--- a/test/php/application/forms/Config/Authentication/DbBackendFormTest.php
+++ b/test/php/application/forms/Config/Authentication/DbBackendFormTest.php
@@ -32,13 +32,12 @@ class DbBackendFormTest extends BaseTestCase
->andReturn(2);
$form = new DbBackendForm();
- $form->setBackendName('test');
- $form->setResources(array('test_db_backend' => null));
- $form->create();
- $form->populate(array('backend_test_resource' => 'test_db_backend'));
+ $form->setTokenDisabled();
+ $form->setResources(array('test_db_backend'));
+ $form->populate(array('resource' => 'test_db_backend'));
$this->assertTrue(
- $form->isValidAuthenticationBackend(),
+ $form->isValidAuthenticationBackend($form),
'DbBackendForm claims that a valid authentication backend with users is not valid'
);
}
@@ -55,13 +54,12 @@ class DbBackendFormTest extends BaseTestCase
->andReturn(0);
$form = new DbBackendForm();
- $form->setBackendName('test');
- $form->setResources(array('test_db_backend' => null));
- $form->create();
- $form->populate(array('backend_test_resource' => 'test_db_backend'));
+ $form->setTokenDisabled();
+ $form->setResources(array('test_db_backend'));
+ $form->populate(array('resource' => 'test_db_backend'));
$this->assertFalse(
- $form->isValidAuthenticationBackend(),
+ $form->isValidAuthenticationBackend($form),
'DbBackendForm claims that an invalid authentication backend without users is valid'
);
}
From 7dbc83e21feeee17b41a9a78ce5e281ee64d88cc Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 11:58:07 +0200
Subject: [PATCH 192/277] Drop obsolete BaseBackendFormTest
refs #5525
---
.../Authentication/BaseBackendFormTest.php | 61 -------------------
1 file changed, 61 deletions(-)
delete mode 100644 test/php/application/forms/Config/Authentication/BaseBackendFormTest.php
diff --git a/test/php/application/forms/Config/Authentication/BaseBackendFormTest.php b/test/php/application/forms/Config/Authentication/BaseBackendFormTest.php
deleted file mode 100644
index ca32a1dae..000000000
--- a/test/php/application/forms/Config/Authentication/BaseBackendFormTest.php
+++ /dev/null
@@ -1,61 +0,0 @@
-is_valid;
- }
-}
-
-class BaseBackendFormTest extends BaseTestCase
-{
- public function testIsForceCreationCheckboxBeingAdded()
- {
- $form = new BackendForm();
- $form->is_valid = false;
-
- $this->assertFalse($form->isValid(array()));
- $this->assertNotNull(
- $form->getElement('backend_force_creation'),
- 'Checkbox to force a backend\'s creation is not being added though the backend is invalid'
- );
- }
-
- public function testIsForceCreationCheckboxNotBeingAdded()
- {
- $form = new BackendForm();
- $form->is_valid = true;
-
- $this->assertTrue($form->isValid(array()));
- $this->assertNull(
- $form->getElement('backend_force_creation'),
- 'Checkbox to force a backend\'s creation is being added though the backend is valid'
- );
- }
-
- public function testIsTheFormValidIfForceCreationTrue()
- {
- $form = new BackendForm();
- $form->is_valid = false;
-
- $this->assertTrue(
- $form->isValid(array('backend_force_creation' => 1)),
- 'BaseBackendForm with invalid backend is not valid though force creation is set'
- );
- }
-}
From 40947acd163d56658578e75fe076a6d50b96aa13 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 12:02:51 +0200
Subject: [PATCH 193/277] Fix, rename and move ReorderFormTest
refs #5525
---
.../Config/Authentication/ReorderFormTest.php | 80 -------------------
.../AuthenticationBackendReorderFormTest.php | 61 ++++++++++++++
2 files changed, 61 insertions(+), 80 deletions(-)
delete mode 100644 test/php/application/forms/Config/Authentication/ReorderFormTest.php
create mode 100644 test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php
diff --git a/test/php/application/forms/Config/Authentication/ReorderFormTest.php b/test/php/application/forms/Config/Authentication/ReorderFormTest.php
deleted file mode 100644
index 808806f1a..000000000
--- a/test/php/application/forms/Config/Authentication/ReorderFormTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
- $this->order);
- }
-}
-
-class ReorderFormTest extends BaseTestCase
-{
- public function setUp()
- {
- parent::setUp();
- $this->viewMock = Mockery::mock('\Zend_View');
- $this->viewMock->shouldReceive('icon')->andReturn('');
- }
-
- public function testMoveBackendUp()
- {
- $config = new Zend_Config(
- array(
- 'test1' => '',
- 'test2' => '',
- 'test3' => ''
- )
- );
- $oldOrder = array_keys($config->toArray());
-
- $form = new RequestLessReorderForm();
- $form->setCurrentOrder($oldOrder);
- $form->setBackendName('test3');
- $form->setView($this->viewMock);
- $form->create();
-
- $form->order = $form->getSubForm('btn_reorder_up')->getElement('form_backend_order')->getValue();
- $this->assertSame(
- $form->getReorderedConfig($config),
- array('test1' => '', 'test3' => '', 'test2' => ''),
- 'Moving elements up with ReorderForm does not seem to properly work'
- );
- }
-
- public function testMoveBackendDown()
- {
- $config = new Zend_Config(
- array(
- 'test1' => '',
- 'test2' => '',
- 'test3' => ''
- )
- );
- $oldOrder = array_keys($config->toArray());
-
- $form = new RequestLessReorderForm();
- $form->setCurrentOrder($oldOrder);
- $form->setBackendName('test1');
- $form->setView($this->viewMock);
- $form->create();
-
- $form->order = $form->getSubForm('btn_reorder_down')->getElement('form_backend_order')->getValue();
- $this->assertSame(
- $form->getReorderedConfig($config),
- array('test2' => '', 'test1' => '', 'test3' => ''),
- 'Moving elements down with ReorderForm does not seem to properly work'
- );
- }
-}
diff --git a/test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php b/test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php
new file mode 100644
index 000000000..c79b12fd9
--- /dev/null
+++ b/test/php/application/forms/Config/AuthenticationBackendReorderFormTest.php
@@ -0,0 +1,61 @@
+config;
+ return false;
+ }
+}
+
+class AuthenticationBackendReorderFormProvidingConfigFormWithoutSave extends AuthenticationBackendReorderForm
+{
+ public function getConfigForm()
+ {
+ $form = new AuthenticationBackendConfigFormWithoutSave();
+ $form->setIniConfig($this->config);
+ return $form;
+ }
+}
+
+class AuthenticationBackendReorderFormTest extends BaseTestCase
+{
+ public function testMoveBackend()
+ {
+ $config = new Config(
+ array(
+ 'test1' => '',
+ 'test2' => '',
+ 'test3' => ''
+ )
+ );
+
+ $this->getRequestMock()->shouldReceive('getMethod')->andReturn('POST')
+ ->shouldReceive('isPost')->andReturn(true)
+ ->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1'));
+
+ $form = new AuthenticationBackendReorderFormProvidingConfigFormWithoutSave();
+ $form->setIniConfig($config);
+ $form->setTokenDisabled();
+ $form->setUidDisabled();
+ $form->handleRequest();
+
+ $this->assertEquals(
+ array('test1', 'test3', 'test2'),
+ AuthenticationBackendConfigFormWithoutSave::$newConfig->keys(),
+ 'Moving elements with AuthenticationBackendReorderForm does not seem to properly work'
+ );
+ }
+}
From 9d8f810e1037a9ac1e76cd635c4fba5125041e59 Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 13:01:09 +0200
Subject: [PATCH 194/277] Icinga\Web\Request::getParam() should be mocked as
well by default
---
library/Icinga/Test/BaseTestCase.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php
index 4ff58c521..a735550cb 100644
--- a/library/Icinga/Test/BaseTestCase.php
+++ b/library/Icinga/Test/BaseTestCase.php
@@ -153,7 +153,9 @@ namespace Icinga\Test {
$requestMock = Mockery::mock('Icinga\Web\Request')->shouldDeferMissing();
$requestMock->shouldReceive('getPathInfo')->andReturn('')->byDefault()
->shouldReceive('getBaseUrl')->andReturn('/')->byDefault()
- ->shouldReceive('getQuery')->andReturn(array())->byDefault();
+ ->shouldReceive('getQuery')->andReturn(array())->byDefault()
+ ->shouldReceive('getParam')->with(Mockery::type('string'), Mockery::type('string'))
+ ->andReturnUsing(function ($name, $default) { return $default; })->byDefault();
$responseMock = Mockery::mock('Icinga\Web\Response')->shouldDeferMissing();
From 0693e7cf2db3e49c54e27cab3ddbad060395205e Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 13:06:30 +0200
Subject: [PATCH 195/277] Fix ResourceForm tests
refs #5525
---
.../Config/Resource/DbResourceFormTest.php | 66 +++++
.../Config/Resource/LdapResourceFormTest.php | 66 +++++
.../Resource/LivestatusResourceFormTest.php | 67 +++++
.../Resource/ResourceFormTestBroken.php | 268 ------------------
4 files changed, 199 insertions(+), 268 deletions(-)
create mode 100644 test/php/application/forms/Config/Resource/DbResourceFormTest.php
create mode 100644 test/php/application/forms/Config/Resource/LdapResourceFormTest.php
create mode 100644 test/php/application/forms/Config/Resource/LivestatusResourceFormTest.php
delete mode 100644 test/php/application/forms/Config/Resource/ResourceFormTestBroken.php
diff --git a/test/php/application/forms/Config/Resource/DbResourceFormTest.php b/test/php/application/forms/Config/Resource/DbResourceFormTest.php
new file mode 100644
index 000000000..1b624c49f
--- /dev/null
+++ b/test/php/application/forms/Config/Resource/DbResourceFormTest.php
@@ -0,0 +1,66 @@
+setUpResourceFactoryMock(
+ Mockery::mock()->shouldReceive('getConnection')->atMost()->twice()->andReturn(Mockery::self())->getMock()
+ );
+
+ $form = new DbResourceForm();
+
+ $this->assertTrue(
+ $form->isValidResource($form),
+ 'ResourceForm claims that a valid db resource is not valid'
+ );
+ }
+
+ /**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testInvalidDbResourceIsNotValid()
+ {
+ $this->setUpResourceFactoryMock(
+ Mockery::mock()->shouldReceive('getConnection')->once()->andThrow('\Exception')->getMock()
+ );
+
+ $form = new DbResourceForm();
+
+ $this->assertFalse(
+ $form->isValidResource($form),
+ 'ResourceForm claims that an invalid db resource is valid'
+ );
+ }
+
+ protected function setUpResourceFactoryMock($resourceMock)
+ {
+ Mockery::mock('alias:Icinga\Data\ResourceFactory')
+ ->shouldReceive('createResource')
+ ->with(Mockery::type('\Zend_Config'))
+ ->andReturn($resourceMock);
+ }
+}
diff --git a/test/php/application/forms/Config/Resource/LdapResourceFormTest.php b/test/php/application/forms/Config/Resource/LdapResourceFormTest.php
new file mode 100644
index 000000000..078a11146
--- /dev/null
+++ b/test/php/application/forms/Config/Resource/LdapResourceFormTest.php
@@ -0,0 +1,66 @@
+setUpResourceFactoryMock(
+ Mockery::mock()->shouldReceive('connect')->getMock()
+ );
+
+ $form = new LdapResourceForm();
+
+ $this->assertTrue(
+ $form->isValidResource($form),
+ 'ResourceForm claims that a valid ldap resource is not valid'
+ );
+ }
+
+ /**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testInvalidLdapResourceIsNotValid()
+ {
+ $this->setUpResourceFactoryMock(
+ Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
+ );
+
+ $form = new LdapResourceForm();
+
+ $this->assertFalse(
+ $form->isValidResource($form),
+ 'ResourceForm claims that an invalid ldap resource is valid'
+ );
+ }
+
+ protected function setUpResourceFactoryMock($resourceMock)
+ {
+ Mockery::mock('alias:Icinga\Data\ResourceFactory')
+ ->shouldReceive('createResource')
+ ->with(Mockery::type('\Zend_Config'))
+ ->andReturn($resourceMock);
+ }
+}
diff --git a/test/php/application/forms/Config/Resource/LivestatusResourceFormTest.php b/test/php/application/forms/Config/Resource/LivestatusResourceFormTest.php
new file mode 100644
index 000000000..300adebed
--- /dev/null
+++ b/test/php/application/forms/Config/Resource/LivestatusResourceFormTest.php
@@ -0,0 +1,67 @@
+setUpResourceFactoryMock(
+ Mockery::mock()->shouldReceive('connect')->andReturn(Mockery::self())
+ ->shouldReceive('disconnect')->getMock()
+ );
+
+ $form = new LivestatusResourceForm();
+
+ $this->assertTrue(
+ $form->isValidResource($form),
+ 'ResourceForm claims that a valid livestatus resource is not valid'
+ );
+ }
+
+ /**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testInvalidLivestatusResourceIsNotValid()
+ {
+ $this->setUpResourceFactoryMock(
+ Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
+ );
+
+ $form = new LivestatusResourceForm();
+
+ $this->assertFalse(
+ $form->isValidResource($form),
+ 'ResourceForm claims that an invalid livestatus resource is valid'
+ );
+ }
+
+ protected function setUpResourceFactoryMock($resourceMock)
+ {
+ Mockery::mock('alias:Icinga\Data\ResourceFactory')
+ ->shouldReceive('createResource')
+ ->with(Mockery::type('\Zend_Config'))
+ ->andReturn($resourceMock);
+ }
+}
diff --git a/test/php/application/forms/Config/Resource/ResourceFormTestBroken.php b/test/php/application/forms/Config/Resource/ResourceFormTestBroken.php
deleted file mode 100644
index 6dba6ce54..000000000
--- a/test/php/application/forms/Config/Resource/ResourceFormTestBroken.php
+++ /dev/null
@@ -1,268 +0,0 @@
-is_valid;
- }
-}
-
-class ResourceFormTest extends BaseTestCase
-{
- public function tearDown()
- {
- parent::tearDown();
- Mockery::close(); // Necessary because some tests run in a separate process
- }
-
- public function testIsForceCreationCheckboxBeingAdded()
- {
- $form = new TestResourceForm();
- $form->is_valid = false;
-
- $this->assertFalse($form->isValid(array()));
- $this->assertNotNull(
- $form->getElement('resource_force_creation'),
- 'Checkbox to force the creation of a resource is not being added though the resource is invalid'
- );
- }
-
- public function testIsForceCreationCheckboxNotBeingAdded()
- {
- $form = new TestResourceForm();
- $form->is_valid = true;
-
- $this->assertTrue($form->isValid(array()));
- $this->assertNull(
- $form->getElement('resource_force_creation'),
- 'Checkbox to force the creation of a resource is being added though the resource is valid'
- );
- }
-
- public function testIsTheFormValidIfForceCreationTrue()
- {
- $form = new TestResourceForm();
- $form->is_valid = false;
-
- $this->assertTrue(
- $form->isValid(array('resource_force_creation' => 1)),
- 'ResourceForm with invalid resource is not valid though force creation is set'
- );
- }
-
- /**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testValidDbResourceIsValid()
- {
- $this->setUpResourceFactoryMock(
- Mockery::mock()->shouldReceive('getConnection')->atMost()->twice()->andReturn(Mockery::self())->getMock()
- );
- $form = $this->buildResourceForm(new Zend_Config(array('type' => 'db')));
-
- $this->assertTrue(
- $form->isValidResource(),
- 'ResourceForm claims that a valid db resource is not valid'
- );
- }
-
- /**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testInvalidDbResourceIsNotValid()
- {
- $this->setUpResourceFactoryMock(
- Mockery::mock()->shouldReceive('getConnection')->once()->andThrow('\Exception')->getMock()
- );
- $form = $this->buildResourceForm(new Zend_Config(array('type' => 'db')));
-
- $this->assertFalse(
- $form->isValidResource(),
- 'ResourceForm claims that an invalid db resource is valid'
- );
- }
-
- /**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testValidLdapResourceIsValid()
- {
- $this->setUpResourceFactoryMock(
- Mockery::mock()->shouldReceive('connect')->getMock()
- );
- $form = $this->buildResourceForm(new Zend_Config(array('type' => 'ldap')));
-
- $this->assertTrue(
- $form->isValidResource(),
- 'ResourceForm claims that a valid ldap resource is not valid'
- );
- }
-
- /**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testInvalidLdapResourceIsNotValid()
- {
- $this->setUpResourceFactoryMock(
- Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
- );
- $form = $this->buildResourceForm(new Zend_Config(array('type' => 'ldap')));
-
- $this->assertFalse(
- $form->isValidResource(),
- 'ResourceForm claims that an invalid ldap resource is valid'
- );
- }
-
- /**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testValidLivestatusResourceIsValid()
- {
- $this->setUpResourceFactoryMock(
- Mockery::mock()->shouldReceive('connect')->andReturn(Mockery::self())
- ->shouldReceive('disconnect')->getMock()
- );
- $form = $this->buildResourceForm(new Zend_Config(array('type' => 'livestatus')));
-
- $this->assertTrue(
- $form->isValidResource(),
- 'ResourceForm claims that a valid livestatus resource is not valid'
- );
- }
-
- /**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testInvalidLivestatusResourceIsNotValid()
- {
- $this->setUpResourceFactoryMock(
- Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
- );
- $form = $this->buildResourceForm(new Zend_Config(array('type' => 'livestatus')));
-
- $this->assertFalse(
- $form->isValidResource(),
- 'ResourceForm claims that an invalid livestatus resource is valid'
- );
- }
-
- public function testValidFileResourceIsValid()
- {
- $form = $this->buildResourceForm(
- new Zend_Config(
- array(
- 'type' => 'file',
- 'filename' => BaseTestCase::$testDir . '/res/status/icinga.status.dat'
- )
- )
- );
-
- $this->assertTrue(
- $form->isValidResource(),
- 'ResourceForm claims that a valid file resource is not valid'
- );
- }
-
- public function testInvalidFileResourceIsNotValid()
- {
- $form = $this->buildResourceForm(
- new Zend_Config(
- array(
- 'type' => 'file',
- 'filename' => 'not_existing'
- )
- )
- );
-
- $this->assertFalse(
- $form->isValidResource(),
- 'ResourceForm claims that an invalid file resource is valid'
- );
- }
-
- public function testValidStatusdatResourceIsValid()
- {
- $form = $this->buildResourceForm(
- new Zend_Config(
- array(
- 'type' => 'statusdat',
- 'status_file' => BaseTestCase::$testDir . '/res/status/icinga.status.dat',
- 'object_file' => BaseTestCase::$testDir . '/res/status/icinga.objects.cache',
- )
- )
- );
-
- $this->assertTrue(
- $form->isValidResource(),
- 'ResourceForm claims that a valid statusdat resource is not valid'
- );
- }
-
- public function testInvalidStatusdatResourceIsNotValid()
- {
- $form = $this->buildResourceForm(
- new Zend_Config(
- array(
- 'type' => 'statusdat',
- 'status_file' => 'not_existing',
- 'object_file' => 'not_existing'
- )
- )
- );
-
- $this->assertFalse(
- $form->isValidResource(),
- 'ResourceForm claims that an invalid statusdat resource is valid'
- );
- }
-
- protected function buildResourceForm($resourceConfig)
- {
- $form = new ResourceForm();
- $form->setRequest($this->getRequestMock());
- $form->setResource($resourceConfig);
- $form->create();
-
- return $form;
- }
-
- protected function getRequestMock()
- {
- return Mockery::mock('\Zend_Controller_Request_Abstract')
- ->shouldReceive('getParam')
- ->with(Mockery::type('string'), Mockery::type('string'))
- ->andReturnUsing(function ($name, $default) { return $default; })
- ->getMock();
- }
-
- protected function setUpResourceFactoryMock($resourceMock)
- {
- Mockery::mock('alias:Icinga\Data\ResourceFactory')
- ->shouldReceive('createResource')
- ->with(Mockery::type('\Zend_Config'))
- ->andReturn($resourceMock);
- }
-}
From 6bde740d21b66640161dd32ed6c07f4b965b47ae Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 13:22:51 +0200
Subject: [PATCH 196/277] Fix Icinga\Form\ConfigForm show config feature not
available for modules
refs #5525
---
application/forms/ConfigForm.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php
index a354fa538..86790d618 100644
--- a/application/forms/ConfigForm.php
+++ b/application/forms/ConfigForm.php
@@ -54,6 +54,7 @@ class ConfigForm extends Form
$writer->write();
} catch (Exception $e) {
$this->addDecorator('ViewScript', array(
+ 'viewModule' => 'default',
'viewScript' => 'showConfiguration.phtml',
'errorMessage' => $e->getMessage(),
'configString' => $writer->render(),
From ceeb3a9ff8e119370b82bdd1199392c3227c0bcd Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 13:24:39 +0200
Subject: [PATCH 197/277] Fix createElements() not returning self where
applicable
refs #5525
---
.../forms/Config/Authentication/AutologinBackendForm.php | 2 ++
application/forms/Config/Authentication/DbBackendForm.php | 2 ++
application/forms/Config/Authentication/LdapBackendForm.php | 2 ++
application/forms/Config/General/ApplicationConfigForm.php | 2 ++
application/forms/Config/General/LoggingConfigForm.php | 2 ++
application/forms/Config/Resource/DbResourceForm.php | 2 ++
application/forms/Config/Resource/FileResourceForm.php | 2 ++
application/forms/Config/Resource/LdapResourceForm.php | 2 ++
application/forms/Config/Resource/LivestatusResourceForm.php | 2 ++
application/forms/Config/Resource/StatusdatResourceForm.php | 2 ++
.../application/forms/Config/Instance/LocalInstanceForm.php | 2 ++
.../application/forms/Config/Instance/RemoteInstanceForm.php | 2 ++
12 files changed, 24 insertions(+)
diff --git a/application/forms/Config/Authentication/AutologinBackendForm.php b/application/forms/Config/Authentication/AutologinBackendForm.php
index d4e0547a9..4f4df73e3 100644
--- a/application/forms/Config/Authentication/AutologinBackendForm.php
+++ b/application/forms/Config/Authentication/AutologinBackendForm.php
@@ -69,6 +69,8 @@ class AutologinBackendForm extends Form
'value' => 'autologin'
)
);
+
+ return $this;
}
/**
diff --git a/application/forms/Config/Authentication/DbBackendForm.php b/application/forms/Config/Authentication/DbBackendForm.php
index 960a6d07c..23335f8fa 100644
--- a/application/forms/Config/Authentication/DbBackendForm.php
+++ b/application/forms/Config/Authentication/DbBackendForm.php
@@ -77,6 +77,8 @@ class DbBackendForm extends Form
'value' => 'db'
)
);
+
+ return $this;
}
/**
diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php
index a0c20b949..6056b0911 100644
--- a/application/forms/Config/Authentication/LdapBackendForm.php
+++ b/application/forms/Config/Authentication/LdapBackendForm.php
@@ -97,6 +97,8 @@ class LdapBackendForm extends Form
'value' => 'ldap'
)
);
+
+ return $this;
}
/**
diff --git a/application/forms/Config/General/ApplicationConfigForm.php b/application/forms/Config/General/ApplicationConfigForm.php
index 5f592eefc..fda695886 100644
--- a/application/forms/Config/General/ApplicationConfigForm.php
+++ b/application/forms/Config/General/ApplicationConfigForm.php
@@ -112,5 +112,7 @@ class ApplicationConfigForm extends Form
)
);
}
+
+ return $this;
}
}
diff --git a/application/forms/Config/General/LoggingConfigForm.php b/application/forms/Config/General/LoggingConfigForm.php
index 33e182b5d..135dd9e28 100644
--- a/application/forms/Config/General/LoggingConfigForm.php
+++ b/application/forms/Config/General/LoggingConfigForm.php
@@ -102,6 +102,8 @@ class LoggingConfigForm extends Form
)
);
}
+
+ return $this;
}
/**
diff --git a/application/forms/Config/Resource/DbResourceForm.php b/application/forms/Config/Resource/DbResourceForm.php
index 136e9e645..4fd7297d9 100644
--- a/application/forms/Config/Resource/DbResourceForm.php
+++ b/application/forms/Config/Resource/DbResourceForm.php
@@ -92,6 +92,8 @@ class DbResourceForm extends Form
'description' => t('The password to use for authentication')
)
);
+
+ return $this;
}
/**
diff --git a/application/forms/Config/Resource/FileResourceForm.php b/application/forms/Config/Resource/FileResourceForm.php
index 2654ad949..d1d33a749 100644
--- a/application/forms/Config/Resource/FileResourceForm.php
+++ b/application/forms/Config/Resource/FileResourceForm.php
@@ -44,5 +44,7 @@ class FileResourceForm extends Form
'description' => t('The regular expression by which to identify columns')
)
);
+
+ return $this;
}
}
diff --git a/application/forms/Config/Resource/LdapResourceForm.php b/application/forms/Config/Resource/LdapResourceForm.php
index 752516956..6196f3a17 100644
--- a/application/forms/Config/Resource/LdapResourceForm.php
+++ b/application/forms/Config/Resource/LdapResourceForm.php
@@ -78,6 +78,8 @@ class LdapResourceForm extends Form
'description' => t('The password to use for querying the ldap server')
)
);
+
+ return $this;
}
/**
diff --git a/application/forms/Config/Resource/LivestatusResourceForm.php b/application/forms/Config/Resource/LivestatusResourceForm.php
index ad0b382c2..92534f220 100644
--- a/application/forms/Config/Resource/LivestatusResourceForm.php
+++ b/application/forms/Config/Resource/LivestatusResourceForm.php
@@ -39,6 +39,8 @@ class LivestatusResourceForm extends Form
'value' => realpath(Icinga::app()->getApplicationDir() . '/../var/rw/livestatus')
)
);
+
+ return $this;
}
/**
diff --git a/application/forms/Config/Resource/StatusdatResourceForm.php b/application/forms/Config/Resource/StatusdatResourceForm.php
index 15563ff39..f150056d1 100644
--- a/application/forms/Config/Resource/StatusdatResourceForm.php
+++ b/application/forms/Config/Resource/StatusdatResourceForm.php
@@ -48,5 +48,7 @@ class StatusdatResourceForm extends Form
'validators' => array(new ReadablePathValidator())
)
);
+
+ return $this;
}
}
diff --git a/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php
index 6f0d37e25..513ba2433 100644
--- a/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php
+++ b/modules/monitoring/application/forms/Config/Instance/LocalInstanceForm.php
@@ -31,5 +31,7 @@ class LocalInstanceForm extends Form
'description' => t('The file path where the icinga commandpipe can be found')
)
);
+
+ return $this;
}
}
diff --git a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php
index 36991425b..0e78a0aec 100644
--- a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php
+++ b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php
@@ -62,5 +62,7 @@ class RemoteInstanceForm extends Form
'description' => t('The file path where the icinga commandpipe can be found')
)
);
+
+ return $this;
}
}
From e7c021845d38a4ad616822dbd7af7fe0965785bf Mon Sep 17 00:00:00 2001
From: Johannes Meyer
Date: Tue, 9 Sep 2014 15:00:33 +0200
Subject: [PATCH 198/277] Simplify subform usage
refs #5525
---
library/Icinga/Web/Form.php | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php
index fd5cbf510..f0695242e 100644
--- a/library/Icinga/Web/Form.php
+++ b/library/Icinga/Web/Form.php
@@ -370,7 +370,7 @@ class Form extends Zend_Form
*/
public function addSubmitButton()
{
- if ($this->submitLabel !== null) {
+ if ($this->submitLabel) {
$this->addElement(
'submit',
'btn_submit',
@@ -388,6 +388,31 @@ class Form extends Zend_Form
return $this;
}
+ /**
+ * Add a subform
+ *
+ * @param Zend_Form $form The subform to add
+ * @param string $name The name of the subform or null to use the name of $form
+ * @param int $order The location where to insert the form
+ *
+ * @return Zend_Form
+ */
+ public function addSubForm(Zend_Form $form, $name = null, $order = null)
+ {
+ if ($form instanceof self) {
+ $form->removeDecorator('Form');
+ $form->setSubmitLabel('');
+ $form->setTokenDisabled();
+ $form->setUidDisabled();
+ }
+
+ if ($name === null) {
+ $name = $form->getName();
+ }
+
+ return parent::addSubForm($form, $name, $order);
+ }
+
/**
* Create a new element
*
From a841b0956d03c5f032f92b45d8cd51917ab28698 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 9 Sep 2014 16:35:06 +0200
Subject: [PATCH 199/277] monitoring/commands: Do not require command objects
to return the command string
There will be command renderer instead.
refs #6593
---
.../Monitoring/Command/IcingaCommand.php | 29 ++-----------------
1 file changed, 3 insertions(+), 26 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Command/IcingaCommand.php b/modules/monitoring/library/Monitoring/Command/IcingaCommand.php
index dd8dd97fe..d88f8dba0 100644
--- a/modules/monitoring/library/Monitoring/Command/IcingaCommand.php
+++ b/modules/monitoring/library/Monitoring/Command/IcingaCommand.php
@@ -10,35 +10,12 @@ namespace Icinga\Module\Monitoring\Command;
abstract class IcingaCommand
{
/**
- * Get the command string
+ * Get the name of the command
*
* @return string
*/
- abstract public function getCommandString();
-
- /**
- * Escape a command string
- *
- * @param string $commandString
- *
- * @return string
- */
- public function escape($commandString)
+ public function getName()
{
- return str_replace(array("\r", "\n"), array('\r', '\n'), $commandString);
- }
-
- /**
- * Get the command as string with the current timestamp as the command submission time
- *
- * @return string
- */
- public function __toString()
- {
- return sprintf(
- '[%u] %s',
- time(),
- $this->escape($this->getCommandString())
- );
+ return substr_replace(end(explode('\\', get_called_class())), '', -7); // Remove 'Command' Suffix
}
}
From d9fbbca447c71ef84d2a40933a73dfcbf9a32908 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 9 Sep 2014 16:39:22 +0200
Subject: [PATCH 200/277] monitoring/commands: Move `AddCommentCommand' to
`WithCommentCommand'
`AddCommentCommand' will be the command for adding both host and service comments.
refs #6593
---
.../Command/Common/WithCommentCommand.php | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php
diff --git a/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php
new file mode 100644
index 000000000..c913e5bd3
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php
@@ -0,0 +1,71 @@
+author = (string) $author;
+ return $this;
+ }
+
+ /**
+ * Get the author
+ *
+ * @return string
+ */
+ public function getAuthor()
+ {
+ return $this->author;
+ }
+
+ /**
+ * Set the comment
+ *
+ * @param string $comment
+ *
+ * @return $this
+ */
+ public function setComment($comment)
+ {
+ $this->comment = (string) $comment;
+ return $this;
+ }
+
+ /**
+ * Get the comment
+ *
+ * @return string
+ */
+ public function getComment()
+ {
+ return $this->comment;
+ }
+}
From 28a66c85412c38a3a83977312a533ca082847e75 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 9 Sep 2014 16:40:09 +0200
Subject: [PATCH 201/277] monitoring/commands: Introduce `ObjectCommand' for
commands that involve a Icinga object
refs #6593
---
.../Command/Common/ObjectCommand.php | 62 +++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php
diff --git a/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php b/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php
new file mode 100644
index 000000000..8727c237b
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php
@@ -0,0 +1,62 @@
+assertOneOf($this->allowedObjects);
+ $this->object = $object;
+ return $this;
+ }
+
+ /**
+ * Get the involved object
+ *
+ * @return MonitoredObject
+ */
+ public function getObject()
+ {
+ return $this->object;
+ }
+}
From 171b3667440dc21f68f5e9ee9c12be11805066c5 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 9 Sep 2014 16:41:41 +0200
Subject: [PATCH 202/277] monitoring/commands: Let `AddCommentCommand' be the
command object for adding both host and service commands
refs #6593
---
.../Command/Common/AddCommentCommand.php | 103 ++++++------------
1 file changed, 35 insertions(+), 68 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php
index 67c6cc330..5d56011ae 100644
--- a/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php
+++ b/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php
@@ -4,80 +4,47 @@
namespace Icinga\Module\Monitoring\Command\Common;
-use Icinga\Module\Monitoring\Command\IcingaCommand;
-use Icinga\User;
-
/**
- * Base class for commands adding comments
+ * Add a comment to a host or service
*/
-abstract class AddCommentCommand extends IcingaCommand
+class AddCommentCommand extends WithCommentCommand
{
- /**
- * Author of the comment
- *
- * @var User
- */
- protected $author;
-
- /**
- * Comment
- *
- * @var string
- */
- protected $comment;
-
- /**
- * Set the author
- *
- * @param User $author
- *
- * @return $this
- */
- public function setAuthor(User $author)
- {
- $this->author = $author;
- return $this;
- }
-
- /**
- * Get the author
- *
- * @return User
- */
- public function getAuthor()
- {
- return $this->author;
- }
-
- /**
- * Set the comment
- *
- * @param string $comment
- *
- * @return $this
- */
- public function setComment($comment)
- {
- $this->comment = (string) $comment;
- return $this;
- }
-
- /**
- * Get the comment
- *
- * @return string
- */
- public function getComment()
- {
- return $this->comment;
- }
-
/**
* (non-PHPDoc)
- * @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation.
+ * @see \Icinga\Module\Monitoring\Command\Common\ObjectCommand::$allowedObjects For the property documentation.
*/
- public function getCommandString()
+ protected $allowedObjects = array(
+ self::TYPE_HOST,
+ self::TYPE_SERVICE
+ );
+
+ /**
+ * Whether the comment is persistent
+ *
+ * Persistent comments are not lost the next time the monitoring host restarts.
+ */
+ protected $persistent;
+
+ /**
+ * Set whether the comment is persistent
+ *
+ * @param bool $persistent
+ *
+ * @return $this
+ */
+ public function setPersistent($persistent = true)
{
- return sprintf('%s;%s', $this->author->getUsername(), $this->comment);
+ $this->persistent = $persistent;
+ return $this;
+ }
+
+ /**
+ * Is the comment persistent?
+ *
+ * @return bool
+ */
+ public function getPersistent()
+ {
+ return $this->persistent;
}
}
From 5757a6f34b3e295f567add51346c0a822df4c8f4 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Wed, 10 Sep 2014 09:23:48 +0200
Subject: [PATCH 203/277] monitoring: Fix typo in the `Downtime' data view
---
modules/monitoring/library/Monitoring/DataView/Downtime.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php
index 214e1afb5..217fb2cac 100644
--- a/modules/monitoring/library/Monitoring/DataView/Downtime.php
+++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php
@@ -31,7 +31,7 @@ class Downtime extends DataView
'downtime_host',
'downtime_service',
'downtime_host_state',
- 'downtiem_service_state'
+ 'downtime_service_state'
);
}
From 1247fdcad488f27cb64d024894fccbec54ab1d9e Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:10:20 +0200
Subject: [PATCH 204/277] monitoring/commands: Move toggle instance feature
commands into a single command
refs #6593
---
.../Instance/ToggleActiveHostChecks.php | 22 ----
.../Instance/ToggleActiveServiceChecks.php | 22 ----
.../Command/Instance/ToggleEventHandlers.php | 22 ----
.../Command/Instance/ToggleFlapDetection.php | 22 ----
.../Instance/ToggleInstanceFeatureCommand.php | 123 ++++++++++++++++++
.../Command/Instance/ToggleNotifications.php | 54 --------
.../ToggleObsessingOverHostChecks.php | 22 ----
.../ToggleObsessingOverServiceChecks.php | 22 ----
.../Instance/TogglePassiveHostChecks.php | 22 ----
.../Instance/TogglePassiveServiceChecks.php | 22 ----
.../Instance/TogglePerformanceData.php | 22 ----
11 files changed, 123 insertions(+), 252 deletions(-)
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveHostChecks.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveServiceChecks.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleEventHandlers.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleFlapDetection.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleInstanceFeatureCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleNotifications.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverHostChecks.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverServiceChecks.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveHostChecks.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveServiceChecks.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Instance/TogglePerformanceData.php
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveHostChecks.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveHostChecks.php
deleted file mode 100644
index 99ea2992f..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveHostChecks.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'START_EXECUTING_HOST_CHECKS' : 'STOP_EXECUTING_HOST_CHECKS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveServiceChecks.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveServiceChecks.php
deleted file mode 100644
index 3ad2afe25..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleActiveServiceChecks.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'START_EXECUTING_SVC_CHECKS' : 'STOP_EXECUTING_SVC_CHECKS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleEventHandlers.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleEventHandlers.php
deleted file mode 100644
index e2e6cf3a2..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleEventHandlers.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'ENABLE_EVENT_HANDLERS' : 'DISABLE_EVENT_HANDLERS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleFlapDetection.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleFlapDetection.php
deleted file mode 100644
index 2951d448d..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleFlapDetection.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'ENABLE_FLAP_DETECTION' : 'DISABLE_FLAP_DETECTION';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleInstanceFeatureCommand.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleInstanceFeatureCommand.php
new file mode 100644
index 000000000..01b26a009
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Instance/ToggleInstanceFeatureCommand.php
@@ -0,0 +1,123 @@
+feature = (string) $feature;
+ return $this;
+ }
+
+ /**
+ * Get the feature that is to be enabled or disabled
+ *
+ * @return string
+ */
+ public function getFeature()
+ {
+ return $this->feature;
+ }
+
+ /**
+ * Set whether the feature should be enabled or disabled
+ *
+ * @param bool $enabled
+ *
+ * @return $this
+ */
+ public function setEnabled($enabled = true)
+ {
+ $this->enabled = (bool) $enabled;
+ return $this;
+ }
+
+ /**
+ * Get whether the feature should be enabled or disabled
+ *
+ * @return bool
+ */
+ public function getEnabled()
+ {
+ return $this->enabled;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleNotifications.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleNotifications.php
deleted file mode 100644
index 6b1d5e362..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleNotifications.php
+++ /dev/null
@@ -1,54 +0,0 @@
-expireTime = $expireTime !== null ? (int) $expireTime : null;
- return parent::disable();
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation.
- */
- public function getCommandString()
- {
- if ($this->enable === true) {
- return 'ENABLE_NOTIFICATIONS';
- }
- if ($this->expireTime !== null) {
- return sprintf(
- '%s;%u;%u',
- 'DISABLE_NOTIFICATIONS_EXPIRE_TIME',
- time(), // Schedule time. According to the Icinga documentation schedule time has no effect currently
- // and should be set to the current timestamp.
- $this->expireTime
- );
- }
- return 'DISABLE_NOTIFICATIONS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverHostChecks.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverHostChecks.php
deleted file mode 100644
index 0584c5e9c..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverHostChecks.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'START_OBSESSING_OVER_HOST_CHECKS' : 'STOP_OBSESSING_OVER_HOST_CHECKS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverServiceChecks.php b/modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverServiceChecks.php
deleted file mode 100644
index 86653a4ba..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/ToggleObsessingOverServiceChecks.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'START_OBSESSING_OVER_SVC_CHECKS' : 'STOP_OBSESSING_OVER_SVC_CHECKS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveHostChecks.php b/modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveHostChecks.php
deleted file mode 100644
index 7ce45d7f0..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveHostChecks.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'ENABLE_PASSIVE_HOST_CHECKS' : 'DISABLE_PASSIVE_HOST_CHECKS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveServiceChecks.php b/modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveServiceChecks.php
deleted file mode 100644
index 391b372c6..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/TogglePassiveServiceChecks.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'ENABLE_PASSIVE_SVC_CHECKS' : 'DISABLE_PASSIVE_SVC_CHECKS';
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/TogglePerformanceData.php b/modules/monitoring/library/Monitoring/Command/Instance/TogglePerformanceData.php
deleted file mode 100644
index 16091ca11..000000000
--- a/modules/monitoring/library/Monitoring/Command/Instance/TogglePerformanceData.php
+++ /dev/null
@@ -1,22 +0,0 @@
-enable === true ? 'ENABLE_PERFORMANCE_DATA' : 'DISABLE_PERFORMANCE_DATA';
- }
-}
From c40ac6f9dc9f2223fc6bb4eeab140a1165ed52b7 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:11:32 +0200
Subject: [PATCH 205/277] monitoring/commands: Add
`DisableNotificationsExpireCommand'
refs #6593
---
.../DisableNotificationsExpireCommand.php | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Instance/DisableNotificationsExpireCommand.php
diff --git a/modules/monitoring/library/Monitoring/Command/Instance/DisableNotificationsExpireCommand.php b/modules/monitoring/library/Monitoring/Command/Instance/DisableNotificationsExpireCommand.php
new file mode 100644
index 000000000..309cb9e2f
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Instance/DisableNotificationsExpireCommand.php
@@ -0,0 +1,43 @@
+expireTime = (int) $expireTime;
+ return $this;
+ }
+
+ /**
+ * Get the date and time when notifications should be re-enabled after disabling
+ *
+ * @return int|null Unix timestamp
+ */
+ public function getExpireTime()
+ {
+ return $this->expireTime;
+ }
+}
From 22771e6f6f5282d906ee41ada23803596323f070 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:13:57 +0200
Subject: [PATCH 206/277] monitoring/commands: Rename
`DisableNotificationsCommandForm' to `DisableNotificationsExpireCommandForm'
The associated command also has 'Expired' in its name.
refs #6593
---
...DisableNotificationsExpireCommandForm.php} | 35 +++++++------------
1 file changed, 12 insertions(+), 23 deletions(-)
rename modules/monitoring/application/forms/Command/Instance/{DisableNotificationsCommandForm.php => DisableNotificationsExpireCommandForm.php} (66%)
diff --git a/modules/monitoring/application/forms/Command/Instance/DisableNotificationsCommandForm.php b/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
similarity index 66%
rename from modules/monitoring/application/forms/Command/Instance/DisableNotificationsCommandForm.php
rename to modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
index 43263cb84..08b1f1813 100644
--- a/modules/monitoring/application/forms/Command/Instance/DisableNotificationsCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
@@ -6,7 +6,7 @@ namespace Icinga\Module\Monitoring\Form\Command\Instance;
use DateTime;
use DateInterval;
-use Icinga\Module\Monitoring\Command\Instance\ToggleNotifications;
+use Icinga\Module\Monitoring\Command\Instance\DisableNotificationsExpireCommand;
use Icinga\Module\Monitoring\Form\Command\CommandForm;
use Icinga\Web\Form\Element\DateTimePicker;
use Icinga\Web\Notification;
@@ -15,7 +15,7 @@ use Icinga\Web\Request;
/**
* Form for disabling host and service notifications w/ an optional expire date and time on an Icinga instance
*/
-class DisableNotificationsCommandForm extends CommandForm
+class DisableNotificationsExpireCommandForm extends CommandForm
{
/**
* (non-PHPDoc)
@@ -42,43 +42,32 @@ class DisableNotificationsCommandForm extends CommandForm
)
)
);
- $expire = new DateTime();
- $expire->add(new DateInterval('PT1H'));
+ $expireTime = new DateTime();
+ $expireTime->add(new DateInterval('PT1H'));
$this->addElement(
new DateTimePicker(
- 'expire',
+ 'expire_time',
array(
'required' => true,
- 'label' => t('Expire Time'),
- 'description' => mt('monitoring', 'Set the start date and time for the service downtime.'),
- 'value' => $expire
+ 'label' => mt('monitoring', 'Expire Time'),
+ 'description' => mt('monitoring', 'Set the expire time.'),
+ 'value' => $expireTime
)
)
);
return $this;
}
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleNotifications
- */
- public function getCommand()
- {
- return new ToggleNotifications();
- }
-
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
- $toggleNotifications = $this->getCommand();
- $toggleNotifications
- ->disable()
- ->setExpire($this->getElement('expire')->getValue());
- $this->getTransport($request)->send($toggleNotifications);
+ $disableNotifications = new DisableNotificationsExpireCommand();
+ $disableNotifications
+ ->setExpireTime($this->getElement('expire_time')->getValue());
+ $this->getTransport($request)->send($disableNotifications);
Notification::success(mt('monitoring', 'Disabling host and service notifications..'));
return true;
}
From 92571599dfc8cc151fabce4e2266182129c946fe Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:16:13 +0200
Subject: [PATCH 207/277] monitoring/commands: Move toggle instance feature
command forms into a single form
refs #6593
---
.../ToggleActiveHostChecksCommandForm.php | 33 ----
.../ToggleActiveServiceChecksCommandForm.php | 33 ----
.../ToggleEventHandlersCommandForm.php | 33 ----
.../Instance/ToggleFeatureCommandForm.php | 90 ---------
.../ToggleFlapDetectionCommandForm.php | 33 ----
.../ToggleInstanceFeaturesCommandForm.php | 179 ++++++++++++++++++
.../ToggleNotificationsCommandForm.php | 33 ----
...ggleObsessingOverHostChecksCommandForm.php | 33 ----
...eObsessingOverServiceChecksCommandForm.php | 33 ----
.../TogglePassiveHostChecksCommandForm.php | 33 ----
.../TogglePassiveServiceChecksCommandForm.php | 33 ----
.../TogglePerformanceDataCommandForm.php | 33 ----
12 files changed, 179 insertions(+), 420 deletions(-)
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleActiveHostChecksCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleActiveServiceChecksCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleEventHandlersCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleFeatureCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleFlapDetectionCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleNotificationsCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverHostChecksCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverServiceChecksCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/TogglePassiveHostChecksCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/TogglePassiveServiceChecksCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Instance/TogglePerformanceDataCommandForm.php
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleActiveHostChecksCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleActiveHostChecksCommandForm.php
deleted file mode 100644
index 0ee0fe2ee..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleActiveHostChecksCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Active Host Checks'));
- $this->setFeature('active_host_checks_enabled', mt('monitoring', 'Active Host Checks Being Executed'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleActiveHostChecks
- */
- public function getCommand()
- {
- return new ToggleActiveHostChecks();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleActiveServiceChecksCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleActiveServiceChecksCommandForm.php
deleted file mode 100644
index 8d412392a..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleActiveServiceChecksCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Active Service Checks'));
- $this->setFeature('active_service_checks_enabled', mt('monitoring', 'Active Service Checks Being Executed'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleActiveServiceChecks
- */
- public function getCommand()
- {
- return new ToggleActiveServiceChecks();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleEventHandlersCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleEventHandlersCommandForm.php
deleted file mode 100644
index a90fb529a..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleEventHandlersCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Event Handlers'));
- $this->setFeature('event_handlers_enabled', mt('monitoring', 'Event Handlers Enabled'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleEventHandlers
- */
- public function getCommand()
- {
- return new ToggleEventHandlers();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleFeatureCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleFeatureCommandForm.php
deleted file mode 100644
index ed48069e8..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleFeatureCommandForm.php
+++ /dev/null
@@ -1,90 +0,0 @@
-feature = $feature;
- $this->label = $label;
- return $this;
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Web\Form::createElements() For the method documentation.
- */
- public function createElements(array $formData = array())
- {
- if (isset($formData[$this->feature])) {
- $enabled = (bool) $formData[$this->feature];
- } else {
- $enabled = (bool) $this->backend
- ->select()
- ->from(
- 'programstatus',
- array($this->feature)
- )
- ->getQuery()
- ->fetchRow();
- }
- $this->addElement(
- 'checkbox',
- $this->feature,
- array(
- 'label' => $this->label,
- 'autosubmit' => $this->inline,
- 'value' => $enabled
- )
- );
- return $this;
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Web\Form::onSuccess() For the method documentation.
- */
- public function onSuccess(Request $request)
- {
- $toggleFeature = $this->getCommand();
- (bool) $request->getParam($this->feature) === true ? $toggleFeature->enable() : $toggleFeature->disable();
- $this->getTransport($request)->send($toggleFeature);
- Notification::success(mt('monitoring', 'Command sent'));
- return true;
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleFlapDetectionCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleFlapDetectionCommandForm.php
deleted file mode 100644
index a436ec2ff..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleFlapDetectionCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Flap Detection'));
- $this->setFeature('flap_detection_enabled', mt('monitoring', 'Flap Detection Enabled'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleFlapDetection
- */
- public function getCommand()
- {
- return new ToggleFlapDetection();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php
new file mode 100644
index 000000000..db584bc1a
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php
@@ -0,0 +1,179 @@
+setAttrib('class', 'inline');
+ }
+
+ /**
+ * Set the instance status
+ *
+ * @param object $status
+ *
+ * @return $this
+ */
+ public function setStatus($status)
+ {
+ $this->status = (object) $status;
+ return $this;
+ }
+
+ /**
+ * Get the instance status
+ *
+ * @return object
+ */
+ public function getStatus()
+ {
+ return $this->status;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $this->addElements(array(
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS,
+ array(
+ 'label' => mt('monitoring', 'Active Host Checks Being Executed'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS,
+ array(
+ 'label' => mt('monitoring', 'Active Service Checks Being Executed'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS,
+ array(
+ 'label' => mt('monitoring', 'Event Handlers Enabled'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION,
+ array(
+ 'label' => mt('monitoring', 'Flap Detection Enabled'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
+ array(
+ 'label' => mt('monitoring', 'Notifications Enabled'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING,
+ array(
+ 'label' => mt('monitoring', 'Obsessing Over Hosts'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING,
+ array(
+ 'label' => mt('monitoring', 'Obsessing Over Services'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS,
+ array(
+ 'label' => mt('monitoring', 'Passive Host Checks Being Accepted'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS,
+ array(
+ 'label' => mt('monitoring', 'Passive Service Checks Being Accepted'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA,
+ array(
+ 'label' => mt('monitoring', 'Performance Data Being Processed'),
+ 'autosubmit' => true
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * Load feature status
+ *
+ * @param object $instanceStatus
+ *
+ * @return $this
+ */
+ public function load($instanceStatus)
+ {
+ $this->create();
+ foreach ($this->getValues() as $feature => $enabled) {
+ $this->getElement($feature)->setChecked($instanceStatus->{$feature});
+ }
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->getValues() as $feature => $enabled) {
+ $toggleFeature = new ToggleInstanceFeatureCommand();
+ $toggleFeature
+ ->setFeature($feature)
+ ->setEnabled($enabled);
+ $this->getTransport($request)->send($toggleFeature);
+ }
+ Notification::success(mt('monitoring', 'Toggling feature..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleNotificationsCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleNotificationsCommandForm.php
deleted file mode 100644
index 661d57dc5..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleNotificationsCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Notifications'));
- $this->setFeature('notifications_enabled', mt('monitoring', 'Notifications Enabled'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleNotifications
- */
- public function getCommand()
- {
- return new ToggleNotifications();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverHostChecksCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverHostChecksCommandForm.php
deleted file mode 100644
index 3e230e639..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverHostChecksCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Obsessing Over Host Checks'));
- $this->setFeature('obsess_over_hosts', mt('monitoring', 'Obsessing Over Hosts'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleObsessingOverHostChecks
- */
- public function getCommand()
- {
- return new ToggleObsessingOverHostChecks();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverServiceChecksCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverServiceChecksCommandForm.php
deleted file mode 100644
index 012ccb73e..000000000
--- a/modules/monitoring/application/forms/Command/Instance/ToggleObsessingOverServiceChecksCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Obsessing Over Service Checks'));
- $this->setFeature('obsess_over_services', mt('monitoring', 'Obsessing Over Services'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ToggleObsessingOverServiceChecks
- */
- public function getCommand()
- {
- return new ToggleObsessingOverServiceChecks();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/TogglePassiveHostChecksCommandForm.php b/modules/monitoring/application/forms/Command/Instance/TogglePassiveHostChecksCommandForm.php
deleted file mode 100644
index 0c9b657b9..000000000
--- a/modules/monitoring/application/forms/Command/Instance/TogglePassiveHostChecksCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Passive Host Checks'));
- $this->setFeature('passive_host_checks_enabled', mt('monitoring', 'Passive Host Checks Being Accepted'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return TogglePassiveHostChecks
- */
- public function getCommand()
- {
- return new TogglePassiveHostChecks();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/TogglePassiveServiceChecksCommandForm.php b/modules/monitoring/application/forms/Command/Instance/TogglePassiveServiceChecksCommandForm.php
deleted file mode 100644
index 09db8e625..000000000
--- a/modules/monitoring/application/forms/Command/Instance/TogglePassiveServiceChecksCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Passive Service Checks'));
- $this->setFeature('passive_service_checks_enabled', mt('monitoring', 'Passive Service Checks Being Accepted'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return TogglePassiveServiceChecks
- */
- public function getCommand()
- {
- return new TogglePassiveServiceChecks();
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Instance/TogglePerformanceDataCommandForm.php b/modules/monitoring/application/forms/Command/Instance/TogglePerformanceDataCommandForm.php
deleted file mode 100644
index b151cbb1b..000000000
--- a/modules/monitoring/application/forms/Command/Instance/TogglePerformanceDataCommandForm.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setSubmitLabel(mt('monitoring', 'Toggle Performance Data'));
- $this->setFeature('process_performance_data', mt('monitoring', 'Performance Data Being Processed'));
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return TogglePerformanceData
- */
- public function getCommand()
- {
- return new TogglePerformanceData();
- }
-}
From 3845301dfb70fb738e0a574b11caa4ae7c519fdb Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:18:07 +0200
Subject: [PATCH 208/277] monitoring/commands: Add object command classes
refs #6593
---
.../Object/AcknowledgeProblemCommand.php | 145 +++++++++++++
.../Command/Object/AddCommentCommand.php | 50 +++++
.../Command/Object/DeleteCommentCommand.php | 50 +++++
.../Command/Object/DeleteDowntimeCommand.php | 50 +++++
.../Command/Object/ObjectCommand.php | 62 ++++++
.../Object/ProcessCheckResultCommand.php | 177 ++++++++++++++++
.../Command/Object/PropagateHostDowntime.php | 49 +++++
.../Object/RemoveAcknowledgementCommand.php | 20 ++
.../Object/ScheduleHostCheckCommand.php | 49 +++++
.../Object/ScheduleHostDowntimeCommand.php | 49 +++++
.../Object/ScheduleServiceCheckCommand.php | 102 ++++++++++
.../Object/ScheduleServiceDowntimeCommand.php | 191 ++++++++++++++++++
.../Object/ToggleObjectFeatureCommand.php | 114 +++++++++++
.../Command/Object/WithCommentCommand.php | 71 +++++++
14 files changed, 1179 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/AcknowledgeProblemCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/AddCommentCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ObjectCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/PropagateHostDowntime.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ScheduleHostCheckCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ScheduleHostDowntimeCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceDowntimeCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/ToggleObjectFeatureCommand.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php
diff --git a/modules/monitoring/library/Monitoring/Command/Object/AcknowledgeProblemCommand.php b/modules/monitoring/library/Monitoring/Command/Object/AcknowledgeProblemCommand.php
new file mode 100644
index 000000000..4dff07c4a
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/AcknowledgeProblemCommand.php
@@ -0,0 +1,145 @@
+sticky = (bool) $sticky;
+ return $this;
+ }
+
+ /**
+ * Is the acknowledgement sticky?
+ *
+ * @return bool
+ */
+ public function getSticky()
+ {
+ return $this->sticky;
+ }
+
+ /**
+ * Set whether to send a notification about the acknowledgement
+ *
+ * @param bool $notify
+ *
+ * @return $this
+ */
+ public function setNotify($notify = true)
+ {
+ $this->notify = (bool) $notify;
+ return $this;
+ }
+
+ /**
+ * Get whether to send a notification about the acknowledgement
+ *
+ * @return bool
+ */
+ public function getNotify()
+ {
+ return $this->notify;
+ }
+
+ /**
+ * Set whether the comment associated with the acknowledgement is persistent
+ *
+ * @param bool $persistent
+ *
+ * @return $this
+ */
+ public function setPersistent($persistent = true)
+ {
+ $this->persistent = (bool) $persistent;
+ return $this;
+ }
+
+ /**
+ * Is the comment associated with the acknowledgement is persistent?
+ *
+ * @return bool
+ */
+ public function getPersistent()
+ {
+ return $this->persistent;
+ }
+
+ /**
+ * Set the time when the acknowledgement should expire
+ *
+ * @param int $expireTime
+ *
+ * @return $this
+ */
+ public function setExpireTime($expireTime)
+ {
+ $this->expireTime = (int) $expireTime;
+ return $this;
+ }
+
+ /**
+ * Get the time when the acknowledgement should expire
+ *
+ * @return int|null
+ */
+ public function getExpireTime()
+ {
+ return $this->expireTime;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/AddCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Object/AddCommentCommand.php
new file mode 100644
index 000000000..a7540f4f8
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/AddCommentCommand.php
@@ -0,0 +1,50 @@
+persistent = $persistent;
+ return $this;
+ }
+
+ /**
+ * Is the comment persistent?
+ *
+ * @return bool
+ */
+ public function getPersistent()
+ {
+ return $this->persistent;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php
new file mode 100644
index 000000000..850566ff9
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php
@@ -0,0 +1,50 @@
+commentId = (int) $commentId;
+ return $this;
+ }
+
+ /**
+ * Get the ID of the comment that is to be deleted
+ *
+ * @return int
+ */
+ public function getCommentId()
+ {
+ return $this->commentId;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php
new file mode 100644
index 000000000..67e271dbb
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php
@@ -0,0 +1,50 @@
+downtimeId = (int) $downtimeId;
+ return $this;
+ }
+
+ /**
+ * Get the ID of the downtime that is to be deleted
+ *
+ * @return int
+ */
+ public function getDowntimeId()
+ {
+ return $this->downtimeId;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ObjectCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ObjectCommand.php
new file mode 100644
index 000000000..1c8910066
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/ObjectCommand.php
@@ -0,0 +1,62 @@
+assertOneOf($this->allowedObjects);
+ $this->object = $object;
+ return $this;
+ }
+
+ /**
+ * Get the involved object
+ *
+ * @return MonitoredObject
+ */
+ public function getObject()
+ {
+ return $this->object;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php
new file mode 100644
index 000000000..9866aeb52
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/ProcessCheckResultCommand.php
@@ -0,0 +1,177 @@
+ array(
+ self::HOST_UP, self::HOST_DOWN, self::HOST_UNREACHABLE
+ ),
+ self::TYPE_SERVICE => array(
+ self::SERVICE_OK, self::SERVICE_WARNING, self::SERVICE_CRITICAL, self::SERVICE_UNKNOWN
+ )
+ );
+
+ /**
+ * Status code of the host or service check result
+ *
+ * @var int
+ */
+ protected $status;
+
+ /**
+ * Text output of the host or service check result
+ *
+ * @var string
+ */
+ protected $output;
+
+ /**
+ * Optional performance data of the host or service check result
+ *
+ * @var string
+ */
+ protected $performanceData;
+
+
+ /**
+ * Set the status code of the host or service check result
+ *
+ * @param int $status
+ *
+ * @return $this
+ *
+ * @throws LogicException If the object is null
+ * @throws InvalidArgumentException If status is not one of the valid status codes for the object's type
+ */
+ public function setStatus($status)
+ {
+ if ($this->object === null) {
+ throw new LogicException('You\'re required to call setObject() before calling setStatus()');
+ }
+ $status = (int) $status;
+ if (! in_array($status, self::$statusCodes[$this->object->getType()])) {
+ throw new InvalidArgumentException(sprintf(
+ 'The status code %u you provided is not one of the valid status codes for type %s',
+ $status,
+ $this->object->getType()
+ ));
+ }
+ $this->status = $status;
+ return $this;
+ }
+
+ /**
+ * Get the status code of the host or service check result
+ *
+ * @return int
+ */
+ public function getStatus()
+ {
+ return $this->status;
+ }
+
+ /**
+ * Set the text output of the host or service check result
+ *
+ * @param string $output
+ *
+ * @return $this
+ */
+ public function setOutput($output)
+ {
+ $this->output = (string) $output;
+ return $this;
+ }
+
+ /**
+ * Get the text output of the host or service check result
+ *
+ * @return string
+ */
+ public function getOutput()
+ {
+ return $this->output;
+ }
+
+ /**
+ * Set the performance data of the host or service check result
+ *
+ * @param string $performanceData
+ *
+ * @return $this
+ */
+ public function setPerformanceData($performanceData)
+ {
+ $this->performanceData = (string) $performanceData;
+ return $this;
+ }
+
+ /**
+ * Get the performance data of the host or service check result
+ *
+ * @return string
+ */
+ public function getPerformanceData()
+ {
+ return $this->performanceData;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/PropagateHostDowntime.php b/modules/monitoring/library/Monitoring/Command/Object/PropagateHostDowntime.php
new file mode 100644
index 000000000..89591c8fc
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/PropagateHostDowntime.php
@@ -0,0 +1,49 @@
+triggered = (bool) $triggered;
+ return $this;
+ }
+
+ /**
+ * Get whether the downtime for child hosts are all set to be triggered by this' host downtime
+ *
+ * @return bool
+ */
+ public function getTriggered()
+ {
+ return $this->triggered;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php b/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php
new file mode 100644
index 000000000..6f9f99432
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php
@@ -0,0 +1,20 @@
+ofAllServices = (bool) $ofAllServices;
+ return $this;
+ }
+
+ /**
+ * Get whether to schedule a check of all services associated with a particular host
+ *
+ * @return bool
+ */
+ public function getOfAllServices()
+ {
+ return $this->ofAllServices;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ScheduleHostDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ScheduleHostDowntimeCommand.php
new file mode 100644
index 000000000..ea7e31dc6
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/ScheduleHostDowntimeCommand.php
@@ -0,0 +1,49 @@
+forAllServices = (bool) $forAllServices;
+ return $this;
+ }
+
+ /**
+ * Get whether to schedule a downtime for all services associated with a particular host
+ *
+ * @return bool
+ */
+ public function getForAllServices()
+ {
+ return $this->forAllServices;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php
new file mode 100644
index 000000000..9bf719a25
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php
@@ -0,0 +1,102 @@
+checkTime = (int) $checkTime;
+ return $this;
+ }
+
+ /**
+ * Get the time when the next check of a host or service is to be scheduled
+ *
+ * @return int Unix timestamp
+ */
+ public function getCheckTime()
+ {
+ return $this->checkTime;
+ }
+
+ /**
+ * Set whether the check is forced
+ *
+ * @param bool $forced
+ *
+ * @return $this
+ */
+ public function setForced($forced = true)
+ {
+ $this->forced = (bool) $forced;
+ return $this;
+ }
+
+ /**
+ * Is the check forced?
+ *
+ * @return bool
+ */
+ public function getForced()
+ {
+ return $this->forced;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Module\Monitoring\Command\Object\IcingaCommand::getName() For the method documentation.
+ */
+ public function getName()
+ {
+ return 'ScheduleCheck';
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceDowntimeCommand.php
new file mode 100644
index 000000000..24be3512b
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceDowntimeCommand.php
@@ -0,0 +1,191 @@
+start = (int) $start;
+ return $this;
+ }
+
+ /**
+ * Get the time when the downtime should start
+ *
+ * @return int Unix timestamp
+ */
+ public function getStart()
+ {
+ return $this->start;
+ }
+
+ /**
+ * Set the time when the downtime should end
+ *
+ * @param int $end Unix timestamp
+ *
+ * @return $this
+ */
+ public function setEnd($end)
+ {
+ $this->end = (int) $end;
+ return $this;
+ }
+
+ /**
+ * Get the time when the downtime should end
+ *
+ * @return int Unix timestamp
+ */
+ public function getEnd()
+ {
+ return $this->end;
+ }
+
+ /**
+ * Set whether it's a fixed or flexible downtime
+ *
+ * @param boolean $fixed
+ *
+ * @return $this
+ */
+ public function setFixed($fixed = true)
+ {
+ $this->fixed = (bool) $fixed;
+ return $this;
+ }
+
+ /**
+ * Is the downtime fixed?
+ *
+ * @return boolean
+ */
+ public function getFixed()
+ {
+ return $this->fixed;
+ }
+
+ /**
+ * Set the ID of the downtime which triggers this downtime
+ *
+ * @param int $triggerId
+ *
+ * @return $this
+ */
+ public function setTriggerId($triggerId)
+ {
+ $this->triggerId = (int) $triggerId;
+ return $this;
+ }
+
+ /**
+ * Get the ID of the downtime which triggers this downtime
+ *
+ * @return int|null
+ */
+ public function getTriggerId()
+ {
+ return $this->triggerId;
+ }
+
+ /**
+ * Set the duration in seconds the downtime must last if it's a flexible downtime
+ *
+ * @param int $duration
+ *
+ * @return $this
+ */
+ public function setDuration($duration)
+ {
+ $this->duration = (int) $duration;
+ return $this;
+ }
+
+ /**
+ * Get the duration in seconds the downtime must last if it's a flexible downtime
+ *
+ * @return int|null
+ */
+ public function getDuration()
+ {
+ return $this->duration;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Module\Monitoring\Command\Object\IcingaCommand::getName() For the method documentation.
+ */
+ public function getName()
+ {
+ return 'ScheduleDowntime';
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ToggleObjectFeatureCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ToggleObjectFeatureCommand.php
new file mode 100644
index 000000000..c6cbeaa50
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/ToggleObjectFeatureCommand.php
@@ -0,0 +1,114 @@
+feature = (string) $feature;
+ return $this;
+ }
+
+ /**
+ * Get the feature that is to be enabled or disabled
+ *
+ * @return string
+ */
+ public function getFeature()
+ {
+ return $this->feature;
+ }
+
+ /**
+ * Set whether the feature should be enabled or disabled
+ *
+ * @param bool $enabled
+ *
+ * @return $this
+ */
+ public function setEnabled($enabled = true)
+ {
+ $this->enabled = (bool) $enabled;
+ return $this;
+ }
+
+ /**
+ * Get whether the feature should be enabled or disabled
+ *
+ * @return bool
+ */
+ public function getEnabled()
+ {
+ return $this->enabled;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php
new file mode 100644
index 000000000..695c53cc6
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php
@@ -0,0 +1,71 @@
+author = (string) $author;
+ return $this;
+ }
+
+ /**
+ * Get the author
+ *
+ * @return string
+ */
+ public function getAuthor()
+ {
+ return $this->author;
+ }
+
+ /**
+ * Set the comment
+ *
+ * @param string $comment
+ *
+ * @return $this
+ */
+ public function setComment($comment)
+ {
+ $this->comment = (string) $comment;
+ return $this;
+ }
+
+ /**
+ * Get the comment
+ *
+ * @return string
+ */
+ public function getComment()
+ {
+ return $this->comment;
+ }
+}
From 746e75e5ed26c25f5ccb00240f6edc472c1c9a74 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:19:00 +0200
Subject: [PATCH 209/277] monitroing/commands: Remove method
`CommandForm::inline()'
Inline forms will set themselves as inline.
refs #6593
---
.../application/forms/Command/CommandForm.php | 28 -------------------
1 file changed, 28 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/CommandForm.php b/modules/monitoring/application/forms/Command/CommandForm.php
index ee74b1fb0..0a7cd19f9 100644
--- a/modules/monitoring/application/forms/Command/CommandForm.php
+++ b/modules/monitoring/application/forms/Command/CommandForm.php
@@ -21,13 +21,6 @@ abstract class CommandForm extends Form
*/
protected $backend;
- /**
- * Whether the form's inline
- *
- * @var bool
- */
- protected $inline = false;
-
/**
* Set the monitoring backend
*
@@ -51,27 +44,6 @@ abstract class CommandForm extends Form
return $this->backend;
}
- /**
- * Set the form as inline
- *
- * @return $this
- */
- public function inline()
- {
- $this->inline = true;
- $this->submitLabel = null; // Inline forms must not have a submit button
- $class = $this->getAttrib('class');
- if (is_array($class)) {
- $class[] = 'inline';
- } elseif ($class === null) {
- $class = 'inline';
- } else {
- $class .= 'inline';
- }
- $this->setAttrib('class', $class);
- return $this;
- }
-
/**
* Get the transport used to send commands
*
From b4faa0142bbdbf8090e8dd6b877086e4106cf9f9 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:20:20 +0200
Subject: [PATCH 210/277] monitoring/commands: Add object command forms
refs #6593
---
.../Object/AcknowledgeProblemCommandForm.php | 166 ++++++++++++++
.../Command/Object/AddCommentCommandForm.php | 91 ++++++++
.../Command/Object/CheckNowCommandForm.php | 51 +++++
.../Object/DeleteCommentCommandForm.php | 61 ++++++
.../Object/DeleteDowntimeCommandForm.php | 61 ++++++
.../Command/Object/ObjectsCommandForm.php | 48 ++++
.../RemoveAcknowledgementCommandForm.php | 41 ++++
.../ScheduleServiceCheckCommandForm.php | 91 ++++++++
.../ScheduleServiceDowntimeCommandForm.php | 206 ++++++++++++++++++
.../ToggleObjectFeaturesCommandForm.php | 123 +++++++++++
10 files changed, 939 insertions(+)
create mode 100644 modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/ObjectsCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php
create mode 100644 modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php
diff --git a/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php b/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php
new file mode 100644
index 000000000..8da595a0d
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php
@@ -0,0 +1,166 @@
+setSubmitLabel(mt('monitoring', 'Acknowledge Problem'));
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $this->addElements(array(
+ array(
+ 'note',
+ 'command-info',
+ array(
+ 'value' => mt(
+ 'monitoring',
+ 'This command is used to acknowledge host or service problems. When a problem is acknowledged,'
+ . ' future notifications about problems are temporarily disabled until the host or service'
+ . ' recovers.'
+ )
+ )
+ ),
+ array(
+ 'textarea',
+ 'comment',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Comment'),
+ 'description' => mt(
+ 'monitoring',
+ 'If you work with other administrators, you may find it useful to share information about the'
+ . ' the host or service that is having problems. Make sure you enter a brief description of'
+ . ' what you are doing.'
+ )
+ )
+ ),
+ array(
+ 'checkbox',
+ 'persistent',
+ array(
+ 'label' => mt('monitoring', 'Persistent Comment'),
+ 'description' => mt(
+ 'monitoring',
+ 'If you would like the comment to remain even when the acknowledgement is removed, check this'
+ . ' option.'
+ )
+ )
+ ),
+ array(
+ 'checkbox',
+ 'expire',
+ array(
+ 'label' => mt('monitoring', 'Use Expire Time'),
+ 'description' => mt('monitoring', 'If the acknowledgement should expire, check this option.'),
+ 'autosubmit' => true
+ )
+ )
+ ));
+ if (isset($formData['expire']) && (bool) $formData['expire'] === true) {
+ $expireTime = new DateTime();
+ $expireTime->add(new DateInterval('PT1H'));
+ $this->addElement(
+ new DateTimePicker(
+ 'expire_time',
+ array(
+ 'label' => mt('monitoring', 'Expire Time'),
+ 'value' => $expireTime,
+ 'description' => mt(
+ 'monitoring',
+ 'Enter the expire date and time for this acknowledgement here. Icinga will delete the'
+ . ' acknowledgement after this time expired.'
+ )
+ )
+ )
+ );
+ $this->addDisplayGroup(
+ array('expire', 'expire_time'),
+ 'expire-expire_time',
+ array(
+ 'decorators' => array(
+ 'FormElements',
+ array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
+ )
+ )
+ );
+ }
+ $this->addElements(array(
+ array(
+ 'checkbox',
+ 'sticky',
+ array(
+ 'label' => mt('monitoring', 'Sticky Acknowledgement'),
+ 'value' => true,
+ 'description' => mt(
+ 'monitoring',
+ 'If you want the acknowledgement to disable notifications until the host or service recovers,'
+ . 'check this option.'
+ )
+ )
+ ),
+ array(
+ 'checkbox',
+ 'notify',
+ array(
+ 'label' => mt('monitoring', 'Send Notification'),
+ 'value' => true,
+ 'description' => mt(
+ 'monitoring',
+ 'If you do not want an acknowledgement notification to be sent out to the appropriate contacts,'
+ . 'uncheck this option.'
+ )
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ $ack = new AcknowledgeProblemCommand();
+ $ack
+ ->setObject($object)
+ ->setComment($this->getElement('comment')->getValue())
+ ->setAuthor($request->getUser()->getUsername())
+ ->setPersistent($this->getElement('persistent')->isChecked())
+ ->setSticky($this->getElement('sticky')->isChecked())
+ ->setNotify($this->getElement('notify')->isChecked());
+ if ($this->getElement('expire')->isChecked()) {
+ $ack->setExpireTime($this->getElement('expire_time')->getValue()->getTimestamp());
+ }
+ $this->getTransport($request)->send($ack);
+ }
+ Notification::success(mt('monitoring', 'Acknowledging problem..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php b/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php
new file mode 100644
index 000000000..777d96868
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php
@@ -0,0 +1,91 @@
+setSubmitLabel(mt('monitoring', 'Add Comment'));
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $this->addElements(array(
+ array(
+ 'note',
+ 'command-info',
+ array(
+ 'value' => mt(
+ 'monitoring',
+ 'This command is used to add host or service comments.'
+ )
+ )
+ ),
+ array(
+ 'textarea',
+ 'comment',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Comment'),
+ 'description' => mt(
+ 'monitoring',
+ 'If you work with other administrators, you may find it useful to share information about the'
+ . ' the host or service that is having problems. Make sure you enter a brief description of'
+ . ' what you are doing.'
+ )
+ )
+ ),
+ array(
+ 'checkbox',
+ 'persistent',
+ array(
+ 'label' => mt('monitoring', 'Persistent'),
+ 'value' => true,
+ 'description' => mt(
+ 'monitoring',
+ 'If you uncheck this option, the comment will automatically be deleted the next time Icinga is'
+ . ' restarted.'
+ )
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ $comment = new AddCommentCommand();
+ $comment->setObject($object);
+ $comment->setComment($this->getElement('comment')->getValue());
+ $comment->setAuthor($request->getUser()->getUsername());
+ $comment->setPersistent((bool) $this->getElement('persistent')->getValue());
+ $this->getTransport($request)->send($comment);
+ }
+ Notification::success(mt('monitoring', 'Adding comment..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php b/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
new file mode 100644
index 000000000..ecf933102
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
@@ -0,0 +1,51 @@
+setSubmitLabel(mt('monitoring', 'Check Now'));
+ $this->setAttrib('class', 'inline link-like');
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ if ($object->getType() === $object::TYPE_HOST) {
+ $check = new ScheduleHostCheckCommand();
+ } else {
+ $check = new ScheduleServiceCheckCommand();
+ }
+ $check
+ ->setObject($object)
+ ->setForced()
+ ->setCheckTime(time());
+ $this->getTransport($request)->send($check);
+ }
+ Notification::success(mt('monitoring', 'Scheduling check..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php
new file mode 100644
index 000000000..c1a24ef50
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php
@@ -0,0 +1,61 @@
+setSubmitLabel(mt('monitoring', 'X'));
+ $this->setAttrib('class', 'inline link-like');
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $this->addElements(array(
+ array(
+ 'hidden',
+ 'comment_id',
+ array(
+ 'required' => true
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ $delComment = new DeleteCommentCommand();
+ $delComment
+ ->setObject($object)
+ ->setCommentId($this->getElement('comment_id')->getValue());
+ $this->getTransport($request)->send($delComment);
+ }
+ Notification::success(mt('monitoring', 'Deleting comment..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php
new file mode 100644
index 000000000..4558b71da
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php
@@ -0,0 +1,61 @@
+setSubmitLabel(mt('monitoring', 'X'));
+ $this->setAttrib('class', 'inline link-like');
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $this->addElements(array(
+ array(
+ 'hidden',
+ 'downtime_id',
+ array(
+ 'required' => true
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ $delDowntime = new DeleteDowntimeCommand();
+ $delDowntime
+ ->setObject($object)
+ ->setDowntimeId($this->getElement('downtime_id')->getValue());
+ $this->getTransport($request)->send($delDowntime);
+ }
+ Notification::success(mt('monitoring', 'Deleting downtime..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/ObjectsCommandForm.php b/modules/monitoring/application/forms/Command/Object/ObjectsCommandForm.php
new file mode 100644
index 000000000..bf603a7b5
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/ObjectsCommandForm.php
@@ -0,0 +1,48 @@
+objects = array($objects);
+ } else {
+ $this->objects = $objects;
+ }
+ return $this;
+ }
+
+ /**
+ * Get the involved Icinga objects
+ *
+ * @return array|\ArrayAccess|\Traversable
+ */
+ public function getObjects()
+ {
+ return $this->objects;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php b/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php
new file mode 100644
index 000000000..c76cca19c
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php
@@ -0,0 +1,41 @@
+setSubmitLabel(mt('monitoring', 'Remove Problem Acknowledgement'));
+ $this->setAttrib('class', 'inline link-like');
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ $removeAck = new RemoveAcknowledgementCommand();
+ $removeAck->setObject($object);
+ $this->getTransport($request)->send($removeAck);
+ }
+ Notification::success(mt('monitoring', 'Removing problem acknowledgement..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php b/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php
new file mode 100644
index 000000000..a93fcf4ae
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php
@@ -0,0 +1,91 @@
+setSubmitLabel(mt('monitoring', 'Schedule Check'));
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $checkTime = new DateTime();
+ $checkTime->add(new DateInterval('PT1H'));
+ $this->addElements(array(
+ array(
+ 'note',
+ 'command-info',
+ array(
+ 'value' => mt(
+ 'monitoring',
+ 'This command is used to schedule the next check of hosts or services. Icinga will re-queue the'
+ . ' hosts or services to be checked at the time you specify.'
+ )
+ )
+ ),
+ new DateTimePicker(
+ 'check_time',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Check Time'),
+ 'description' => mt('monitoring', 'Set the date and time when the check should be scheduled.'),
+ 'value' => $checkTime
+ )
+ ),
+ array(
+ 'checkbox',
+ 'force_check',
+ array(
+ 'label' => mt('monitoring', 'Force Check'),
+ 'description' => mt(
+ 'monitoring',
+ 'If you select this option, Icinga will force a check regardless of both what time the'
+ . 'scheduled check occurs and whether or not checks are enabled.'
+ )
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $check = new ScheduleServiceCheckCommand();
+ $check
+ ->setObject($object)
+ ->setForced((bool) $this->getElement('force_check')->getValue())
+ ->setCheckTime($this->getElement('check_time')->getValue());
+ $this->getTransport($request)->send($check);
+ }
+ Notification::success(mt('monitoring', 'Scheduling service check..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php
new file mode 100644
index 000000000..76d36d214
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php
@@ -0,0 +1,206 @@
+setSubmitLabel(mt('monitoring', 'Schedule Downtime'));
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $start = new DateTime;
+ $end = clone $start;
+ $end->add(new DateInterval('PT1H'));
+ $this->addElements(array(
+ array(
+ 'note',
+ 'command-info',
+ array(
+ 'value' => mt(
+ 'monitoring',
+ 'This command is used to schedule host and service downtimes. During the specified downtime,'
+ . ' Icinga will not send notifications out about the hosts and services. When the scheduled'
+ . ' downtime expires, Icinga will send out notifications for the hosts and services as it'
+ . ' normally would. Scheduled downtimes are preserved across program shutdowns and'
+ . ' restarts.'
+ )
+ )
+ ),
+ array(
+ 'textarea',
+ 'comment',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Comment'),
+ 'description' => mt(
+ 'monitoring',
+ 'If you work with other administrators, you may find it useful to share information about the'
+ . ' the host or service that is having problems. Make sure you enter a brief description of'
+ . ' what you are doing.'
+ )
+ )
+ ),
+ new DateTimePicker(
+ 'start',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Start Time'),
+ 'description' => mt('monitoring', 'Set the start date and time for the downtime.'),
+ 'value' => $start
+ )
+ ),
+ new DateTimePicker(
+ 'end',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'End Time'),
+ 'description' => mt('monitoring', 'Set the end date and time for the downtime.'),
+ 'value' => $end
+ )
+ ),
+ array(
+ 'select',
+ 'type',
+ array(
+ 'required' => true,
+ 'autosubmit' => true,
+ 'label' => mt('monitoring', 'Type'),
+ 'description' => mt(
+ 'monitoring',
+ 'If you select the fixed option, the downtime will be in effect between the start and end'
+ . ' times you specify whereas a flexible downtime starts when the host or service enters a'
+ . ' problem state sometime between the start and end times you specified and lasts as long'
+ . ' as the duration time you enter. The duration fields do not apply for fixed downtimes.'
+ ),
+ 'multiOptions' => array(
+ self::FIXED => mt('monitoring', 'Fixed'),
+ self::FLEXIBLE => mt('monitoring', 'Flexible')
+ ),
+ 'validators' => array(
+ array(
+ 'InArray',
+ true,
+ array(array(self::FIXED, self::FLEXIBLE))
+ )
+ )
+ )
+ )
+ ));
+ $this->addDisplayGroup(
+ array('start', 'end'),
+ 'start-end',
+ array(
+ 'decorators' => array(
+ 'FormElements',
+ array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
+ )
+ )
+ );
+ if (isset($formData['type']) && $formData['type'] === self::FLEXIBLE) {
+ $this->addElements(array(
+ new Number(
+ 'hours',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Hours'),
+ 'value' => 2,
+ 'min' => -1
+ )
+ ),
+ new Number(
+ 'minutes',
+ array(
+ 'required' => true,
+ 'label' => mt('monitoring', 'Minutes'),
+ 'value' => 0,
+ 'min' => -1
+ )
+ )
+ ));
+ $this->addDisplayGroup(
+ array('hours', 'minutes'),
+ 'duration',
+ array(
+ 'legend' => mt('monitoring', 'Flexible Duration'),
+ 'description' => mt(
+ 'monitoring',
+ 'Enter here the duration of the downtime. The downtime will be automatically deleted after this'
+ . ' time expired.'
+ ),
+ 'decorators' => array(
+ 'FormElements',
+ array('HtmlTag', array('tag' => 'div', 'class' => 'control-group')),
+ array(
+ 'Description',
+ array('tag' => 'span', 'class' => 'description', 'placement' => 'prepend')
+ ),
+ 'Fieldset'
+ )
+ )
+ );
+ }
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $downtime = new ScheduleServiceDowntimeCommand();
+ $downtime
+ ->setObject($object)
+ ->setComment($this->getElement('comment')->getValue())
+ ->setAuthor($request->getUser()->getUsername())
+ ->setStart($this->getElement('start')->getValue()->getTimestamp())
+ ->setEnd($this->getElement('end')->getValue()->getTimestamp());
+ if ($this->getElement('type')->getValue() === self::FLEXIBLE) {
+ $downtime->setFixed(false);
+ $downtime->setDuration(
+ (float) $this->getElement('hours')->getValue() * 3600
+ + (float) $this->getElement('minutes')->getValue() * 60
+ );
+ }
+ $this->getTransport($request)->send($downtime);
+ }
+ Notification::success(mt('monitoring', 'Scheduling service downtime..'));
+ return true;
+ }
+}
diff --git a/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php b/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php
new file mode 100644
index 000000000..146fd7001
--- /dev/null
+++ b/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php
@@ -0,0 +1,123 @@
+setAttrib('class', 'inline');
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::createElements() For the method documentation.
+ */
+ public function createElements(array $formData = array())
+ {
+ $this->addElements(array(
+ array(
+ 'checkbox',
+ ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS,
+ array(
+ 'label' => mt('monitoring', 'Active Checks'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS,
+ array(
+ 'label' => mt('monitoring', 'Passive Checks'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleObjectFeatureCommand::FEATURE_OBSESSING,
+ array(
+ 'label' => mt('monitoring', 'Obsessing'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS,
+ array(
+ 'label' => mt('monitoring', 'Notifications'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER,
+ array(
+ 'label' => mt('monitoring', 'Event Handler'),
+ 'autosubmit' => true
+ )
+ ),
+ array(
+ 'checkbox',
+ ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION,
+ array(
+ 'label' => mt('monitoring', 'Flap Detection'),
+ 'autosubmit' => true
+ )
+ )
+ ));
+ return $this;
+ }
+
+ /**
+ * Load feature status
+ *
+ * @param MonitoredObject $object
+ *
+ * @return $this
+ */
+ public function load(MonitoredObject $object)
+ {
+ $this->create();
+ foreach ($this->getValues() as $feature => $enabled) {
+ $this->getElement($feature)->setChecked($object->{$feature});
+ }
+ return $this;
+ }
+
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::onSuccess() For the method documentation.
+ */
+ public function onSuccess(Request $request)
+ {
+ foreach ($this->objects as $object) {
+ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
+ foreach ($this->getValues() as $feature => $enabled) {
+ if ((bool) $object->{$feature} !== (bool) $enabled) {
+ $toggleFeature = new ToggleObjectFeatureCommand();
+ $toggleFeature
+ ->setFeature($feature)
+ ->setObject($object)
+ ->setEnabled($enabled);
+ $this->getTransport($request)->send($toggleFeature);
+ }
+ }
+ }
+ Notification::success(mt('monitoring', 'Toggling feature..'));
+ return true;
+ }
+}
From 1df8076234efc1312127a2a319c35d46f33ad84b Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Thu, 11 Sep 2014 17:39:13 +0200
Subject: [PATCH 211/277] monitoring/commands: Add command renderer for the
Icinga command file
refs #6593
---
.../IcingaCommandFileCommandRenderer.php | 389 ++++++++++++++++++
.../IcingaCommandRendererInterface.php | 8 +
2 files changed, 397 insertions(+)
create mode 100644 modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
create mode 100644 modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php
diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
new file mode 100644
index 000000000..5045a8ade
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
@@ -0,0 +1,389 @@
+getName();
+ if (! method_exists($this, $renderMethod)) {
+ die($renderMethod);
+ }
+ if ($now === null) {
+ $now = time();
+ }
+ return sprintf('[%u] %s', $now, $this->$renderMethod($command));
+ }
+
+ public function renderAddComment(AddCommentCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ 'ADD_HOST_COMMENT;%s',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ 'ADD_SVC_COMMENT;%s;%s',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return sprintf(
+ '%s;%u;%s;%s',
+ $commandString,
+ $command->getPersistent(),
+ $command->getAuthor(),
+ $command->getComment()
+ );
+ }
+
+ public function renderSendCustomNotification(SendCustomNotificationCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ 'SEND_CUSTOM_HOST_NOTIFICATION;%s',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ 'SEND_CUSTOM_SVC_NOTIFICATION;%s;%s',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ $options = 0; // 0 for no options
+ if ($command->getBroadcast() === true) {
+ $options |= 1;
+ }
+ if ($command->getForced() === true) {
+ $options |= 2;
+ }
+ return sprintf(
+ '%s;%u;%s;%s',
+ $commandString,
+ $options,
+ $command->getAuthor(),
+ $command->getComment()
+ );
+ }
+
+ public function renderProcessCheckResult(ProcessCheckResultCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ 'PROCESS_HOST_CHECK_RESULT;%s',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ 'PROCESS_SVC_CHECK_RESULT;%s;%s',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ $output = $command->getOutput();
+ if ($command->getPerformanceData() !== null) {
+ $output .= '|' . $command->getPerformanceData();
+ }
+ return sprintf(
+ '%s;%u;%s',
+ $commandString,
+ $command->getStatus(),
+ $output
+ );
+ }
+
+ public function renderScheduleCheck(ScheduleServiceCheckCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ /** @var \Icinga\Module\Monitoring\Command\Object\ScheduleHostCheckCommand $command */
+ if ($command->getOfAllServices() === true) {
+ if ($command->getForced() === true) {
+ $commandName = 'SCHEDULE_FORCED_HOST_SVC_CHECKS';
+ } else {
+ $commandName = 'SCHEDULE_HOST_SVC_CHECKS';
+ }
+ } else {
+ if ($command->getForced() === true) {
+ $commandName = 'SCHEDULE_FORCED_HOST_CHECK';
+ } else {
+ $commandName = 'SCHEDULE_HOST_CHECK';
+ }
+ }
+ $commandString = sprintf(
+ '%s;%s',
+ $commandName,
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ '%s;%s;%s',
+ $command->getForced() === true ? 'SCHEDULE_FORCED_SVC_CHECK' : 'SCHEDULE_SVC_CHECK',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return sprintf(
+ '%s;%u',
+ $commandString,
+ $command->getCheckTime()
+ );
+ }
+
+ public function renderScheduleDowntime(ScheduleServiceDowntimeCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ /** @var \Icinga\Module\Monitoring\Command\Object\ScheduleHostDowntimeCommand $command */
+ if ($command->getForAllServices() === true) {
+ $commandName = 'SCHEDULE_HOST_SVC_DOWNTIME';
+ } else {
+ $commandName = 'SCHEDULE_HOST_DOWNTIME';
+ }
+ $commandString = sprintf(
+ '%s;%s',
+ $commandName,
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ '%s;%s;%s',
+ 'SCHEDULE_SVC_DOWNTIME',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return sprintf(
+ '%s;%u;%u;%u;%u;%u;%s;%s',
+ $commandString,
+ $command->getStart(),
+ $command->getEnd(),
+ $command->getFixed(),
+ $command->getTriggerId(),
+ $command->getDuration(),
+ $command->getAuthor(),
+ $command->getComment()
+ );
+ }
+
+ public function renderAcknowledgeProblem(AcknowledgeProblemCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ '%s;%s',
+ $command->getExpireTime() !== null ? 'ACKNOWLEDGE_HOST_PROBLEM_EXPIRE' : 'ACKNOWLEDGE_HOST_PROBLEM',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ '%s;%s;%s',
+ $command->getExpireTime() !== null ? 'ACKNOWLEDGE_SVC_PROBLEM_EXPIRE' : 'ACKNOWLEDGE_SVC_PROBLEM',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ $commandString = sprintf(
+ '%s;%u;%u;%u',
+ $commandString,
+ $command->getSticky(),
+ $command->getNotify(),
+ $command->getPersistent()
+ );
+ if ($command->getExpireTime() !== null) {
+ $commandString = sprintf(
+ '%s;%u',
+ $commandString,
+ $command->getExpireTime()
+ );
+ }
+ return sprintf(
+ '%s;%s;%s',
+ $commandString,
+ $command->getAuthor(),
+ $command->getComment()
+ );
+ }
+
+ public function renderToggleObjectFeature(ToggleObjectFeatureCommand $command)
+ {
+ if ($command->getEnabled() === true) {
+ $commandPrefix = 'ENABLE';
+ } else {
+ $commandPrefix = 'DISABLE';
+ }
+ switch ($command->getFeature()) {
+ case ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS:
+ $commandFormat = sprintf('%s_%%s_CHECK', $commandPrefix);
+ break;
+ case ToggleObjectFeatureCommand::FEATURE_PASSIVE_CHECKS:
+ $commandFormat = sprintf('%s_PASSIVE_%%s_CHECKS', $commandPrefix);
+ break;
+ case ToggleObjectFeatureCommand::FEATURE_OBSESSING:
+ if ($command->getEnabled() === true) {
+ $commandPrefix = 'START';
+ } else {
+ $commandPrefix = 'STOP';
+ }
+ $commandFormat = sprintf('%s_OBSESSING_OVER_%%s', $commandPrefix);
+ break;
+ case ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS:
+ $commandFormat = sprintf('%s_%%s_NOTIFICATIONS', $commandPrefix);
+ break;
+ case ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER:
+ $commandFormat = sprintf('%s_%%s_EVENT_HANDLER', $commandPrefix);
+ break;
+ case ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION:
+ $commandFormat = sprintf('%s_%%s_FLAP_DETECTION', $commandPrefix);
+ break;
+ default:
+ throw new InvalidArgumentException($command->getFeature());
+ }
+ $object = $command->getObject();
+ if ($object->getType() === ToggleObjectFeatureCommand::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ $commandFormat . ';%s',
+ 'HOST',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ $commandFormat . ';%s;%s',
+ 'SVC',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return $commandString;
+ }
+
+ public function renderDeleteComment(DeleteCommentCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ '%s;%s',
+ 'DEL_HOST_DOWNTIME',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ '%s;%s;%s',
+ 'DEL_SVC_COMMENT',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return sprintf(
+ '%s;%u',
+ $commandString,
+ $command->getCommentId()
+ );
+ }
+
+ public function renderDeleteDowntime(DeleteDowntimeCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ '%s;%s',
+ 'DEL_HOST_DOWNTIME',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ '%s;%s;%s',
+ 'DEL_SVC_DOWNTIME',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return sprintf(
+ '%s;%u',
+ $commandString,
+ $command->getDowntimeId()
+ );
+ }
+
+ public function renderRemoveAcknowledgement(RemoveAcknowledgementCommand $command)
+ {
+ $object = $command->getObject();
+ if ($command->getObject()->getType() === $command::TYPE_HOST) {
+ /** @var \Icinga\Module\Monitoring\Object\Host $object */
+ $commandString = sprintf(
+ '%s;%s',
+ 'REMOVE_HOST_ACKNOWLEDGEMENT',
+ $object->getHost()
+ );
+ } else {
+ /** @var \Icinga\Module\Monitoring\Object\Service $object */
+ $commandString = sprintf(
+ '%s;%s;%s',
+ 'REMOVE_SVC_ACKNOWLEDGEMENT',
+ $object->getHost(),
+ $object->getService()
+ );
+ }
+ return $commandString;
+ }
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php
new file mode 100644
index 000000000..dddd16742
--- /dev/null
+++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php
@@ -0,0 +1,8 @@
+
Date: Thu, 11 Sep 2014 17:39:59 +0200
Subject: [PATCH 212/277] monitoring/commands: Let transports use the Icinga
command file command renderer
refs #6593
---
.../Command/Transport/CommandTransport.php | 6 ++--
.../Transport/CommandTransportInterface.php | 14 +---------
.../Command/Transport/LocalCommandFile.php | 28 +++++++++++++++----
.../Command/Transport/RemoteCommandFile.php | 26 ++++++++++++++---
4 files changed, 49 insertions(+), 25 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php
index 9adbbb062..84845f23f 100644
--- a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php
+++ b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php
@@ -58,13 +58,13 @@ abstract class CommandTransport
$transport = new LocalCommandFile();
break;
default:
- throw new ConfigurationError;
+ throw new ConfigurationError();
}
unset($config->transport);
foreach ($config as $key => $value) {
$method = 'set' . ucfirst($key);
if (! method_exists($transport, $method)) {
- throw new ConfigurationError;
+ throw new ConfigurationError();
}
$transport->$method($value);
}
@@ -83,7 +83,7 @@ abstract class CommandTransport
{
$config = self::getConfig()->get($name);
if ($config === null) {
- throw new ConfigurationError;
+ throw new ConfigurationError();
}
return self::fromConfig($config);
}
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php
index bb0da2716..5f0908fa3 100644
--- a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php
+++ b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransportInterface.php
@@ -4,19 +4,7 @@
namespace Icinga\Module\Monitoring\Command\Transport;
-use Icinga\Module\Monitoring\Command\IcingaCommand;
-
/**
* Interface for Icinga command transports
*/
-interface CommandTransportInterface
-{
- /**
- * Send the command
- *
- * @param IcingaCommand $command
- *
- * @throws \Icinga\Module\Monitoring\Command\Exception\TransportException
- */
- public function send(IcingaCommand $command);
-}
+interface CommandTransportInterface {}
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php b/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php
index 8278b79b0..2fc68d315 100644
--- a/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php
+++ b/modules/monitoring/library/Monitoring/Command/Transport/LocalCommandFile.php
@@ -9,6 +9,7 @@ use LogicException;
use Icinga\Logger\Logger;
use Icinga\Module\Monitoring\Command\Exception\TransportException;
use Icinga\Module\Monitoring\Command\IcingaCommand;
+use Icinga\Module\Monitoring\Command\Renderer\IcingaCommandFileCommandRenderer;
use Icinga\Util\File;
/**
@@ -30,6 +31,21 @@ class LocalCommandFile implements CommandTransportInterface
*/
protected $openMode = 'wn';
+ /**
+ * Command renderer
+ *
+ * @var IcingaCommandFileCommandRenderer
+ */
+ protected $renderer;
+
+ /**
+ * Create a new local command file command transport
+ */
+ public function __construct()
+ {
+ $this->renderer = new IcingaCommandFileCommandRenderer();
+ }
+
/**
* Set the path to the local Icinga command file
*
@@ -79,26 +95,28 @@ class LocalCommandFile implements CommandTransportInterface
/**
* Write the command to the local Icinga command file
*
- * @param IcingaCommand $command
+ * @param IcingaCommand $command
+ * @param int|null $now
*
* @throws LogicException
* @throws TransportException
*/
- public function send(IcingaCommand $command)
+ public function send(IcingaCommand $command, $now = null)
{
if (! isset($this->path)) {
throw new LogicException;
}
+ $commandString = $this->renderer->render($command, $now);
Logger::debug(
sprintf(
mt('monitoring', 'Sending external Icinga command "%s" to the local command file "%s"'),
- $command,
+ $commandString,
$this->path
)
);
try {
$file = new File($this->path, $this->openMode);
- $file->fwrite($command . "\n");
+ $file->fwrite($commandString . "\n");
$file->fflush();
} catch (Exception $e) {
throw new TransportException(
@@ -106,7 +124,7 @@ class LocalCommandFile implements CommandTransportInterface
'monitoring',
'Can\'t send external Icinga command "%s" to the local command file "%s": %s'
),
- $command,
+ $commandString,
$this->path,
$e
);
diff --git a/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php b/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php
index 8092a00bd..c019106cc 100644
--- a/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php
+++ b/modules/monitoring/library/Monitoring/Command/Transport/RemoteCommandFile.php
@@ -8,6 +8,7 @@ use LogicException;
use Icinga\Logger\Logger;
use Icinga\Module\Monitoring\Command\Exception\TransportException;
use Icinga\Module\Monitoring\Command\IcingaCommand;
+use Icinga\Module\Monitoring\Command\Renderer\IcingaCommandFileCommandRenderer;
/**
* A remote Icinga command file
@@ -46,6 +47,21 @@ class RemoteCommandFile implements CommandTransportInterface
*/
protected $path;
+ /**
+ * Command renderer
+ *
+ * @var IcingaCommandFileCommandRenderer
+ */
+ protected $renderer;
+
+ /**
+ * Create a new remote command file command transport
+ */
+ public function __construct()
+ {
+ $this->renderer = new IcingaCommandFileCommandRenderer();
+ }
+
/**
* Set the remote host
*
@@ -143,12 +159,13 @@ class RemoteCommandFile implements CommandTransportInterface
/**
* Write the command to the Icinga command file on the remote host
*
- * @param IcingaCommand $command
+ * @param IcingaCommand $command
+ * @param int|null $now
*
* @throws LogicException
* @throws TransportException
*/
- public function send(IcingaCommand $command)
+ public function send(IcingaCommand $command, $now = null)
{
if (! isset($this->path)) {
throw new LogicException;
@@ -156,10 +173,11 @@ class RemoteCommandFile implements CommandTransportInterface
if (! isset($this->host)) {
throw new LogicException;
}
+ $commandString = $this->renderer->render($command, $now);
Logger::debug(
sprintf(
mt('monitoring', 'Sending external Icinga command "%s" to the remote command file "%s:%u%s"'),
- $command,
+ $commandString,
$this->host,
$this->port,
$this->path
@@ -173,7 +191,7 @@ class RemoteCommandFile implements CommandTransportInterface
$ssh .= sprintf(
' %s "echo %s > %s" 2>&1', // Redirect stderr to stdout
escapeshellarg($this->host),
- escapeshellarg($command),
+ escapeshellarg($commandString),
escapeshellarg($this->path)
);
exec($ssh, $output, $status);
From aca5a2e466657531bb3f8b4cd9fca788edaabfc6 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 10:16:31 +0200
Subject: [PATCH 213/277] monitoring: Fetch Icinga object properties lazily
---
.../Monitoring/Object/MonitoredObject.php | 461 +++++++++++-------
1 file changed, 288 insertions(+), 173 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
index 8ff79f7b8..cb95c2e41 100644
--- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
+++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
@@ -2,127 +2,249 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
-/*
-CREATE INDEX tgelf_comments ON icinga_comments (object_id, comment_type, comment_time);
-
-CREATE INDEX tgelf_scheduleddowntime ON icinga_scheduleddowntime (object_id, is_in_effect, scheduled_start_time);
-
-*/
-
namespace Icinga\Module\Monitoring\Object;
-use Icinga\Module\Monitoring\DataView\Contact;
-use Icinga\Module\Monitoring\DataView\Contactgroup;
-use Icinga\Module\Monitoring\DataView\Downtime;
-use Icinga\Module\Monitoring\DataView\EventHistory;
-use Icinga\Module\Monitoring\DataView\Hostgroup;
-use Icinga\Module\Monitoring\DataView\Comment;
-use Icinga\Module\Monitoring\DataView\Servicegroup;
-use Icinga\Module\Monitoring\DataView\Customvar;
-use Icinga\Web\UrlParams;
+use InvalidArgumentException;
use Icinga\Application\Config;
+use Icinga\Exception\InvalidPropertyException;
+use Icinga\Module\Monitoring\Backend;
-
+/**
+ * A monitored Icinga object, i.e. host or service
+ */
abstract class MonitoredObject
{
- public $type;
- public $prefix;
+ /**
+ * Type host
+ */
+ const TYPE_HOST = 'host';
- public $comments = array();
- public $downtimes = array();
- public $hostgroups = array();
- public $servicegroups = array();
- public $contacts = array();
- public $contactgroups = array();
- public $customvars = array();
- public $events = array();
+ /**
+ * Type service
+ */
+ const TYPE_SERVICE = 'service';
- protected $view;
- private $properties = array();
- protected $params;
+ /**
+ * Backend to fetch object information from
+ *
+ * @var Backend
+ */
+ protected $backend;
- // TODO: Fetching parent states if any would be nice
- // Same goes for host/service dependencies
+ /**
+ * Type of the Icinga object, i.e. 'host' or 'service'
+ *
+ * @var string
+ */
+ protected $type;
- public function __construct(UrlParams $params)
+ /**
+ * Prefix of the Icinga object, i.e. 'host_' or 'service_'
+ *
+ * @var string
+ */
+ protected $prefix;
+
+ /**
+ * Properties
+ *
+ * @var object
+ */
+ protected $properties;
+
+ /**
+ * Comments
+ *
+ * @var array
+ */
+ protected $comments;
+
+ /**
+ * Downtimes
+ *
+ * @var array
+ */
+ protected $downtimes;
+
+ /**
+ * Host groups
+ *
+ * @var array
+ */
+ protected $hostgroups;
+
+ /**
+ * Service groups
+ *
+ * @var array
+ */
+ protected $servicegroups;
+
+ /**
+ * Contacts
+ *
+ * @var array
+ */
+ protected $contacts;
+
+ /**
+ * Contact groups
+ *
+ * @var array
+ */
+ protected $contactgroups;
+
+ /**
+ * Custom variables
+ *
+ * @var array
+ */
+ protected $customvars;
+
+ /**
+ * Event history
+ *
+ * @var \Icinga\Module\Monitoring\DataView\EventHistory
+ */
+ protected $eventhistory;
+
+ /**
+ * Create a monitored object, i.e. host or service
+ *
+ * @param Backend $backend Backend to fetch object information from
+ */
+ public function __construct(Backend $backend)
{
- $this->params = $params;
- $this->properties = $this->getProperties();
+ $this->backend = $backend;
}
- abstract protected function getProperties();
+ /**
+ * Get the object's data view
+ *
+ * @return \Icinga\Module\Monitoring\DataView\DataView
+ */
+ abstract protected function getDataView();
+ /**
+ * Fetch the object's properties
+ *
+ * @return bool
+ */
+ public function fetch()
+ {
+ $this->properties = $this->getDataView()->getQuery()->fetchRow();
+ return $this->properties !== false;
+ }
+
+ /**
+ * Get the type of the object
+ *
+ * @return string
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ /**
+ * Require the object's type to be one of the given types
+ *
+ * @param array $oneOf
+ *
+ * @return bool
+ * @throws InvalidArgumentException If the object's type is not one of the given types.
+ */
+ public function assertOneOf(array $oneOf)
+ {
+ if (! in_array($this->type, $oneOf)) {
+ throw new InvalidArgumentException;
+ }
+ return true;
+ }
+
+ /**
+ * Fetch the object's comments
+ *
+ * @return $this
+ */
public function fetchComments()
{
- // WTF???
- $query = Comment::fromParams(array('backend' => null), array(
+ $comments = $this->backend->select()->from('comment', array(
'id' => 'comment_internal_id',
'timestamp' => 'comment_timestamp',
'author' => 'comment_author',
'comment' => 'comment_data',
'type' => 'comment_type',
- ));
- $query->where('comment_type', array('comment', 'ack'));
- $query->where('comment_objecttype', $this->type);
- $query->where('comment_host', $this->host_name);
- if ($this->type === 'service') {
- $query->where('comment_service', $this->service_description);
+ ))
+ ->where('comment_type', array('comment', 'ack'))
+ ->where('comment_objecttype', $this->type)
+ ->where('comment_host', $this->host);
+ if ($this->type === self::TYPE_SERVICE) {
+ $comments->where('comment_service', $this->service);
}
- $this->comments = $query->getQuery()->fetchAll();
+ $this->comments = $comments->getQuery()->fetchAll();
return $this;
}
+ /**
+ * Fetch the object's downtimes
+ *
+ * @return $this
+ */
public function fetchDowntimes()
{
- // TODO: We want to check for objecttype = 'host', not type_id = 1
-
- // WTF???
- $query = Downtime::fromParams(array('backend' => null), array(
- 'id' => 'downtime_internal_id',
- 'objecttype' => 'downtime_objecttype',
- 'comment' => 'downtime_comment',
- 'author' => 'downtime_author',
- 'start' => 'downtime_start',
- 'scheduled_start' => 'downtime_scheduled_start',
- 'end' => 'downtime_end',
- 'duration' => 'downtime_duration',
- 'is_flexible' => 'downtime_is_flexible',
- 'is_fixed' => 'downtime_is_fixed',
- 'is_in_effect' => 'downtime_is_in_effect',
- 'entry_time' => 'downtime_entry_time',
- 'host' => 'downtime_host',
- 'service' => 'downtime_service'
- ));
-
- $query->where('downtime_objecttype', $this->type);
- $query->where('downtime_host', $this->host_name);
- if ($this->type === 'service') {
- $query->where('downtime_service', $this->service_description);
+ $downtimes = $this->backend->select()->from('downtime', array(
+ 'id' => 'downtime_internal_id',
+ 'objecttype' => 'downtime_objecttype',
+ 'comment' => 'downtime_comment',
+ 'author' => 'downtime_author',
+ 'start' => 'downtime_start',
+ 'scheduled_start' => 'downtime_scheduled_start',
+ 'end' => 'downtime_end',
+ 'duration' => 'downtime_duration',
+ 'is_flexible' => 'downtime_is_flexible',
+ 'is_fixed' => 'downtime_is_fixed',
+ 'is_in_effect' => 'downtime_is_in_effect',
+ 'entry_time' => 'downtime_entry_time',
+ 'host' => 'downtime_host',
+ 'service' => 'downtime_service'
+ ))
+ ->where('downtime_objecttype', $this->type)
+ ->where('downtime_host', $this->host)
+ ->order('downtime_is_in_effect', 'DESC')
+ ->order('downtime_scheduled_start', 'ASC');
+ if ($this->type === self::TYPE_SERVICE) {
+ $downtimes->where('downtime_service', $this->service);
}
- $query->order('downtime_is_in_effect', 'DESC')->order('downtime_scheduled_start', 'ASC');
-
- $this->downtimes = $query->getQuery()->fetchAll();
- return $this;
-
- $this->downtimes = Downtime::fromRequest($this->request)->getQuery()->fetchAll();
+ $this->downtimes = $downtimes->getQuery()->fetchAll();
return $this;
}
+ /**
+ * Fetch the object's host groups
+ *
+ * @return $this
+ */
public function fetchHostgroups()
{
- $query = HostGroup::fromParams(array('backend' => null), array(
+ $hostGroups = $this->backend->select()->from('hostGroup', array(
'hostgroup_name',
'hostgroup_alias'
- ))->where('host_name', $this->host_name);
-
- $this->hostgroups = $query->getQuery()->fetchPairs();
+ ))
+ ->where('host_name', $this->host);
+ $this->hostgroups = $hostGroups->getQuery()->fetchPairs();
return $this;
}
+ /**
+ * Fetch the object's custom variables
+ *
+ * @return $this
+ */
public function fetchCustomvars()
{
$blacklist = array();
- $blacklistPattern = '/^(.*pw.*|.*pass.*|community)$/';
+ $blacklistPattern = '/^(.*pw.*|.*pass.*|community)$/i';
if ($security = Config::module('monitoring')->get('security')) {
@@ -138,23 +260,20 @@ abstract class MonitoredObject
$blacklistPattern = '/^(' . implode('|', $blacklist) . ')$/i';
}
- $query = Customvar::fromParams(array('backend' => null), array(
- 'varname',
- 'varvalue'
- )
- );
-
- if ($this->type === 'host') {
- $query->where('host_name', $this->host_name)
- ->where('object_type', 'host');
- } else {
- $query->where('host_name', $this->host_name)
- ->where('object_type', 'service')
- ->where('service_description', $this->service_description);
+ $query = $this->backend->select()->from('customvar', array(
+ 'varname',
+ 'varvalue'
+ ))
+ ->where('object_type', $this->type)
+ ->where('host_name', $this->host);
+ if ($this->type === self::TYPE_SERVICE) {
+ $query->where('service_description', $this->service);
}
+ $this->customvars = array();
+
$customvars = $query->getQuery()->fetchPairs();
- foreach ($customvars as $name => &$value) {
+ foreach ($customvars as $name => $value) {
$name = ucwords(str_replace('_', ' ', strtolower($name)));
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$value = '***';
@@ -165,83 +284,71 @@ abstract class MonitoredObject
return $this;
}
+ /**
+ * Fetch the object's contacts
+ *
+ * @return $this
+ */
public function fetchContacts()
{
-/*
- $query = Contact::fromRequest(
- $this->request,
- array(
+ $contacts = $this->backend->select()->from('contact', array(
'contact_name',
'contact_alias',
'contact_email',
'contact_pager',
- )
- )->getQuery()
+ ))
->where('host_name', $this->host_name);
-*/
-
- $query = Contact::fromParams(array('backend' => null), array(
- 'contact_name',
- 'contact_alias',
- 'contact_email',
- 'contact_pager',
- ));
-
- if ($this->type === 'service') {
- $query->where('service_host_name', $this->host_name);
- $query->where('service_description', $this->service_description);
- } else {
- $query->where('host_name', $this->host_name);
+ if ($this->type === self::TYPE_SERVICE) {
+ $contacts->where('service_description', $this->service);
}
-
- $this->contacts = $query->getQuery()->fetchAll();
+ $this->contacts = $contacts->getQuery()->fetchAll();
return $this;
}
+ /**
+ * Fetch the object's service groups
+ *
+ * @return $this
+ */
public function fetchServicegroups()
{
- $query = Servicegroup::fromParams(array('backend' => null), array(
+ $serviceGroups = $this->backend->select()->from('serviceGroup', array(
'servicegroup_name',
- 'servicegroup_alias',
- )
- );
- $query->where('service_host_name', $this->host_name);
- $query->where('service_description', $this->service_description);
- $this->servicegroups = $query->getQuery()->fetchPairs();
+ 'servicegroup_alias'
+ ))
+ ->where('service_host_name', $this->host)
+ ->where('service_description', $this->service);
+ $this->servicegroups = $serviceGroups->getQuery()->fetchPairs();
return $this;
}
+ /**
+ * Fetch the object's contact groups
+ *
+ * @return $this
+ */
public function fetchContactgroups()
{
-
- $query = Contactgroup::fromParams(array('backend' => null), array(
+ $contactsGroups = $this->backend->select()->from('contactGroup', array(
'contactgroup_name',
'contactgroup_alias'
- ));
-
- if ($this->type === 'service') {
- $query->where('service_host_name', $this->host_name);
- $query->where('service_description', $this->service_description);
- } else {
- $query->where('host_name', $this->host_name);
+ ))
+ ->where('host_name', $this->host);
+ if ($this->type === self::TYPE_SERVICE) {
+ $contactsGroups->where('service_description', $this->service);
}
-/*
- $query = Contactgroup::fromRequest(
- $this->request,
- array(
- 'contactgroup_name',
- 'contactgroup_alias'
- )
- )->getQuery();
-*/
- $this->contactgroups = $query->getQuery()->fetchAll();
-
+ $this->contactgroups = $contactsGroups->getQuery()->fetchAll();
return $this;
}
- public function fetchEventHistory()
+ /**
+ * Fetch the object's event history
+ *
+ * @return $this
+ */
+ public function fetchEventhistory()
{
- $query = EventHistory::fromParams(array('backend' => null), array(
+ $eventHistory = $this->backend->select()->from('eventHistory', array(
'object_type',
'host_name',
'service_description',
@@ -251,42 +358,50 @@ abstract class MonitoredObject
'max_attempts',
'output',
'type'
- )
- )->sort('timestamp', 'DESC');
- if ($this->type === 'service') {
- $query->where('service_host_name', $this->host_name);
- $query->where('service_description', $this->service_description);
- } else {
- $query->where('host_name', $this->host_name);
+ ))
+ ->order('timestamp', 'DESC')
+ ->where('host_name', $this->host);
+ if ($this->type === self::TYPE_SERVICE) {
+ $eventHistory->where('service_description', $this->service);
}
-
- $this->eventhistory = $query->getQuery();
+ $this->eventhistory = $eventHistory->getQuery();
return $this;
}
- public function __get($param)
+ /**
+ * Fetch all available data of the object
+ *
+ * @return $this
+ */
+ public function populate()
{
-
- if (isset($this->properties->$param)) {
- return $this->properties->$param;
- } elseif (isset($this->$param)) {
- return $this->$param;
- }
- if (substr($param, 0, strlen($this->prefix)) === $this->prefix) {
- return false;
- }
- $expandedName = $this->prefix . strtolower($param);
- return $this->$expandedName;
+ $this
+ ->fetchComments()
+ ->fetchContacts()
+ ->fetchContactgroups()
+ ->fetchCustomvars()
+ ->fetchDowntimes();
+ // Call fetchHostgroups or fetchServicegroups depending on the object's type
+ $fetchGroups = 'fetch' . ucfirst($this->type) . 'groups';
+ $this->$fetchGroups();
+ return $this;
}
- public static function fromParams(UrlParams $params)
+ public function __get($name)
{
- if ($params->has('service') && $params->has('host')) {
- return new Service($params);
- } elseif ($params->has('host')) {
- return new Host($params);
+ if (property_exists($this->properties, $name)) {
+ return $this->properties->$name;
+ } elseif (isset($this->$name)) {
+ return $this->$name;
+ } elseif (property_exists($this, $name)) {
+ $fetchMethod = 'fetch' . ucfirst($name);
+ $this->$fetchMethod();
+ return $this->$name;
}
+ if (substr($name, 0, strlen($this->prefix)) === $this->prefix) {
+ throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
+ }
+ $prefixedName = $this->prefix . strtolower($name);
+ return $this->$prefixedName;
}
-
- abstract public function populate();
}
From c0e3447339f7c378d15053208700fe528599cc24 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 10:17:46 +0200
Subject: [PATCH 214/277] monitoring: Adapt host and service classes to match
their base class' interface
---
.../library/Monitoring/Object/Host.php | 66 ++++++++---
.../library/Monitoring/Object/Service.php | 110 +++++++++++-------
2 files changed, 119 insertions(+), 57 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php
index 1773337eb..0b482cfce 100644
--- a/modules/monitoring/library/Monitoring/Object/Host.php
+++ b/modules/monitoring/library/Monitoring/Object/Host.php
@@ -4,32 +4,64 @@
namespace Icinga\Module\Monitoring\Object;
-use Icinga\Module\Monitoring\DataView\HostStatus;
-use Icinga\Data\Db\DbQuery;
+use Icinga\Module\Monitoring\Backend;
+/**
+ * A Icinga host
+ */
class Host extends MonitoredObject
{
- public $type = 'host';
+ /**
+ * Type of the Icinga host
+ *
+ * @var string
+ */
+ public $type = self::TYPE_HOST;
+
+ /**
+ * Prefix of the Icinga host
+ *
+ * @var string
+ */
public $prefix = 'host_';
- protected function applyObjectFilter(DbQuery $query)
+ /**
+ * Host name
+ *
+ * @var string
+ */
+ protected $host;
+
+ /**
+ * Create a new host
+ *
+ * @param Backend $backend Backend to fetch host information from
+ * @param string $host Host name
+ */
+ public function __construct(Backend $backend, $host)
{
- return $query->where('host_name', $this->host_name);
+ parent::__construct($backend);
+ $this->host = $host;
}
- public function populate()
+ /**
+ * Get the host name
+ *
+ * @return string
+ */
+ public function getHost()
{
- $this->fetchComments()
- ->fetchHostgroups()
- ->fetchContacts()
- ->fetchContactGroups()
- ->fetchCustomvars()
- ->fetchDowntimes();
+ return $this->host;
}
- protected function getProperties()
+ /**
+ * Get the data view to fetch the host information from
+ *
+ * @return \Icinga\Module\Monitoring\DataView\HostStatus
+ */
+ protected function getDataView()
{
- $this->view = HostStatus::fromParams(array('backend' => null), array(
+ return $this->backend->select()->from('hostStatus', array(
'host_name',
'host_alias',
'host_address',
@@ -70,8 +102,8 @@ class Host extends MonitoredObject
'host_notes_url',
'host_modified_host_attributes',
'host_problem',
- 'process_perfdata' => 'host_process_performance_data',
- ))->where('host_name', $this->params->get('host'));
- return $this->view->getQuery()->fetchRow();
+ 'host_process_performance_data'
+ ))
+ ->where('host_name', $this->host);
}
}
diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 3325ecc6b..1c1c80679 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -4,33 +4,83 @@
namespace Icinga\Module\Monitoring\Object;
-use Icinga\Module\Monitoring\DataView\ServiceStatus;
-use Icinga\Data\Db\DbQuery;
+use Icinga\Module\Monitoring\Backend;
+/**
+ * A Icinga service
+ */
class Service extends MonitoredObject
{
- public $type = 'service';
+ /**
+ * Type of the Icinga service
+ *
+ * @var string
+ */
+ public $type = self::TYPE_SERVICE;
+
+ /**
+ * Prefix of the Icinga service
+ *
+ * @var string
+ */
public $prefix = 'service_';
- protected function applyObjectFilter(DbQuery $query)
+ /**
+ * Host name the service is running on
+ *
+ * @var string
+ */
+ protected $host;
+
+ /**
+ * Service name
+ *
+ * @var string
+ */
+ protected $service;
+
+ /**
+ * Create a new service
+ *
+ * @param Backend $backend Backend to fetch service information from
+ * @param string $host Host name the service is running on
+ * @param string $service Service name
+ */
+ public function __construct(Backend $backend, $host, $service)
{
- return $query->where('service_host_name', $this->host_name)
- ->where('service_description', $this->service_description);
+ parent::__construct($backend);
+ $this->host = $host;
+ $this->service = $service;
}
- public function populate()
+ /**
+ * Get the host name the service is running on
+ *
+ * @return string
+ */
+ public function getHost()
{
- $this->fetchComments()
- ->fetchServicegroups()
- ->fetchContacts()
- ->fetchContactGroups()
- ->fetchCustomvars()
- ->fetchDowntimes();
+ return $this->host;
}
- protected function getProperties()
+ /**
+ * Get the service name
+ *
+ * @return string
+ */
+ public function getService()
{
- $this->view = ServiceStatus::fromParams(array('backend' => null), array(
+ return $this->service;
+ }
+
+ /**
+ * Get the data view
+ *
+ * @return \Icinga\Module\Monitoring\DataView\ServiceStatus
+ */
+ protected function getDataView()
+ {
+ return $this->backend->select()->from('serviceStatus', array(
'host_name',
'host_state',
'host_state_type',
@@ -114,30 +164,10 @@ class Service extends MonitoredObject
'service_flap_detection_enabled',
'service_flap_detection_enabled_changed',
'service_modified_service_attributes',
- 'process_perfdata' => 'service_process_performance_data',
- ))->where('host_name', $this->params->get('host'))
- ->where('service_description', $this->params->get('service'));
-
- return $this->view->getQuery()->fetchRow();
- }
-
- /**
- * Get the host name the service is running on
- *
- * @return string
- */
- public function getHostName()
- {
- return $this->params->get('host');
- }
-
- /**
- * Get the service name
- *
- * @return string
- */
- public function getName()
- {
- return $this->params->get('service');
+ 'service_process_performance_data',
+ 'service_percent_state_change'
+ ))
+ ->where('host_name', $this->host)
+ ->where('service_description', $this->service);
}
}
From beecf16ad0cc266fac7ba6c7a61314d6fb306d60 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 10:18:48 +0200
Subject: [PATCH 215/277] lib: Add `InvalidPropertyException'
---
library/Icinga/Exception/InvalidPropertyException.php | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 library/Icinga/Exception/InvalidPropertyException.php
diff --git a/library/Icinga/Exception/InvalidPropertyException.php b/library/Icinga/Exception/InvalidPropertyException.php
new file mode 100644
index 000000000..f79055f0b
--- /dev/null
+++ b/library/Icinga/Exception/InvalidPropertyException.php
@@ -0,0 +1,10 @@
+
Date: Fri, 12 Sep 2014 10:20:38 +0200
Subject: [PATCH 216/277] monitoring/commands: Remove superseded command forms
and command objects
refs #6593
---
.../forms/Command/AcknowledgeForm.php | 154 -----
.../application/forms/Command/CommentForm.php | 75 ---
.../Common/ScheduleDowntimeCommandForm.php | 153 -----
.../forms/Command/CustomNotificationForm.php | 93 ---
.../forms/Command/DelayNotificationForm.php | 65 --
.../DisableNotificationWithExpireForm.php | 56 --
.../forms/Command/MultiCommandFlagForm.php | 147 -----
.../forms/Command/RescheduleNextCheckForm.php | 82 ---
.../forms/Command/ScheduleDowntimeForm.php | 336 ----------
.../ScheduleServiceDowntimeCommandForm.php | 113 ----
.../Command/SingleArgumentCommandForm.php | 169 -----
.../Command/SubmitPassiveCheckResultForm.php | 177 -----
.../forms/Command/WithChildrenCommandForm.php | 37 --
.../Monitoring/Command/AcknowledgeCommand.php | 164 -----
.../Monitoring/Command/AddCommentCommand.php | 79 ---
.../Monitoring/Command/CommandPipe.php | 603 ------------------
.../library/Monitoring/Command/Comment.php | 61 --
.../Command/Common/AddCommentCommand.php | 50 --
.../Command/Common/ObjectCommand.php | 62 --
.../Common/ScheduleDowntimeCommand.php | 193 ------
.../Command/Common/ToggleFeature.php | 42 --
.../Command/Common/WithCommentCommand.php | 71 ---
.../Command/CustomNotificationCommand.php | 139 ----
.../Command/DelayNotificationCommand.php | 87 ---
.../DisableNotificationWithExpireCommand.php | 92 ---
.../Exception/InvalidCommandException.php | 12 -
.../Monitoring/Command/PropertyModifier.php | 110 ----
.../Command/ScheduleCheckCommand.php | 108 ----
.../Command/Service/AddServiceComment.php | 34 -
.../ScheduleServiceDowntimeCommand.php | 59 --
.../Command/SingleArgumentCommand.php | 183 ------
.../SubmitPassiveCheckresultCommand.php | 133 ----
32 files changed, 3939 deletions(-)
delete mode 100644 modules/monitoring/application/forms/Command/AcknowledgeForm.php
delete mode 100644 modules/monitoring/application/forms/Command/CommentForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/CustomNotificationForm.php
delete mode 100644 modules/monitoring/application/forms/Command/DelayNotificationForm.php
delete mode 100644 modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php
delete mode 100644 modules/monitoring/application/forms/Command/MultiCommandFlagForm.php
delete mode 100644 modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php
delete mode 100644 modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php
delete mode 100644 modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php
delete mode 100644 modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php
delete mode 100644 modules/monitoring/application/forms/Command/WithChildrenCommandForm.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/AddCommentCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/CommandPipe.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Comment.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/PropertyModifier.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php
delete mode 100644 modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php
diff --git a/modules/monitoring/application/forms/Command/AcknowledgeForm.php b/modules/monitoring/application/forms/Command/AcknowledgeForm.php
deleted file mode 100644
index 4ac4901b0..000000000
--- a/modules/monitoring/application/forms/Command/AcknowledgeForm.php
+++ /dev/null
@@ -1,154 +0,0 @@
-addNote(
- t(
- 'This command is used to acknowledge host or service problems. When a problem is '
- . 'acknowledged, future notifications about problems are temporarily disabled until the '
- . 'host/service changes from its current state.'
- )
- );
-
- $this->addElement($this->createAuthorField());
-
- $this->addElement(
- 'textarea',
- 'comment',
- array(
- 'label' => t('Comment'),
- 'rows' => 4,
- 'cols' => 72,
- 'required' => true,
- 'helptext' => t(
- ' If you work with other administrators you may find it useful to share information '
- . 'about a host or service that is having problems if more than one of you may be working on '
- . 'it. Make sure you enter a brief description of what you are doing.'
- )
- )
- );
-
- $this->addElement(
- 'checkbox',
- 'persistent',
- array(
- 'label' => t('Persistent Comment'),
- 'value' => false,
- 'helptext' => t(
- 'If you would like the comment to remain even when the acknowledgement is removed, '
- . 'check this option.'
- )
- )
- );
-
- $this->addElement(
- 'checkbox',
- 'expire',
- array(
- 'label' => t('Use Expire Time'),
- 'helptext' => t('If the acknowledgement should expire, check this option.')
- )
- );
- $this->enableAutoSubmit(array('expire'));
-
- if ($this->getRequest()->getPost('expire', '0') === '1') {
- $now = DateTimeFactory::create();
- $this->addElement(
- new DateTimePicker(
- array(
- 'name' => 'expiretime',
- 'label' => t('Expire Time'),
- 'value' => $now->getTimestamp() + 3600,
- 'patterns' => $this->getValidDateTimeFormats(),
- 'helptext' => t(
- 'Enter the expire date/time for this acknowledgement here. Icinga will '
- . ' delete the acknowledgement after this date expired.'
- ),
- 'jspicker' => true
- )
- )
- );
- }
-
- $this->addElement(
- 'checkbox',
- 'sticky',
- array(
- 'label' => t('Sticky Acknowledgement'),
- 'value' => true,
- 'helptext' => t(
- 'If you want the acknowledgement to disable notifications until the host/service '
- . 'recovers, check this option.'
- )
- )
- );
-
- $this->addElement(
- 'checkbox',
- 'notify',
- array(
- 'label' => t('Send Notification'),
- 'value' => true,
- 'helptext' => t(
- 'If you do not want an acknowledgement notification to be sent out to the appropriate '
- . 'contacts, uncheck this option.'
- )
- )
- );
-
- $this->setSubmitLabel(t('Acknowledge Problem'));
-
- parent::create();
- }
-
- /**
- * Add validator for dependent fields
- *
- * @param array $data
- *
- * @see \Icinga\Web\Form::preValidation()
- */
- protected function preValidation(array $data)
- {
- if (isset($data['expire']) && intval($data['expire']) === 1) {
- $expireTime = $this->getElement('expiretime');
- $expireTime->setRequired(true);
- }
- }
-
- /**
- * Create the acknowledgement command object
- *
- * @return AcknowledgeCommand
- */
- public function createCommand()
- {
- return new AcknowledgeCommand(
- new Comment(
- $this->getAuthorName(),
- $this->getValue('comment'),
- $this->getValue('persistent')
- ),
- $this->getValue('expire') ? $this->getValue('expire') : -1,
- $this->getValue('notify'),
- $this->getValue('sticky')
- );
- }
-}
diff --git a/modules/monitoring/application/forms/Command/CommentForm.php b/modules/monitoring/application/forms/Command/CommentForm.php
deleted file mode 100644
index 497c276f1..000000000
--- a/modules/monitoring/application/forms/Command/CommentForm.php
+++ /dev/null
@@ -1,75 +0,0 @@
-setName('form_CommentForm');
-
- $this->addNote(t('This command is used to add a comment to hosts or services.'));
-
- $this->addElement($this->createAuthorField());
-
- $this->addElement(
- 'textarea',
- 'comment',
- array(
- 'label' => t('Comment'),
- 'rows' => 4,
- 'cols' => 72,
- 'required' => true,
- 'helptext' => t(
- 'If you work with other administrators, you may find it useful to share information '
- . 'about a host or service that is having problems if more than one of you may be working on '
- . 'it. Make sure you enter a brief description of what you are doing.'
- )
- )
- );
-
- $this->addElement(
- 'checkbox',
- 'persistent',
- array(
- 'label' => t('Persistent'),
- 'value' => true,
- 'helptext' => t(
- 'If you uncheck this option, the comment will automatically be deleted the next time '
- . 'Icinga is restarted.'
- )
- )
- );
-
- $this->setSubmitLabel(t('Post Comment'));
-
- parent::create();
- }
-
- /**
- * Create the command object to add comments
- *
- * @return AddCommentCommand
- */
- public function createCommand()
- {
- return new AddCommentCommand(
- new Comment(
- $this->getAuthorName(),
- $this->getValue('comment'),
- $this->getValue('persistent')
- )
- );
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php
deleted file mode 100644
index d48b814e7..000000000
--- a/modules/monitoring/application/forms/Command/Common/ScheduleDowntimeCommandForm.php
+++ /dev/null
@@ -1,153 +0,0 @@
-add(new DateInterval('PT1H'));
- $this->addElements(array(
- array(
- 'textarea',
- 'comment',
- array(
- 'required' => true,
- 'label' => mt('monitoring', 'Comment'),
- 'description' => mt(
- 'monitoring',
- 'If you work with other administrators, you may find it useful to share information about the'
- . ' the host or service that is having problems. Make sure you enter a brief description of'
- . ' what you are doing.'
- )
- )
- ),
- new DateTimePicker(
- 'start',
- array(
- 'required' => true,
- 'label' => t('Start Time'),
- 'description' => mt('monitoring', 'Set the start date and time for the downtime.'),
- 'value' => $start
- )
- ),
- new DateTimePicker(
- 'end',
- array(
- 'required' => true,
- 'label' => t('End Time'),
- 'description' => mt('monitoring', 'Set the end date and time for the downtime.'),
- 'value' => $end
- )
- ),
- array(
- 'select',
- 'type',
- array(
- 'required' => true,
- 'autosubmit' => true,
- 'label' => mt('monitoring', 'Type'),
- 'description' => mt(
- 'monitoring',
- 'If you select the fixed option, the downtime will be in effect between the start and end'
- . ' times you specify whereas a flexible downtime starts when the host or service enters a'
- . ' problem state sometime between the start and end times you specified and lasts as long'
- . ' as the duration time you enter. The duration fields do not apply for fixed downtimes.'
- ),
- 'multiOptions' => array(
- self::FIXED => mt('monitoring', 'Fixed'),
- self::FLEXIBLE => mt('monitoring', 'Flexible')
- ),
- 'validators' => array(
- array(
- 'InArray',
- true,
- array(array(self::FIXED, self::FLEXIBLE))
- )
- )
- )
- )
- ));
- $this->addDisplayGroup(
- array('start', 'end'),
- 'start-end',
- array(
- 'decorators' => array(
- 'FormElements',
- array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
- )
- )
- );
- if (isset($formData['type']) && $formData['type'] === self::FLEXIBLE) {
- $this->addElements(array(
- new Number(
- 'hours',
- array(
- 'required' => true,
- 'label' => mt('monitoring', 'Hours'),
- 'value' => 2,
- 'min' => -1
- )
- ),
- new Number(
- 'minutes',
- array(
- 'required' => true,
- 'label' => mt('monitoring', 'Minutes'),
- 'value' => 0,
- 'min' => -1
- )
- )
- ));
- $this->addDisplayGroup(
- array('hours', 'minutes'),
- 'duration',
- array(
- 'legend' => mt('monitoring', 'Flexible Duration'),
- 'description' => mt(
- 'monitoring',
- 'Enter here the duration of the downtime. The downtime will be automatically deleted after this'
- . ' time expired.'
- ),
- 'decorators' => array(
- 'FormElements',
- array('HtmlTag', array('tag' => 'div', 'class' => 'control-group')),
- array(
- 'Description',
- array('tag' => 'span', 'class' => 'description', 'placement' => 'prepend')
- ),
- 'Fieldset'
- )
- )
- );
- }
- return $this;
- }
-}
diff --git a/modules/monitoring/application/forms/Command/CustomNotificationForm.php b/modules/monitoring/application/forms/Command/CustomNotificationForm.php
deleted file mode 100644
index 9eb75a67b..000000000
--- a/modules/monitoring/application/forms/Command/CustomNotificationForm.php
+++ /dev/null
@@ -1,93 +0,0 @@
-addNote(
- t(
- 'This command is used to send a custom notification about hosts or services. Useful in '
- . 'emergencies when you need to notify admins of an issue regarding a monitored system or '
- . 'service.'
- )
- );
-
- $this->addElement($this->createAuthorField());
-
- $this->addElement(
- 'textarea',
- 'comment',
- array(
- 'label' => t('Comment'),
- 'rows' => 4,
- 'cols' => 72,
- 'required' => true,
- 'helptext' => t(
- 'If you work with other administrators, you may find it useful to share information '
- . 'about a host or service that is having problems if more than one of you may be working on '
- . 'it. Make sure you enter a brief description of what you are doing.'
- )
- )
- );
-
- $this->addElement(
- 'checkbox',
- 'forced',
- array(
- 'label' => t('Forced'),
- 'helptext' => t(
- 'Custom notifications normally follow the regular notification logic in Icinga. Selecting this '
- . 'option will force the notification to be sent out, regardless of time restrictions, '
- . 'whether or not notifications are enabled, etc.'
- )
- )
- );
-
- $this->addElement(
- 'checkbox',
- 'broadcast',
- array(
- 'label' => t('Broadcast'),
- 'helptext' => t(
- 'Selecting this option causes the notification to be sent out to all normal (non-escalated) '
- . ' and escalated contacts. These options allow you to override the normal notification logic '
- . 'if you need to get an important message out.'
- )
- )
- );
-
- $this->setSubmitLabel(t('Send Custom Notification'));
-
- parent::create();
- }
-
- /**
- * Create the command object to send custom notifications
- *
- * @return CustomNotificationCommand
- */
- public function createCommand()
- {
- return new CustomNotificationCommand(
- new Comment(
- $this->getAuthorName(),
- $this->getValue('comment')
- ),
- $this->getValue('forced'),
- $this->getValue('broadcast')
- );
- }
-}
diff --git a/modules/monitoring/application/forms/Command/DelayNotificationForm.php b/modules/monitoring/application/forms/Command/DelayNotificationForm.php
deleted file mode 100644
index efb6eae0f..000000000
--- a/modules/monitoring/application/forms/Command/DelayNotificationForm.php
+++ /dev/null
@@ -1,65 +0,0 @@
-addNote(t('This command is used to delay the next problem notification that is sent out.'));
-
- $this->addElement(
- 'text',
- 'minutes',
- array(
- 'label' => t('Notification Delay (Minutes From Now)'),
- 'style' => 'width: 80px;',
- 'value' => 0,
- 'required' => true,
- 'validators' => array(
- array(
- 'between',
- true,
- array(
- 'min' => 1,
- 'max' => self::MAX_DELAY
- )
- )
- ),
- 'helptext' => t(
- 'The notification delay will be disregarded if the host/service changes state before the next '
- . 'notification is scheduled to be sent out.'
- )
- )
- );
-
- $this->setSubmitLabel(t('Delay Notification'));
-
- parent::create();
- }
-
- /**
- * Create the command object to delay notifications
- *
- * @return DelayNotificationCommand
- */
- public function createCommand()
- {
- return new DelayNotificationCommand($this->getValue('minutes') * 60);
- }
-}
diff --git a/modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php b/modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php
deleted file mode 100644
index d6657dd37..000000000
--- a/modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php
+++ /dev/null
@@ -1,56 +0,0 @@
-addNote('Disable notifications for a specific time on a program-wide basis');
-
- $now = DateTimeFactory::create();
- $this->addElement(
- new DateTimePicker(
- array(
- 'name' => 'expiretime',
- 'label' => t('Expire Time'),
- 'value' => $now->getTimestamp() + 3600,
- 'patterns' => $this->getValidDateTimeFormats(),
- 'helptext' => t(
- 'Enter the expire date/time for this acknowledgement here. Icinga will '
- . ' delete the acknowledgement after this date expired.'
- )
- )
- )
- );
-
- $this->setSubmitLabel('Disable notifications');
-
- parent::create();
- }
-
-
- /**
- * Create command object for CommandPipe protocol
- *
- * @return AcknowledgeCommand
- */
- public function createCommand()
- {
- $command = new DisableNotificationWithExpireCommand();
- $command->setExpirationTimestamp($this->getValue('expiretime'));
- return $command;
- }
-}
diff --git a/modules/monitoring/application/forms/Command/MultiCommandFlagForm.php b/modules/monitoring/application/forms/Command/MultiCommandFlagForm.php
deleted file mode 100644
index e413848c8..000000000
--- a/modules/monitoring/application/forms/Command/MultiCommandFlagForm.php
+++ /dev/null
@@ -1,147 +0,0 @@
-flags = $flags;
- parent::__construct();
- $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
- }
-
- /**
- * Initialise the form values with the array of items to configure.
- *
- * @param mixed $items The items that will be edited with this form.
- */
- public function initFromItems($items)
- {
- $this->values = $this->valuesFromObjects($items);
- $this->buildForm();
- $this->populate($this->values);
- }
-
- /**
- * Return only the values that have been updated.
- */
- public function getChangedValues()
- {
- $values = $this->getValues();
- $changed = array();
- foreach ($values as $key => $value) {
- $oldKey = $key . self::OLD_VALUE_MARKER;
- if (array_key_exists($oldKey, $values)) {
- if ($values[$oldKey] !== $value) {
- $changed[$key] = $value;
- }
- }
- }
- return $changed;
- }
-
- private function valuesFromObjects($items)
- {
- $values = array();
- foreach ($items as $item) {
- foreach ($this->flags as $key => $unused) {
- if (isset($item->{$key})) {
- $value = $item->{$key};
- // convert strings
- if ($value === '1' || $value === '0') {
- $value = intval($value);
- }
- // init key with first value
- if (!array_key_exists($key, $values)) {
- $values[$key] = $value;
- continue;
- }
- // already a mixed state ?
- if ($values[$key] === 'unchanged') {
- continue;
- }
- // values differ?
- if ($values[$key] ^ $value) {
- $values[$key] = 'unchanged';
- }
- }
- }
- }
- $old = array();
- foreach ($values as $key => $value) {
- $old[$key . self::OLD_VALUE_MARKER] = $value;
- }
- return array_merge($values, $old);
- }
-
- public function buildCheckboxes()
- {
- $checkboxes = array();
- foreach ($this->flags as $flag => $description) {
- $checkboxes[] = new TriStateCheckbox(
- $flag,
- array(
- 'label' => $description,
- 'required' => true
- )
- );
- }
- return $checkboxes;
- }
-
- /**
- * Create the multi flag form
- *
- * @see Form::create()
- */
- public function create()
- {
- $this->setName('form_flag_configuration');
- foreach ($this->buildCheckboxes() as $checkbox) {
- $this->addElement($checkbox);
- $old = new Zend_Form_Element_Hidden($checkbox->getName() . self::OLD_VALUE_MARKER);
- $this->addElement($old);
- }
- $this->setSubmitLabel('Save Configuration');
- }
-}
diff --git a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php b/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php
deleted file mode 100644
index cb7ab90f1..000000000
--- a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php
+++ /dev/null
@@ -1,82 +0,0 @@
-addNote(
- t(
- 'This command is used to schedule the next check of hosts/services. Icinga will re-queue the '
- . 'check at the time you specify.'
- )
- );
-
- $this->addElement(
- new DateTimePicker(
- array(
- 'name' => 'checktime',
- 'label' => t('Check Time'),
- 'patterns' => $this->getValidDateTimeFormats(),
- 'value' => DateTimeFactory::create()->getTimestamp(),
- 'required' => !$this->getRequest()->getPost('forcecheck'),
- 'helptext' => t('Set the date/time when this check should be executed.')
- )
- )
- );
-
- $this->addElement(
- new Zend_Form_Element_Checkbox(
- array(
- 'name' => 'forcecheck',
- 'label' => t('Force Check'),
- 'value' => true,
- 'helptext' => t(
- 'If you select this option, Icinga will force a check regardless of both what time the '
- . 'scheduled check occurs and whether or not checks are enabled.'
- )
- )
- )
- );
-
- // TODO: As of the time of writing it's possible to set hosts AND services as affected by this command but
- // with children only makes sense on hosts
- if ($this->getWithChildren() === true) {
- $this->addNote(t('TODO: Help message when with children is enabled'));
- } else {
- $this->addNote(t('TODO: Help message when with children is disabled'));
- }
-
- $this->setSubmitLabel(t('Reschedule Check'));
-
- parent::create();
- }
-
- /**
- * Create the command object to schedule checks
- *
- * @return ScheduleCheckCommand
- */
- public function createCommand()
- {
- $command = new ScheduleCheckCommand(
- $this->getValue('checktime'),
- $this->getValue('forcecheck')
- );
- return $command->excludeHost($this->getWithChildren());
- }
-}
diff --git a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php
deleted file mode 100644
index 73ce2666c..000000000
--- a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php
+++ /dev/null
@@ -1,336 +0,0 @@
-setName('ScheduleDowntimeForm');
- }
-
- /**
- * Generate translated multi options based on type constants
- *
- * @return array
- */
- private function getDowntimeTypeOptions()
- {
- return array(
- self::TYPE_FIXED => t('Fixed'),
- self::TYPE_FLEXIBLE => t('Flexible')
- );
- }
-
- /**
- * Fetch all available downtimes from the database
- *
- * @return array
- */
- private function getCurrentDowntimes()
- {
- if (isset($this->downtimes)) {
- return $this->downtimes;
- }
-
- $cfg = $this->getConfiguration();
- $preferences = $this->getUserPreferences();
- $object = MonitoredObject::fromParams(Url::fromRequest()->getParams());
- $object->fetchDowntimes();
- $downtimes = $object->downtimes;
-/*
-
- $downtimes = Backend::createBackend($this->getRequest()->getParam('backend'))->select()
- ->from(
- 'downtime',
- array(
- 'host',
- 'service',
- 'downtime_start',
- 'downtime_scheduled_start_time',
- 'downtime_internal_downtime_id'
- )
- )->fetchAll();
-*/
- $options = array(
- '0' => 'No Triggered Downtime'
- );
- $dateFormat = $this->getView()->dateFormat();
- foreach ($downtimes as $downtime) {
- $label = sprintf(
- 'ID %s: %s%s Starting @ %s',
- $downtime->id,
- $object->host_name,
- $object instanceof Service ? ' (' . $object->service_description . ')' : '',
- $dateFormat->formatDateTime($downtime->scheduled_start)
- );
- $options[$downtime->id] = $label;
- }
- return $options;
- }
-
- /**
- * Set the downtimes displayed by this form (used for testing)
- *
- * @param array $downtimes list of strings
- */
- public function setCurrentDowntimes($downtimes)
- {
- $this->downtimes = $downtimes;
- }
-
- /**
- * Create the form's elements
- */
- protected function create()
- {
- $this->addNote(
- t(
- 'This command is used to schedule downtime for hosts/services. During the specified downtime, '
- . 'Icinga will not send notifications out about the affected objects. When the scheduled '
- . 'downtime expires, Icinga will send out notifications as it normally would. Scheduled '
- . 'downtimes are preserved across program shutdowns and restarts.'
- )
- );
-
- $this->addElement($this->createAuthorField());
-
- $this->addElement(
- 'textarea',
- 'comment',
- array(
- 'label' => t('Comment'),
- 'rows' => 4,
- 'cols' => 72,
- 'required' => true,
- 'helptext' => t(
- 'If you work with other administrators, you may find it useful to share information '
- . 'about a host or service that is having problems if more than one of you may be working on '
- . 'it. Make sure you enter a brief description of what you are doing.'
- )
- )
- );
-
- $this->addElement(
- 'select',
- 'triggered',
- array(
- 'label' => t('Triggered by'),
- 'required' => true,
- 'multiOptions' => $this->getCurrentDowntimes()
- )
- );
-
- $now = DateTimeFactory::create();
-
- $this->addElement(
- new DateTimePicker(
- array(
- 'name' => 'starttime',
- 'label' => t('Start Time'),
- 'value' => $now->getTimestamp(),
- 'patterns' => $this->getValidDateTimeFormats(),
- 'helptext' => t('Set the start date/time for the downtime.')
- )
- )
- );
- $this->addElement(
- new DateTimePicker(
- array(
- 'name' => 'endtime',
- 'label' => t('End Time'),
- 'value' => $now->getTimestamp() + 3600,
- 'patterns' => $this->getValidDateTimeFormats(),
- 'helptext' => t('Set the end date/time for the downtime.')
- )
- )
- );
-
- $this->addElement(
- 'select',
- 'type',
- array(
- 'label' => t('Downtime Type'),
- 'multiOptions' => $this->getDowntimeTypeOptions(),
- 'required' => true,
- 'validators' => array(
- array(
- 'InArray',
- true,
- array(
- array_keys($this->getDowntimeTypeOptions())
- )
- )
- ),
- 'helptext' => t(
- 'If you select the fixed option, the downtime will be in effect between the start and end '
- . 'times you specify whereas a flexible downtime starts when the service enters a non-OK state '
- . '(sometime between the start and end times you specified) and lasts as long as the duration '
- . 'of time you enter. The duration fields do not apply for fixed downtime.'
- )
- )
- );
- $this->enableAutoSubmit(array('type'));
-
- if ($this->getRequest()->getPost('type') === self::TYPE_FLEXIBLE) {
- $hoursText = new Zend_Form_Element_Text('hours');
- $hoursText->setLabel(t('Flexible Duration'));
- $hoursText->setAttrib('style', 'width: 40px;');
- $hoursText->setValue(1);
- $hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true));
- $hoursText->addDecorator(
- 'Callback',
- array(
- 'callback' => function () {
- return t('Hours');
- }
- )
- );
- $minutesText = new Zend_Form_Element_Text('minutes');
- $minutesText->setLabel(t('Minutes'));
- $minutesText->setAttrib('style', 'width: 40px;');
- $minutesText->setValue(0);
- $minutesText->removeDecorator('HtmlTag');
- $minutesText->removeDecorator('Label');
- $minutesText->addDecorator(
- 'Callback',
- array(
- 'callback' => function () {
- return t('Minutes');
- }
- )
- );
- $this->addElements(array($hoursText, $minutesText));
- $this->addNote(
- t(
- 'Enter here the duration of the downtime. Icinga will automatically delete the downtime '
- . 'after this time expired.'
- )
- );
- }
-
- // TODO: As of the time of writing it's possible to set hosts AND services as affected by this command but
- // with children only makes sense on hosts
- if ($this->getWithChildren() === true) {
- $this->addNote(t('TODO: Help message when with children is enabled'));
- } else {
- $this->addElement(
- 'select',
- 'childobjects',
- array(
- 'label' => t('Child Objects'),
- 'required' => true,
- 'multiOptions' => array(
- 0 => t('Do nothing with child objects'),
- 1 => t('Schedule triggered downtime for all child objects'),
- 2 => t('Schedule non-triggered downtime for all child objects')
- ),
- 'validators' => array(
- array(
- 'Digits',
- true
- ),
- array(
- 'InArray',
- true,
- array(
- array(0, 1, 2)
- )
- )
- )
- )
- );
- $this->addNote(t('TODO: Help message when with children is disabled'));
- }
-
- $this->setSubmitLabel(t('Schedule Downtime'));
-
- parent::create();
- }
-
- /**
- * Change validators at runtime
- *
- * @param array $data The user provided data that will go into validation
- *
- * @see Form::preValidation
- */
- protected function preValidation(array $data)
- {
- /*
- * Other values needed when downtime type change to flexible
- */
- if (isset($data['type']) && $data['type'] === self::TYPE_FLEXIBLE) {
- $greaterThanValidator = new Zend_Validate_GreaterThan(-1);
- $digitsValidator = new Zend_Validate_Digits();
-
- $hours = $this->getElement('hours');
- $hours->setRequired(true);
- $hours->addValidator($digitsValidator, true);
- $hours->addValidator($greaterThanValidator, true);
-
- $minutes = $this->getElement('minutes');
- $minutes->setRequired(true);
- $minutes->addValidator($digitsValidator, true);
- $minutes->addValidator($greaterThanValidator, true);
- }
- }
-
- /**
- * Create ScheduleDowntimeCommand object
- *
- * @return ScheduleDowntimeCommand
- */
- public function createCommand()
- {
- // TODO: Add support for host-/servicegroups and services only (#4588)
- $command = new ScheduleDowntimeCommand(
- $this->getValue('starttime'),
- $this->getValue('endtime'),
- new Comment(
- $this->getRequest()->getUser()->getUsername(),
- $this->getValue('comment')
- ),
- $this->getValue('type') === self::TYPE_FIXED,
- $this->getValue('hours') * 3600 + $this->getValue('minutes') * 60,
- $this->getValue('triggered')
- );
-
- return $command->includeChildren(
- $this->getWithChildren(),
- $this->getValue('childobjects') === 1
- );
- }
-}
diff --git a/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php
deleted file mode 100644
index 7f13034a0..000000000
--- a/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php
+++ /dev/null
@@ -1,113 +0,0 @@
-service = $service;
- return $this;
- }
-
- /**
- * Get the service to set in downtime
- *
- * @return Service
- */
- public function getService()
- {
- return $this->service;
- }
-
- /**
- * (non-PHPDoc)
- * @see \Zend_Form::init() For the method documentation.
- */
- public function init()
- {
- $this->setSubmitLabel(mt('monitoring', 'Schedule Service Downtime'));
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Web\Form::createElements() For the method documentation.
- */
- public function createElements(array $formData = array())
- {
- $this->addElement(
- 'note',
- 'command-info',
- array(
- 'value' => mt(
- 'monitoring',
- 'This command is used to schedule a service downtime. During the specified downtime,'
- . ' Icinga will not send notifications out about the service. When the scheduled downtime'
- . ' expires, Icinga will send out notifications for the service as it normally would.'
- . ' Scheduled downtimes are preserved across program shutdowns and restarts.'
- )
- )
- );
- parent::createElements($formData);
- return $this;
- }
-
- /**
- * Get the command which is to be sent to an Icinga instance
- *
- * @return ScheduleServiceDowntimeCommand
- */
- public function getCommand()
- {
- return new ScheduleServiceDowntimeCommand();
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Web\Form::onSuccess() For the method documentation.
- */
- public function onSuccess(Request $request)
- {
- $scheduleDowntime = $this->getCommand();
- $scheduleDowntime->setService($this->service);
- $scheduleDowntime->setComment($this->getElement('comment')->getValue());
- $scheduleDowntime->setAuthor($request->getUser());
- $scheduleDowntime->setStart($this->getElement('start')->getValue());
- $scheduleDowntime->setEnd($this->getElement('end')->getValue());
- if ($this->getElement('type')->getValue() === self::FLEXIBLE) {
- $scheduleDowntime->setFlexible();
- $scheduleDowntime->setDuration(
- (float) $this->getElement('hours')->getValue() * 3600
- + (float) $this->getElement('minutes')->getValue() * 60
- );
- }
- $this->getTransport($request)->send($scheduleDowntime);
- Notification::success(mt('monitoring', 'Scheduling service downtime..'));
- return true;
- }
-}
diff --git a/modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php b/modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php
deleted file mode 100644
index d7228ebdf..000000000
--- a/modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php
+++ /dev/null
@@ -1,169 +0,0 @@
-hostCommand = $hostCommand;
-
- if ($serviceCommand !== null) {
- $this->serviceCommand = $serviceCommand;
- }
- }
-
- /**
- * Setter for global commands
- *
- * @param string $hostOrGenericGlobalCommand Generic command or one for host
- * @param string $serviceGlobalCommand If any (leave blank if you need a global global)
- */
- public function setGlobalCommands($hostOrGenericGlobalCommand, $serviceGlobalCommand = null)
- {
- $this->globalCommands[] = $hostOrGenericGlobalCommand;
-
- if ($serviceGlobalCommand !== null) {
- $this->globalCommands[] = $serviceGlobalCommand;
- }
- }
-
- /**
- * Use an explicit value to send with command
- *
- * @param mixed $parameterValue
- */
- public function setParameterValue($parameterValue)
- {
- $this->parameterValue = $parameterValue;
- }
-
- /**
- * Use a form field to take the value from
- *
- * @param string $parameterName
- */
- public function setParameterName($parameterName)
- {
- $this->parameterName = $parameterName;
- }
-
- /**
- * Flag to ignore every objects
- *
- * @param bool $flag
- */
- public function setObjectIgnoreFlag($flag = true)
- {
- $this->ignoreObject = (bool) $flag;
- }
-
- /**
- *
- */
- protected function create()
- {
- if ($this->parameterName) {
- $field = new Zend_Form_Element_Hidden($this->parameterName);
- $value = $this->getRequest()->getParam($field->getName());
- $field->setValue($value);
- $this->addElement($field);
- }
- parent::create();
- }
-
- public function setRequest(Zend_Controller_Request_Abstract $request)
- {
- parent::setRequest($request);
-
- if ($this->globalCommand === true) {
- $this->setParameterName('global');
- }
- }
-
-
- /**
- * Create command object for CommandPipe protocol
- *
- * @return SingleArgumentCommand
- */
- public function createCommand()
- {
- $command = new SingleArgumentCommand();
-
- if ($this->parameterValue !== null) {
- $command->setValue($this->parameterValue);
- } else {
- $command->setValue($this->getValue($this->parameterName));
- }
-
- if ($this->provideGlobalCommand() == true) {
- $command->setGlobalCommands($this->globalCommands);
- $this->ignoreObject = true;
- } else {
- $command->setCommand($this->hostCommand, $this->serviceCommand);
- }
-
- $command->setObjectIgnoreFlag($this->ignoreObject);
-
- return $command;
- }
-}
diff --git a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php b/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php
deleted file mode 100644
index c2c9151f3..000000000
--- a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php
+++ /dev/null
@@ -1,177 +0,0 @@
- array(
- 0 => t('UP'),
- 1 => t('DOWN'),
- 2 => t('UNREACHABLE')
- ),
- self::TYPE_SERVICE => array(
- 0 => t('OK'),
- 1 => t('WARNING'),
- 2 => t('CRITICAL'),
- 3 => t('UNKNOWN')
- )
- );
- }
-
- parent::init();
- }
-
- /**
- * Setter for type
- *
- * @param string $type
- */
- public function setType($type)
- {
- $this->type = $type;
- }
-
- /**
- * Getter for type
- *
- * @return string
- */
- public function getType()
- {
- return $this->type;
- }
-
- /**
- * Return array of options
- *
- * @return array
- * @throws \Icinga\Exception\ProgrammingError
- */
- public function getOptions()
- {
- if (in_array($this->getType(), array(self::TYPE_HOST, self::TYPE_SERVICE)) === false) {
- throw new ProgrammingError('Type is not valid');
- }
-
- return self::$options[$this->getType()];
- }
-
- /**
- * Create the form's elements
- */
- protected function create()
- {
- $this->setName('form_submit_passive_checkresult');
-
- $this->addNote(
- t(
- 'This command is used to submit a passive check result for particular hosts/services. It is '
- . 'particularly useful for resetting security-related objects to OK states once they have been '
- . 'dealt with.'
- )
- );
-
- $this->addElement(
- 'select',
- 'pluginstate',
- array(
- 'label' => t('Check Result'),
- 'multiOptions' => $this->getOptions(),
- 'required' => true,
- 'validators' => array(
- array(
- 'Digits',
- true
- ),
- array(
- 'InArray',
- true,
- array(
- array_keys($this->getOptions())
- )
- )
- ),
- 'helptext' => t('Set the state which should be send to Icinga for this objects.')
- )
- );
-
- $this->addElement(
- 'textarea',
- 'checkoutput',
- array(
- 'label' => t('Check Output'),
- 'rows' => 2,
- 'cols' => 72,
- 'required' => true,
- 'helptext' => t('Fill in the check output string which should be send to Icinga.')
- )
- );
-
- $this->addElement(
- 'textarea',
- 'performancedata',
- array(
- 'label' => t('Performance Data'),
- 'rows' => 2,
- 'cols' => 72,
- 'helptext' => t('Fill in the performance data string which should be send to Icinga.')
- )
- );
-
- $this->setSubmitLabel(t('Submit Passive Check Result'));
-
- parent::create();
- }
-
- /**
- * Create the submit passive checkresult command object
- *
- * @return SubmitPassiveCheckresultCommand
- */
- public function createCommand()
- {
- return new SubmitPassiveCheckresultCommand(
- $this->getValue('pluginstate'),
- $this->getValue('checkoutput'),
- $this->getValue('performancedata')
- );
- }
-}
diff --git a/modules/monitoring/application/forms/Command/WithChildrenCommandForm.php b/modules/monitoring/application/forms/Command/WithChildrenCommandForm.php
deleted file mode 100644
index 5ae69173e..000000000
--- a/modules/monitoring/application/forms/Command/WithChildrenCommandForm.php
+++ /dev/null
@@ -1,37 +0,0 @@
-withChildren = $flag;
- }
-
- /**
- * Getter for withChildren
- *
- * @return bool
- */
- public function getWithChildren()
- {
- return $this->withChildren;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php b/modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php
deleted file mode 100644
index 641a2ae73..000000000
--- a/modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php
+++ /dev/null
@@ -1,164 +0,0 @@
-expireTime = $expire;
- $this->comment = $comment;
- $this->notify = $notify;
- $this->sticky = $sticky;
- }
-
- /**
- * Set the time when this acknowledgement should expire
- *
- * @param int $expireTime The time as UNIX timestamp or -1 if it shouldn't expire
- *
- * @return self
- */
- public function setExpire($expireTime)
- {
- $this->expireTime = (int) $expireTime;
- return $this;
- }
-
- /**
- * Set the comment for this acknowledgement
- *
- * @param Comment $comment
- *
- * @return self
- */
- public function setComment(Comment $comment)
- {
- $this->comment = $comment;
- return $this;
- }
-
- /**
- * Set whether the notify flag of this acknowledgment should be set
- *
- * @param bool $state
- *
- * @return self
- */
- public function setNotify($state)
- {
- $this->notify = (bool) $state;
- return $this;
- }
-
- /**
- * Set whether this acknowledgement is of type sticky
- *
- * @param bool $state
- *
- * @return self
- */
- public function setSticky($state)
- {
- $this->sticky = (bool) $state;
- return $this;
- }
-
- /**
- * Return this command's parameters properly arranged in an array
- *
- * @return array
- * @see Command::getArguments()
- */
- public function getArguments()
- {
- $parameters = array_merge(
- array(
- $this->sticky ? '2' : '0',
- $this->notify ? '1' : '0'
- ),
- $this->comment->getArguments()
- );
-
- if ($this->expireTime > -1) {
- array_splice($parameters, 3, 0, array($this->expireTime));
- }
-
- return $parameters;
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- * @see Command::getHostCommand()
- */
- public function getHostCommand($hostname)
- {
- $parameters = $this->getArguments();
- return sprintf('ACKNOWLEDGE_HOST_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '')
- . implode(';', array_merge(array($hostname), $parameters));
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- * @see Command::getServiceCommand()
- */
- public function getServiceCommand($hostname, $servicename)
- {
- $parameters = $this->getArguments();
- return sprintf('ACKNOWLEDGE_SVC_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '')
- . implode(';', array_merge(array($hostname, $servicename), $parameters));
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/AddCommentCommand.php b/modules/monitoring/library/Monitoring/Command/AddCommentCommand.php
deleted file mode 100644
index 0464d5cb2..000000000
--- a/modules/monitoring/library/Monitoring/Command/AddCommentCommand.php
+++ /dev/null
@@ -1,79 +0,0 @@
-comment = $comment;
- }
-
- /**
- * Set the comment for this command
- *
- * @param Comment $comment
- *
- * @return self
- */
- public function setComment(Comment $comment)
- {
- $this->comment = $comment;
- return $this;
- }
-
- public function getArguments()
- {
- return $this->comment->getArguments();
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- * @see Command::getHostCommand()
- */
- public function getHostCommand($hostname)
- {
- return sprintf('ADD_HOST_COMMENT;%s;', $hostname) . implode(';', $this->getArguments());
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- * @see Command::getServiceCommand()
- */
- public function getServiceCommand($hostname, $servicename)
- {
- return sprintf('ADD_SVC_COMMENT;%s;%s;', $hostname, $servicename)
- . implode(';', $this->getArguments());
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/CommandPipe.php b/modules/monitoring/library/Monitoring/Command/CommandPipe.php
deleted file mode 100644
index 8d149dd20..000000000
--- a/modules/monitoring/library/Monitoring/Command/CommandPipe.php
+++ /dev/null
@@ -1,603 +0,0 @@
-getTransportForConfiguration($config);
- $this->name = $config->name;
- }
-
- /**
- * Setup the @see Icinga\Protocol\Commandpipe\Transport.php class that will be used for accessing the command pipe
- *
- * Currently this method uses SecureShell when a host is given, otherwise it assumes the pipe is accessible
- * via the machines filesystem
- *
- * @param \Zend_Config $config The configuration as defined in the instances.ini
- */
- private function getTransportForConfiguration(\Zend_Config $config)
- {
- if (isset($config->host)) {
- $this->transport = new SecureShell();
- $this->transport->setEndpoint($config);
- } else {
- $this->transport = new LocalPipe();
- $this->transport->setEndpoint($config);
- }
- }
-
- /**
- * Send the command string $command to the icinga pipe
- *
- * This method just delegates the send command to the underlying transport
- *
- * @param String $command The command string to send, without the timestamp
- */
- public function send($command)
- {
- $this->transport->send($this->escape($command));
- }
-
- /**
- * Return the given command string with escaped newlines
- *
- * @param string $command The command string to escape
- *
- * @return string The escaped command string
- */
- public function escape($command)
- {
- return str_replace(array("\r", "\n"), array('\r', '\n'), $command);
- }
-
- /**
- * Send a command to the icinga pipe
- *
- * @param Command $command
- * @param array $objects
- */
- public function sendCommand(Command $command, array $objects = array())
- {
- if ($command->provideGlobalCommand() === true) {
- $this->send($command->getGlobalCommand());
- } else {
- foreach ($objects as $object) {
- $objectType = $this->getObjectType($object);
- if ($objectType === self::TYPE_SERVICE) {
- $this->send($command->getServiceCommand($object->host_name, $object->service_description));
- } else {
- $this->send($command->getHostCommand($object->host_name));
- }
- }
- }
- }
-
- /**
- * Remove the acknowledgements of the provided objects
- *
- * @param array $objects An array of mixed service and host objects whose acknowledgments will be removed
- */
- public function removeAcknowledge($objects)
- {
- foreach ($objects as $object) {
- if (isset($object->service_description)) {
- $this->send("REMOVE_SVC_ACKNOWLEDGEMENT;$object->host_name;$object->service_description");
- } else {
- $this->send("REMOVE_HOST_ACKNOWLEDGEMENT;$object->host_name");
- }
- }
- }
-
- /**
- * Removes the submitted comments
- *
- * @param array $objectsOrComments An array of hosts and services (to remove all their comments)
- * or single comment objects to remove
- */
- public function removeComment($objectsOrComments)
- {
- foreach ($objectsOrComments as $object) {
- if (isset($object->comment_id)) {
- if (isset($object->service_description)) {
- $type = "SERVICE_COMMENT";
- } else {
- $type = "HOST_COMMENT";
- }
- $this->send("DEL_{$type};" . intval($object->comment_id));
- } else {
- if (isset($object->service_description)) {
- $type = "SERVICE_COMMENT";
- } else {
- $type = "HOST_COMMENT";
- }
- $cmd = "DEL_ALL_{$type}S;" . $object->host_name;
- if ($type == "SERVICE_COMMENT") {
- $cmd .= ";" . $object->service_description;
- }
- $this->send($cmd);
- }
- }
- }
-
- /**
- * Globally enable notifications for this instance
- *
- */
- public function enableGlobalNotifications()
- {
- $this->send("ENABLE_NOTIFICATIONS");
- }
-
- /**
- * Globally disable notifications for this instance
- *
- */
- public function disableGlobalNotifications()
- {
- $this->send("DISABLE_NOTIFICATIONS");
- }
-
- /**
- * Return the object type of the provided object (TYPE_SERVICE or TYPE_HOST)
- *
- * @param $object The object to identify
- * @return string TYPE_SERVICE or TYPE_HOST
- */
- private function getObjectType($object)
- {
- //@TODO: This must be refactored once more commands are supported
- if (isset($object->service_description)) {
- return self::TYPE_SERVICE;
- }
- return self::TYPE_HOST;
- }
-
- /**
- * Remove downtimes for objects
- *
- * @param array $objects An array containing hosts, service or downtime objects
- * @param int $starttime An optional starttime to use for the DEL_DOWNTIME_BY_HOST_NAME command
- */
- public function removeDowntime($objects, $starttime = 0)
- {
- foreach ($objects as $object) {
- $type = $this->getObjectType($object);
- if (isset($object->downtime_id)) {
- $this->send("DEL_" . $type . "_DOWNTIME;" . $object->downtime_id);
- continue;
- }
- $cmd = "DEL_DOWNTIME_BY_HOST_NAME;" . $object->host_name;
- if ($type == self::TYPE_SERVICE) {
- $cmd .= ";" . $object->service_description;
- }
- if ($starttime != 0) {
- $cmd .= ";" . $starttime;
- }
- $this->send($cmd);
- }
- }
-
- /**
- * Restart the icinga instance
- *
- */
- public function restartIcinga()
- {
- $this->send("RESTART_PROCESS");
- }
-
- /**
- * Modify monitoring flags for the provided objects
- *
- * @param array $objects An arry of service and/or host objects to modify
- * @param PropertyModifier $flags The Monitoring attributes to modify
- */
- public function setMonitoringProperties($objects, PropertyModifier $flags)
- {
- foreach ($objects as $object) {
- $type = $this->getObjectType($object);
- $formatArray = $flags->getFormatString($type);
- foreach ($formatArray as $format) {
- $format .= ";"
- . $object->host_name
- . ($type == self::TYPE_SERVICE ? ";" . $object->service_description : "");
- $this->send($format);
- }
- }
- }
-
- /**
- * Enable active checks for all provided objects
- *
- * @param array $objects An array containing services and hosts to enable active checks for
- */
- public function enableActiveChecks($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::ACTIVE => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Disable active checks for all provided objects
- *
- * @param array $objects An array containing services and hosts to disable active checks
- */
- public function disableActiveChecks($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::ACTIVE => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Enable passive checks for all provided objects
- *
- * @param array $objects An array containing services and hosts to enable passive checks for
- */
- public function enablePassiveChecks($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::PASSIVE => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Enable passive checks for all provided objects
- *
- * @param array $objects An array containing services and hosts to enable passive checks for
- */
- public function disablePassiveChecks($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::PASSIVE => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Enable flap detection for all provided objects
- *
- * @param array $objects An array containing services and hosts to enable flap detection
- *
- */
- public function enableFlappingDetection($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::FLAPPING => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Disable flap detection for all provided objects
- *
- * @param array $objects An array containing services and hosts to disable flap detection
- *
- */
- public function disableFlappingDetection($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::FLAPPING => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Enable notifications for all provided objects
- *
- * @param array $objects An array containing services and hosts to enable notification
- *
- */
- public function enableNotifications($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::NOTIFICATIONS => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Disable flap detection for all provided objects
- *
- * @param array $objects An array containing services and hosts to disable notifications
- *
- */
- public function disableNotifications($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::NOTIFICATIONS => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Enable freshness checks for all provided objects
- *
- * @param array $objects An array of hosts and/or services
- */
- public function enableFreshnessChecks($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::FRESHNESS => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Disable freshness checks for all provided objects
- *
- * @param array $objects An array of hosts and/or services
- */
- public function disableFreshnessChecks($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::FRESHNESS => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Enable event handler for all provided objects
- *
- * @param array $objects An array of hosts and/or services
- */
- public function enableEventHandler($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::EVENTHANDLER => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Disable event handler for all provided objects
- *
- * @param array $objects An array of hosts and/or services
- */
- public function disableEventHandler($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::EVENTHANDLER => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Enable performance data parsing for all provided objects
- *
- * @param array $objects An array of hosts and/or services
- */
- public function enablePerfdata($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::PERFDATA => PropertyModifier::STATE_ENABLE
- )
- )
- );
- }
-
- /**
- * Disable performance data parsing for all provided objects
- *
- * @param array $objects An array of hosts and/or services
- */
- public function disablePerfdata($objects)
- {
- $this->setMonitoringProperties(
- $objects,
- new PropertyModifier(
- array(
- PropertyModifier::PERFDATA => PropertyModifier::STATE_DISABLE
- )
- )
- );
- }
-
- /**
- * Disable notifications for all services of the provided hosts
- *
- * @param array $objects An array of hosts
- */
- public function disableNotificationsForServices($objects)
- {
- foreach ($objects as $host) {
- $msg = 'DISABLE_HOST_SVC_NOTIFICATIONS;'.$host->host_name;
- $this->send($msg);
- }
- }
-
- /**
- * Enable notifications for all services of the provided hosts
- *
- * @param array $objects An array of hosts
- */
- public function enableNotificationsForServices($objects)
- {
- foreach ($objects as $host) {
- $msg = 'ENABLE_HOST_SVC_NOTIFICATIONS;'.$host->host_name;
- $this->send($msg);
- }
- }
-
- /**
- * Disable active checks for all services of the provided hosts
- *
- * @param array $objects An array of hosts
- */
- public function disableActiveChecksWithChildren($objects)
- {
- foreach ($objects as $host) {
- $msg = 'DISABLE_HOST_SVC_CHECKS;'.$host->host_name;
- $this->send($msg);
- }
- }
-
- /**
- * Enable active checks for all services of the provided hosts
- *
- * @param array $objects An array of hosts
- */
- public function enableActiveChecksWithChildren($objects)
- {
- foreach ($objects as $host) {
- $msg = 'ENABLE_HOST_SVC_CHECKS;'.$host->host_name;
- $this->send($msg);
- }
- }
-
- /**
- * Reset modified attributes for all provided objects
- *
- * @param array $objects An array of hosts and services
- */
- public function resetAttributes($objects)
- {
- foreach ($objects as $object) {
- $type = $this->getObjectType($object);
- if ($type === self::TYPE_SERVICE) {
- $this->send('CHANGE_SVC_MODATTR;'.$object->host_name.';'.$object->service_description.';0');
- } else {
- $this->send('CHANGE_HOST_MODATTR;'.$object->host_name.';0');
- }
- }
- }
-
- /**
- * Return the transport handler that handles actual sending of commands
- *
- * @return Transport
- */
- public function getTransport()
- {
- return $this->transport;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Comment.php b/modules/monitoring/library/Monitoring/Command/Comment.php
deleted file mode 100644
index 2b8caf52b..000000000
--- a/modules/monitoring/library/Monitoring/Command/Comment.php
+++ /dev/null
@@ -1,61 +0,0 @@
-author = $author;
- $this->content = $content;
- $this->persistent = $persistent;
- }
-
- /**
- * Return this comment's properties as list of command parameters
- *
- * @param bool $ignorePersistentFlag Whether the persistent flag should be included or not
- * @return array
- */
- public function getArguments($ignorePersistentFlag = false)
- {
- if ($ignorePersistentFlag) {
- return array($this->author, $this->content);
- } else {
- return array($this->persistent ? '1' : '0', $this->author, $this->content);
- }
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php
deleted file mode 100644
index 5d56011ae..000000000
--- a/modules/monitoring/library/Monitoring/Command/Common/AddCommentCommand.php
+++ /dev/null
@@ -1,50 +0,0 @@
-persistent = $persistent;
- return $this;
- }
-
- /**
- * Is the comment persistent?
- *
- * @return bool
- */
- public function getPersistent()
- {
- return $this->persistent;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php b/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php
deleted file mode 100644
index 8727c237b..000000000
--- a/modules/monitoring/library/Monitoring/Command/Common/ObjectCommand.php
+++ /dev/null
@@ -1,62 +0,0 @@
-assertOneOf($this->allowedObjects);
- $this->object = $object;
- return $this;
- }
-
- /**
- * Get the involved object
- *
- * @return MonitoredObject
- */
- public function getObject()
- {
- return $this->object;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php
deleted file mode 100644
index 0afb4087a..000000000
--- a/modules/monitoring/library/Monitoring/Command/Common/ScheduleDowntimeCommand.php
+++ /dev/null
@@ -1,193 +0,0 @@
-start = $start;
- return $this;
- }
-
- /**
- * Get the date and time when the downtime should start
- *
- * @return DateTime
- */
- public function getStart()
- {
- return $this->start;
- }
-
- /**
- * Set the date and time when the downtime should end
- *
- * @param DateTime $end
- *
- * @return $this
- */
- public function setEnd(DateTime $end)
- {
- $this->end = $end;
- return $this;
- }
-
- /**
- * Get the date and time when the downtime should end
- *
- * @return DateTime
- */
- public function getEnd()
- {
- return $this->end;
- }
-
- /**
- * Set whether is flexible or fixed
- *
- * @param boolean $flexible
- *
- * @return $this
- */
- public function setFlexible($flexible = true)
- {
- $this->flexible = (bool) $flexible;
- return $this;
- }
-
- /**
- * Is the downtime flexible?
- *
- * @return boolean
- */
- public function getFlexible()
- {
- return $this->flexible;
- }
-
- /**
- * Set the ID of the downtime which triggers this downtime
- *
- * @param int $triggerId
- *
- * @return $this
- */
- public function setTriggerId($triggerId)
- {
- $this->triggerId = (int) $triggerId;
- return $this;
- }
-
- /**
- * Get the ID of the downtime which triggers this downtime
- *
- * @return int|null
- */
- public function getTriggerId()
- {
- return $this->triggerId;
- }
-
- /**
- * Set the duration in seconds the downtime must last if it's a flexible downtime
- *
- * @param int $duration
- *
- * @return $this
- */
- public function setDuration($duration)
- {
- $this->duration = (int) $duration;
- return $this;
- }
-
- /**
- * Get the duration in seconds the downtime must last if it's a flexible downtime
- *
- * @return int|null
- */
- public function getDuration()
- {
- return $this->duration;
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation.
- */
- public function getCommandString()
- {
- return sprintf(
- '%u;%u;%u;%u;%u;%s',
- $this->start->getTimestamp(),
- $this->end->getTimestamp(),
- ! $this->flexible,
- $this->triggerId,
- $this->duration,
- parent::getCommandString()
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php b/modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php
deleted file mode 100644
index 7002cd1e4..000000000
--- a/modules/monitoring/library/Monitoring/Command/Common/ToggleFeature.php
+++ /dev/null
@@ -1,42 +0,0 @@
-enable = true;
- return $this;
- }
-
- /**
- * Disable the feature
- *
- * @return $this
- */
- public function disable()
- {
- $this->enable = false;
- return $this;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php
deleted file mode 100644
index c913e5bd3..000000000
--- a/modules/monitoring/library/Monitoring/Command/Common/WithCommentCommand.php
+++ /dev/null
@@ -1,71 +0,0 @@
-author = (string) $author;
- return $this;
- }
-
- /**
- * Get the author
- *
- * @return string
- */
- public function getAuthor()
- {
- return $this->author;
- }
-
- /**
- * Set the comment
- *
- * @param string $comment
- *
- * @return $this
- */
- public function setComment($comment)
- {
- $this->comment = (string) $comment;
- return $this;
- }
-
- /**
- * Get the comment
- *
- * @return string
- */
- public function getComment()
- {
- return $this->comment;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php b/modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php
deleted file mode 100644
index 21cf22520..000000000
--- a/modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php
+++ /dev/null
@@ -1,139 +0,0 @@
-comment = $comment;
- $this->forced = $forced;
- $this->broadcast = $broadcast;
- }
-
- /**
- * Set the comment for this notification
- *
- * @param Comment $comment
- *
- * @return self
- */
- public function setComment(Comment $comment)
- {
- $this->comment = $comment;
- return $this;
- }
-
- /**
- * Set whether this notification is forced
- *
- * @param bool $state
- *
- * @return self
- */
- public function setForced($state)
- {
- $this->forced = (bool) $state;
- return $this;
- }
-
- /**
- * Set whether this notification is sent to all contacts
- *
- * @param bool $state
- *
- * @return self
- */
- public function setBroadcast($state)
- {
- $this->broadcast = (bool) $state;
- return $this;
- }
-
- /**
- * Return this command's parameters properly arranged in an array
- *
- * @return array
- * @see Command::getArguments()
- */
- public function getArguments()
- {
- $options = 0;
- if ($this->forced) {
- $options |= 2;
- }
- if ($this->broadcast) {
- $options |= 1;
- }
- return array_merge(array($options), $this->comment->getArguments(true));
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- * @see Command::getHostCommand()
- */
- public function getHostCommand($hostname)
- {
- return 'SEND_CUSTOM_HOST_NOTIFICATION;' . implode(';', array_merge(array($hostname), $this->getArguments()));
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- * @see Command::getServiceCommand()
- */
- public function getServiceCommand($hostname, $servicename)
- {
- return 'SEND_CUSTOM_SVC_NOTIFICATION;' . implode(
- ';',
- array_merge(
- array($hostname, $servicename),
- $this->getArguments()
- )
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php b/modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php
deleted file mode 100644
index 7f8dcf749..000000000
--- a/modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php
+++ /dev/null
@@ -1,87 +0,0 @@
-delay = $delay;
- }
-
- /**
- * Set how long notifications should be delayed
- *
- * @param int $seconds In seconds
- *
- * @return self
- */
- public function setDelay($seconds)
- {
- $this->delay = (int) $seconds;
- return $this;
- }
-
- /**
- * Return this command's parameters properly arranged in an array
- *
- * @return array
- * @see Command::getArguments()
- */
- public function getArguments()
- {
- return array($this->delay);
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- * @see Command::getHostCommand()
- */
- public function getHostCommand($hostname)
- {
- return 'DELAY_HOST_NOTIFICATION;' . implode(';', array_merge(array($hostname), $this->getArguments()));
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- * @see Command::getServiceCommand()
- */
- public function getServiceCommand($hostname, $servicename)
- {
- return 'DELAY_SVC_NOTIFICATION;' . implode(
- ';',
- array_merge(
- array($hostname, $servicename),
- $this->getArguments()
- )
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php b/modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php
deleted file mode 100644
index d6fb6322a..000000000
--- a/modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php
+++ /dev/null
@@ -1,92 +0,0 @@
-globalCommand = true;
- }
-
- /**
- * Setter for expiration timestamp
- *
- * @param integer $timestamp
- */
- public function setExpirationTimestamp($timestamp)
- {
- $this->expirationTimestamp = $timestamp;
- }
-
- /**
- * Return this command's arguments in the order expected by the actual command definition
- *
- * @return array
- */
- public function getArguments()
- {
- return array($this->expirationTimestamp);
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- * @throws ProgrammingError
- *
- * @return string The string representation of the command
- */
- public function getHostCommand($hostname)
- {
- throw new ProgrammingError('This is not supported for single objects');
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- * @throws ProgrammingError
- * @return string The string representation of the command#
- */
- public function getServiceCommand($hostname, $servicename)
- {
- throw new ProgrammingError('This is not supported for single objects');
- }
-
- /**
- * Create a global command
- *
- * @param string $instance
- *
- * @return string
- */
- public function getGlobalCommand($instance = null)
- {
- return sprintf(
- 'DISABLE_NOTIFICATIONS_EXPIRE_TIME;%d;%s',
- time(),
- implode(';', $this->getArguments())
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php b/modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php
deleted file mode 100644
index 662a156e9..000000000
--- a/modules/monitoring/library/Monitoring/Command/Exception/InvalidCommandException.php
+++ /dev/null
@@ -1,12 +0,0 @@
- self::STATE_KEEP,
- self::ACTIVE => self::STATE_KEEP,
- self::PASSIVE => self::STATE_KEEP,
- self::NOTIFICATIONS => self::STATE_KEEP,
- self::FRESHNESS => self::STATE_KEEP,
- self::EVENTHANDLER => self::STATE_KEEP
- );
-
- /**
- * Create a new PropertyModified object using the given flags
- *
- * @param array $flags Flags to enable/disable/keep different monitoring attributes
- */
- public function __construct(array $flags)
- {
- foreach ($flags as $type => $value) {
- if (isset($this->flags[$type])) {
- $this->flags[$type] = $value;
- }
- }
- }
-
- /**
- * Return this object as a template for the given object type
- *
- * @param $type Either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE
- * @return array An array of external command templates for the given type representing the containers state
- */
- public function getFormatString($type)
- {
- $cmd = array();
- foreach ($this->flags as $cmdTemplate => $setting) {
- if ($setting == self::STATE_KEEP) {
- continue;
- }
- $commandString = ($setting == self::STATE_ENABLE ? "ENABLE_" : "DISABLE_");
- $targetString = $type;
- if ($type == CommandPipe::TYPE_SERVICE && $cmdTemplate == self::FRESHNESS) {
- // the external command definition is inconsistent here..
- $targetString = "SERVICE";
- }
- $commandString .= sprintf($cmdTemplate, $targetString);
- $cmd[] = $commandString;
- }
- return $cmd;
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php b/modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php
deleted file mode 100644
index 7908e637d..000000000
--- a/modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php
+++ /dev/null
@@ -1,108 +0,0 @@
-checkTime = $checkTime;
- $this->forced = $forced;
- }
-
- /**
- * Set when to schedule this check
- *
- * @param int $checkTime The time as UNIX timestamp
- *
- * @return self
- */
- public function setCheckTime($checkTime)
- {
- $this->checkTime = (int) $checkTime;
- return $this;
- }
-
- /**
- * Set whether this check is forced
- *
- * @param bool $state
- *
- * @return self
- */
- public function setForced($state)
- {
- $this->forced = (bool) $state;
- return $this;
- }
-
- /**
- * Return this command's parameters properly arranged in an array
- *
- * @return array
- * @see Command::getArguments()
- */
- public function getArguments()
- {
- return array($this->checkTime);
- }
-
- /**
- * Return the command as a string for the given host or all of it's services
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- * @see Command::getHostCommand()
- */
- public function getHostCommand($hostname)
- {
- return sprintf(
- 'SCHEDULE%s_HOST_%s;',
- $this->forced ? '_FORCED' : '',
- $this->onlyServices ? 'SVC_CHECKS' : 'CHECK'
- ) . implode(';', array_merge(array($hostname), $this->getArguments()));
- }
-
- /**
- * Return the command as a string for the given service
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- * @see Command::getServiceCommand()
- */
- public function getServiceCommand($hostname, $servicename)
- {
- return sprintf('SCHEDULE%s_SVC_CHECK;', $this->forced ? '_FORCED' : '')
- . implode(';', array_merge(array($hostname, $servicename), $this->getArguments()));
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php b/modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php
deleted file mode 100644
index 926084bbf..000000000
--- a/modules/monitoring/library/Monitoring/Command/Service/AddServiceComment.php
+++ /dev/null
@@ -1,34 +0,0 @@
-serivce = (string) $service;
- }
-
- public function getCommand()
- {
- return sprintf(
- 'ADD_SVC_COMMENT;%s;%u;%s',
- $this->host,
- $this->persistent,
- parent::getCommand()
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php
deleted file mode 100644
index 4697be36b..000000000
--- a/modules/monitoring/library/Monitoring/Command/Service/ScheduleServiceDowntimeCommand.php
+++ /dev/null
@@ -1,59 +0,0 @@
-service = $service;
- return $this;
- }
-
- /**
- * Get the service to set in downtime
- *
- * @return Service
- */
- public function getService()
- {
- return $this->service;
- }
-
- /**
- * (non-PHPDoc)
- * @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation.
- */
- public function getCommandString()
- {
- return sprintf(
- '%s;%s;%s;%s',
- 'SCHEDULE_SVC_DOWNTIME',
- $this->service->getHostName(),
- $this->service->getName(),
- parent::getCommandString()
- );
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php b/modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php
deleted file mode 100644
index 27fecd48d..000000000
--- a/modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php
+++ /dev/null
@@ -1,183 +0,0 @@
-value = $value;
- }
-
- /**
- * Setter for command names
- *
- * @param string $hostCommand
- * @param string $serviceCommand
- */
- public function setCommand($hostCommand, $serviceCommand)
- {
- $this->hostCommand = $hostCommand;
- $this->serviceCommand = $serviceCommand;
- }
-
- /**
- * Set a bunch of global commands
- *
- * @param array $commands One or more commands to control global parameters
- */
- public function setGlobalCommands(array $commands)
- {
- $this->globalCommands = $commands;
- $this->globalCommand = true;
- }
-
- /**
- * Ignore object values upon command creation
- *
- * @param bool $flag
- */
- public function setObjectIgnoreFlag($flag = true)
- {
- $this->ignoreObject = (bool) $flag;
- }
-
- /**
- * Return this command's arguments in the order expected by the actual command definition
- *
- * @return array
- */
- public function getArguments()
- {
- if ($this->value !== null) {
- return array($this->value);
- } else {
- return array();
- }
- }
-
- /**
- * Build the argument string based on objects and arguments
- *
- * @param array $objectNames
- *
- * @return string String to append to command
- */
- private function getArgumentString(array $objectNames)
- {
- $data = array();
- if ($this->ignoreObject === true) {
- $data = $this->getArguments();
- } else {
- $data = array_merge($objectNames, $this->getArguments());
- }
-
- return implode(';', $data);
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- */
- public function getHostCommand($hostname)
- {
- return strtoupper($this->hostCommand). ';' . $this->getArgumentString(array($hostname));
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- */
- public function getServiceCommand($hostname, $servicename)
- {
- return strtoupper($this->serviceCommand)
- . ';'
- . $this->getArgumentString(array($hostname, $servicename));
- }
-
- /**
- * Getter for global command if configured
- *
- * @param string $instance
- *
- * @throws ProgrammingError
- * @return string
- */
- public function getGlobalCommand($instance = null)
- {
- if (!count($this->globalCommands)) {
- // This throws exception for us that globalCommand
- // is not implemented properly
- parent::getGlobalCommand();
- }
-
- if ($this->value === 'host') {
- return strtoupper($this->globalCommands[0]);
- }
-
- if ($this->value === 'service') {
- if (count($this->globalCommands) < 2) {
- throw new ProgrammingError('If use global values you need at least 2 global commands');
- }
-
- return strtoupper($this->globalCommands[1]);
- }
-
- return strtoupper(implode(';', $this->globalCommands));
- }
-}
diff --git a/modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php b/modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php
deleted file mode 100644
index 262987de1..000000000
--- a/modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php
+++ /dev/null
@@ -1,133 +0,0 @@
-state = $state;
- $this->output = $output;
- $this->perfData = $perfData;
- }
-
- /**
- * Set which plugin-state is being reported
- *
- * @param int $state
- *
- * @return self
- */
- public function setState($state)
- {
- $this->state = (int) $state;
- return $this;
- }
-
- /**
- * Set the plugin-output to include in the result
- *
- * @param string $output
- *
- * @return self
- */
- public function setOutput($output)
- {
- $this->output = (string) $output;
- return $this;
- }
-
- /**
- * Set the performance data to include in the result
- *
- * @param string $perfData
- * @return self
- */
- public function setPerformanceData($perfData)
- {
- $this->perfData = (string) $perfData;
- return $this;
- }
-
- /**
- * Return this command's parameters properly arranged in an array
- *
- * @return array
- * @see Command::getArguments()
- */
- public function getArguments()
- {
- return array(
- $this->state,
- $this->perfData ? $this->output . '|' . $this->perfData : $this->output
- );
- }
-
- /**
- * Return the command as a string with the given host being inserted
- *
- * @param string $hostname The name of the host to insert
- *
- * @return string The string representation of the command
- * @see Command::getHostCommand()
- */
- public function getHostCommand($hostname)
- {
- return 'PROCESS_HOST_CHECK_RESULT;' . implode(';', array_merge(array($hostname), $this->getArguments()));
- }
-
- /**
- * Return the command as a string with the given host and service being inserted
- *
- * @param string $hostname The name of the host to insert
- * @param string $servicename The name of the service to insert
- *
- * @return string The string representation of the command
- * @see Command::getServiceCommand()
- */
- public function getServiceCommand($hostname, $servicename)
- {
- return 'PROCESS_SERVICE_CHECK_RESULT;' . implode(
- ';',
- array_merge(
- array($hostname, $servicename),
- $this->getArguments()
- )
- );
- }
-}
From 1d54c7f8360405c9b707d5201612b8a0a25fa241 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 10:42:48 +0200
Subject: [PATCH 217/277] monitoring/commands: Support
'DISABLE_NOTIFICATIONS_EXPIRE_TIME'
refs #6593
---
.../Instance/DisableNotificationsExpireCommandForm.php | 2 +-
.../Renderer/IcingaCommandFileCommandRenderer.php | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php b/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
index 08b1f1813..4ebe83c58 100644
--- a/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
@@ -66,7 +66,7 @@ class DisableNotificationsExpireCommandForm extends CommandForm
{
$disableNotifications = new DisableNotificationsExpireCommand();
$disableNotifications
- ->setExpireTime($this->getElement('expire_time')->getValue());
+ ->setExpireTime($this->getElement('expire_time')->getValue()->getTimestamp());
$this->getTransport($request)->send($disableNotifications);
Notification::success(mt('monitoring', 'Disabling host and service notifications..'));
return true;
diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
index 5045a8ade..ce813b7a2 100644
--- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
+++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
@@ -2,6 +2,7 @@
namespace Icinga\Module\Monitoring\Command\Renderer;
+use Icinga\Module\Monitoring\Command\Instance\DisableNotificationsExpireCommand;
use Icinga\Module\Monitoring\Command\Object\AcknowledgeProblemCommand;
use Icinga\Module\Monitoring\Command\Object\AddCommentCommand;
use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
@@ -386,4 +387,13 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
}
return $commandString;
}
+
+ public function renderDisableNotificationsExpire(DisableNotificationsExpireCommand $command)
+ {
+ return sprintf(
+ '%s;%u',
+ 'DISABLE_NOTIFICATIONS_EXPIRE_TIME',
+ $command->getExpireTime()
+ );
+ }
}
From 16bc0e5d5addca6ac4d9c6aa07e9278fa3f4ab53 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 13:29:23 +0200
Subject: [PATCH 218/277] monitoring/commands: Add icon to the check now
command form
refs #6593
---
.../Command/Object/CheckNowCommandForm.php | 40 +++++++++++++++++--
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php b/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
index ecf933102..65ef67ff5 100644
--- a/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
@@ -6,7 +6,6 @@ namespace Icinga\Module\Monitoring\Form\Command\Object;
use Icinga\Module\Monitoring\Command\Object\ScheduleHostCheckCommand;
use Icinga\Module\Monitoring\Command\Object\ScheduleServiceCheckCommand;
-use Icinga\Module\Monitoring\Form\Command\Object\ObjectsCommandForm;
use Icinga\Web\Notification;
use Icinga\Web\Request;
@@ -15,17 +14,52 @@ use Icinga\Web\Request;
*/
class CheckNowCommandForm extends ObjectsCommandForm
{
-
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
- $this->setSubmitLabel(mt('monitoring', 'Check Now'));
$this->setAttrib('class', 'inline link-like');
}
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
+ */
+ public function addSubmitButton()
+ {
+ $this->addElements(array(
+ array(
+ 'note',
+ 'icon',
+ array(
+ 'decorators' => array(
+ array(
+ 'HtmlTag',
+ array(
+ 'tag' => 'img',
+ 'src' => $this->getView()->href('img/icons/refresh_petrol.png'),
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'submit',
+ 'btn_submit',
+ array(
+ 'ignore' => true,
+ 'label' => mt('monitoring', 'Check Now'),
+ 'decorators' => array(
+ 'ViewHelper'
+ )
+ )
+ )
+ ));
+ return $this;
+ }
+
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
From e5e806a3a12a3fae824ce373dbb3071f8f32df44 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 15:02:31 +0200
Subject: [PATCH 219/277] monitoring/commands: Fix instance command forms code
compliance
refs #6593
---
.../DisableNotificationsExpireCommandForm.php | 1 -
.../ToggleInstanceFeaturesCommandForm.php | 28 ++++++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php b/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
index 4ebe83c58..67d2c7fc6 100644
--- a/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Instance/DisableNotificationsExpireCommandForm.php
@@ -71,5 +71,4 @@ class DisableNotificationsExpireCommandForm extends CommandForm
Notification::success(mt('monitoring', 'Disabling host and service notifications..'));
return true;
}
-
}
diff --git a/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php b/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php
index db584bc1a..9b3f79801 100644
--- a/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Instance/ToggleInstanceFeaturesCommandForm.php
@@ -59,6 +59,21 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
*/
public function createElements(array $formData = array())
{
+ if ((bool) $this->status->notifications_enabled) {
+ $description = sprintf(
+ '%s',
+ mt('monitoring', 'Disable notifications for a specific time on a program-wide basis'),
+ $this->getView()->href('monitoring/process/disable-notifications'),
+ mt('monitoring', 'Disable temporarily')
+ );
+ } elseif ($this->status->disable_notif_expire_time) {
+ $description = sprintf(
+ mt('monitoring', 'Notifications will be re-enabled in %s'),
+ $this->getView()->timeUntil($this->status->disable_notif_expire_time)
+ );
+ } else {
+ $description = '';
+ }
$this->addElements(array(
array(
'checkbox',
@@ -97,7 +112,18 @@ class ToggleInstanceFeaturesCommandForm extends CommandForm
ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS,
array(
'label' => mt('monitoring', 'Notifications Enabled'),
- 'autosubmit' => true
+ 'autosubmit' => true,
+ 'description' => $description,
+ 'decorators' => array(
+ 'ViewHelper',
+ 'Errors',
+ array(
+ 'Description',
+ array('tag' => 'span', 'class' => 'feature-instance-notifications', 'escape' => false)
+ ),
+ 'Label',
+ array('HtmlTag', array('tag' => 'div'))
+ ),
)
),
array(
From 442f956945181e0bc92bc26ed744ffe315b5101c Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 15:03:03 +0200
Subject: [PATCH 220/277] monitoring/commands: Fix object command forms code
compliance
refs #6593
---
.../Object/AcknowledgeProblemCommandForm.php | 16 +++++++--------
.../Command/Object/AddCommentCommandForm.php | 6 +++---
.../Command/Object/CheckNowCommandForm.php | 17 +++++-----------
.../ScheduleServiceCheckCommandForm.php | 4 ++--
.../ScheduleServiceDowntimeCommandForm.php | 20 +++++++++----------
5 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php b/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php
index 8da595a0d..a9c1549af 100644
--- a/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/AcknowledgeProblemCommandForm.php
@@ -39,8 +39,8 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'value' => mt(
'monitoring',
'This command is used to acknowledge host or service problems. When a problem is acknowledged,'
- . ' future notifications about problems are temporarily disabled until the host or service'
- . ' recovers.'
+ . ' future notifications about problems are temporarily disabled until the host or service'
+ . ' recovers.'
)
)
),
@@ -53,8 +53,8 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you work with other administrators, you may find it useful to share information about the'
- . ' the host or service that is having problems. Make sure you enter a brief description of'
- . ' what you are doing.'
+ . ' the host or service that is having problems. Make sure you enter a brief description of'
+ . ' what you are doing.'
)
)
),
@@ -66,7 +66,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you would like the comment to remain even when the acknowledgement is removed, check this'
- . ' option.'
+ . ' option.'
)
)
),
@@ -92,7 +92,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'Enter the expire date and time for this acknowledgement here. Icinga will delete the'
- . ' acknowledgement after this time expired.'
+ . ' acknowledgement after this time expired.'
)
)
)
@@ -118,7 +118,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you want the acknowledgement to disable notifications until the host or service recovers,'
- . 'check this option.'
+ . 'check this option.'
)
)
),
@@ -131,7 +131,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you do not want an acknowledgement notification to be sent out to the appropriate contacts,'
- . 'uncheck this option.'
+ . 'uncheck this option.'
)
)
)
diff --git a/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php b/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php
index 777d96868..1183070fc 100644
--- a/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/AddCommentCommandForm.php
@@ -48,8 +48,8 @@ class AddCommentCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you work with other administrators, you may find it useful to share information about the'
- . ' the host or service that is having problems. Make sure you enter a brief description of'
- . ' what you are doing.'
+ . ' the host or service that is having problems. Make sure you enter a brief description of'
+ . ' what you are doing.'
)
)
),
@@ -62,7 +62,7 @@ class AddCommentCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you uncheck this option, the comment will automatically be deleted the next time Icinga is'
- . ' restarted.'
+ . ' restarted.'
)
)
)
diff --git a/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php b/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
index 65ef67ff5..ade78402c 100644
--- a/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/CheckNowCommandForm.php
@@ -34,15 +34,10 @@ class CheckNowCommandForm extends ObjectsCommandForm
'note',
'icon',
array(
- 'decorators' => array(
- array(
- 'HtmlTag',
- array(
- 'tag' => 'img',
- 'src' => $this->getView()->href('img/icons/refresh_petrol.png'),
- )
- )
- )
+ 'decorators' => array(array(
+ 'HtmlTag',
+ array('tag' => 'img', 'src' => $this->getView()->href('img/icons/refresh_petrol.png'))
+ ))
)
),
array(
@@ -51,9 +46,7 @@ class CheckNowCommandForm extends ObjectsCommandForm
array(
'ignore' => true,
'label' => mt('monitoring', 'Check Now'),
- 'decorators' => array(
- 'ViewHelper'
- )
+ 'decorators' => array('ViewHelper')
)
)
));
diff --git a/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php b/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php
index a93fcf4ae..477fb1733 100644
--- a/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/ScheduleServiceCheckCommandForm.php
@@ -41,7 +41,7 @@ class ScheduleServiceCheckCommandForm extends ObjectsCommandForm
'value' => mt(
'monitoring',
'This command is used to schedule the next check of hosts or services. Icinga will re-queue the'
- . ' hosts or services to be checked at the time you specify.'
+ . ' hosts or services to be checked at the time you specify.'
)
)
),
@@ -62,7 +62,7 @@ class ScheduleServiceCheckCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you select this option, Icinga will force a check regardless of both what time the'
- . 'scheduled check occurs and whether or not checks are enabled.'
+ . 'scheduled check occurs and whether or not checks are enabled.'
)
)
)
diff --git a/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php
index 76d36d214..b5d153dd5 100644
--- a/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php
@@ -53,10 +53,10 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
'value' => mt(
'monitoring',
'This command is used to schedule host and service downtimes. During the specified downtime,'
- . ' Icinga will not send notifications out about the hosts and services. When the scheduled'
- . ' downtime expires, Icinga will send out notifications for the hosts and services as it'
- . ' normally would. Scheduled downtimes are preserved across program shutdowns and'
- . ' restarts.'
+ . ' Icinga will not send notifications out about the hosts and services. When the scheduled'
+ . ' downtime expires, Icinga will send out notifications for the hosts and services as it'
+ . ' normally would. Scheduled downtimes are preserved across program shutdowns and'
+ . ' restarts.'
)
)
),
@@ -69,8 +69,8 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you work with other administrators, you may find it useful to share information about the'
- . ' the host or service that is having problems. Make sure you enter a brief description of'
- . ' what you are doing.'
+ . ' the host or service that is having problems. Make sure you enter a brief description of'
+ . ' what you are doing.'
)
)
),
@@ -102,9 +102,9 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'If you select the fixed option, the downtime will be in effect between the start and end'
- . ' times you specify whereas a flexible downtime starts when the host or service enters a'
- . ' problem state sometime between the start and end times you specified and lasts as long'
- . ' as the duration time you enter. The duration fields do not apply for fixed downtimes.'
+ . ' times you specify whereas a flexible downtime starts when the host or service enters a'
+ . ' problem state sometime between the start and end times you specified and lasts as long'
+ . ' as the duration time you enter. The duration fields do not apply for fixed downtimes.'
),
'multiOptions' => array(
self::FIXED => mt('monitoring', 'Fixed'),
@@ -159,7 +159,7 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
'description' => mt(
'monitoring',
'Enter here the duration of the downtime. The downtime will be automatically deleted after this'
- . ' time expired.'
+ . ' time expired.'
),
'decorators' => array(
'FormElements',
From 4d784c6097a09c50ee4a7b80980c865879ecc0d8 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 16:42:00 +0200
Subject: [PATCH 221/277] monitoring/commands: Re-add the changed identifier to
object features
refs #6593
---
.../Command/Object/ToggleObjectFeaturesCommandForm.php | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php b/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php
index 146fd7001..8e5e5408c 100644
--- a/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/ToggleObjectFeaturesCommandForm.php
@@ -20,7 +20,7 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
*/
public function init()
{
- $this->setAttrib('class', 'inline');
+ $this->setAttrib('class', 'inline object-features');
}
/**
@@ -93,7 +93,11 @@ class ToggleObjectFeaturesCommandForm extends ObjectsCommandForm
{
$this->create();
foreach ($this->getValues() as $feature => $enabled) {
- $this->getElement($feature)->setChecked($object->{$feature});
+ $element = $this->getElement($feature);
+ $element->setChecked($object->{$feature});
+ if ((bool) $object->{$feature . '_changed'} === true) {
+ $element->setDescription(mt('monitoring', 'changed'));
+ }
}
return $this;
}
From 3a9774e6e5d42d28ac0cfd28692c1c4bcc87ef44 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 16:43:18 +0200
Subject: [PATCH 222/277] monitoring/commands: Support toggling instance
features
refs #6593
---
.../IcingaCommandFileCommandRenderer.php | 113 +++++++++++++++++-
.../IcingaCommandRendererInterface.php | 4 +-
2 files changed, 113 insertions(+), 4 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
index ce813b7a2..84731c905 100644
--- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
+++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
@@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Command\Renderer;
use Icinga\Module\Monitoring\Command\Instance\DisableNotificationsExpireCommand;
+use Icinga\Module\Monitoring\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Monitoring\Command\Object\AcknowledgeProblemCommand;
use Icinga\Module\Monitoring\Command\Object\AddCommentCommand;
use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
@@ -36,8 +37,8 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
/**
* Render a command
*
- * @param IcingaCommand $command
- * @param int|null $now
+ * @param IcingaCommand $command
+ * @param int|null $now
*
* @return string
*/
@@ -391,9 +392,115 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
public function renderDisableNotificationsExpire(DisableNotificationsExpireCommand $command)
{
return sprintf(
- '%s;%u',
+ '%s;%u;%u',
'DISABLE_NOTIFICATIONS_EXPIRE_TIME',
+ time(),
$command->getExpireTime()
);
}
+
+ public function renderToggleInstanceFeature(ToggleInstanceFeatureCommand $command)
+ {
+ switch ($command->getFeature()) {
+ case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS:
+ case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS:
+ case ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING:
+ case ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING:
+ case ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS:
+ case ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS:
+ if ($command->getEnabled() === true) {
+ $commandPrefix = 'START';
+ } else {
+ $commandPrefix = 'STOP';
+ }
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS:
+ case ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION:
+ case ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS:
+ case ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA:
+ if ($command->getEnabled() === true) {
+ $commandPrefix = 'ENABLE';
+ } else {
+ $commandPrefix = 'DISABLE';
+ }
+ break;
+ default:
+ throw new InvalidArgumentException($command->getFeature());
+ }
+ switch ($command->getFeature()) {
+ case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'EXECUTING_HOST_CHECKS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'EXECUTING_SVC_CHECKS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'EVENT_HANDLERS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'FLAP_DETECTION'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'NOTIFICATIONS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_HOST_OBSESSING:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'OBSESSING_OVER_HOST_CHECKS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_SERVICE_OBSESSING:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'OBSESSING_OVER_SVC_CHECKS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_PASSIVE_HOST_CHECKS:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'ACCEPTING_PASSIVE_HOST_CHECKS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_PASSIVE_SERVICE_CHECKS:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'ACCEPTING_PASSIVE_SVC_CHECKS'
+ );
+ break;
+ case ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA:
+ $commandString = sprintf(
+ '%s_%s',
+ $commandPrefix,
+ 'PERFORMANCE_DATA'
+ );
+ break;
+ default:
+ throw new InvalidArgumentException($command->getFeature());
+ }
+ return $commandString;
+ }
}
diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php
index dddd16742..f901e3850 100644
--- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php
+++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandRendererInterface.php
@@ -5,4 +5,6 @@ namespace Icinga\Module\Monitoring\Command\Renderer;
/**
* Interface for Icinga command renderer
*/
-interface IcingaCommandRendererInterface {}
+interface IcingaCommandRendererInterface
+{
+}
From 5f13db73ce536ff5b041b76146aee722c6e49116 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 12 Sep 2014 16:46:07 +0200
Subject: [PATCH 223/277] monitoring/commands: Use the toggle instance features
command form in the process controller
refs #6593
---
.../controllers/ProcessController.php | 135 +++++++----
.../process/disable-notifications.phtml | 15 ++
.../views/scripts/process/info.phtml | 224 ++++--------------
3 files changed, 156 insertions(+), 218 deletions(-)
create mode 100644 modules/monitoring/application/views/scripts/process/disable-notifications.phtml
diff --git a/modules/monitoring/application/controllers/ProcessController.php b/modules/monitoring/application/controllers/ProcessController.php
index 49f5715b1..98cba000f 100644
--- a/modules/monitoring/application/controllers/ProcessController.php
+++ b/modules/monitoring/application/controllers/ProcessController.php
@@ -2,66 +2,113 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
-use Icinga\Module\Monitoring\Controller as MonitoringController;
+use Icinga\Module\Monitoring\Controller;
+use Icinga\Module\Monitoring\Form\Command\Instance\DisableNotificationsExpireCommandForm;
+use Icinga\Module\Monitoring\Form\Command\Instance\ToggleInstanceFeaturesCommandForm;
/**
- * Display process information and global commands
+ * Display process and performance information of the monitoring host and program-wide commands
*/
-class Monitoring_ProcessController extends MonitoringController
+class Monitoring_ProcessController extends Controller
{
/**
- * Retrieve backend and hooks for this controller
+ * Add tabs
*
- * @see ActionController::init
+ * @see \Icinga\Web\Controller\ActionController::init()
*/
public function init()
{
- $this->getTabs()->add('info', array(
- 'title' => 'Process Info',
- 'url' =>'monitoring/process/info'
- ))->add('performance', array(
- 'title' => 'Performance Info',
- 'url' =>'monitoring/process/performance'
- ));
+ $this
+ ->getTabs()
+ ->add(
+ 'info',
+ array(
+ 'title' => $this->translate('Process Info'),
+ 'url' =>'monitoring/process/info'
+ )
+ )
+ ->add(
+ 'performance',
+ array(
+ 'title' => $this->translate('Performance Info'),
+ 'url' => 'monitoring/process/performance'
+ )
+ );
}
+ /**
+ * Display process information and program-wide commands
+ */
public function infoAction()
{
+ $this->view->title = $this->translate('Process Info');
$this->getTabs()->activate('info');
$this->setAutorefreshInterval(10);
-
- // TODO: This one is broken right now, doublecheck default columns
- $this->view->programstatus = $this->backend->select()
- ->from('programstatus', array(
- 'id',
- 'status_update_time',
- 'program_start_time',
- 'program_end_time',
- 'is_currently_running',
- 'process_id',
- 'daemon_mode',
- 'last_command_check',
- 'last_log_rotation',
- 'notifications_enabled',
- 'disable_notif_expire_time',
- 'active_service_checks_enabled',
- 'passive_service_checks_enabled',
- 'active_host_checks_enabled',
- 'passive_host_checks_enabled',
- 'event_handlers_enabled',
- 'flap_detection_enabled',
- 'failure_prediction_enabled',
- 'process_performance_data',
- 'obsess_over_hosts',
- 'obsess_over_services',
- 'modified_host_attributes',
- 'modified_service_attributes',
- 'global_host_event_handler',
- 'global_service_event_handler'
- ))
- ->getQuery()->fetchRow();
-
$this->view->backendName = $this->backend->getName();
+ $programStatus = $this->backend
+ ->select()
+ ->from(
+ 'programstatus',
+ array(
+ 'is_currently_running',
+ 'process_id',
+ 'program_start_time',
+ 'status_update_time',
+ 'last_command_check',
+ 'last_log_rotation',
+ 'global_service_event_handler',
+ 'global_host_event_handler',
+ 'notifications_enabled',
+ 'disable_notif_expire_time',
+ 'active_service_checks_enabled',
+ 'passive_service_checks_enabled',
+ 'active_host_checks_enabled',
+ 'passive_host_checks_enabled',
+ 'event_handlers_enabled',
+ 'obsess_over_services',
+ 'obsess_over_hosts',
+ 'flap_detection_enabled',
+ 'process_performance_data'
+ )
+ )
+ ->getQuery()
+ ->fetchRow();
+ $this->view->programStatus = $programStatus;
+ $toggleFeaturesForm = new ToggleInstanceFeaturesCommandForm();
+ $toggleFeaturesForm
+ ->setStatus($programStatus)
+ ->load($programStatus)
+ ->handleRequest();
+ $this->view->toggleFeaturesForm = $toggleFeaturesForm;
+ }
+
+ /**
+ * Disable notifications w/ an optional expire time
+ */
+ public function disableNotificationsAction()
+ {
+ $this->view->title = $this->translate('Disable Notifications');
+ $programStatus = $this->backend
+ ->select()
+ ->from(
+ 'programstatus',
+ array(
+ 'notifications_enabled',
+ 'disable_notif_expire_time'
+ )
+ )
+ ->getQuery()
+ ->fetchRow();
+ $this->view->programStatus = $programStatus;
+ if ((bool) $programStatus->notifications_enabled === false) {
+ return;
+ } else {
+ $form = new DisableNotificationsExpireCommandForm();
+ $form
+ ->setRedirectUrl('monitoring/process/info')
+ ->handleRequest();
+ $this->view->form = $form;
+ }
}
public function performanceAction()
diff --git a/modules/monitoring/application/views/scripts/process/disable-notifications.phtml b/modules/monitoring/application/views/scripts/process/disable-notifications.phtml
new file mode 100644
index 000000000..6b45a1f22
--- /dev/null
+++ b/modules/monitoring/application/views/scripts/process/disable-notifications.phtml
@@ -0,0 +1,15 @@
+
+
= $title ?>
+ notifications_enabled === false): ?>
+
+ = $this->translate('Host and service notifications are already disabled.') ?>
+ programStatus->disable_notif_expire_time): ?>
+ = sprintf(
+ $this->translate('Notifications will be re-enabled in %s.'),
+ $this->timeUntil($this->programStatus->disable_notif_expire_time)); ?>
+
+
+ = sprintf(
+ $this->translate('%s has been up and running with PID %d since %s'),
+ $this->backendName,
+ $this->programStatus->process_id,
+ $this->timeSince($this->programStatus->program_start_time)) ?>
+
+
+
+ = sprintf($this->translate('%s is not running'), $this->backendName) ?>
+
diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
index 4ad204e5c..ae257e9f1 100644
--- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
+++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
@@ -119,4 +119,33 @@ abstract class MonitoredObjectController extends Controller
* Schedule a downtime
*/
abstract public function scheduleDowntimeAction();
+
+
+ /**
+ * Remove a comment
+ */
+ public function removeCommentAction()
+ {
+ /*
+ * TODO(el): This is here because monitoring/list/comments has buttons to remove comments. Because of the nature
+ * of an action, the form is accessible via GET which does not make much sense because the form requires
+ * us to populate the ID of the comment which is to be deleted. We may introduce a combo box for choosing
+ * the comment ID on GET or deny GET access.
+ */
+ $this->handleCommandForm(new DeleteCommentCommandForm());
+ }
+
+ /**
+ * Remove a downtime
+ */
+ public function deleteDowntimeAction()
+ {
+ /*
+ * TODO(el): This is here because monitoring/list/downtimes has buttons to remove comments. Because of the
+ * nature of an action, the form is accessible via GET which does not make much sense because the form requires
+ * us to populate the ID of the downtime which is to be deleted. We may introduce a combo box for choosing
+ * the downtime ID on GET or deny GET access.
+ */
+ $this->handleCommandForm(new DeleteDowntimeCommandForm());
+ }
}
From 27650be48193acad588f32fb1b5926d95b32d148 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 19 Sep 2014 14:41:51 +0200
Subject: [PATCH 260/277] monitoring/commands: Add missing `ListController'
change from the last commit
refs #6593
---
modules/monitoring/application/controllers/ListController.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php
index bd0bb047f..e2caee336 100644
--- a/modules/monitoring/application/controllers/ListController.php
+++ b/modules/monitoring/application/controllers/ListController.php
@@ -4,6 +4,8 @@
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Backend;
+use Icinga\Module\Monitoring\Form\Command\Object\DeleteCommentCommandForm;
+use Icinga\Module\Monitoring\Form\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Hook;
use Icinga\Web\Widget\Tabextension\DashboardAction;
@@ -297,6 +299,7 @@ class Monitoring_ListController extends Controller
'downtime_scheduled_end' => 'Scheduled End',
'downtime_duration' => 'Duration',
));
+ $this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
}
/**
@@ -426,6 +429,7 @@ class Monitoring_ListController extends Controller
'comment_expiration' => 'Expiration',
)
);
+ $this->view->delCommentForm = new DeleteCommentCommandForm();
}
public function servicegroupsAction()
From 119e23e79e0578e7531d196570f1d201afc728a7 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 19 Sep 2014 14:43:25 +0200
Subject: [PATCH 261/277] Make `InlinePie's setters fluent
---
library/Icinga/Web/Widget/Chart/InlinePie.php | 67 ++++++++++++++-----
1 file changed, 49 insertions(+), 18 deletions(-)
diff --git a/library/Icinga/Web/Widget/Chart/InlinePie.php b/library/Icinga/Web/Widget/Chart/InlinePie.php
index da63ec403..4b4409e78 100644
--- a/library/Icinga/Web/Widget/Chart/InlinePie.php
+++ b/library/Icinga/Web/Widget/Chart/InlinePie.php
@@ -24,7 +24,7 @@ class InlinePie extends AbstractWidget
const NUMBER_FORMAT_TIME = 'time';
const NUMBER_FORMAT_BYTES = 'bytes';
const NUMBER_FORMAT_RATIO = 'ratio';
-
+
/**
* The template string used for rendering this widget
* The template string used for rendering this widget
@@ -137,7 +137,7 @@ EOD;
* @var string
*/
private $tooltipFormat = '{{title}} {{label}}: {{formatted}} ({{percent}}%)';
-
+
/**
* The number format used to render numeric values in tooltips
*
@@ -148,30 +148,36 @@ EOD;
/**
* Set if the tooltip for the empty area should be hidden
*
- * @param bool $hide Whether to hide the empty area
+ * @param bool $hide Whether to hide the empty area
+ *
+ * @return $this
*/
public function setHideEmptyLabel($hide = true)
{
$this->hideEmptyLabel = $hide;
+ return $this;
}
/**
* Set the data to be displayed.
*
- * @param $data array
+ * @param $data array
+ *
+ * @return $this
*/
public function setData(array $data)
{
$this->data = $data;
$this->url->setParam('data', implode(',', $data));
+ return $this;
}
/**
* The labels to be displayed in the pie-chart
*
- * @param mixed $label The label of the displayed value, or null for no labels
+ * @param mixed $label The label of the displayed value, or null for no labels
*
- * @return $this Fluent interface
+ * @return $this
*/
public function setLabel($label)
{
@@ -191,7 +197,9 @@ EOD;
/**
* Set the colors used by the slices of the pie chart.
*
- * @param array $colors
+ * @param array $colors
+ *
+ * @return $this
*/
public function setColors(array $colors = null)
{
@@ -201,18 +209,22 @@ EOD;
} else {
$this->url->setParam('colors', null);
}
+ return $this;
}
/**
* Set the used number format
*
- * @param $format string 'bytes' or 'time'
+ * @param $format string 'bytes' or 'time'
+ *
+ * @return $this
*/
public function setNumberFormat($format)
{
$this->format = $format;
+ return $this;
}
-
+
/**
* A format string used to render the content of the piechart tooltips
*
@@ -225,16 +237,23 @@ EOD;
*
percent: The percentage of the current value
*
* Note: Changes will only affect JavaScript sparklines and not the SVG charts used for fallback
+ *
+ * @param $format
+ *
+ * @return $this
*/
public function setTooltipFormat($format)
{
$this->tooltipFormat = $format;
+ return $this;
}
/**
- * @param $height
+ * Set the height
*
- * @return $this
+ * @param $height
+ *
+ * @return $this
*/
public function setHeight($height)
{
@@ -245,17 +264,22 @@ EOD;
/**
* Set the border width of the pie chart
*
- * @param float $width Width in px
+ * @param float $width Width in px
+ *
+ * @return $this
*/
public function setBorderWidth($width)
{
$this->borderWidth = $width;
+ return $this;
}
/**
* Set the color of the pie chart border
*
- * @param string $col The color string
+ * @param string $col The color string
+ *
+ * @return $this
*/
public function setBorderColor($col)
{
@@ -263,9 +287,11 @@ EOD;
}
/**
- * @param $width
+ * Set the width
*
- * @return $this
+ * @param $width
+ *
+ * @return $this
*/
public function setWidth($width)
{
@@ -276,7 +302,9 @@ EOD;
/**
* Set the styling of the created HtmlElement
*
- * @param string $style
+ * @param string $style
+ *
+ * @return $this
*/
public function setStyle($style)
{
@@ -286,11 +314,14 @@ EOD;
/**
* Set the title of the displayed Data
*
- * @param string $title
+ * @param string $title
+ *
+ * @return $this
*/
public function setTitle($title)
{
$this->title = $title;
+ return $this;
}
/**
@@ -346,7 +377,7 @@ EOD;
{
$template = $this->template;
$template = str_replace('{url}', $this->url, $template);
-
+
// style
$template = str_replace('{width}', $this->width, $template);
$template = str_replace('{height}', $this->height, $template);
From 264d8181337d6d0bf58b45a05ed49578731975e0 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 19 Sep 2014 14:44:21 +0200
Subject: [PATCH 262/277] Do not save config references in the
`ActionController'
This is redundant because our `Config' class already caches loaded configs.
---
.../Icinga/Web/Controller/ActionController.php | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php
index fb3345077..d3fc54535 100644
--- a/library/Icinga/Web/Controller/ActionController.php
+++ b/library/Icinga/Web/Controller/ActionController.php
@@ -39,10 +39,6 @@ class ActionController extends Zend_Controller_Action
*/
protected $requiresAuthentication = true;
- private $config;
-
- private $configs = array();
-
private $autorefreshInterval;
private $reloadCss = false;
@@ -110,17 +106,10 @@ class ActionController extends Zend_Controller_Action
public function Config($file = null)
{
if ($file === null) {
- if ($this->config === null) {
- $this->config = Config::app();
- }
- return $this->config;
+ return Config::app();
} else {
- if (! array_key_exists($file, $this->configs)) {
- $this->configs[$file] = Config::module($module, $file);
- }
- return $this->configs[$file];
+ return Config::app($file);
}
- return $this->config;
}
public function Auth()
From 2dd81d12ba5a63f16e8ed446ae4b24ae62c2f30c Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Fri, 19 Sep 2014 15:42:13 +0200
Subject: [PATCH 263/277] monitoring: Add `DataView::count()'
---
.../library/Monitoring/DataView/DataView.php | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php
index b7035a850..2b91c1673 100644
--- a/modules/monitoring/library/Monitoring/DataView/DataView.php
+++ b/modules/monitoring/library/Monitoring/DataView/DataView.php
@@ -4,6 +4,7 @@
namespace Icinga\Module\Monitoring\DataView;
+use Countable;
use Icinga\Data\Filter\Filter;
use Icinga\Data\SimpleQuery;
use Icinga\Data\Browsable;
@@ -18,7 +19,7 @@ use Icinga\Module\Monitoring\Backend;
/**
* A read-only view of an underlying query
*/
-abstract class DataView implements Browsable, Filterable, Sortable
+abstract class DataView implements Browsable, Countable, Filterable, Sortable
{
/**
* The query used to populate the view
@@ -26,7 +27,7 @@ abstract class DataView implements Browsable, Filterable, Sortable
* @var SimpleQuery
*/
private $query;
-
+
protected $filter;
protected $connection;
@@ -328,4 +329,14 @@ public function dump()
{
return $this->query->paginate($itemsPerPage, $pageNumber);
}
+
+ /**
+ * Count result set
+ *
+ * @return int
+ */
+ public function count()
+ {
+ return count($this->query);
+ }
}
From b10737017d34569756f5b5ba58fa82b18cd615f0 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 17:36:15 -0700
Subject: [PATCH 264/277] monitoring/commands: Default 'reschedule all service
checks on the hosts' to false
refs #6593
---
.../forms/Command/Object/ScheduleHostCheckCommandForm.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/Object/ScheduleHostCheckCommandForm.php b/modules/monitoring/application/forms/Command/Object/ScheduleHostCheckCommandForm.php
index e7d71b9f2..89d39716c 100644
--- a/modules/monitoring/application/forms/Command/Object/ScheduleHostCheckCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/ScheduleHostCheckCommandForm.php
@@ -26,10 +26,9 @@ class ScheduleHostCheckCommandForm extends ScheduleServiceCheckCommandForm
'all_services',
array(
'label' => mt('monitoring', 'All Services'),
- 'value' => true,
'description' => mt(
'monitoring',
- 'Schedule check for all services on the hosts and the hosts themself.'
+ 'Schedule check for all services on the hosts and the hosts themselves.'
)
)
)
From 9601942116c2614f9c208af212037850ecbc5372 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 17:39:32 -0700
Subject: [PATCH 265/277] monitoring/commands: Default 'schedule downtime for
all services on the hosts' to false
refs #6593
---
.../forms/Command/Object/ScheduleHostDowntimeCommandForm.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/modules/monitoring/application/forms/Command/Object/ScheduleHostDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Object/ScheduleHostDowntimeCommandForm.php
index ee7dff5bb..25caa0f20 100644
--- a/modules/monitoring/application/forms/Command/Object/ScheduleHostDowntimeCommandForm.php
+++ b/modules/monitoring/application/forms/Command/Object/ScheduleHostDowntimeCommandForm.php
@@ -28,10 +28,9 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
'all_services',
array(
'label' => mt('monitoring', 'All Services'),
- 'value' => true,
'description' => mt(
'monitoring',
- 'Schedule downtime for all services on the hosts and the hosts themself.'
+ 'Schedule downtime for all services on the hosts and the hosts themselves.'
)
)
),
From 70500be5f72dfa70dc0f830b38b0ad0d38f726b4 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 17:40:13 -0700
Subject: [PATCH 266/277] monitoring/commands: Fix the delete comment and
delete downtime commands
They included the involved object's name which is wrong.
refs #6593
---
.../IcingaCommandFileCommandRenderer.php | 32 +++----------------
1 file changed, 4 insertions(+), 28 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
index 67de7a02d..8b4c2d0a0 100644
--- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
+++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php
@@ -322,22 +322,10 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
public function renderDeleteComment(DeleteCommentCommand $command)
{
- $object = $command->getObject();
if ($command->getObject()->getType() === $command::TYPE_HOST) {
- /** @var \Icinga\Module\Monitoring\Object\Host $object */
- $commandString = sprintf(
- '%s;%s',
- 'DEL_HOST_DOWNTIME',
- $object->getName()
- );
+ $commandString = 'DEL_HOST_COMMENT';
} else {
- /** @var \Icinga\Module\Monitoring\Object\Service $object */
- $commandString = sprintf(
- '%s;%s;%s',
- 'DEL_SVC_COMMENT',
- $object->getHost()->getName(),
- $object->getName()
- );
+ $commandString = 'DEL_SVC_COMMENT';
}
return sprintf(
'%s;%u',
@@ -348,22 +336,10 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
public function renderDeleteDowntime(DeleteDowntimeCommand $command)
{
- $object = $command->getObject();
if ($command->getObject()->getType() === $command::TYPE_HOST) {
- /** @var \Icinga\Module\Monitoring\Object\Host $object */
- $commandString = sprintf(
- '%s;%s',
- 'DEL_HOST_DOWNTIME',
- $object->getName()
- );
+ $commandString = 'DEL_HOST_DOWNTIME';
} else {
- /** @var \Icinga\Module\Monitoring\Object\Service $object */
- $commandString = sprintf(
- '%s;%s;%s',
- 'DEL_SVC_DOWNTIME',
- $object->getHost()->getName(),
- $object->getName()
- );
+ $commandString = 'DEL_SVC_DOWNTIME';
}
return sprintf(
'%s;%u',
From 6625e8d391f12bf9052a7062f33527e02d901363 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 22:16:33 -0700
Subject: [PATCH 267/277] monitoring: Add tabs to the host and service
controller
---
.../controllers/HostController.php | 10 +++
.../controllers/ServiceController.php | 10 +++
.../Controller/MonitoredObjectController.php | 79 ++++++++++++++++++-
3 files changed, 98 insertions(+), 1 deletion(-)
diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php
index 7799cb4ec..f77d11deb 100644
--- a/modules/monitoring/application/controllers/HostController.php
+++ b/modules/monitoring/application/controllers/HostController.php
@@ -29,6 +29,16 @@ class Monitoring_HostController extends MonitoredObjectController
throw new Zend_Controller_Action_Exception($this->translate('Host not found'));
}
$this->object = $host;
+ $this->createTabs();
+ }
+
+ /**
+ * Show a host
+ */
+ public function showAction()
+ {
+ $this->getTabs()->activate('host');
+ parent::showAction();
}
/**
diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php
index 24bb23024..ea29aa54a 100644
--- a/modules/monitoring/application/controllers/ServiceController.php
+++ b/modules/monitoring/application/controllers/ServiceController.php
@@ -29,6 +29,16 @@ class Monitoring_ServiceController extends MonitoredObjectController
throw new Zend_Controller_Action_Exception($this->translate('Service not found'));
}
$this->object = $service;
+ $this->createTabs();
+ }
+
+ /**
+ * Show a service
+ */
+ public function showAction()
+ {
+ $this->getTabs()->activate('service');
+ parent::showAction();
}
/**
diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
index ae257e9f1..856496ca8 100644
--- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
+++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
@@ -12,7 +12,10 @@ use Icinga\Module\Monitoring\Form\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Module\Monitoring\Form\Command\Object\ObjectsCommandForm;
use Icinga\Module\Monitoring\Form\Command\Object\RemoveAcknowledgementCommandForm;
use Icinga\Module\Monitoring\Form\Command\Object\ToggleObjectFeaturesCommandForm;
+use Icinga\Web\Hook;
use Icinga\Web\Url;
+use Icinga\Web\Widget\Tabextension\DashboardAction;
+use Icinga\Web\Widget\Tabextension\OutputFormat;
/**
* Base class for the host and service controller
@@ -33,6 +36,21 @@ abstract class MonitoredObjectController extends Controller
*/
protected $commandRedirectUrl;
+ /**
+ * (non-PHPDoc)
+ * @see \Icinga\Web\Controller\ActionController For the method documentation.
+ */
+ public function prepareInit()
+ {
+ parent::prepareInit();
+ if (Hook::has('ticket')) {
+ $this->view->tickets = Hook::first('ticket');
+ }
+ if (Hook::has('grapher')) {
+ $this->view->grapher = Hook::first('grapher');
+ }
+ }
+
/**
* Show a host or service
*/
@@ -120,7 +138,6 @@ abstract class MonitoredObjectController extends Controller
*/
abstract public function scheduleDowntimeAction();
-
/**
* Remove a comment
*/
@@ -148,4 +165,64 @@ abstract class MonitoredObjectController extends Controller
*/
$this->handleCommandForm(new DeleteDowntimeCommandForm());
}
+
+ /**
+ * Create tabs
+ */
+ protected function createTabs()
+ {
+ $tabs = $this->getTabs();
+ $object = $this->object;
+ if ($object->getType() === $object::TYPE_HOST) {
+ $params = array(
+ 'host' => $object->getName()
+ );
+ } else {
+ $params = array(
+ 'host' => $object->getHost()->getName(),
+ 'service' => $object->getName()
+ );
+ }
+ $tabs->add(
+ 'host',
+ array(
+ 'title' => 'Host',
+ 'icon' => 'img/icons/host.png',
+ 'url' => 'monitoring/host/show',
+ 'urlParams' => $params
+ )
+ );
+ if (isset($params['service'])) {
+ $tabs->add(
+ 'service',
+ array(
+ 'title' => 'Service',
+ 'icon' => 'img/icons/service.png',
+ 'url' => 'monitoring/service/show',
+ 'urlParams' => $params
+ )
+ );
+ }
+ $tabs->add(
+ 'services',
+ array(
+ 'title' => 'Services',
+ 'icon' => 'img/icons/service.png',
+ 'url' => 'monitoring/show/services',
+ 'urlParams' => $params
+ )
+ );
+ $tabs->add(
+ 'history',
+ array(
+ 'title' => 'History',
+ 'icon' => 'img/icons/history.png',
+ 'url' => 'monitoring/show/history',
+ 'urlParams' => $params
+ )
+ );
+ $tabs
+ ->extend(new OutputFormat())
+ ->extend(new DashboardAction());
+ }
}
From df18eab69b99423679cd3ff0133534f4c2338154 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 22:17:22 -0700
Subject: [PATCH 268/277] monitoring: Provide service stats on both the host
and the service object
---
.../library/Monitoring/Object/Host.php | 37 --------------
.../Monitoring/Object/MonitoredObject.php | 51 +++++++++++++++++++
2 files changed, 51 insertions(+), 37 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php
index fbd90f2a5..e7521ae6b 100644
--- a/modules/monitoring/library/Monitoring/Object/Host.php
+++ b/modules/monitoring/library/Monitoring/Object/Host.php
@@ -60,13 +60,6 @@ class Host extends MonitoredObject
*/
protected $services;
- /**
- * Stats
- *
- * @var object
- */
- protected $stats;
-
/**
* Create a new host
*
@@ -160,36 +153,6 @@ class Host extends MonitoredObject
return $this;
}
- /**
- * Fetch stats
- *
- * @return $this
- */
- public function fetchStats()
- {
- $this->stats = $this->backend->select()->from('statusSummary', array(
- 'services_total',
- 'services_ok',
- 'services_problem',
- 'services_problem_handled',
- 'services_problem_unhandled',
- 'services_critical',
- 'services_critical_unhandled',
- 'services_critical_handled',
- 'services_warning',
- 'services_warning_unhandled',
- 'services_warning_handled',
- 'services_unknown',
- 'services_unknown_unhandled',
- 'services_unknown_handled',
- 'services_pending',
- ))
- ->where('service_host_name', $this->host)
- ->getQuery()
- ->fetchRow();
- return $this;
- }
-
/**
* Get the optional translated textual representation of a host state
*
diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
index e3044d2b3..3171af5e8 100644
--- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
+++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
@@ -8,6 +8,7 @@ use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Exception\InvalidPropertyException;
use Icinga\Module\Monitoring\Backend;
+use Icinga\Web\UrlParams;
/**
* A monitored Icinga object, i.e. host or service
@@ -108,6 +109,13 @@ abstract class MonitoredObject
*/
protected $eventhistory;
+ /**
+ * Stats
+ *
+ * @var object
+ */
+ protected $stats;
+
/**
* Create a monitored object, i.e. host or service
*
@@ -381,6 +389,36 @@ abstract class MonitoredObject
return $this;
}
+ /**
+ * Fetch stats
+ *
+ * @return $this
+ */
+ public function fetchStats()
+ {
+ $this->stats = $this->backend->select()->from('statusSummary', array(
+ 'services_total',
+ 'services_ok',
+ 'services_problem',
+ 'services_problem_handled',
+ 'services_problem_unhandled',
+ 'services_critical',
+ 'services_critical_unhandled',
+ 'services_critical_handled',
+ 'services_warning',
+ 'services_warning_unhandled',
+ 'services_warning_handled',
+ 'services_unknown',
+ 'services_unknown_unhandled',
+ 'services_unknown_handled',
+ 'services_pending',
+ ))
+ ->where('service_host_name', $this->host_name)
+ ->getQuery()
+ ->fetchRow();
+ return $this;
+ }
+
/**
* Fetch all available data of the object
*
@@ -419,4 +457,17 @@ abstract class MonitoredObject
}
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
}
+
+ /**
+ * @deprecated
+ */
+ public static function fromParams(UrlParams $params)
+ {
+ if ($params->has('service') && $params->has('host')) {
+ return new Service(Backend::createBackend(), $params->get('host'), $params->get('service'));
+ } elseif ($params->has('host')) {
+ return new Host(Backend::createBackend(), $params->get('host'));
+ }
+ return null;
+ }
}
From 051c9691a96d9a355ca3d115df23bf251a1a0a65 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 22:18:06 -0700
Subject: [PATCH 269/277] Remove "WTF" comment
---
modules/monitoring/application/views/scripts/show/contact.phtml | 1 -
1 file changed, 1 deletion(-)
diff --git a/modules/monitoring/application/views/scripts/show/contact.phtml b/modules/monitoring/application/views/scripts/show/contact.phtml
index c4dc41b9e..a755266ea 100644
--- a/modules/monitoring/application/views/scripts/show/contact.phtml
+++ b/modules/monitoring/application/views/scripts/show/contact.phtml
@@ -40,7 +40,6 @@
-
= $this->translate('Commands') ?>:
From e8477701353f62658d823e4d314cb8d9aca3e20e Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 22:19:35 -0700
Subject: [PATCH 270/277] monitoring/commands: Remove false property from the
schedule service check command
refs #6593
---
.../Monitoring/Command/Exception/TransportException.php | 4 +++-
.../Command/Object/ScheduleServiceCheckCommand.php | 7 -------
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php b/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php
index db06e67ba..440f21770 100644
--- a/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php
+++ b/modules/monitoring/library/Monitoring/Command/Exception/TransportException.php
@@ -9,4 +9,6 @@ use Icinga\Exception\IcingaException;
/**
* Exception thrown if a command was not sent
*/
-class TransportException extends IcingaException {}
+class TransportException extends IcingaException
+{
+}
diff --git a/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php b/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php
index 9bf719a25..fc2037146 100644
--- a/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php
+++ b/modules/monitoring/library/Monitoring/Command/Object/ScheduleServiceCheckCommand.php
@@ -38,13 +38,6 @@ class ScheduleServiceCheckCommand extends ObjectCommand
*/
protected $forced = false;
- /**
- * Whether to schedule a check of all services associated with a particular host
- *
- * @var bool
- */
- protected $ofAllServices = false;
-
/**
* Set the time when the next check of a host or service is to be scheduled
*
From 4258b13d45b21958f09873f81fd095aaea959a63 Mon Sep 17 00:00:00 2001
From: Eric Lippmann
Date: Tue, 23 Sep 2014 22:21:23 -0700
Subject: [PATCH 271/277] monitoring/commands: Remove `MonitoringCommands' view
helper
The helper is not used anywhere.
refs #6593
---
.../controllers/MonitoringCommands.php | 75 -------------------
1 file changed, 75 deletions(-)
delete mode 100644 modules/monitoring/application/controllers/MonitoringCommands.php
diff --git a/modules/monitoring/application/controllers/MonitoringCommands.php b/modules/monitoring/application/controllers/MonitoringCommands.php
deleted file mode 100644
index 16b713d4c..000000000
--- a/modules/monitoring/application/controllers/MonitoringCommands.php
+++ /dev/null
@@ -1,75 +0,0 @@
-getCommandForObject($object, $type);
- $out = '