[icinga-checkins] icinga.org: icingaweb2-module-director/feature/nested-apply-rules-12033: Notification: add fields support

git at icinga.org git at icinga.org
Fri Oct 21 10:08:04 CEST 2016


Module: icingaweb2-module-director
Branch: feature/nested-apply-rules-12033
Commit: cf4dccc817212fcc4dd96a2b2b26e6fe62f04e19
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=cf4dccc817212fcc4dd96a2b2b26e6fe62f04e19

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 13 14:34:25 2016 +0000

Notification: add fields support

fixes #12642

---

 library/Director/Objects/IcingaNotification.php    |    2 ++
 .../Director/Objects/IcingaNotificationField.php   |   18 ++++++++++++++
 schema/mysql-migrations/upgrade_117.sql            |   20 +++++++++++++++
 schema/mysql.sql                                   |   19 +++++++++++++-
 schema/pgsql-migrations/upgrade_117.sql            |   26 ++++++++++++++++++++
 schema/pgsql.sql                                   |   25 ++++++++++++++++++-
 6 files changed, 108 insertions(+), 2 deletions(-)

diff --git a/library/Director/Objects/IcingaNotification.php b/library/Director/Objects/IcingaNotification.php
index 37e74f1..c5c5cb5 100644
--- a/library/Director/Objects/IcingaNotification.php
+++ b/library/Director/Objects/IcingaNotification.php
@@ -29,6 +29,8 @@ class IcingaNotification extends IcingaObject
 
     protected $supportsCustomVars = true;
 
+    protected $supportsFields = true;
+
     protected $supportsImports = true;
 
     protected $supportsApplyRules = true;
diff --git a/library/Director/Objects/IcingaNotificationField.php b/library/Director/Objects/IcingaNotificationField.php
new file mode 100644
index 0000000..7e3e912
--- /dev/null
+++ b/library/Director/Objects/IcingaNotificationField.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Icinga\Module\Director\Objects;
+
+use Icinga\Module\Director\Data\Db\DbObject;
+
+class IcingaNotificationField extends DbObject
+{
+    protected $keyName = array('notification_id', 'datafield_id');
+
+    protected $table = 'icinga_notification_field';
+
+    protected $defaultProperties = array(
+        'notification_id' => null,
+        'datafield_id'    => null,
+        'is_required'     => null
+    );
+}
diff --git a/schema/mysql-migrations/upgrade_117.sql b/schema/mysql-migrations/upgrade_117.sql
new file mode 100644
index 0000000..e0ab4f3
--- /dev/null
+++ b/schema/mysql-migrations/upgrade_117.sql
@@ -0,0 +1,20 @@
+CREATE TABLE icinga_notification_field (
+  notification_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates',
+  datafield_id INT(10) UNSIGNED NOT NULL,
+  is_required ENUM('y', 'n') NOT NULL,
+  PRIMARY KEY (notification_id, datafield_id),
+  CONSTRAINT icinga_notification_field_notification
+  FOREIGN KEY notification (notification_id)
+    REFERENCES icinga_notification (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE,
+  CONSTRAINT icinga_notification_field_datafield
+  FOREIGN KEY datafield(datafield_id)
+  REFERENCES director_datafield (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO director_schema_migration
+  (schema_version, migration_time)
+  VALUES (117, NOW());
diff --git a/schema/mysql.sql b/schema/mysql.sql
index e972358..9e37ed6 100644
--- a/schema/mysql.sql
+++ b/schema/mysql.sql
@@ -1089,6 +1089,23 @@ CREATE TABLE icinga_notification_var (
     ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+CREATE TABLE icinga_notification_field (
+  notification_id INT(10) UNSIGNED NOT NULL COMMENT 'Makes only sense for templates',
+  datafield_id INT(10) UNSIGNED NOT NULL,
+  is_required ENUM('y', 'n') NOT NULL,
+  PRIMARY KEY (notification_id, datafield_id),
+  CONSTRAINT icinga_notification_field_notification
+  FOREIGN KEY notification (notification_id)
+    REFERENCES icinga_notification (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE,
+  CONSTRAINT icinga_notification_field_datafield
+  FOREIGN KEY datafield(datafield_id)
+  REFERENCES director_datafield (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 CREATE TABLE icinga_notification_inheritance (
   notification_id INT(10) UNSIGNED NOT NULL,
   parent_notification_id INT(10) UNSIGNED NOT NULL,
@@ -1398,4 +1415,4 @@ CREATE TABLE sync_run (
 
 INSERT INTO director_schema_migration
   SET migration_time = NOW(),
-      schema_version = 116;
+      schema_version = 117;
diff --git a/schema/pgsql-migrations/upgrade_117.sql b/schema/pgsql-migrations/upgrade_117.sql
new file mode 100644
index 0000000..6f3820f
--- /dev/null
+++ b/schema/pgsql-migrations/upgrade_117.sql
@@ -0,0 +1,26 @@
+CREATE TABLE icinga_notification_field (
+  notification_id integer NOT NULL,
+  datafield_id integer NOT NULL,
+  is_required enum_boolean NOT NULL,
+  PRIMARY KEY (notification_id, datafield_id),
+  CONSTRAINT icinga_notification_field_notification
+  FOREIGN KEY (notification_id)
+    REFERENCES icinga_notification (id)
+  ON DELETE CASCADE
+  ON UPDATE CASCADE,
+  CONSTRAINT icinga_notification_field_datafield
+  FOREIGN KEY (datafield_id)
+    REFERENCES director_datafield (id)
+  ON DELETE CASCADE
+  ON UPDATE CASCADE
+);
+
+CREATE UNIQUE INDEX notification_field_key ON icinga_notification_field (notification_id, datafield_id);
+CREATE INDEX notification_field_notification ON icinga_notification_field (notification_id);
+CREATE INDEX notification_field_datafield ON icinga_notification_field (datafield_id);
+COMMENT ON COLUMN icinga_notification_field.notification_id IS 'Makes only sense for templates';
+
+
+INSERT INTO director_schema_migration
+  (schema_version, migration_time)
+  VALUES (117, NOW());
diff --git a/schema/pgsql.sql b/schema/pgsql.sql
index 6e050c1..7e72201 100644
--- a/schema/pgsql.sql
+++ b/schema/pgsql.sql
@@ -1601,6 +1601,29 @@ CREATE TABLE icinga_notification_var (
 CREATE UNIQUE INDEX notification_var_search_idx ON icinga_notification_var (varname);
 
 
+CREATE TABLE icinga_notification_field (
+  notification_id integer NOT NULL,
+  datafield_id integer NOT NULL,
+  is_required enum_boolean NOT NULL,
+  PRIMARY KEY (notification_id, datafield_id),
+  CONSTRAINT icinga_notification_field_notification
+  FOREIGN KEY (notification_id)
+    REFERENCES icinga_notification (id)
+  ON DELETE CASCADE
+  ON UPDATE CASCADE,
+  CONSTRAINT icinga_notification_field_datafield
+  FOREIGN KEY (datafield_id)
+    REFERENCES director_datafield (id)
+  ON DELETE CASCADE
+  ON UPDATE CASCADE
+);
+
+CREATE UNIQUE INDEX notification_field_key ON icinga_notification_field (notification_id, datafield_id);
+CREATE INDEX notification_field_notification ON icinga_notification_field (notification_id);
+CREATE INDEX notification_field_datafield ON icinga_notification_field (datafield_id);
+COMMENT ON COLUMN icinga_notification_field.notification_id IS 'Makes only sense for templates';
+
+
 CREATE TABLE icinga_notification_inheritance (
   notification_id integer NOT NULL,
   parent_notification_id integer NOT NULL,
@@ -1623,4 +1646,4 @@ CREATE UNIQUE INDEX notification_inheritance ON icinga_notification_inheritance
 
 INSERT INTO director_schema_migration
   (schema_version, migration_time)
-  VALUES (116, NOW());
+  VALUES (117, NOW());



More information about the icinga-checkins mailing list