2015-04-21 14:49:27 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2015-04-23 11:31:53 +02:00
|
|
|
use Icinga\Module\Monitoring\Object\Service;
|
|
|
|
use Icinga\Module\Monitoring\Object\Host;
|
2015-04-30 16:50:55 +02:00
|
|
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
2015-05-07 14:03:09 +02:00
|
|
|
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
|
2015-04-21 14:49:27 +02:00
|
|
|
use Icinga\Web\Url;
|
|
|
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display detailed information about a downtime
|
|
|
|
*/
|
|
|
|
class Monitoring_DowntimeController extends Controller
|
|
|
|
{
|
2015-05-04 16:30:26 +02:00
|
|
|
/**
|
|
|
|
* The fetched downtime
|
|
|
|
*
|
|
|
|
* @var stdClass
|
|
|
|
*/
|
2015-04-21 14:49:27 +02:00
|
|
|
protected $downtime;
|
2015-05-04 16:30:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the downtime is a service or not
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2015-04-21 17:24:17 +02:00
|
|
|
protected $isService;
|
2015-05-04 16:30:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the downtime matching the given id and add tabs
|
|
|
|
*/
|
2015-04-21 14:49:27 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2015-05-21 17:17:25 +02:00
|
|
|
$downtimeId = $this->params->getRequired('downtime_id');
|
|
|
|
|
2015-06-15 15:59:50 +02:00
|
|
|
$query = $this->backend->select()->from('downtime', array(
|
2015-04-21 14:49:27 +02:00
|
|
|
'id' => 'downtime_internal_id',
|
2015-05-26 17:15:03 +02:00
|
|
|
'objecttype' => 'object_type',
|
2015-04-21 14:49:27 +02:00
|
|
|
'comment' => 'downtime_comment',
|
|
|
|
'author_name' => 'downtime_author_name',
|
|
|
|
'start' => 'downtime_start',
|
|
|
|
'scheduled_start' => 'downtime_scheduled_start',
|
|
|
|
'scheduled_end' => 'downtime_scheduled_end',
|
|
|
|
'end' => 'downtime_end',
|
|
|
|
'duration' => 'downtime_duration',
|
|
|
|
'is_flexible' => 'downtime_is_flexible',
|
|
|
|
'is_fixed' => 'downtime_is_fixed',
|
|
|
|
'is_in_effect' => 'downtime_is_in_effect',
|
|
|
|
'entry_time' => 'downtime_entry_time',
|
2015-05-26 17:15:03 +02:00
|
|
|
'host_state',
|
|
|
|
'service_state',
|
2015-04-21 14:49:27 +02:00
|
|
|
'host_name',
|
|
|
|
'service_description',
|
|
|
|
'host_display_name',
|
|
|
|
'service_display_name'
|
2015-06-15 15:59:50 +02:00
|
|
|
))->where('downtime_internal_id', $downtimeId);
|
|
|
|
$this->applyRestriction('monitoring/filter/objects', $query);
|
2015-05-21 17:17:25 +02:00
|
|
|
|
2015-06-15 15:59:50 +02:00
|
|
|
$this->downtime = $query->getQuery()->fetchRow();
|
2015-05-21 17:17:25 +02:00
|
|
|
if ($this->downtime === false) {
|
|
|
|
$this->httpNotFound($this->translate('Downtime not found'));
|
2015-04-27 17:53:17 +02:00
|
|
|
}
|
2015-05-21 17:17:25 +02:00
|
|
|
|
2015-04-21 17:24:17 +02:00
|
|
|
if (isset($this->downtime->service_description)) {
|
|
|
|
$this->isService = true;
|
|
|
|
} else {
|
|
|
|
$this->isService = false;
|
|
|
|
}
|
2015-05-21 17:17:25 +02:00
|
|
|
|
2015-04-21 14:49:27 +02:00
|
|
|
$this->getTabs()
|
|
|
|
->add(
|
|
|
|
'downtime',
|
|
|
|
array(
|
|
|
|
'title' => $this->translate(
|
|
|
|
'Display detailed information about a downtime.'
|
|
|
|
),
|
|
|
|
'icon' => 'plug',
|
|
|
|
'label' => $this->translate('Downtime'),
|
|
|
|
'url' =>'monitoring/downtimes/show'
|
|
|
|
)
|
2015-05-07 17:17:24 +02:00
|
|
|
)->activate('downtime')->extend(new DashboardAction());
|
2015-04-21 14:49:27 +02:00
|
|
|
}
|
2015-05-04 16:30:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the detail view for a downtime
|
|
|
|
*/
|
2015-04-21 14:49:27 +02:00
|
|
|
public function showAction()
|
|
|
|
{
|
|
|
|
$this->view->downtime = $this->downtime;
|
2015-04-21 17:24:17 +02:00
|
|
|
$this->view->isService = $this->isService;
|
2015-05-07 17:17:24 +02:00
|
|
|
$this->view->stateName = isset($this->downtime->service_description) ?
|
2015-04-23 11:31:53 +02:00
|
|
|
Service::getStateText($this->downtime->service_state) :
|
|
|
|
Host::getStateText($this->downtime->host_state);
|
2015-04-21 14:49:27 +02:00
|
|
|
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
|
|
|
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
|
2015-05-26 17:15:03 +02:00
|
|
|
->setParam('host', $this->downtime->host_name);
|
2015-04-21 14:49:27 +02:00
|
|
|
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
2015-05-26 17:15:03 +02:00
|
|
|
->setParam('host', $this->downtime->host_name)
|
2015-04-21 14:49:27 +02:00
|
|
|
->setParam('service', $this->downtime->service_description);
|
2015-04-27 18:04:10 +02:00
|
|
|
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
|
|
|
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
2015-05-07 14:03:09 +02:00
|
|
|
$this->view->delDowntimeForm->populate(
|
|
|
|
array(
|
|
|
|
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
|
|
|
'downtime_id' => $this->downtime->id,
|
|
|
|
'downtime_is_service' => $this->isService
|
|
|
|
)
|
|
|
|
);
|
2015-04-27 18:04:10 +02:00
|
|
|
}
|
2015-04-21 14:49:27 +02:00
|
|
|
}
|
2015-05-04 16:30:26 +02:00
|
|
|
|
2015-05-04 17:59:16 +02:00
|
|
|
/**
|
|
|
|
* Receive DeleteDowntimeCommandForm post from other controller
|
|
|
|
*/
|
|
|
|
public function removeAction()
|
|
|
|
{
|
|
|
|
$this->assertHttpMethod('POST');
|
|
|
|
$this->createDelDowntimeForm();
|
|
|
|
}
|
|
|
|
|
2015-05-04 16:30:26 +02:00
|
|
|
/**
|
|
|
|
* Create a command form to delete a single comment
|
|
|
|
*
|
|
|
|
* @return DeleteDowntimeCommandForm
|
|
|
|
*/
|
2015-04-21 17:24:17 +02:00
|
|
|
private function createDelDowntimeForm()
|
|
|
|
{
|
2015-04-27 18:04:10 +02:00
|
|
|
$this->assertPermission('monitoring/command/downtime/delete');
|
2015-04-30 16:50:55 +02:00
|
|
|
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
|
|
|
$delDowntimeForm->setAction(
|
|
|
|
Url::fromPath('monitoring/downtime/show')
|
|
|
|
->setParam('downtime_id', $this->downtime->id)
|
|
|
|
);
|
2015-04-27 18:04:10 +02:00
|
|
|
$delDowntimeForm->handleRequest();
|
2015-04-21 17:24:17 +02:00
|
|
|
return $delDowntimeForm;
|
|
|
|
}
|
2015-04-21 14:49:27 +02:00
|
|
|
}
|