parent
f27f1097ca
commit
1b1223ea2e
|
@ -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'
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue