monitoring/API: Expose scheduling host downtimes

refs #9606
This commit is contained in:
Eric Lippmann 2015-08-20 15:54:33 +02:00
parent f27f1097ca
commit 1b1223ea2e
1 changed files with 29 additions and 2 deletions

View File

@ -1,8 +1,11 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
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\Object\HostList;
/**
* Monitoring API
@ -14,12 +17,36 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
*/
class Monitoring_ActionsController extends Controller
{
/**
* Schedule host downtimes
*/
public function scheduleHostDowntimeAction()
{
// @TODO(el): Require a filter
// @TODO(el): $this->backend->list('host')->handleRequest()->fetchAll()
$hostList = new HostList($this->backend);
$this->applyRestriction('monitoring/filter/objects', $hostList);
$hostList->addFilter(Filter::fromQueryString((string) $this->params));
if (! $hostList->count()) {
// @TODO(el): Use ApiResponse class for unified response handling.
$this->getRequest()->sendJson(array(
'status' => 'fail',
'message' => 'No hosts found matching the given filter'
));
}
$form = new ScheduleHostDowntimeCommandForm();
$form
->setIsApiTarget(true)
->setObjects($hostList->fetch())
->handleRequest($this->getRequest());
}
/**
* Remove host downtimes
*/
public function removeHostDowntimeAction()
{
// @TODO(el): Require a filter?
// @TODO(el): Require a filter
$downtimes = $this->backend
->select()
->from('downtime', array('host_name', 'id' => 'downtime_internal_id'))
@ -30,7 +57,7 @@ class Monitoring_ActionsController extends Controller
if (empty($downtimes)) {
// @TODO(el): Use ApiResponse class for unified response handling.
$this->getRequest()->sendJson(array(
'status' => 'error',
'status' => 'fail',
'message' => 'No downtimes found matching the given filter'
));
}