From 1c7a90e79f4ddadb95996b394dab71981b858d18 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jul 2013 10:23:19 +0200 Subject: [PATCH] Implement enable/disable notifications for hosts/services Added action and mask for enabling/disabling notifications of hosts and services. refs #4355 --- .../controllers/CommandController.php | 84 +++++++++++++++++++ .../command/disablenotifications.phtml | 1 + .../scripts/command/enablenotifications.phtml | 1 + 3 files changed, 86 insertions(+) create mode 100644 modules/monitoring/application/views/scripts/command/disablenotifications.phtml create mode 100644 modules/monitoring/application/views/scripts/command/enablenotifications.phtml diff --git a/modules/monitoring/application/controllers/CommandController.php b/modules/monitoring/application/controllers/CommandController.php index fb065a9fe..87cb9b232 100644 --- a/modules/monitoring/application/controllers/CommandController.php +++ b/modules/monitoring/application/controllers/CommandController.php @@ -225,6 +225,90 @@ class Monitoring_CommandController extends ModuleActionController } } + public function enablenotificationsAction() + { + // @TODO: Elaborate how "withChilds", "childHosts" and "forHosts" can be utilised + $form = new SendCommand("Enable notifications?"); + if ($this->_request->isPost()) { + if ($form->isValid()) { + $services = $form->getServices(); + $withChilds = $forHosts = $childHosts = false; + + 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 { + $form->addCheckbox("childHosts", "", false); + $childHosts = $form->isChecked("childHosts"); + $targets = $this->selectCommandTargets($form->getHosts()); + } + + $this->target->enableNotifications($targets); + } + } else { + $services = $this->getParameter("services", false); + if ($services) { + $form->addCheckbox("forHosts", "Enable for hosts too?", false); + } else { + $form->addCheckbox("childHosts", "Enable notifications for ". + "child 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 disablenotificationsAction() + { + // @TODO: Elaborate how "withChilds", "childHosts" and "forHosts" can be utilised + $form = new SendCommand("Disable notifications?"); + if ($this->_request->isPost()) { + if ($form->isValid()) { + $services = $form->getServices(); + $withChilds = $forHosts = $childHosts = false; + + 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 { + $form->addCheckbox("childHosts", "", false); + $childHosts = $form->isChecked("childHosts"); + $targets = $this->selectCommandTargets($form->getHosts()); + } + + $this->target->disableNotifications($targets); + } + } else { + $services = $this->getParameter("services", false); + if ($services) { + $form->addCheckbox("forHosts", "Disable for hosts too?", false); + } else { + $form->addCheckbox("childHosts", "Disable notifications for ". + "child 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 sendPassivechecks() { if ($this->getMandatoryParameter("enable")) { diff --git a/modules/monitoring/application/views/scripts/command/disablenotifications.phtml b/modules/monitoring/application/views/scripts/command/disablenotifications.phtml new file mode 100644 index 000000000..3ded5a7be --- /dev/null +++ b/modules/monitoring/application/views/scripts/command/disablenotifications.phtml @@ -0,0 +1 @@ +form ?> diff --git a/modules/monitoring/application/views/scripts/command/enablenotifications.phtml b/modules/monitoring/application/views/scripts/command/enablenotifications.phtml new file mode 100644 index 000000000..3ded5a7be --- /dev/null +++ b/modules/monitoring/application/views/scripts/command/enablenotifications.phtml @@ -0,0 +1 @@ +form ?>