Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitoring/commands: Add command form for scheduling a service downtime
refs #6593
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
// {{{ICINGA_LICENSE_HEADER}}} | ||
// {{{ICINGA_LICENSE_HEADER}}} | ||
|
||
namespace Icinga\Module\Monitoring\Form\Command\Service; | ||
|
||
use Icinga\Module\Monitoring\Command\Service\ScheduleServiceDowntimeCommand; | ||
use Icinga\Module\Monitoring\Form\Command\Common\ScheduleDowntimeCommandForm; | ||
use Icinga\Module\Monitoring\Object\Service; | ||
use Icinga\Web\Notification; | ||
use Icinga\Web\Request; | ||
|
||
/** | ||
* Form for scheduling a service downtime on an Icinga instance | ||
*/ | ||
class ScheduleServiceDowntimeCommandForm extends ScheduleDowntimeCommandForm | ||
{ | ||
/** | ||
* Service to set in downtime | ||
* | ||
* @var Service | ||
*/ | ||
protected $service; | ||
|
||
/** | ||
* Set the service to set in downtime | ||
* | ||
* @param Service $service | ||
* | ||
* @return $this | ||
*/ | ||
public function setService(Service $service) | ||
{ | ||
$this->service = $service; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get the service to set in downtime | ||
* | ||
* @return Service | ||
*/ | ||
public function getService() | ||
{ | ||
return $this->service; | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Zend_Form::init() For the method documentation. | ||
*/ | ||
public function init() | ||
{ | ||
$this->setSubmitLabel(mt('monitoring', 'Schedule Service Downtime')); | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Icinga\Web\Form::createElements() For the method documentation. | ||
*/ | ||
public function createElements(array $formData = array()) | ||
{ | ||
$this->addElement( | ||
'note', | ||
'command-info', | ||
array( | ||
'value' => mt( | ||
'monitoring', | ||
'This command is used to schedule a service downtime. During the specified downtime,' | ||
. ' Icinga will not send notifications out about the service. When the scheduled downtime' | ||
. ' expires, Icinga will send out notifications for the service as it normally would.' | ||
. ' Scheduled downtimes are preserved across program shutdowns and restarts.' | ||
) | ||
) | ||
); | ||
parent::createElements($formData); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get the command which is to be sent to an Icinga instance | ||
* | ||
* @return ScheduleServiceDowntimeCommand | ||
*/ | ||
public function getCommand() | ||
{ | ||
return new ScheduleServiceDowntimeCommand(); | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Icinga\Web\Form::onSuccess() For the method documentation. | ||
*/ | ||
public function onSuccess(Request $request) | ||
{ | ||
$scheduleDowntime = $this->getCommand(); | ||
$scheduleDowntime->setService($this->service); | ||
$scheduleDowntime->setComment($this->getElement('comment')->getValue()); | ||
$scheduleDowntime->setAuthor($request->getUser()); | ||
$scheduleDowntime->setStart($this->getElement('start')->getValue()); | ||
$scheduleDowntime->setEnd($this->getElement('end')->getValue()); | ||
if ($this->getElement('type')->getValue() === self::FLEXIBLE) { | ||
$scheduleDowntime->setFlexible(); | ||
$scheduleDowntime->setDuration( | ||
(float) $this->getElement('hours')->getValue() * 3600 | ||
+ (float) $this->getElement('minutes')->getValue() * 60 | ||
); | ||
} | ||
$this->getTransport($request)->send($scheduleDowntime); | ||
Notification::success(mt('monitoring', 'Scheduling service downtime..')); | ||
return true; | ||
} | ||
} |