/usr/share/icingaweb2/modules/monitoring/application/forms/Command/Object/ScheduleServiceDowntimeCommandForm.php is in icingaweb2-module-monitoring 2.1.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Forms\Command\Object;
use DateTime;
use DateInterval;
use Icinga\Module\Monitoring\Command\Object\ScheduleServiceDowntimeCommand;
use Icinga\Web\Notification;
use Icinga\Web\Request;
/**
* Form for scheduling service downtimes
*/
class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
{
/**
* Fixed downtime
*/
const FIXED = 'fixed';
/**
* Flexible downtime
*/
const FLEXIBLE = 'flexible';
/**
* Initialize this form
*/
public function init()
{
$this->addDescription($this->translate(
'This command is used to schedule host and service downtimes. During the specified downtime,'
. ' Icinga will not send notifications out about the hosts and services. When the scheduled'
. ' downtime expires, Icinga will send out notifications for the hosts and services as it'
. ' normally would. Scheduled downtimes are preserved across program shutdowns and'
. ' restarts.'
));
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation.
*/
public function getSubmitLabel()
{
return $this->translatePlural('Schedule downtime', 'Schedule downtimes', count($this->objects));
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$start = new DateTime;
$end = clone $start;
$end->add(new DateInterval('PT1H'));
$this->addElements(array(
array(
'textarea',
'comment',
array(
'required' => true,
'label' => $this->translate('Comment'),
'description' => $this->translate(
'If you work with other administrators, you may find it useful to share information about the'
. ' the host or service that is having problems. Make sure you enter a brief description of'
. ' what you are doing.'
)
)
),
array(
'dateTimePicker',
'start',
array(
'required' => true,
'label' => $this->translate('Start Time'),
'description' => $this->translate('Set the start date and time for the downtime.'),
'value' => $start
)
),
array(
'dateTimePicker',
'end',
array(
'required' => true,
'label' => $this->translate('End Time'),
'description' => $this->translate('Set the end date and time for the downtime.'),
'value' => $end
)
),
array(
'select',
'type',
array(
'required' => true,
'autosubmit' => true,
'label' => $this->translate('Type'),
'description' => $this->translate(
'If you select the fixed option, the downtime will be in effect between the start and end'
. ' times you specify whereas a flexible downtime starts when the host or service enters a'
. ' problem state sometime between the start and end times you specified and lasts as long'
. ' as the duration time you enter. The duration fields do not apply for fixed downtimes.'
),
'multiOptions' => array(
self::FIXED => $this->translate('Fixed'),
self::FLEXIBLE => $this->translate('Flexible')
),
'validators' => array(
array(
'InArray',
true,
array(array(self::FIXED, self::FLEXIBLE))
)
)
)
)
));
$this->addDisplayGroup(
array('start', 'end'),
'start-end',
array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div'))
)
)
);
if (isset($formData['type']) && $formData['type'] === self::FLEXIBLE) {
$this->addElements(array(
array(
'number',
'hours',
array(
'required' => true,
'label' => $this->translate('Hours'),
'value' => 2,
'min' => -1
)
),
array(
'number',
'minutes',
array(
'required' => true,
'label' => $this->translate('Minutes'),
'value' => 0,
'min' => -1
)
)
));
$this->addDisplayGroup(
array('hours', 'minutes'),
'duration',
array(
'legend' => $this->translate('Flexible Duration'),
'description' => $this->translate(
'Enter here the duration of the downtime. The downtime will be automatically deleted after this'
. ' time expired.'
),
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div')),
array(
'Description',
array('tag' => 'span', 'class' => 'description', 'placement' => 'prepend')
),
'Fieldset'
)
)
);
}
return $this;
}
public function scheduleDowntime(ScheduleServiceDowntimeCommand $downtime, Request $request)
{
$downtime
->setComment($this->getElement('comment')->getValue())
->setAuthor($request->getUser()->getUsername())
->setStart($this->getElement('start')->getValue()->getTimestamp())
->setEnd($this->getElement('end')->getValue()->getTimestamp());
if ($this->getElement('type')->getValue() === self::FLEXIBLE) {
$downtime->setFixed(false);
$downtime->setDuration(
(float) $this->getElement('hours')->getValue() * 3600
+ (float) $this->getElement('minutes')->getValue() * 60
);
}
$this->getTransport($request)->send($downtime);
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess()
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\Service $object */
$downtime = new ScheduleServiceDowntimeCommand();
$downtime->setObject($object);
$this->scheduleDowntime($downtime, $this->request);
}
Notification::success($this->translatePlural(
'Scheduling service downtime..',
'Scheduling service downtimes..',
count($this->objects)
));
return true;
}
}
|