From 53ab6dbbf1b98698edb895c67697dd2aefbcef40 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Sat, 19 Oct 2013 15:28:51 +0200 Subject: [PATCH] Implement global command toggle form in process view refs #4918 --- config/modules/monitoring/instances.ini | 2 +- library/Icinga/Web/Form.php | 2 +- .../application/views/helpers/CommandForm.php | 34 +++ .../views/scripts/process/performance.phtml | 194 +++++++++++++++++- public/css/icinga/main.less | 6 + .../icinga/components/ajaxPostSubmitForm.js | 4 +- 6 files changed, 236 insertions(+), 6 deletions(-) diff --git a/config/modules/monitoring/instances.ini b/config/modules/monitoring/instances.ini index 18213f142..2f54e11e3 100644 --- a/config/modules/monitoring/instances.ini +++ b/config/modules/monitoring/instances.ini @@ -1,2 +1,2 @@ [icinga] -path=/usr/local/icinga/var/rw/icinga.cmd +path = "/usr/local/icinga-mysql/var/rw/icinga.cmd" diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index e50207571..a3e118253 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -402,7 +402,7 @@ class Form extends Zend_Form foreach ($triggerElements as $elementName) { $element = $this->getElement($elementName); if ($element !== null) { - $element->setAttrib('onchange', 'this.form.submit()'); + $element->setAttrib('onchange', '$(this.form).submit();'); $element->setAttrib('data-icinga-form-autosubmit', true); } else { throw new ProgrammingError( diff --git a/modules/monitoring/application/views/helpers/CommandForm.php b/modules/monitoring/application/views/helpers/CommandForm.php index 4f32d064c..14d5194dc 100644 --- a/modules/monitoring/application/views/helpers/CommandForm.php +++ b/modules/monitoring/application/views/helpers/CommandForm.php @@ -94,6 +94,40 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract return $form; } + public function toggleSubmitForm($label, $checkValue, $enabledCommand, $disabledCommand, array $arguments = array()) + { + if ($checkValue === '1') { + $commandName = $disabledCommand; + } else { + $commandName = $enabledCommand; + } + + $form = $this->simpleForm($commandName, $arguments); + $form->setAttrib('class', 'pull-right'); + + $uniqueName = uniqid('check'); + + $checkBox = new Zend_Form_Element_Checkbox($uniqueName); + + if ($checkValue === '1') { + $checkBox->setChecked(true); + } + + $form->addElement($checkBox); + $form->enableAutoSubmit(array($uniqueName)); + + $checkBox->setDecorators(array('ViewHelper')); + $checkBox->setAttrib('class', ''); + $checkBox->setAttrib('id', $uniqueName); + + $submit_identifier = new Zend_Form_Element_Hidden('btn_submit'); + $submit_identifier->setValue('1'); + $form->addElement($submit_identifier); + $form->getElement('btn_submit')->setDecorators(array('ViewHelper')); + + return '' . $form; + } + /** * Merges css class names together * diff --git a/modules/monitoring/application/views/scripts/process/performance.phtml b/modules/monitoring/application/views/scripts/process/performance.phtml index 46cdfa4e9..0ed318b44 100644 --- a/modules/monitoring/application/views/scripts/process/performance.phtml +++ b/modules/monitoring/application/views/scripts/process/performance.phtml @@ -1,8 +1,9 @@ runtimevariables; $ps = $this->programstatus; - $cp = $this->checkPerformance()->create($this->checkperformance); + /** @var Zend_View_Helper_CommandForm $ch */ + $ch = $this->getHelper('CommandForm'); ?>

Process Information

@@ -180,6 +181,195 @@
-
Global commands goes here
+

Commands

+ + labelSubmitForm( + 'Shutdown monitoring process', + 'Shutdown the monitoring process', + 'btn-cta', + 'shutdownprocess' + ); + ?> + +
+ + labelSubmitForm( + 'Restart monitoring process', + 'Restart the monitoring process', + 'btn-cta', + 'restartprocess' + ); + ?> + + notifications_enabled === '1'): ?> + +
+ + + Dislable notification with expire + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ toggleSubmitForm( + 'Notifications enabled', + $ps->notifications_enabled, + 'enablenotifications', + 'disablenotifications', + array( + 'global' => '1' + ) + ); + ?> +
+ toggleSubmitForm( + 'Execute active service checks', + $ps->active_service_checks_enabled, + 'enableactivechecks', + 'disableactivechecks', + array( + 'global' => 'service' + ) + ); + ?> +
+ toggleSubmitForm( + 'Accept passive service checks', + $ps->passive_service_checks_enabled, + 'startacceptingpassivechecks', + 'stopacceptingpassivechecks', + array( + 'global' => 'service' + ) + ); + ?> +
+ toggleSubmitForm( + 'Execute active host checks', + $ps->active_host_checks_enabled, + 'enableactivechecks', + 'disableactivechecks', + array( + 'global' => 'host' + ) + ); + ?> +
+ toggleSubmitForm( + 'Accept passive host checks', + $ps->passive_host_checks_enabled, + 'startacceptingpassivechecks', + 'stopacceptingpassivechecks', + array( + 'global' => 'host' + ) + ); + ?> +
+ toggleSubmitForm( + 'Eventhandlers enabled', + $ps->event_handlers_enabled, + 'enableeventhandler', + 'disableeventhandler', + array( + 'global' => '1' + ) + ); + ?> +
+ toggleSubmitForm( + 'Obsessing over host checks', + $ps->obsess_over_hosts, + 'startobsessing', + 'stopobsessing', + array( + 'global' => 'host' + ) + ); + ?> +
+ toggleSubmitForm( + 'Obsessing over service checks', + $ps->obsess_over_services, + 'startobsessing', + 'stopobsessing', + array( + 'global' => 'service' + ) + ); + ?> +
+ toggleSubmitForm( + 'Flap detection enabled', + $ps->flap_detection_enabled, + 'enableflapdetection', + 'disableflapdetection', + array( + 'global' => '1' + ) + ); + ?> +
+ toggleSubmitForm( + 'Process performance data', + $ps->process_performance_data, + 'enableperformancedata', + 'disableperformancedata', + array( + 'global' => '1' + ) + ); + ?> +
\ No newline at end of file diff --git a/public/css/icinga/main.less b/public/css/icinga/main.less index b86bb206d..a8b22774b 100644 --- a/public/css/icinga/main.less +++ b/public/css/icinga/main.less @@ -84,6 +84,11 @@ p { Common elements ========================================================================= */ +.label-horizontal { + display: inline; + font-weight: normal; +} + .inline-image { display: inline-block; width: 16px; @@ -126,6 +131,7 @@ a { a.button { height: 30px; + display: block; } a.btn-small { diff --git a/public/js/icinga/components/ajaxPostSubmitForm.js b/public/js/icinga/components/ajaxPostSubmitForm.js index f5beb30bf..c26ae16c2 100644 --- a/public/js/icinga/components/ajaxPostSubmitForm.js +++ b/public/js/icinga/components/ajaxPostSubmitForm.js @@ -52,13 +52,13 @@ define(['components/app/container', 'jquery'], function(Container, $) { * @param {Event} e */ var submitHandler = function(e) { + e.preventDefault(); + var form = $(this); var url = form.attr('action'); var submit = form.find('button[type="submit"]', 'input[type="submit"]'); var data = form.serialize(); - e.preventDefault(); - // Submit name is missing for valid submission if (data) { data += '&';