Don't let the user schedule illogical host or service downtimes

refs #10847
This commit is contained in:
Alexander A. Klimov 2016-04-18 17:55:29 +02:00
parent 242cdab754
commit 66bdae81ac
2 changed files with 32 additions and 0 deletions

View File

@ -61,6 +61,22 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
*/
public function onSuccess()
{
$end = $this->getValue('end')->getTimestamp();
if ($end <= $this->getValue('start')->getTimestamp()) {
$endElement = $this->_elements['end'];
$endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
$endElement->addError($this->translate('The end time must be greater than the start time'));
return false;
}
$now = new DateTime;
if ($end <= $now->getTimestamp()) {
$endElement = $this->_elements['end'];
$endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
$endElement->addError($this->translate('A downtime must not be in the past'));
return false;
}
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\Host $object */
if (($childHostsEl = $this->getElement('child_hosts')) !== null) {

View File

@ -197,6 +197,22 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
*/
public function onSuccess()
{
$end = $this->getValue('end')->getTimestamp();
if ($end <= $this->getValue('start')->getTimestamp()) {
$endElement = $this->_elements['end'];
$endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
$endElement->addError($this->translate('The end time must be greater than the start time'));
return false;
}
$now = new DateTime;
if ($end <= $now->getTimestamp()) {
$endElement = $this->_elements['end'];
$endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
$endElement->addError($this->translate('A downtime must not be in the past'));
return false;
}
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\Service $object */
$downtime = new ScheduleServiceDowntimeCommand();