2015-08-20 14:25:12 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
2015-08-20 15:54:33 +02:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2015-08-20 14:25:12 +02:00
|
|
|
use Icinga\Module\Monitoring\Controller;
|
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
|
2015-08-20 15:54:33 +02:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
|
|
|
|
use Icinga\Module\Monitoring\Object\HostList;
|
2015-08-20 14:25:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Monitoring API
|
|
|
|
*/
|
|
|
|
class Monitoring_ActionsController extends Controller
|
|
|
|
{
|
2015-08-20 15:54:33 +02:00
|
|
|
/**
|
|
|
|
* 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());
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:25:12 +02:00
|
|
|
/**
|
|
|
|
* Remove host downtimes
|
|
|
|
*/
|
|
|
|
public function removeHostDowntimeAction()
|
|
|
|
{
|
2015-08-20 15:54:33 +02:00
|
|
|
// @TODO(el): Require a filter
|
2015-08-20 14:25:12 +02:00
|
|
|
$downtimes = $this->backend
|
|
|
|
->select()
|
|
|
|
->from('downtime', array('host_name', 'id' => 'downtime_internal_id'))
|
|
|
|
->where('object_type', 'host')
|
|
|
|
->applyFilter($this->getRestriction('monitoring/filter/objects'))
|
|
|
|
->handleRequest($this->getRequest())
|
|
|
|
->fetchAll();
|
|
|
|
if (empty($downtimes)) {
|
|
|
|
// @TODO(el): Use ApiResponse class for unified response handling.
|
|
|
|
$this->getRequest()->sendJson(array(
|
2015-08-20 15:54:33 +02:00
|
|
|
'status' => 'fail',
|
2015-08-20 14:25:12 +02:00
|
|
|
'message' => 'No downtimes found matching the given filter'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
$form = new DeleteDowntimesCommandForm();
|
|
|
|
$form
|
|
|
|
->setIsApiTarget(true)
|
|
|
|
->setDowntimes($downtimes)
|
|
|
|
->handleRequest($this->getRequest());
|
|
|
|
// @TODO(el): Respond w/ the downtimes deleted instead of the notifiaction added by
|
|
|
|
// DeleteDowntimesCommandForm::onSuccess().
|
|
|
|
}
|
|
|
|
}
|