From 4aeaf9a947aa9ca49cc6fc05ef63160e04a502bb Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 6 Feb 2014 16:44:46 +0100 Subject: [PATCH] DB IDO: Add icinga_node to *history tables. Refs #5470 --- components/db_ido_mysql/schema/mysql.sql | 14 ++++++++++++++ components/db_ido_pgsql/schema/pgsql.sql | 14 ++++++++++++++ lib/db_ido/servicedbobject.cpp | 11 +++++++++++ 3 files changed, 39 insertions(+) diff --git a/components/db_ido_mysql/schema/mysql.sql b/components/db_ido_mysql/schema/mysql.sql index 97012fa7b..9cdc64f7a 100644 --- a/components/db_ido_mysql/schema/mysql.sql +++ b/components/db_ido_mysql/schema/mysql.sql @@ -39,6 +39,7 @@ CREATE TABLE IF NOT EXISTS icinga_acknowledgements ( persistent_comment smallint default 0, notify_contacts smallint default 0, end_time timestamp default '0000-00-00 00:00:00', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (acknowledgement_id) ) ENGINE=InnoDB COMMENT='Current and historical host and service acknowledgements'; @@ -82,6 +83,7 @@ CREATE TABLE IF NOT EXISTS icinga_commenthistory ( expiration_time timestamp default '0000-00-00 00:00:00', deletion_time timestamp default '0000-00-00 00:00:00', deletion_time_usec int default 0, + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (commenthistory_id), UNIQUE KEY instance_id (instance_id,object_id,comment_time,internal_comment_id) ) ENGINE=InnoDB COMMENT='Historical host and service comments'; @@ -232,6 +234,7 @@ CREATE TABLE IF NOT EXISTS icinga_contactnotifications ( start_time_usec int default 0, end_time timestamp default '0000-00-00 00:00:00', end_time_usec int default 0, + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (contactnotification_id), UNIQUE KEY instance_id (instance_id,contact_object_id,start_time,start_time_usec) ) ENGINE=InnoDB COMMENT='Historical record of contact notifications'; @@ -407,6 +410,7 @@ CREATE TABLE IF NOT EXISTS icinga_downtimehistory ( was_cancelled smallint default 0, is_in_effect smallint default 0, trigger_time timestamp default '0000-00-00 00:00:00', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (downtimehistory_id), UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id) ) ENGINE=InnoDB COMMENT='Historical scheduled host and service downtime'; @@ -437,6 +441,7 @@ CREATE TABLE IF NOT EXISTS icinga_eventhandlers ( return_code smallint default 0, output TEXT character set latin1 default '', long_output TEXT default '', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (eventhandler_id), UNIQUE KEY instance_id (instance_id,object_id,start_time,start_time_usec) ) ENGINE=InnoDB COMMENT='Historical host and service event handlers'; @@ -454,6 +459,7 @@ CREATE TABLE IF NOT EXISTS icinga_externalcommands ( command_type smallint default 0, command_name varchar(128) character set latin1 default '', command_args TEXT character set latin1 default '', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (externalcommand_id) ) ENGINE=InnoDB COMMENT='Historical record of processed external commands'; @@ -477,6 +483,7 @@ CREATE TABLE IF NOT EXISTS icinga_flappinghistory ( high_threshold double default '0', comment_time timestamp default '0000-00-00 00:00:00', internal_comment_id bigint unsigned default 0, + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (flappinghistory_id) ) ENGINE=InnoDB COMMENT='Current and historical record of host and service flapping'; @@ -511,6 +518,7 @@ CREATE TABLE IF NOT EXISTS icinga_hostchecks ( output TEXT character set latin1 default '', long_output TEXT default '', perfdata TEXT character set latin1 default '', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (hostcheck_id) ) ENGINE=InnoDB COMMENT='Historical host checks'; @@ -820,6 +828,7 @@ CREATE TABLE IF NOT EXISTS icinga_logentries ( realtime_data smallint default 0, inferred_data_extracted smallint default 0, object_id bigint unsigned default NULL, + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (logentry_id) ) ENGINE=InnoDB COMMENT='Historical record of log entries'; @@ -844,6 +853,7 @@ CREATE TABLE IF NOT EXISTS icinga_notifications ( long_output TEXT default '', escalated smallint default 0, contacts_notified smallint default 0, + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (notification_id), UNIQUE KEY instance_id (instance_id,object_id,start_time,start_time_usec) ) ENGINE=InnoDB COMMENT='Historical record of host and service notifications'; @@ -881,6 +891,7 @@ CREATE TABLE IF NOT EXISTS icinga_processevents ( program_name varchar(16) character set latin1 default '', program_version varchar(20) character set latin1 default '', program_date varchar(10) character set latin1 default '', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (processevent_id) ) ENGINE=InnoDB COMMENT='Historical Icinga process events'; @@ -995,6 +1006,7 @@ CREATE TABLE IF NOT EXISTS icinga_servicechecks ( output TEXT character set latin1 default '', long_output TEXT default '', perfdata TEXT character set latin1 default '', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (servicecheck_id) ) ENGINE=InnoDB COMMENT='Historical service checks'; @@ -1278,6 +1290,7 @@ CREATE TABLE IF NOT EXISTS icinga_statehistory ( output TEXT character set latin1 default '', long_output TEXT default '', check_source varchar(255) character set latin1 default NULL, + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (statehistory_id) ) ENGINE=InnoDB COMMENT='Historical host and service state changes'; @@ -1301,6 +1314,7 @@ CREATE TABLE IF NOT EXISTS icinga_systemcommands ( return_code smallint default 0, output TEXT character set latin1 default '', long_output TEXT default '', + icinga_node varchar(255) character set latin1 default NULL, PRIMARY KEY (systemcommand_id), UNIQUE KEY instance_id (instance_id,start_time,start_time_usec) ) ENGINE=InnoDB COMMENT='Historical system commands that are executed'; diff --git a/components/db_ido_pgsql/schema/pgsql.sql b/components/db_ido_pgsql/schema/pgsql.sql index f7e7e94fd..a281e03c4 100644 --- a/components/db_ido_pgsql/schema/pgsql.sql +++ b/components/db_ido_pgsql/schema/pgsql.sql @@ -65,6 +65,7 @@ CREATE TABLE icinga_acknowledgements ( persistent_comment INTEGER default 0, notify_contacts INTEGER default 0, end_time timestamp with time zone default '1970-01-01 00:00:00', + icinga_node text default NULL, CONSTRAINT PK_acknowledgement_id PRIMARY KEY (acknowledgement_id) ) ; @@ -108,6 +109,7 @@ CREATE TABLE icinga_commenthistory ( expiration_time timestamp with time zone default '1970-01-01 00:00:00', deletion_time timestamp with time zone default '1970-01-01 00:00:00', deletion_time_usec INTEGER default 0, + icinga_node text default NULL, CONSTRAINT PK_commenthistory_id PRIMARY KEY (commenthistory_id) , CONSTRAINT UQ_commenthistory UNIQUE (instance_id,object_id,comment_time,internal_comment_id) ); @@ -258,6 +260,7 @@ CREATE TABLE icinga_contactnotifications ( start_time_usec INTEGER default 0, end_time timestamp with time zone default '1970-01-01 00:00:00', end_time_usec INTEGER default 0, + icinga_node text default NULL, CONSTRAINT PK_contactnotification_id PRIMARY KEY (contactnotification_id) , CONSTRAINT UQ_contactnotifications UNIQUE (instance_id,contact_object_id,start_time,start_time_usec) ) ; @@ -434,6 +437,7 @@ CREATE TABLE icinga_downtimehistory ( was_cancelled INTEGER default 0, is_in_effect INTEGER default 0, trigger_time timestamp with time zone default '1970-01-01 00:00:00', + icinga_node text default NULL, CONSTRAINT PK_downtimehistory_id PRIMARY KEY (downtimehistory_id) , CONSTRAINT UQ_downtimehistory UNIQUE (instance_id,object_id,entry_time,internal_downtime_id) ) ; @@ -464,6 +468,7 @@ CREATE TABLE icinga_eventhandlers ( return_code INTEGER default 0, output TEXT default '', long_output TEXT default '', + icinga_node text default NULL, CONSTRAINT PK_eventhandler_id PRIMARY KEY (eventhandler_id) , CONSTRAINT UQ_eventhandlers UNIQUE (instance_id,object_id,start_time,start_time_usec) ) ; @@ -481,6 +486,7 @@ CREATE TABLE icinga_externalcommands ( command_type INTEGER default 0, command_name TEXT default '', command_args TEXT default '', + icinga_node text default NULL, CONSTRAINT PK_externalcommand_id PRIMARY KEY (externalcommand_id) ) ; @@ -504,6 +510,7 @@ CREATE TABLE icinga_flappinghistory ( high_threshold double precision default 0, comment_time timestamp with time zone default '1970-01-01 00:00:00', internal_comment_id bigint default 0, + icinga_node text default NULL, CONSTRAINT PK_flappinghistory_id PRIMARY KEY (flappinghistory_id) ) ; @@ -538,6 +545,7 @@ CREATE TABLE icinga_hostchecks ( output TEXT default '', long_output TEXT default '', perfdata TEXT default '', + icinga_node text default NULL, CONSTRAINT PK_hostcheck_id PRIMARY KEY (hostcheck_id) ) ; @@ -846,6 +854,7 @@ CREATE TABLE icinga_logentries ( realtime_data INTEGER default 0, inferred_data_extracted INTEGER default 0, object_id bigint default NULL, + icinga_node text default NULL, CONSTRAINT PK_logentry_id PRIMARY KEY (logentry_id) ) ; @@ -870,6 +879,7 @@ CREATE TABLE icinga_notifications ( long_output TEXT default '', escalated INTEGER default 0, contacts_notified INTEGER default 0, + icinga_node text default NULL, CONSTRAINT PK_notification_id PRIMARY KEY (notification_id) , CONSTRAINT UQ_notifications UNIQUE (instance_id,object_id,start_time,start_time_usec) ) ; @@ -908,6 +918,7 @@ CREATE TABLE icinga_processevents ( program_name TEXT default '', program_version TEXT default '', program_date TEXT default '', + icinga_node text default NULL, CONSTRAINT PK_processevent_id PRIMARY KEY (processevent_id) ) ; @@ -1022,6 +1033,7 @@ CREATE TABLE icinga_servicechecks ( output TEXT default '', long_output TEXT default '', perfdata TEXT default '', + icinga_node text default NULL, CONSTRAINT PK_servicecheck_id PRIMARY KEY (servicecheck_id) ) ; @@ -1304,6 +1316,7 @@ CREATE TABLE icinga_statehistory ( output TEXT default '', long_output TEXT default '', check_source varchar(255) default NULL, + icinga_node text default NULL, CONSTRAINT PK_statehistory_id PRIMARY KEY (statehistory_id) ) ; @@ -1327,6 +1340,7 @@ CREATE TABLE icinga_systemcommands ( return_code INTEGER default 0, output TEXT default '', long_output TEXT default '', + icinga_node text default NULL, CONSTRAINT PK_systemcommand_id PRIMARY KEY (systemcommand_id) , CONSTRAINT UQ_systemcommands UNIQUE (instance_id,start_time,start_time_usec) ) ; diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 6b7dff5c2..d1eb22687 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -30,6 +30,7 @@ #include "icinga/eventcommand.h" #include "icinga/externalcommandprocessor.h" #include "icinga/compatutility.h" +#include "icinga/icingaapplication.h" #include #include @@ -402,6 +403,7 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const C query1.Table = "comments"; } else { query1.Table = "commenthistory"; + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); } query1.Type = DbQueryInsert; query1.Category = DbCatComment; @@ -567,6 +569,7 @@ void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const query1.Table = "scheduleddowntime"; } else { query1.Table = "downtimehistory"; + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); } query1.Type = DbQueryInsert; query1.Category = DbCatDowntime; @@ -743,6 +746,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con fields1->Set("comment_data", comment); fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0); fields1->Set("end_time", DbValue::FromTimestamp(end_time)); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ query1.Fields = fields1; @@ -793,6 +797,7 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati fields1->Set("escalated", 0); fields1->Set("contacts_notified", static_cast(users.size())); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ query1.Fields = fields1; @@ -864,6 +869,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const C fields1->Set("check_source", cr->GetCheckSource()); } + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ query1.Fields = fields1; @@ -1166,6 +1172,7 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer, fields1->Set("object_id", service); // added in 1.10 see #4754 fields1->Set("logentry_type", type); fields1->Set("logentry_data", buffer); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -1222,6 +1229,7 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt fields1->Set("percent_state_change", service->GetFlappingCurrent()); fields1->Set("low_threshold", service->GetFlappingThreshold()); fields1->Set("high_threshold", service->GetFlappingThreshold()); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -1280,6 +1288,7 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr)); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ fields1->Set("service_object_id", service); @@ -1327,6 +1336,7 @@ void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service) fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first)); fields1->Set("end_time_usec", time_bag.second); fields1->Set("command_object_id", service->GetEventCommand()); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -1360,6 +1370,7 @@ void ServiceDbObject::AddExternalCommandHistory(double time, const String& comma fields1->Set("command_type", CompatUtility::MapExternalCommandType(command)); fields1->Set("command_name", command); fields1->Set("command_args", boost::algorithm::join(arguments, ";")); + fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ -- 2.40.0