[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: WIP: IcingaHostGroup: Add apply statements

git at icinga.org git at icinga.org
Wed Jun 8 16:48:21 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: 2535edec78a22b2bc05b4d3f6b0bb5af60df643b
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=2535edec78a22b2bc05b4d3f6b0bb5af60df643b

Author: Markus Frosch <lazyfrosch at icinga.org>
Date:   Wed Jun  8 16:45:46 2016 +0200

WIP: IcingaHostGroup: Add apply statements

---

 application/forms/IcingaHostGroupForm.php          |   13 +++++++++++++
 library/Director/Objects/IcingaHostGroup.php       |    3 +++
 .../Director/Objects/IcingaHostGroupAssignment.php |   20 ++++++++++++++++++++
 schema/mysql-migrations/upgrade_X2.sql             |   16 ++++++++++++++++
 schema/mysql.sql                                   |   13 +++++++++++++
 schema/pgsql-migrations/upgrade_X2.sql             |   16 ++++++++++++++++
 schema/pgsql.sql                                   |   12 ++++++++++++
 7 files changed, 93 insertions(+)

diff --git a/application/forms/IcingaHostGroupForm.php b/application/forms/IcingaHostGroupForm.php
index 8b404e1..cd422df 100644
--- a/application/forms/IcingaHostGroupForm.php
+++ b/application/forms/IcingaHostGroupForm.php
@@ -18,5 +18,18 @@ class IcingaHostGroupForm extends DirectorObjectForm
 
         $this->addGroupDisplayNameElement()
              ->setButtons();
+        $this->addAssignmentElements();
+    }
+
+    public function addAssignmentElements()
+    {
+        $sub = new AssignListSubForm();
+        $sub->setObject($this->object());
+        $sub->setup();
+        $sub->setOrder(30);
+
+        $this->addSubForm($sub, 'assignlist');
+
+        return $this;
     }
 }
diff --git a/library/Director/Objects/IcingaHostGroup.php b/library/Director/Objects/IcingaHostGroup.php
index 51adae2..1e65a30 100644
--- a/library/Director/Objects/IcingaHostGroup.php
+++ b/library/Director/Objects/IcingaHostGroup.php
@@ -5,4 +5,7 @@ namespace Icinga\Module\Director\Objects;
 class IcingaHostGroup extends IcingaObjectGroup
 {
     protected $table = 'icinga_hostgroup';
+
+    // TODO: move to IcingaObjectGroup when supported for ServiceGroup
+    protected $supportsApplyRules = true;
 }
diff --git a/library/Director/Objects/IcingaHostGroupAssignment.php b/library/Director/Objects/IcingaHostGroupAssignment.php
new file mode 100644
index 0000000..4e0e5a2
--- /dev/null
+++ b/library/Director/Objects/IcingaHostGroupAssignment.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Icinga\Module\Director\Objects;
+
+class IcingaHostGroupAssignment extends IcingaObject
+{
+    protected $table = 'icinga_hostgroup_assignment';
+
+    protected $keyName = 'id';
+
+    protected $defaultProperties = array(
+        'id'            => null,
+        'service_id'    => null,
+        'filter_string' => null,
+    );
+
+    protected $relations = array(
+        'service' => 'IcingaHostGroup',
+    );
+}
diff --git a/schema/mysql-migrations/upgrade_X2.sql b/schema/mysql-migrations/upgrade_X2.sql
new file mode 100644
index 0000000..fb4d979
--- /dev/null
+++ b/schema/mysql-migrations/upgrade_X2.sql
@@ -0,0 +1,16 @@
+CREATE TABLE icinga_hostgroup_assignment (
+  id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+  hostgroup_id INT(10) UNSIGNED NOT NULL,
+  filter_string TEXT NOT NULL,
+  assign_type ENUM('assign', 'ignore') NOT NULL DEFAULT 'assign',
+  PRIMARY KEY (id),
+  CONSTRAINT icinga_hostgroup_assignment
+  FOREIGN KEY hostgroup (hostgroup_id)
+  REFERENCES icinga_hostgroup (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+-- INSERT INTO director_schema_migration
+--   (schema_version, migration_time)
+--   VALUES (X2, NOW());
diff --git a/schema/mysql.sql b/schema/mysql.sql
index 1013d70..1771313 100644
--- a/schema/mysql.sql
+++ b/schema/mysql.sql
@@ -697,6 +697,19 @@ CREATE TABLE icinga_hostgroup_inheritance (
     ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+CREATE TABLE icinga_hostgroup_assignment (
+  id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+  hostgroup_id INT(10) UNSIGNED NOT NULL,
+  filter_string TEXT NOT NULL,
+  assign_type ENUM('assign', 'ignore') NOT NULL DEFAULT 'assign',
+  PRIMARY KEY (id),
+  CONSTRAINT icinga_hostgroup_assignment
+  FOREIGN KEY hostgroup (hostgroup_id)
+  REFERENCES icinga_hostgroup (id)
+    ON DELETE CASCADE
+    ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
 CREATE TABLE icinga_servicegroup (
   id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
   object_name VARCHAR(255) DEFAULT NULL,
diff --git a/schema/pgsql-migrations/upgrade_X2.sql b/schema/pgsql-migrations/upgrade_X2.sql
new file mode 100644
index 0000000..365e76d
--- /dev/null
+++ b/schema/pgsql-migrations/upgrade_X2.sql
@@ -0,0 +1,16 @@
+CREATE TABLE icinga_hostgroup_assignment (
+  id bigserial,
+  hostgroup_id integer NOT NULL,
+  filter_string TEXT NOT NULL,
+  assign_type enum_assign_type NOT NULL DEFAULT 'assign',
+  PRIMARY KEY (id),
+  CONSTRAINT icinga_hostgroup_assignment
+  FOREIGN KEY (hostgroup_id)
+  REFERENCES icinga_hostgroup (id)
+  ON DELETE CASCADE
+  ON UPDATE CASCADE
+);
+
+-- INSERT INTO director_schema_migration
+--   (schema_version, migration_time)
+--   VALUES (X2, NOW());
diff --git a/schema/pgsql.sql b/schema/pgsql.sql
index dd057a4..7b8c10f 100644
--- a/schema/pgsql.sql
+++ b/schema/pgsql.sql
@@ -874,6 +874,18 @@ CREATE UNIQUE INDEX hostgroup_inheritance_unique_order ON icinga_hostgroup_inher
 CREATE INDEX hostgroup_inheritance_hostgroup ON icinga_hostgroup_inheritance (hostgroup_id);
 CREATE INDEX hostgroup_inheritance_hostgroup_parent ON icinga_hostgroup_inheritance (parent_hostgroup_id);
 
+CREATE TABLE icinga_hostgroup_assignment (
+  id bigserial,
+  hostgroup_id integer NOT NULL,
+  filter_string TEXT NOT NULL,
+  assign_type enum_assign_type NOT NULL DEFAULT 'assign',
+  PRIMARY KEY (id),
+  CONSTRAINT icinga_hostgroup_assignment
+  FOREIGN KEY (hostgroup_id)
+  REFERENCES icinga_hostgroup (id)
+  ON DELETE CASCADE
+  ON UPDATE CASCADE
+);
 
 CREATE TABLE icinga_servicegroup (
   id serial,



More information about the icinga-checkins mailing list