Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce child options for service downtimes #1091

Open
wants to merge 2 commits into
base: dependencies
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 9 additions & 48 deletions application/forms/Command/Object/ScheduleHostDowntimeForm.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?php

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Ignored error pattern #^Cannot call method getTimestamp\(\) on mixed\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Ignored error pattern #^Cannot call method getUsername\(\) on Icinga\\User\|null\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Ignored error pattern #^Cannot cast mixed to int\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Ignored error pattern #^Parameter \#1 \$comment of method Icinga\\Module\\Icingadb\\Command\\Object\\WithCommentCommand\:\:setComment\(\) expects string, mixed given\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Ignored error pattern #^Cannot call method getTimestamp\(\) on mixed\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Ignored error pattern #^Cannot call method getUsername\(\) on Icinga\\User\|null\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Ignored error pattern #^Cannot cast mixed to int\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

Check failure on line 1 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Ignored error pattern #^Parameter \#1 \$comment of method Icinga\\Module\\Icingadb\\Command\\Object\\WithCommentCommand\:\:setComment\(\) expects string, mixed given\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php was not matched in reported errors.

/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */

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 @@

$decorator = new IcingaFormDecorator();

$this->addElement(
$allServices = $this->createElement(
'checkbox',
'all_services',
[
Expand All @@ -72,54 +68,19 @@
'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()) {

Check failure on line 78 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Ignored error pattern #^Call to an undefined method ipl\\Html\\Contract\\FormElement\:\:isChecked\(\)\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php is expected to occur 2 times, but occurred only 1 time.

Check failure on line 78 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Ignored error pattern #^Call to an undefined method ipl\\Html\\Contract\\FormElement\:\:isChecked\(\)\.$# in path /home/runner/work/icingadb-web/icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.php is expected to occur 2 times, but occurred only 1 time.
yield from parent::getCommands($objects);
}

yield $command;
foreach (parent::getCommands($objects) as $command) {
yield $command->setForAllServices();

Check failure on line 83 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Call to an undefined method Icinga\Module\Icingadb\Command\IcingaCommand::setForAllServices().

Check failure on line 83 in application/forms/Command/Object/ScheduleHostDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Icingadb\Command\IcingaCommand::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 @@

$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 @@

$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'));

Check failure on line 283 in application/forms/Command/Object/ScheduleServiceDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Cannot cast mixed to int.

Check failure on line 283 in application/forms/Command/Object/ScheduleServiceDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Parameter #1 $option of method Icinga\Module\Icingadb\Command\Object\ScheduleDowntimeCommand::setChildOption() expects 0|1|2, int given.

Check failure on line 283 in application/forms/Command/Object/ScheduleServiceDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Cannot cast mixed to int.

Check failure on line 283 in application/forms/Command/Object/ScheduleServiceDowntimeForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Parameter #1 $option of method Icinga\Module\Icingadb\Command\Object\ScheduleDowntimeCommand::setChildOption() expects 0|1|2, int given.

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
Loading