From 1358a5d49f3a615361009ff42648a6d38aa9cc39 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 4 Sep 2014 15:42:46 +0200 Subject: [PATCH] monitoring/commands: Add command form for scheduling a service downtime refs #6593 --- .../ScheduleServiceDowntimeCommandForm.php | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php diff --git a/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php new file mode 100644 index 000000000..7f13034a0 --- /dev/null +++ b/modules/monitoring/application/forms/Command/Service/ScheduleServiceDowntimeCommandForm.php @@ -0,0 +1,113 @@ +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; + } +}