mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 00:34:03 +02:00
parent
b186ce2cac
commit
6ddb004230
@ -4,7 +4,7 @@
|
|||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Object\Service;
|
use Icinga\Module\Monitoring\Object\Service;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
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\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||||
|
|
||||||
@ -85,38 +85,27 @@ class Monitoring_DowntimeController extends Controller
|
|||||||
$this->view->stateName = isset($this->downtime->service_description) ?
|
$this->view->stateName = isset($this->downtime->service_description) ?
|
||||||
Service::getStateText($this->downtime->service_state) :
|
Service::getStateText($this->downtime->service_state) :
|
||||||
Host::getStateText($this->downtime->host_state);
|
Host::getStateText($this->downtime->host_state);
|
||||||
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
||||||
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
|
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
|
||||||
->setParam('host', $this->downtime->host);
|
->setParam('host', $this->downtime->host);
|
||||||
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
||||||
->setParam('host', $this->downtime->host)
|
->setParam('host', $this->downtime->host)
|
||||||
->setParam('service', $this->downtime->service_description);
|
->setParam('service', $this->downtime->service_description);
|
||||||
|
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
|
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createDelDowntimeForm()
|
private function createDelDowntimeForm()
|
||||||
{
|
{
|
||||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
$this->assertPermission('monitoring/command/downtime/delete');
|
||||||
$delDowntimeForm->setObjects($this->downtime);
|
|
||||||
$delDowntimeForm->populate(
|
$delDowntimeForm = new DeleteDowntimeQuickCommandForm();
|
||||||
array(
|
$delDowntimeForm->setDowntimes(array($this->downtime))
|
||||||
'downtime_id' => $this->downtime->id,
|
->populate(
|
||||||
'redirect' => Url::fromPath('monitoring/list/downtimes')
|
array('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->handleRequest();
|
||||||
$delDowntimeForm->setAction(
|
|
||||||
$this->view->url('monitoring/service/delete-downtime', array(
|
|
||||||
'host' => $this->downtime->host_name,
|
|
||||||
'service' => $this->downtime->service_description
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $delDowntimeForm;
|
return $delDowntimeForm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,39 +94,28 @@ class Monitoring_DowntimesController extends Controller
|
|||||||
|
|
||||||
public function showAction()
|
public function showAction()
|
||||||
{
|
{
|
||||||
if (false === $this->downtimes) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->view->downtimes = $this->downtimes;
|
$this->view->downtimes = $this->downtimes;
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
||||||
->setQueryString($this->filter->toQueryString());
|
->setQueryString($this->filter->toQueryString());
|
||||||
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/removeAll')
|
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/remove-all')
|
||||||
->setParams($this->params);
|
->setParams($this->params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeAllAction()
|
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 = new DeleteDowntimeCommandForm();
|
||||||
$delDowntimeForm->setObjects($this->downtimes);
|
$delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
|
||||||
$delDowntimeForm->populate(
|
$delDowntimeForm->addDescription(sprintf(
|
||||||
array(
|
$this->translate('Confirm removal of %d downtimes.'),
|
||||||
'downtime_id' => $this->downtime->id,
|
count($this->downtimes)
|
||||||
'redirect' => Url::fromPath('monitoring/list/downtimes')
|
));
|
||||||
)
|
$delDowntimeForm->setDowntimes($this->downtimes)
|
||||||
);
|
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
|
||||||
if (! $this->isService) {
|
->handleRequest();
|
||||||
$delDowntimeForm->setAction(
|
$this->view->delDowntimeForm = $delDowntimeForm;
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
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\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||||
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
||||||
@ -294,7 +294,7 @@ class Monitoring_ListController extends Controller
|
|||||||
));
|
));
|
||||||
|
|
||||||
if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
|
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;
|
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
|
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
|
||||||
|
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form for deleting host or service downtimes
|
* Form for deleting host or service downtimes
|
||||||
*/
|
*/
|
||||||
class DeleteDowntimeCommandForm extends ObjectsCommandForm
|
class DeleteDowntimeCommandForm extends CommandForm
|
||||||
{
|
{
|
||||||
|
protected $downtimes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Zend_Form::init() For the method documentation.
|
* @see \Zend_Form::init() For the method documentation.
|
||||||
@ -27,14 +30,6 @@ class DeleteDowntimeCommandForm extends ObjectsCommandForm
|
|||||||
public function createElements(array $formData = array())
|
public function createElements(array $formData = array())
|
||||||
{
|
{
|
||||||
$this->addElements(array(
|
$this->addElements(array(
|
||||||
array(
|
|
||||||
'hidden',
|
|
||||||
'downtime_id',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'decorators' => array('ViewHelper')
|
|
||||||
)
|
|
||||||
),
|
|
||||||
array(
|
array(
|
||||||
'hidden',
|
'hidden',
|
||||||
'redirect',
|
'redirect',
|
||||||
@ -45,48 +40,50 @@ class DeleteDowntimeCommandForm extends ObjectsCommandForm
|
|||||||
));
|
));
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (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(
|
return $this->translatePlural('Remove', 'Remove All', count($this->downtimes));
|
||||||
'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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
foreach ($this->objects as $object) {
|
foreach ($this->downtimes as $downtime) {
|
||||||
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
|
|
||||||
$delDowntime = new DeleteDowntimeCommand();
|
$delDowntime = new DeleteDowntimeCommand();
|
||||||
$delDowntime
|
$delDowntime->setDowntimeId($downtime->id);
|
||||||
->setObject($object)
|
$delDowntime->setDowntimeType(
|
||||||
->setDowntimeId($this->getElement('downtime_id')->getValue());
|
isset($downtime->service_description) ?
|
||||||
|
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
||||||
|
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
||||||
|
);
|
||||||
$this->getTransport($this->request)->send($delDowntime);
|
$this->getTransport($this->request)->send($delDowntime);
|
||||||
}
|
}
|
||||||
$redirect = $this->getElement('redirect')->getValue();
|
$redirect = $this->getElement('redirect')->getValue();
|
||||||
if (! empty($redirect)) {
|
if (! empty($redirect)) {
|
||||||
$this->setRedirectUrl($redirect);
|
$this->setRedirectUrl($redirect);
|
||||||
}
|
}
|
||||||
Notification::success($this->translate('Deleting downtime..'));
|
Notification::success($this->translate('Deleting downtime.'));
|
||||||
return true;
|
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;
|
namespace Icinga\Module\Monitoring\Command\Object;
|
||||||
|
|
||||||
|
use Icinga\Module\Monitoring\Command\IcingaCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a host or service downtime
|
* Delete a host or service downtime
|
||||||
*/
|
*/
|
||||||
class DeleteDowntimeCommand extends ObjectCommand
|
class DeleteDowntimeCommand extends IcingaCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* Downtime for a host
|
||||||
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
|
|
||||||
*/
|
*/
|
||||||
protected $allowedObjects = array(
|
const DOWNTIME_TYPE_HOST = 'host';
|
||||||
self::TYPE_HOST,
|
|
||||||
self::TYPE_SERVICE
|
/**
|
||||||
);
|
* Downtime for a service
|
||||||
|
*/
|
||||||
|
const DOWNTIME_TYPE_SERVICE = 'service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID of the downtime that is to be deleted
|
* ID of the downtime that is to be deleted
|
||||||
@ -23,6 +26,31 @@ class DeleteDowntimeCommand extends ObjectCommand
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $downtimeId;
|
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
|
* Set the ID of the downtime that is to be deleted
|
||||||
|
@ -337,7 +337,7 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
|
|||||||
|
|
||||||
public function renderDeleteDowntime(DeleteDowntimeCommand $command)
|
public function renderDeleteDowntime(DeleteDowntimeCommand $command)
|
||||||
{
|
{
|
||||||
if ($command->getObject()->getType() === $command::TYPE_HOST) {
|
if ($command->getDowntimeType() === 'host') {
|
||||||
$commandString = 'DEL_HOST_DOWNTIME';
|
$commandString = 'DEL_HOST_DOWNTIME';
|
||||||
} else {
|
} else {
|
||||||
$commandString = 'DEL_SVC_DOWNTIME';
|
$commandString = 'DEL_SVC_DOWNTIME';
|
||||||
|
@ -90,7 +90,7 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||||
$delDowntimeForm
|
$delDowntimeForm
|
||||||
->setObjects($this->object)
|
->setDowntimes($this->object->downtimes)
|
||||||
->handleRequest();
|
->handleRequest();
|
||||||
$this->view->delDowntimeForm = $delDowntimeForm;
|
$this->view->delDowntimeForm = $delDowntimeForm;
|
||||||
}
|
}
|
||||||
@ -147,16 +147,6 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
$this->handleCommandForm(new DeleteCommentCommandForm());
|
$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
|
* Create tabs
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user