parent
b186ce2cac
commit
6ddb004230
|
@ -4,7 +4,7 @@
|
|||
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\Module\Monitoring\Forms\Command\Object\DeleteDowntimeQuickCommandForm;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||
|
||||
|
@ -85,38 +85,27 @@ class Monitoring_DowntimeController extends Controller
|
|||
$this->view->stateName = isset($this->downtime->service_description) ?
|
||||
Service::getStateText($this->downtime->service_state) :
|
||||
Host::getStateText($this->downtime->host_state);
|
||||
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
||||
$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()
|
||||
{
|
||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||
$delDowntimeForm->setObjects($this->downtime);
|
||||
$delDowntimeForm->populate(
|
||||
array(
|
||||
'downtime_id' => $this->downtime->id,
|
||||
'redirect' => Url::fromPath('monitoring/list/downtimes')
|
||||
)
|
||||
);
|
||||
if (! $this->isService) {
|
||||
$delDowntimeForm->setAction(
|
||||
$this->view->url('monitoring/host/delete-downtime',
|
||||
array('host' => $this->downtime->host_name))
|
||||
$this->assertPermission('monitoring/command/downtime/delete');
|
||||
|
||||
$delDowntimeForm = new DeleteDowntimeQuickCommandForm();
|
||||
$delDowntimeForm->setDowntimes(array($this->downtime))
|
||||
->populate(
|
||||
array('redirect' => Url::fromPath('monitoring/list/downtimes'))
|
||||
);
|
||||
} else {
|
||||
$delDowntimeForm->setAction(
|
||||
$this->view->url('monitoring/service/delete-downtime', array(
|
||||
'host' => $this->downtime->host_name,
|
||||
'service' => $this->downtime->service_description
|
||||
))
|
||||
);
|
||||
}
|
||||
$delDowntimeForm->handleRequest();
|
||||
return $delDowntimeForm;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,39 +94,28 @@ class Monitoring_DowntimesController extends Controller
|
|||
|
||||
public function showAction()
|
||||
{
|
||||
if (false === $this->downtimes) {
|
||||
return;
|
||||
}
|
||||
$this->view->downtimes = $this->downtimes;
|
||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
||||
->setQueryString($this->filter->toQueryString());
|
||||
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/removeAll')
|
||||
$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 DeleteDowntimeCommandForm();
|
||||
$delDowntimeForm->setObjects($this->downtimes);
|
||||
$delDowntimeForm->populate(
|
||||
array(
|
||||
'downtime_id' => $this->downtime->id,
|
||||
'redirect' => Url::fromPath('monitoring/list/downtimes')
|
||||
)
|
||||
);
|
||||
if (! $this->isService) {
|
||||
$delDowntimeForm->setAction(
|
||||
$this->view->url('monitoring/host/delete-downtime',
|
||||
array('host' => $this->downtime->host_name))
|
||||
);
|
||||
} else {
|
||||
$delDowntimeForm->setAction(
|
||||
$this->view->url('monitoring/service/delete-downtime', array(
|
||||
'host' => $this->downtime->host_name,
|
||||
'service' => $this->downtime->service_description
|
||||
))
|
||||
);
|
||||
}
|
||||
return $delDowntimeForm;
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeQuickCommandForm;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
||||
|
@ -294,7 +294,7 @@ class Monitoring_ListController extends Controller
|
|||
));
|
||||
|
||||
if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
|
||||
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||
$this->view->delDowntimeForm = new DeleteDowntimeQuickCommandForm();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,16 @@
|
|||
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
|
||||
{
|
||||
protected $downtimes;
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Zend_Form::init() For the method documentation.
|
||||
|
@ -27,14 +30,6 @@ class DeleteDowntimeCommandForm extends ObjectsCommandForm
|
|||
public function createElements(array $formData = array())
|
||||
{
|
||||
$this->addElements(array(
|
||||
array(
|
||||
'hidden',
|
||||
'downtime_id',
|
||||
array(
|
||||
'required' => true,
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'hidden',
|
||||
'redirect',
|
||||
|
@ -45,48 +40,50 @@ class DeleteDowntimeCommandForm extends ObjectsCommandForm
|
|||
));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
|
||||
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation.
|
||||
*/
|
||||
public function addSubmitButton()
|
||||
public function getSubmitLabel()
|
||||
{
|
||||
$this->addElement(
|
||||
'button',
|
||||
'btn_submit',
|
||||
array(
|
||||
'ignore' => true,
|
||||
'escape' => false,
|
||||
'type' => 'submit',
|
||||
'class' => 'link-like',
|
||||
'label' => $this->getView()->icon('trash'),
|
||||
'title' => $this->translate('Delete this downtime'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
return $this->translatePlural('Remove', 'Remove All', count($this->downtimes));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
||||
*/
|
||||
public function onSuccess()
|
||||
{
|
||||
foreach ($this->objects as $object) {
|
||||
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
|
||||
foreach ($this->downtimes as $downtime) {
|
||||
$delDowntime = new DeleteDowntimeCommand();
|
||||
$delDowntime
|
||||
->setObject($object)
|
||||
->setDowntimeId($this->getElement('downtime_id')->getValue());
|
||||
$delDowntime->setDowntimeId($downtime->id);
|
||||
$delDowntime->setDowntimeType(
|
||||
isset($downtime->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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the downtimes to be deleted upon success
|
||||
*
|
||||
* @param type $downtimes
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDowntimes($downtimes)
|
||||
{
|
||||
$this->downtimes = $downtimes;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
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 DeleteDowntimeQuickCommandForm extends DeleteDowntimeCommandForm
|
||||
{
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
|
||||
*/
|
||||
public function addSubmitButton()
|
||||
{
|
||||
$this->addElement(
|
||||
'button',
|
||||
'btn_submit',
|
||||
array(
|
||||
'ignore' => true,
|
||||
'escape' => false,
|
||||
'type' => 'submit',
|
||||
'class' => 'link-like',
|
||||
'label' => $this->getView()->icon('trash'),
|
||||
'title' => $this->translate('Delete this downtime'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -3,19 +3,22 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Command\Object;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\IcingaCommand;
|
||||
|
||||
/**
|
||||
* Delete a host or service downtime
|
||||
*/
|
||||
class DeleteDowntimeCommand extends ObjectCommand
|
||||
class DeleteDowntimeCommand extends IcingaCommand
|
||||
{
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
|
||||
* Downtime for a host
|
||||
*/
|
||||
protected $allowedObjects = array(
|
||||
self::TYPE_HOST,
|
||||
self::TYPE_SERVICE
|
||||
);
|
||||
const DOWNTIME_TYPE_HOST = 'host';
|
||||
|
||||
/**
|
||||
* Downtime for a service
|
||||
*/
|
||||
const DOWNTIME_TYPE_SERVICE = 'service';
|
||||
|
||||
/**
|
||||
* ID of the downtime that is to be deleted
|
||||
|
@ -23,6 +26,31 @@ class DeleteDowntimeCommand extends ObjectCommand
|
|||
* @var int
|
||||
*/
|
||||
protected $downtimeId;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var type
|
||||
*/
|
||||
protected $downtimeType = self::DOWNTIME_TYPE_HOST;
|
||||
|
||||
/**
|
||||
* Set the downtime type, either host or service
|
||||
*
|
||||
* @param string $type the downtime type
|
||||
*/
|
||||
public function setDowntimeType($type)
|
||||
{
|
||||
$this->downtimeType = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function getDowntimeType()
|
||||
{
|
||||
return $this->downtimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ID of the downtime that is to be deleted
|
||||
|
|
|
@ -337,7 +337,7 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
|
|||
|
||||
public function renderDeleteDowntime(DeleteDowntimeCommand $command)
|
||||
{
|
||||
if ($command->getObject()->getType() === $command::TYPE_HOST) {
|
||||
if ($command->getDowntimeType() === 'host') {
|
||||
$commandString = 'DEL_HOST_DOWNTIME';
|
||||
} else {
|
||||
$commandString = 'DEL_SVC_DOWNTIME';
|
||||
|
|
|
@ -90,7 +90,7 @@ abstract class MonitoredObjectController extends Controller
|
|||
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||
$delDowntimeForm
|
||||
->setObjects($this->object)
|
||||
->setDowntimes($this->object->downtimes)
|
||||
->handleRequest();
|
||||
$this->view->delDowntimeForm = $delDowntimeForm;
|
||||
}
|
||||
|
@ -147,16 +147,6 @@ abstract class MonitoredObjectController extends Controller
|
|||
$this->handleCommandForm(new DeleteCommentCommandForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a downtime
|
||||
*/
|
||||
public function deleteDowntimeAction()
|
||||
{
|
||||
$this->assertHttpMethod('POST');
|
||||
$this->assertPermission('monitoring/command/downtime/delete');
|
||||
$this->handleCommandForm(new DeleteDowntimeCommandForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create tabs
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue