From 904ec7c4358d753a7f23b3522c499faee64aae3f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 12 Apr 2019 12:12:32 +0200 Subject: [PATCH] ScheduledDowntimes: Hosts with Services, optional schema, form, rendering fixes #1831 --- .../forms/IcingaScheduledDowntimeForm.php | 10 ++++++++ .../Objects/IcingaScheduledDowntime.php | 24 +++++++++++++++++++ schema/mysql-migrations/upgrade_162.sql | 6 +++++ schema/mysql.sql | 3 ++- schema/pgsql-migrations/upgrade_162.sql | 6 +++++ schema/pgsql.sql | 3 ++- 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 schema/mysql-migrations/upgrade_162.sql create mode 100644 schema/pgsql-migrations/upgrade_162.sql diff --git a/application/forms/IcingaScheduledDowntimeForm.php b/application/forms/IcingaScheduledDowntimeForm.php index e9231b6b..d7c83162 100644 --- a/application/forms/IcingaScheduledDowntimeForm.php +++ b/application/forms/IcingaScheduledDowntimeForm.php @@ -93,6 +93,16 @@ class IcingaScheduledDowntimeForm extends DirectorObjectForm return $this; } + if ($applyTo === 'host') { + $this->addBoolean('with_services', [ + 'label' => $this->translate('With Services'), + 'description' => $this->translate( + 'Whether Downtimes should also explicitly be scheduled for' + . ' all Services belonging to affected Hosts' + ) + ]); + } + $suggestionContext = ucfirst($applyTo) . 'FilterColumns'; $this->addAssignFilter([ 'suggestionContext' => $suggestionContext, diff --git a/library/Director/Objects/IcingaScheduledDowntime.php b/library/Director/Objects/IcingaScheduledDowntime.php index c8f59d54..45cf1e3f 100644 --- a/library/Director/Objects/IcingaScheduledDowntime.php +++ b/library/Director/Objects/IcingaScheduledDowntime.php @@ -21,6 +21,7 @@ class IcingaScheduledDowntime extends IcingaObject 'duration' => null, 'apply_to' => null, 'assign_filter' => null, + 'with_services' => null, ]; protected $supportsImports = true; @@ -46,6 +47,7 @@ class IcingaScheduledDowntime extends IcingaObject 'apply_to', 'object_name', 'object_type', + 'with_services', ]; /** @@ -101,8 +103,30 @@ class IcingaScheduledDowntime extends IcingaObject return false; } + /** + * @return string + */ + protected function renderSuffix() + { + if ($this->get('with_services') === 'y' && $this->get('apply_to') === 'host') { + return parent::renderSuffix() . $this->renderCloneForServices(); + } else { + return parent::renderSuffix(); + } + } + protected function prefersGlobalZone() { return false; } + + protected function renderCloneForServices() + { + $services = clone($this); + $services + ->set('with_services', 'n') + ->set('apply_to', 'service'); + + return $services->toConfigString(); + } } diff --git a/schema/mysql-migrations/upgrade_162.sql b/schema/mysql-migrations/upgrade_162.sql new file mode 100644 index 00000000..7af104ac --- /dev/null +++ b/schema/mysql-migrations/upgrade_162.sql @@ -0,0 +1,6 @@ +ALTER TABLE icinga_scheduled_downtime + ADD COLUMN with_services ENUM('y', 'n') NULL DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (162, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql index 1cdc064b..2602b4b9 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -1798,6 +1798,7 @@ CREATE TABLE icinga_scheduled_downtime ( comment TEXT DEFAULT NULL, fixed ENUM('y', 'n') DEFAULT NULL, duration INT(10) UNSIGNED DEFAULT NULL, + with_services ENUM('y', 'n') NULL DEFAULT NULL, PRIMARY KEY (id), UNIQUE INDEX object_name (object_name), CONSTRAINT icinga_scheduled_downtime_zone @@ -1843,4 +1844,4 @@ CREATE TABLE icinga_scheduled_downtime_range ( INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (161, NOW()); + VALUES (162, NOW()); diff --git a/schema/pgsql-migrations/upgrade_162.sql b/schema/pgsql-migrations/upgrade_162.sql new file mode 100644 index 00000000..0bc20caf --- /dev/null +++ b/schema/pgsql-migrations/upgrade_162.sql @@ -0,0 +1,6 @@ +CREATE TABLE icinga_scheduled_downtime + ADD COLUMN with_services enum_boolean NULL DEFAULT NULL; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (162, NOW()); diff --git a/schema/pgsql.sql b/schema/pgsql.sql index c3073948..2c3f2aca 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -2098,6 +2098,7 @@ CREATE TABLE icinga_scheduled_downtime ( comment text DEFAULT NULL, fixed enum_boolean DEFAULT NULL, duration int DEFAULT NULL, + with_services enum_boolean NULL DEFAULT NULL, PRIMARY KEY (id), CONSTRAINT icinga_scheduled_downtime_zone FOREIGN KEY (zone_id) @@ -2155,4 +2156,4 @@ COMMENT ON COLUMN icinga_scheduled_downtime_range.merge_behaviour IS 'set -> = { INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (161, NOW()); + VALUES (162, NOW());