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(); - } -}