From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../application/controllers/ActionsController.php | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 modules/monitoring/application/controllers/ActionsController.php (limited to 'modules/monitoring/application/controllers/ActionsController.php') diff --git a/modules/monitoring/application/controllers/ActionsController.php b/modules/monitoring/application/controllers/ActionsController.php new file mode 100644 index 0000000..bc13e21 --- /dev/null +++ b/modules/monitoring/application/controllers/ActionsController.php @@ -0,0 +1,135 @@ +params); + if ($filter->isEmpty()) { + $this->getResponse()->json() + ->setFailData(array('filter' => 'Filter is required and must not be empty')) + ->sendResponse(); + } + return $filter; + } + + /** + * Schedule host downtimes + */ + public function scheduleHostDowntimeAction() + { + $filter = $this->getFilterOrExitIfEmpty(); + $hostList = new HostList($this->backend); + $hostList + ->applyFilter($this->getRestriction('monitoring/filter/objects')) + ->applyFilter($filter); + if (! $hostList->count()) { + $this->getResponse()->json() + ->setFailData(array('filter' => 'No hosts found matching the filter')) + ->sendResponse(); + } + $form = new ScheduleHostDowntimeCommandForm(); + $form + ->setIsApiTarget(true) + ->setBackend($this->backend) + ->setObjects($hostList->fetch()) + ->handleRequest($this->getRequest()); + } + + /** + * Remove host downtimes + */ + public function removeHostDowntimeAction() + { + $filter = $this->getFilterOrExitIfEmpty(); + $downtimes = $this->backend + ->select() + ->from('downtime', array('host_name', 'id' => 'downtime_internal_id', 'name' => 'downtime_name')) + ->where('object_type', 'host') + ->applyFilter($this->getRestriction('monitoring/filter/objects')) + ->applyFilter($filter); + if (! $downtimes->count()) { + $this->getResponse()->json() + ->setFailData(array('filter' => 'No downtimes found matching the filter')) + ->sendResponse(); + } + $form = new DeleteDowntimesCommandForm(); + $form + ->setIsApiTarget(true) + ->setDowntimes($downtimes->fetchAll()) + ->handleRequest($this->getRequest()); + // @TODO(el): Respond w/ the downtimes deleted instead of the notifiaction added by + // DeleteDowntimesCommandForm::onSuccess(). + } + + /** + * Schedule service downtimes + */ + public function scheduleServiceDowntimeAction() + { + $filter = $this->getFilterOrExitIfEmpty(); + $serviceList = new ServiceList($this->backend); + $serviceList + ->applyFilter($this->getRestriction('monitoring/filter/objects')) + ->applyFilter($filter); + if (! $serviceList->count()) { + $this->getResponse()->json() + ->setFailData(array('filter' => 'No services found matching the filter')) + ->sendResponse(); + } + $form = new ScheduleServiceDowntimeCommandForm(); + $form + ->setIsApiTarget(true) + ->setBackend($this->backend) + ->setObjects($serviceList->fetch()) + ->handleRequest($this->getRequest()); + } + + /** + * Remove service downtimes + */ + public function removeServiceDowntimeAction() + { + $filter = $this->getFilterOrExitIfEmpty(); + $downtimes = $this->backend + ->select() + ->from( + 'downtime', + array('host_name', 'service_description', 'id' => 'downtime_internal_id', 'name' => 'downtime_name') + ) + ->where('object_type', 'service') + ->applyFilter($this->getRestriction('monitoring/filter/objects')) + ->applyFilter($filter); + if (! $downtimes->count()) { + $this->getResponse()->json() + ->setFailData(array('filter' => 'No downtimes found matching the filter')) + ->sendResponse(); + } + $form = new DeleteDowntimesCommandForm(); + $form + ->setIsApiTarget(true) + ->setDowntimes($downtimes->fetchAll()) + ->handleRequest($this->getRequest()); + // @TODO(el): Respond w/ the downtimes deleted instead of the notifiaction added by + // DeleteDowntimesCommandForm::onSuccess(). + } +} -- cgit v1.2.3