From 387811c4a224d44cc390e0500408e5c177be70eb Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jul 2013 10:21:15 +0200 Subject: [PATCH] Implement enable/disable active checks for hosts/services Added action and mask for enabling/disabling active checks of hosts and services. refs #4355 --- .../controllers/CommandController.php | 73 ++++++++++++++++++- .../scripts/command/disableactivechecks.phtml | 1 + .../scripts/command/enableactivechecks.phtml | 1 + 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 modules/monitoring/application/views/scripts/command/disableactivechecks.phtml create mode 100644 modules/monitoring/application/views/scripts/command/enableactivechecks.phtml diff --git a/modules/monitoring/application/controllers/CommandController.php b/modules/monitoring/application/controllers/CommandController.php index 8e05853ef..fb065a9fe 100644 --- a/modules/monitoring/application/controllers/CommandController.php +++ b/modules/monitoring/application/controllers/CommandController.php @@ -151,12 +151,77 @@ class Monitoring_CommandController extends ModuleActionController $this->target->scheduleDowntime($this->selectCommandTargets(), $downtime); } - public function sendActivechecks() + public function enableactivechecksAction() { - if ($this->getMandatoryParameter("enable")) { - $this->target->enableActiveChecks($this->selectCommandTargets()); + // @TODO: Elaborate how "withChilds" and "forHosts" can be utilised + $form = new SendCommand("Enable active checks?"); + if ($this->_request->isPost()) { + if ($form->isValid()) { + $withChilds = $forHosts = false; + $services = $form->getServices(); + + if ($services) { + $withChilds = $services === "all"; + $form->addCheckbox("forHosts", "", false); + $forHosts = $form->isChecked("forHosts"); + if ($withChilds) { + $targets = $this->selectCommandTargets($form->getHosts()); + } else { + $targets = $this->selectCommandTargets($form->getHosts(), $services); + } + } else { + $targets = $this->selectCommandTargets($form->getHosts()); + } + + $this->target->enableActiveChecks($targets); + } } else { - $this->target->disableActiveChecks($this->selectCommandTargets()); + $services = $this->getParameter("services", false); + if ($services) { + $form->addCheckbox("forHosts", "Enable for hosts too?", false); + } + $form->setServices($services); + $form->setHosts($this->getParameter("hosts")); + $form->setAction($this->view->url()); + $form->addSubmitButton("Commit"); + $this->view->form = $form; + } + } + + public function disableactivechecksAction() + { + // @TODO: Elaborate how "withChilds" and "forHosts" can be utilised + $form = new SendCommand("Disable active checks?"); + if ($this->_request->isPost()) { + if ($form->isValid()) { + $withChilds = $forHosts = false; + $services = $form->getServices(); + + if ($services) { + $withChilds = $services === "all"; + $form->addCheckbox("forHosts", "", false); + $forHosts = $form->isChecked("forHosts"); + if ($withChilds) { + $targets = $this->selectCommandTargets($form->getHosts()); + } else { + $targets = $this->selectCommandTargets($form->getHosts(), $services); + } + } else { + $targets = $this->selectCommandTargets($form->getHosts()); + } + + $this->target->disableActiveChecks($targets); + } + } else { + $services = $this->getParameter("services", false); + if ($services) { + $form->addCheckbox("forHosts", "Disable for hosts too?", false); + } + $form->setServices($services); + $form->setHosts($this->getParameter("hosts")); + $form->setAction($this->view->url()); + $form->addSubmitButton("Commit"); + $this->view->form = $form; } } diff --git a/modules/monitoring/application/views/scripts/command/disableactivechecks.phtml b/modules/monitoring/application/views/scripts/command/disableactivechecks.phtml new file mode 100644 index 000000000..3ded5a7be --- /dev/null +++ b/modules/monitoring/application/views/scripts/command/disableactivechecks.phtml @@ -0,0 +1 @@ +form ?> diff --git a/modules/monitoring/application/views/scripts/command/enableactivechecks.phtml b/modules/monitoring/application/views/scripts/command/enableactivechecks.phtml new file mode 100644 index 000000000..3ded5a7be --- /dev/null +++ b/modules/monitoring/application/views/scripts/command/enableactivechecks.phtml @@ -0,0 +1 @@ +form ?>