]> granicus.if.org Git - icinga2/commitdiff
DB IDO: Add zones, zonestatus tables
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 17 Jun 2015 13:45:45 +0000 (15:45 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 14 Jul 2015 16:09:24 +0000 (18:09 +0200)
refs #9286

doc/22-appendix.md
lib/db_ido/CMakeLists.txt
lib/db_ido/dbobject.cpp
lib/db_ido/dbobject.hpp
lib/db_ido/endpointdbobject.cpp
lib/db_ido/zonedbobject.cpp [new file with mode: 0644]
lib/db_ido/zonedbobject.hpp [new file with mode: 0644]
lib/db_ido_mysql/schema/mysql.sql
lib/db_ido_mysql/schema/upgrade/2.4.0.sql
lib/db_ido_pgsql/schema/pgsql.sql
lib/db_ido_pgsql/schema/upgrade/2.4.0.sql

index aaea1e573b540f2515cfb7e1eae3f44b46ced9c2..f8a4f02beb23066e79b9dd11ea0a01d2956001a4 100644 (file)
@@ -168,6 +168,7 @@ New table: `endpointstatus`
   endpoints           | endpoint_object_id | bigint   | NULL    | FK: objects table
   endpoints           | identity           | TEXT     | NULL    | endpoint name
   endpoints           | node               | TEXT     | NULL    | local node name
+  endpoints           | zone_object_id     | bigint   | NULL    | zone object where this endpoint is a member of
 
 New table: `endpointstatus`
 
@@ -177,6 +178,16 @@ New table: `endpointstatus`
   endpointstatus      | identity           | TEXT     | NULL    | endpoint name
   endpointstatus      | node               | TEXT     | NULL    | local node name
   endpointstatus      | is_connected       | smallint | 0       | update on endpoint connect/disconnect
+  endpointstatus      | zone_object_id     | bigint   | NULL    | zone object where this endpoint is a member of
+
+New tables: `zones` and `zonestatus`:
+
+  Table               | Column             | Type     | Default | Description
+  --------------------|--------------------|----------|---------|-------------
+  zones               | zone_object_id     | bigint   | NULL    | FK: objects table
+  zones               | parent_zone_object_id | bigint   | NULL    | FK: zones table
+  zones               | is_global          | smallint | 0       | zone is global
+
 
 New columns:
 
index 9a7baa361d96e4a30e375cc3681818493c321cb2..99b6a8f20f1ec71521420c459489d4da5d85f675 100644 (file)
@@ -25,7 +25,7 @@ set(db_ido_SOURCES
   dbreference.cpp dbtype.cpp dbvalue.cpp endpointdbobject.cpp hostdbobject.cpp
   hostgroupdbobject.cpp idochecktask.cpp servicedbobject.cpp
   servicegroupdbobject.cpp timeperioddbobject.cpp userdbobject.cpp
-  usergroupdbobject.cpp
+  usergroupdbobject.cpp zonedbobject.cpp
 )
 
 if(ICINGA2_UNITY_BUILD)
index b2749364380c7f7f6e3e7eaefb296a5f6dfbe41f..32a89f85561cb7976ef5836100bf539c18438e68 100644 (file)
@@ -122,8 +122,8 @@ void DbObject::SendStatusUpdate(void)
        query.Fields = fields;
        query.Fields->Set(GetType()->GetIDColumn(), GetObject());
 
-       /* do not override our own endpoint dbobject id */
-       if (GetType()->GetTable() != "endpoint") {
+       /* do not override endpoint_object_id for endpoints & zones */
+       if (query.Table != "endpointstatus" && query.Table != "zonestatus") {
                String node = IcingaApplication::GetInstance()->GetNodeName();
 
                Log(LogDebug, "DbObject")
index 559df2f55566d3a2f5708dcab24a5588dd4f6642..296629ae262e2a160ae3c5e6a273323c35822482 100644 (file)
@@ -51,6 +51,7 @@ enum DbObjectType
        DbObjectTypeContactGroup = 11,
        DbObjectTypeCommand = 12,
        DbObjectTypeEndpoint = 13,
+       DbObjectTypeZone = 14,
 };
 
 /**
index 504ba3f2509034a8c9cacc3e6f0d5b0af9cf9599..60a243fd43a85e32e244f76e4303373c05c2844d 100644 (file)
@@ -53,6 +53,7 @@ Dictionary::Ptr EndpointDbObject::GetConfigFields(void) const
 
        fields->Set("identity", endpoint->GetName());
        fields->Set("node", IcingaApplication::GetInstance()->GetNodeName());
+       fields->Set("zone_object_id", endpoint->GetZone());
 
        return fields;
 }
@@ -67,6 +68,7 @@ Dictionary::Ptr EndpointDbObject::GetStatusFields(void) const
 
        fields->Set("identity", endpoint->GetName());
        fields->Set("node", IcingaApplication::GetInstance()->GetNodeName());
+       fields->Set("zone_object_id", endpoint->GetZone());
        fields->Set("is_connected", EndpointIsConnected(endpoint));
 
        return fields;
@@ -120,6 +122,7 @@ void EndpointDbObject::OnConfigUpdate(void)
        Dictionary::Ptr fields1 = new Dictionary();
        fields1->Set("identity", endpoint->GetName());
        fields1->Set("node", IcingaApplication::GetInstance()->GetNodeName());
+       fields1->Set("zone_object_id", endpoint->GetZone());
        fields1->Set("is_connected", EndpointIsConnected(endpoint));
        fields1->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
        fields1->Set("endpoint_object_id", endpoint);
diff --git a/lib/db_ido/zonedbobject.cpp b/lib/db_ido/zonedbobject.cpp
new file mode 100644 (file)
index 0000000..35dfd0b
--- /dev/null
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)    *
+ *                                                                            *
+ * This program is free software; you can redistribute it and/or              *
+ * modify it under the terms of the GNU General Public License                *
+ * as published by the Free Software Foundation; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU General Public License for more details.                               *
+ *                                                                            *
+ * You should have received a copy of the GNU General Public License          *
+ * along with this program; if not, write to the Free Software Foundation     *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+#include "db_ido/zonedbobject.hpp"
+#include "db_ido/dbtype.hpp"
+#include "db_ido/dbvalue.hpp"
+#include "base/logger.hpp"
+
+using namespace icinga;
+
+
+REGISTER_DBTYPE(Zone, "zone", DbObjectTypeZone, "zone_object_id", ZoneDbObject);
+
+ZoneDbObject::ZoneDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
+       : DbObject(type, name1, name2)
+{ }
+
+Dictionary::Ptr ZoneDbObject::GetConfigFields(void) const
+{
+       Dictionary::Ptr fields = new Dictionary();
+       Zone::Ptr zone = static_pointer_cast<Zone>(GetObject());
+
+       fields->Set("is_global", zone->IsGlobal() ? 1 : 0);
+       fields->Set("parent_zone_object_id", zone->GetParent());
+
+       return fields;
+}
+
+Dictionary::Ptr ZoneDbObject::GetStatusFields(void) const
+{
+       Zone::Ptr zone = static_pointer_cast<Zone>(GetObject());
+
+       Log(LogDebug, "ZoneDbObject")
+           << "update status for zone '" << zone->GetName() << "'";
+
+       Dictionary::Ptr fields = new Dictionary();
+       fields->Set("parent_zone_object_id", zone->GetParent());
+
+       return fields;
+}
diff --git a/lib/db_ido/zonedbobject.hpp b/lib/db_ido/zonedbobject.hpp
new file mode 100644 (file)
index 0000000..c0a1395
--- /dev/null
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)    *
+ *                                                                            *
+ * This program is free software; you can redistribute it and/or              *
+ * modify it under the terms of the GNU General Public License                *
+ * as published by the Free Software Foundation; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU General Public License for more details.                               *
+ *                                                                            *
+ * You should have received a copy of the GNU General Public License          *
+ * along with this program; if not, write to the Free Software Foundation     *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+#ifndef ZONEDBOBJECT_H
+#define ZONEDBOBJECT_H
+
+#include "db_ido/dbobject.hpp"
+#include "base/dynamicobject.hpp"
+#include "remote/zone.hpp"
+
+namespace icinga
+{
+
+/**
+ * An Endpoint database object.
+ *
+ * @ingroup ido
+ */
+class ZoneDbObject : public DbObject
+{
+public:
+       DECLARE_PTR_TYPEDEFS(ZoneDbObject);
+
+       ZoneDbObject(const intrusive_ptr<DbType>& type, const String& name1, const String& name2);
+
+       virtual Dictionary::Ptr GetConfigFields(void) const;
+       virtual Dictionary::Ptr GetStatusFields(void) const;
+};
+
+}
+
+#endif /* ZONEDBOBJECT_H */
index 099ffbaa67a1717d64bcdc5dbde1fe5cbee4fa6b..7f6aa86726c624a8fbb452bddc5ac95ce7c4d866 100644 (file)
@@ -1362,6 +1362,7 @@ CREATE TABLE IF NOT EXISTS icinga_endpoints (
   endpoint_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   instance_id bigint unsigned default 0,
   endpoint_object_id bigint(20) unsigned DEFAULT '0',
+  zone_object_id bigint(20) unsigned DEFAULT '0',
   config_type smallint(6) DEFAULT '0',
   identity varchar(255) DEFAULT NULL,
   node varchar(255) DEFAULT NULL,
@@ -1378,6 +1379,7 @@ CREATE TABLE IF NOT EXISTS icinga_endpointstatus (
   endpointstatus_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   instance_id bigint unsigned default 0,
   endpoint_object_id bigint(20) unsigned DEFAULT '0',
+  zone_object_id bigint(20) unsigned DEFAULT '0',
   status_update_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   identity varchar(255) DEFAULT NULL,
   node varchar(255) DEFAULT NULL,
@@ -1385,6 +1387,37 @@ CREATE TABLE IF NOT EXISTS icinga_endpointstatus (
   PRIMARY KEY  (endpointstatus_id)
 ) ENGINE=InnoDB COMMENT='Endpoint status';
 
+--
+-- Table structure for table icinga_zones
+--
+
+CREATE TABLE IF NOT EXISTS icinga_zones (
+  zone_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  instance_id bigint unsigned default 0,
+  zone_object_id bigint(20) unsigned DEFAULT '0',
+  config_type smallint(6) DEFAULT '0',
+  parent_zone_object_id bigint(20) unsigned DEFAULT '0',
+  is_global smallint(6),
+  PRIMARY KEY  (zone_id)
+) ENGINE=InnoDB COMMENT='Zone configuration';
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table icinga_zonestatus
+--
+
+CREATE TABLE IF NOT EXISTS icinga_zonestatus (
+  zonestatus_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  instance_id bigint unsigned default 0,
+  zone_object_id bigint(20) unsigned DEFAULT '0',
+  status_update_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  parent_zone_object_id bigint(20) unsigned DEFAULT '0',
+  PRIMARY KEY  (zonestatus_id)
+) ENGINE=InnoDB COMMENT='Zone status';
+
+
+
 
 ALTER TABLE icinga_servicestatus ADD COLUMN endpoint_object_id bigint default NULL;
 ALTER TABLE icinga_hoststatus ADD COLUMN endpoint_object_id bigint default NULL;
index 86b204c07220953f4559f6391735356ec2a35486..d26564602ec8d69d13680bf1fdb6a7d33708633d 100644 (file)
@@ -7,6 +7,30 @@
 -- Please check http://docs.icinga.org for upgrading information!
 -- -----------------------------------------
 
+
+ALTER TABLE icinga_endpoints ADD COLUMN zone_object_id bigint(20) unsigned DEFAULT '0';
+ALTER TABLE icinga_endpointstatus ADD COLUMN zone_object_id bigint(20) unsigned DEFAULT '0';
+
+CREATE TABLE IF NOT EXISTS icinga_zones (
+  zone_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  instance_id bigint unsigned default 0,
+  zone_object_id bigint(20) unsigned DEFAULT '0',
+  config_type smallint(6) DEFAULT '0',
+  parent_zone_object_id bigint(20) unsigned DEFAULT '0',
+  is_global smallint(6),
+  PRIMARY KEY  (zone_id)
+) ENGINE=InnoDB COMMENT='Zone configuration';
+
+CREATE TABLE IF NOT EXISTS icinga_zonestatus (
+  zonestatus_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  instance_id bigint unsigned default 0,
+  zone_object_id bigint(20) unsigned DEFAULT '0',
+  status_update_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  parent_zone_object_id bigint(20) unsigned DEFAULT '0',
+  PRIMARY KEY  (zonestatus_id)
+) ENGINE=InnoDB COMMENT='Zone status';
+
+
 -- -----------------------------------------
 -- update dbversion
 -- -----------------------------------------
index d1ea5aee29d8c611112beffafc26c31f0c90c5d5..ad4869a812edbfc30f369510d6f73bebbc53672e 100644 (file)
@@ -1388,6 +1388,7 @@ CREATE TABLE  icinga_endpoints (
   endpoint_id bigserial,
   instance_id bigint default 0,
   endpoint_object_id bigint default 0,
+  zone_object_id bigint default 0,
   config_type integer default 0,
   identity text DEFAULT NULL,
   node text DEFAULT NULL,
@@ -1405,6 +1406,7 @@ CREATE TABLE  icinga_endpointstatus (
   endpointstatus_id bigserial,
   instance_id bigint default 0,
   endpoint_object_id bigint default 0,
+  zone_object_id bigint default 0,
   status_update_time timestamp with time zone default '1970-01-01 00:00:00+00',
   identity text DEFAULT NULL,
   node text DEFAULT NULL,
@@ -1413,6 +1415,37 @@ CREATE TABLE  icinga_endpointstatus (
   CONSTRAINT UQ_endpointstatus UNIQUE (endpoint_object_id)
 ) ;
 
+--
+-- Table structure for table icinga_zones
+--
+
+CREATE TABLE  icinga_zones (
+  zone_id bigserial,
+  instance_id bigint default 0,
+  zone_object_id bigint default 0,
+  parent_zone_object_id bigint default 0,
+  config_type integer default 0,
+  is_global integer default 0,
+  CONSTRAINT PK_zone_id PRIMARY KEY (zone_id) ,
+  CONSTRAINT UQ_zones UNIQUE (instance_id,config_type,zone_object_id)
+) ;
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table icinga_zonestatus
+--
+
+CREATE TABLE  icinga_zonestatus (
+  zonestatus_id bigserial,
+  instance_id bigint default 0,
+  zone_object_id bigint default 0,
+  parent_zone_object_id bigint default 0,
+  status_update_time timestamp with time zone default '1970-01-01 00:00:00+00',
+  CONSTRAINT PK_zonestatus_id PRIMARY KEY (zonestatus_id) ,
+  CONSTRAINT UQ_zonestatus UNIQUE (zone_object_id)
+) ;
+
 
 ALTER TABLE icinga_servicestatus ADD COLUMN endpoint_object_id bigint default NULL;
 ALTER TABLE icinga_hoststatus ADD COLUMN endpoint_object_id bigint default NULL;
index 7ae098a20ef975a68d6f560a81a9e4a43e6051b4..e380ebd34d5338749ef07ac83bc0939e05a96804 100644 (file)
@@ -123,6 +123,34 @@ ALTER TABLE icinga_endpointstatus ALTER COLUMN status_update_time SET DEFAULT '1
 ALTER TABLE icinga_statehistory ALTER COLUMN check_source TYPE TEXT;
 ALTER TABLE icinga_statehistory ALTER COLUMN check_source SET default '';
 
+-- -----------------------------------------
+-- #9286 zones table
+-- -----------------------------------------
+
+ALTER TABLE icinga_endpoints ADD COLUMN zone_object_id bigint default 0;
+ALTER TABLE icinga_endpointstatus ADD COLUMN zone_object_id bigint default 0;
+
+CREATE TABLE  icinga_zones (
+  zone_id bigserial,
+  instance_id bigint default 0,
+  zone_object_id bigint default 0,
+  parent_zone_object_id bigint default 0,
+  config_type integer default 0,
+  is_global integer default 0,
+  CONSTRAINT PK_zone_id PRIMARY KEY (zone_id) ,
+  CONSTRAINT UQ_zones UNIQUE (instance_id,config_type,zone_object_id)
+) ;
+
+CREATE TABLE  icinga_zonestatus (
+  zonestatus_id bigserial,
+  instance_id bigint default 0,
+  zone_object_id bigint default 0,
+  parent_zone_object_id bigint default 0,
+  status_update_time timestamp with time zone default '1970-01-01 00:00:00+00',
+  CONSTRAINT PK_zonestatus_id PRIMARY KEY (zonestatus_id) ,
+  CONSTRAINT UQ_zonestatus UNIQUE (zone_object_id)
+) ;
+
 -- -----------------------------------------
 -- update dbversion
 -- -----------------------------------------