parent
f27f1097ca
commit
1b1223ea2e
|
@ -1,8 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Object\HostList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitoring API
|
* Monitoring API
|
||||||
|
@ -14,12 +17,36 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
|
||||||
*/
|
*/
|
||||||
class Monitoring_ActionsController extends Controller
|
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
|
* Remove host downtimes
|
||||||
*/
|
*/
|
||||||
public function removeHostDowntimeAction()
|
public function removeHostDowntimeAction()
|
||||||
{
|
{
|
||||||
// @TODO(el): Require a filter?
|
// @TODO(el): Require a filter
|
||||||
$downtimes = $this->backend
|
$downtimes = $this->backend
|
||||||
->select()
|
->select()
|
||||||
->from('downtime', array('host_name', 'id' => 'downtime_internal_id'))
|
->from('downtime', array('host_name', 'id' => 'downtime_internal_id'))
|
||||||
|
@ -30,7 +57,7 @@ class Monitoring_ActionsController extends Controller
|
||||||
if (empty($downtimes)) {
|
if (empty($downtimes)) {
|
||||||
// @TODO(el): Use ApiResponse class for unified response handling.
|
// @TODO(el): Use ApiResponse class for unified response handling.
|
||||||
$this->getRequest()->sendJson(array(
|
$this->getRequest()->sendJson(array(
|
||||||
'status' => 'error',
|
'status' => 'fail',
|
||||||
'message' => 'No downtimes found matching the given filter'
|
'message' => 'No downtimes found matching the given filter'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue