Skip to content

Commit

Permalink
Introduce child options for service downtimes (#1091)
Browse files Browse the repository at this point in the history
`ScheduleDowntimeCommand` is basically what
`ScheduleServiceDowntimeCommand` previously was. Though, with the
addition of `get|setForAllServices()` which was only part of
`ScheduleHostDowntimeCommand`.

`ScheduleDowntimeCommand::get|setChildOption()` is completely new and
replaces `ScheduleHostDowntimeCommand::get|setTriggered()`.

`ScheduleHostDowntimeCommand`, `PropagateHostDowntimeCommand` and
`ScheduleServiceDowntimeCommand` are now deprecated.

fixes #1090
  • Loading branch information
nilmerg authored Dec 9, 2024
2 parents 2642030 + f85f893 commit 9c86ab9
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 281 deletions.
57 changes: 9 additions & 48 deletions application/forms/Command/Object/ScheduleHostDowntimeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

namespace Icinga\Module\Icingadb\Forms\Command\Object;

use CallbackFilterIterator;
use DateInterval;
use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\PropagateHostDowntimeCommand;
use Icinga\Module\Icingadb\Command\Object\ScheduleHostDowntimeCommand;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\FormDecorator\IcingaFormDecorator;
use Iterator;
use Traversable;
Expand Down Expand Up @@ -60,7 +56,7 @@ protected function assembleElements()

$decorator = new IcingaFormDecorator();

$this->addElement(
$allServices = $this->createElement(
'checkbox',
'all_services',
[
Expand All @@ -72,54 +68,19 @@ protected function assembleElements()
'value' => $this->hostDowntimeAllServices
]
);
$decorator->decorate($this->getElement('all_services'));

$this->addElement(
'select',
'child_options',
array(
'description' => t('Schedule child downtimes.'),
'label' => t('Child Options'),
'options' => [
0 => t('Do nothing with child hosts'),
1 => t('Schedule triggered downtime for all child hosts'),
2 => t('Schedule non-triggered downtime for all child hosts')
]
)
);
$decorator->decorate($this->getElement('child_options'));
$this->insertBefore($allServices, $this->getElement('child_options'));
$this->registerElement($allServices);
$decorator->decorate($allServices);
}

protected function getCommands(Iterator $objects): Traversable
{
$granted = new CallbackFilterIterator($objects, function (Model $object): bool {
return $this->isGrantedOn('icingadb/command/downtime/schedule', $object);
});

$granted->rewind(); // Forwards the pointer to the first element
if ($granted->valid()) {
if (($childOptions = (int) $this->getValue('child_options'))) {
$command = new PropagateHostDowntimeCommand();
$command->setTriggered($childOptions === 1);
} else {
$command = new ScheduleHostDowntimeCommand();
}

$command->setObjects($granted);
$command->setComment($this->getValue('comment'));
$command->setAuthor($this->getAuth()->getUser()->getUsername());
$command->setStart($this->getValue('start')->getTimestamp());
$command->setEnd($this->getValue('end')->getTimestamp());
$command->setForAllServices($this->getElement('all_services')->isChecked());

if ($this->getElement('flexible')->isChecked()) {
$command->setFixed(false);
$command->setDuration(
$this->getValue('hours') * 3600 + $this->getValue('minutes') * 60
);
}
if (! $this->getElement('all_services')->isChecked()) {
yield from parent::getCommands($objects);
}

yield $command;
foreach (parent::getCommands($objects) as $command) {
yield $command->setForAllServices();
}
}
}
26 changes: 24 additions & 2 deletions application/forms/Command/Object/ScheduleServiceDowntimeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use DateInterval;
use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\ScheduleServiceDowntimeCommand;
use Icinga\Module\Icingadb\Command\Object\ScheduleDowntimeCommand;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
Expand Down Expand Up @@ -229,6 +229,27 @@ function ($hoursInputWrapper) use ($minutesInput, $hoursInput) {

$this->add($hoursInput);
}

$this->addElement(
'select',
'child_options',
array(
'description' => t('Schedule child downtimes.'),
'label' => t('Child Options'),
'options' => [
ScheduleDowntimeCommand::IGNORE_CHILDREN => t(
'Do nothing with children'
),
ScheduleDowntimeCommand::TRIGGER_CHILDREN => t(
'Schedule a downtime for all children and trigger them by this downtime'
),
ScheduleDowntimeCommand::SCHEDULE_CHILDREN => t(
'Schedule non-triggered downtime for all children'
)
]
)
);
$decorator->decorate($this->getElement('child_options'));
}

protected function assembleSubmitButton()
Expand All @@ -253,12 +274,13 @@ protected function getCommands(Iterator $objects): Traversable

$granted->rewind(); // Forwards the pointer to the first element
if ($granted->valid()) {
$command = new ScheduleServiceDowntimeCommand();
$command = new ScheduleDowntimeCommand();
$command->setObjects($granted);
$command->setComment($this->getValue('comment'));
$command->setAuthor($this->getAuth()->getUser()->getUsername());
$command->setStart($this->getValue('start')->getTimestamp());
$command->setEnd($this->getValue('end')->getTimestamp());
$command->setChildOption((int) $this->getValue('child_options'));

if ($this->getElement('flexible')->isChecked()) {
$command->setFixed(false);
Expand Down
9 changes: 9 additions & 0 deletions doc/05-Upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
Specific version upgrades are described below. Please note that version upgrades are incremental.
If you are upgrading across multiple versions, make sure to follow the steps for each of them.

## Upgrading to Icinga DB Web v1.2

**Deprecations**

The following classes have been deprecated and will be removed in a future release:
* `\Icinga\Module\Icingadb\Command\Object\PropagateHostDowntimeCommand`
* `\Icinga\Module\Icingadb\Command\Object\ScheduleHostDowntimeCommand`
* `\Icinga\Module\Icingadb\Command\Object\ScheduleServiceDowntimeCommand`

## Upgrading to Icinga DB Web v1.1

**Breaking Changes**
Expand Down
19 changes: 9 additions & 10 deletions library/Icingadb/Command/Object/PropagateHostDowntimeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

/**
* Schedule and propagate host downtime
*
* @deprecated Use {@see ScheduleDowntimeCommand} instead
*/
class PropagateHostDowntimeCommand extends ScheduleHostDowntimeCommand
{
/**
* Whether the downtime for child hosts are all set to be triggered by this' host downtime
*
* @var bool
*/
protected $triggered = false;
protected $childOption = ScheduleDowntimeCommand::SCHEDULE_CHILDREN;

/**
* Set whether the downtime for child hosts are all set to be triggered by this' host downtime
Expand All @@ -25,9 +22,11 @@ class PropagateHostDowntimeCommand extends ScheduleHostDowntimeCommand
*/
public function setTriggered(bool $triggered = true): self
{
$this->triggered = $triggered;

return $this;
return $this->setChildOption(
$triggered
? ScheduleDowntimeCommand::TRIGGER_CHILDREN
: ScheduleDowntimeCommand::SCHEDULE_CHILDREN
);
}

/**
Expand All @@ -37,6 +36,6 @@ public function setTriggered(bool $triggered = true): self
*/
public function getTriggered(): bool
{
return $this->triggered;
return $this->getChildOption() === ScheduleDowntimeCommand::TRIGGER_CHILDREN;
}
}
Loading

0 comments on commit 9c86ab9

Please sign in to comment.