From c35f0976c27ae5e90f76c6dba41b52b03ac4934e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 21 Aug 2015 10:19:46 +0200 Subject: [PATCH] monitoring/API: Expose scheduling service downtimes refs #9606 --- .../controllers/ActionsController.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/ActionsController.php b/modules/monitoring/application/controllers/ActionsController.php index 27d150a98..1704a02f1 100644 --- a/modules/monitoring/application/controllers/ActionsController.php +++ b/modules/monitoring/application/controllers/ActionsController.php @@ -5,7 +5,9 @@ use Icinga\Data\Filter\Filter; use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm; +use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm; use Icinga\Module\Monitoring\Object\HostList; +use Icinga\Module\Monitoring\Object\ServiceList; /** * Monitoring API @@ -24,7 +26,7 @@ class Monitoring_ActionsController extends Controller $hostList->addFilter(Filter::fromQueryString((string) $this->params)); if (! $hostList->count()) { // @TODO(el): Use ApiResponse class for unified response handling. - $this->getRequest()->sendJson(array( + $this->getResponse()->sendJson(array( 'status' => 'fail', 'message' => 'No hosts found matching the given filter' )); @@ -51,7 +53,7 @@ class Monitoring_ActionsController extends Controller ->fetchAll(); if (empty($downtimes)) { // @TODO(el): Use ApiResponse class for unified response handling. - $this->getRequest()->sendJson(array( + $this->getResponse()->sendJson(array( 'status' => 'fail', 'message' => 'No downtimes found matching the given filter' )); @@ -64,4 +66,28 @@ class Monitoring_ActionsController extends Controller // @TODO(el): Respond w/ the downtimes deleted instead of the notifiaction added by // DeleteDowntimesCommandForm::onSuccess(). } + + /** + * Schedule service downtimes + */ + public function scheduleServiceDowntimeAction() + { + // @TODO(el): Require a filter + // @TODO(el): $this->backend->list('service')->handleRequest()->fetchAll() + $serviceList = new ServiceList($this->backend); + $this->applyRestriction('monitoring/filter/objects', $serviceList); + $serviceList->addFilter(Filter::fromQueryString((string) $this->params)); + if (! $serviceList->count()) { + // @TODO(el): Use ApiResponse class for unified response handling. + $this->getResponse()->sendJson(array( + 'status' => 'fail', + 'message' => 'No services found matching the given filter' + )); + } + $form = new ScheduleServiceDowntimeCommandForm(); + $form + ->setIsApiTarget(true) + ->setObjects($serviceList->fetch()) + ->handleRequest($this->getRequest()); + } }