From 775bc67fecf908ddd6ed33acdb65d430ecbc1686 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Mon, 29 Jun 2015 11:11:56 +0200 Subject: [PATCH] Add imports support for Endpoint --- application/forms/IcingaEndpointForm.php | 5 +++++ library/Director/Objects/IcingaEndpoint.php | 2 ++ schema/mysql-changes/upgrade_20.sql | 17 ++++++++++++++++ schema/mysql.sql | 18 +++++++++++++++++ schema/pgsql-changes/upgrade-11.sql | 20 +++++++++++++++++++ schema/pgsql.sql | 22 +++++++++++++++++++++ 6 files changed, 84 insertions(+) create mode 100644 schema/mysql-changes/upgrade_20.sql create mode 100644 schema/pgsql-changes/upgrade-11.sql diff --git a/application/forms/IcingaEndpointForm.php b/application/forms/IcingaEndpointForm.php index 78e0b374..f792eac3 100644 --- a/application/forms/IcingaEndpointForm.php +++ b/application/forms/IcingaEndpointForm.php @@ -53,5 +53,10 @@ class IcingaEndpointForm extends DirectorObjectForm 'description' => $this->translate('Check this host in this specific Icinga cluster zone'), 'required' => true )); + + $this->addElement('text', 'imports', array( + 'label' => $this->translate('Imports'), + 'description' => $this->translate('The inherited endpoint template names') + )); } } diff --git a/library/Director/Objects/IcingaEndpoint.php b/library/Director/Objects/IcingaEndpoint.php index 27673bc3..73e0ab47 100644 --- a/library/Director/Objects/IcingaEndpoint.php +++ b/library/Director/Objects/IcingaEndpoint.php @@ -6,6 +6,8 @@ class IcingaEndpoint extends IcingaObject { protected $table = 'icinga_endpoint'; + protected $supportsImports = true; + protected $defaultProperties = array( 'id' => null, 'zone_id' => null, diff --git a/schema/mysql-changes/upgrade_20.sql b/schema/mysql-changes/upgrade_20.sql new file mode 100644 index 00000000..91a86a27 --- /dev/null +++ b/schema/mysql-changes/upgrade_20.sql @@ -0,0 +1,17 @@ +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id INT(10) UNSIGNED NOT NULL, + parent_endpoint_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + UNIQUE KEY unique_order (endpoint_id, weight), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY endpoint (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY endpoint (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/mysql.sql b/schema/mysql.sql index 9c202863..9b97a1f4 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -295,6 +295,24 @@ CREATE TABLE icinga_endpoint ( ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id INT(10) UNSIGNED NOT NULL, + parent_endpoint_id INT(10) UNSIGNED NOT NULL, + weight MEDIUMINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + UNIQUE KEY unique_order (endpoint_id, weight), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY endpoint (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY endpoint (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE icinga_host ( id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, object_name VARCHAR(255) NOT NULL, diff --git a/schema/pgsql-changes/upgrade-11.sql b/schema/pgsql-changes/upgrade-11.sql new file mode 100644 index 00000000..fce4e61c --- /dev/null +++ b/schema/pgsql-changes/upgrade-11.sql @@ -0,0 +1,20 @@ +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id integer NOT NULL, + parent_endpoint_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX endpoint_inheritance_unique_order ON icinga_endpoint_inheritance (endpoint_id, weight); +CREATE INDEX endpoint_inheritance_endpoint ON icinga_endpoint_inheritance (endpoint_id); +CREATE INDEX endpoint_inheritance_endpoint_parent ON icinga_endpoint_inheritance (parent_endpoint_id); diff --git a/schema/pgsql.sql b/schema/pgsql.sql index b3427d0b..c5c7dee8 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -375,6 +375,28 @@ COMMENT ON COLUMN icinga_endpoint.port IS '5665 if not set'; COMMENT ON COLUMN icinga_endpoint.log_duration IS '1d if not set'; +CREATE TABLE icinga_endpoint_inheritance ( + endpoint_id integer NOT NULL, + parent_endpoint_id integer NOT NULL, + weight integer DEFAULT NULL, + PRIMARY KEY (endpoint_id, parent_endpoint_id), + CONSTRAINT icinga_endpoint_inheritance_endpoint + FOREIGN KEY (endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT icinga_endpoint_inheritance_parent_endpoint + FOREIGN KEY (parent_endpoint_id) + REFERENCES icinga_endpoint (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +); + +CREATE UNIQUE INDEX endpoint_inheritance_unique_order ON icinga_endpoint_inheritance (endpoint_id, weight); +CREATE INDEX endpoint_inheritance_endpoint ON icinga_endpoint_inheritance (endpoint_id); +CREATE INDEX endpoint_inheritance_endpoint_parent ON icinga_endpoint_inheritance (parent_endpoint_id); + + CREATE TABLE icinga_host ( id serial, object_name character varying(255) NOT NULL,