Skip to content

Commit

Permalink
Merge branch 'feature/downtime-detail-view-8902'
Browse files Browse the repository at this point in the history
resolves #8902
  • Loading branch information
majentsch committed May 7, 2015
2 parents 6df031d + d316b31 commit 2ade247
Show file tree
Hide file tree
Showing 15 changed files with 771 additions and 64 deletions.
117 changes: 117 additions & 0 deletions modules/monitoring/application/controllers/DowntimeController.php
@@ -0,0 +1,117 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */

use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Display detailed information about a downtime
*/
class Monitoring_DowntimeController extends Controller
{
protected $downtime;

protected $isService;

/**
* Add tabs
*/
public function init()
{
$downtimeId = $this->params->get('downtime_id');

$this->downtime = $this->backend->select()->from('downtime', array(
'id' => 'downtime_internal_id',
'objecttype' => 'downtime_objecttype',
'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',
'host_state' => 'downtime_host_state',
'service_state' => 'downtime_service_state',
'host_name',
'host',
'service',
'service_description',
'host_display_name',
'service_display_name'
))->where('downtime_internal_id', $downtimeId)->getQuery()->fetchRow();

if (false === $this->downtime) {
throw new Zend_Controller_Action_Exception($this->translate('Downtime not found'));
}

if (isset($this->downtime->service_description)) {
$this->isService = true;
} else {
$this->isService = false;
}

$this->getTabs()
->add(
'downtime',
array(
'title' => $this->translate(
'Display detailed information about a downtime.'
),
'icon' => 'plug',
'label' => $this->translate('Downtime'),
'url' =>'monitoring/downtimes/show'
)
)->activate('downtime')->extend(new DashboardAction());
}

public function showAction()
{
$this->view->downtime = $this->downtime;
$this->view->isService = $this->isService;
$this->view->stateName = isset($this->downtime->service_description) ?
Service::getStateText($this->downtime->service_state) :
Host::getStateText($this->downtime->host_state);
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
->setParam('host', $this->downtime->host);
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
->setParam('host', $this->downtime->host)
->setParam('service', $this->downtime->service_description);
if ($this->hasPermission('monitoring/command/downtime/delete')) {
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
}
}

private function createDelDowntimeForm()
{
$this->assertPermission('monitoring/command/downtime/delete');

$delDowntimeForm = new DeleteDowntimeCommandForm();
$delDowntimeForm->setAction(
Url::fromPath('monitoring/downtime/show')
->setParam('downtime_id', $this->downtime->id)
);
$delDowntimeForm->populate(
array(
'redirect' => Url::fromPath('monitoring/list/downtimes'),
'downtime_id' => $this->downtime->id
)
);
$delDowntimeForm->handleRequest();
return $delDowntimeForm;
}
}
121 changes: 121 additions & 0 deletions modules/monitoring/application/controllers/DowntimesController.php
@@ -0,0 +1,121 @@
<?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\Object\Service;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Display detailed information about a downtime
*/
class Monitoring_DowntimesController extends Controller
{
protected $downtimes;

protected $filter;

/**
* Add tabs
*/
public function init()
{
$this->filter = Filter::fromQueryString(str_replace(
'downtime_id',
'downtime_internal_id',
(string)$this->params
));
$this->downtimes = $this->backend->select()->from('downtime', array(
'id' => 'downtime_internal_id',
'objecttype' => 'downtime_objecttype',
'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',
'host_state' => 'downtime_host_state',
'service_state' => 'downtime_service_state',
'host_name',
'host',
'service',
'service_description',
'host_display_name',
'service_display_name'
))->addFilter($this->filter)->getQuery()->fetchAll();
if (false === $this->downtimes) {
throw new Zend_Controller_Action_Exception(
$this->translate('Downtime not found')
);
}

$this->getTabs()
->add(
'downtimes',
array(
'title' => $this->translate(
'Display detailed information about multiple downtimes.'
),
'icon' => 'plug',
'label' => $this->translate('Downtimes'),
'url' =>'monitoring/downtimes/show'
)
)->activate('downtimes')->extend(new DashboardAction());

foreach ($this->downtimes as $downtime) {
if (isset($downtime->service_description)) {
$downtime->isService = true;
} else {
$downtime->isService = false;
}

if ($downtime->isService) {
$downtime->stateText = Service::getStateText($downtime->service_state);
} else {
$downtime->stateText = Host::getStateText($downtime->host_state);
}
}
}

public function showAction()
{
$this->view->downtimes = $this->downtimes;
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString($this->filter->toQueryString());
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/remove-all')
->setParams($this->params);
}

public function removeAllAction()
{
$this->assertPermission('monitoring/command/downtime/delete');
$this->view->downtimes = $this->downtimes;
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString($this->filter->toQueryString());
$delDowntimeForm = new DeleteDowntimesCommandForm();
$delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
$delDowntimeForm->addDescription(sprintf(
$this->translate('Confirm removal of %d downtimes.'),
count($this->downtimes)
));
$delDowntimeForm->setDowntimes($this->downtimes)
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
->handleRequest();
$this->view->delDowntimeForm = $delDowntimeForm;
}
}
Expand Up @@ -4,12 +4,13 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object;

use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
use Icinga\Web\Notification;

/**
* Form for deleting host or service downtimes
*/
class DeleteDowntimeCommandForm extends ObjectsCommandForm
class DeleteDowntimeCommandForm extends CommandForm
{
/**
* (non-PHPDoc)
Expand All @@ -19,33 +20,34 @@ public function init()
{
$this->setAttrib('class', 'inline');
}

/**
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$this->addElements(array(
$this->addElements(
array(
'hidden',
'downtime_id',
array(
'required' => true,
'decorators' => array('ViewHelper')
)
),
array(
'hidden',
'redirect',
'hidden',
'downtime_id',
array(
'decorators' => array('ViewHelper')
)
),
array(
'decorators' => array('ViewHelper')
'hidden',
'redirect',
array(
'decorators' => array('ViewHelper')
)
)
)
));
);
return $this;
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
Expand All @@ -67,26 +69,32 @@ public function addSubmitButton()
);
return $this;
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess()
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
$delDowntime = new DeleteDowntimeCommand();
$delDowntime
->setObject($object)
->setDowntimeId($this->getElement('downtime_id')->getValue());
$this->getTransport($this->request)->send($delDowntime);
}
$id = $this->getElement('downtime_id')->getValue();

// Presence of downtime id, only delete this specific downtime
$firstDowntime = $this->downtimes[0];

$delDowntime = new DeleteDowntimeCommand();
$delDowntime->setDowntimeId($id);
$delDowntime->setDowntimeType(
isset($firstDowntime->service_description) ?
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
);
$this->getTransport($this->request)->send($delDowntime);

$redirect = $this->getElement('redirect')->getValue();
if (! empty($redirect)) {
$this->setRedirectUrl($redirect);
}
Notification::success($this->translate('Deleting downtime..'));
Notification::success($this->translate('Deleting downtime.'));
return true;
}
}

0 comments on commit 2ade247

Please sign in to comment.