Skip to content

Commit

Permalink
DB IDO: Add icinga_node to *history tables.
Browse files Browse the repository at this point in the history
Refs #5470
  • Loading branch information
Michael Friedrich committed Feb 6, 2014
1 parent 07615f1 commit 4aeaf9a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/db_ido_mysql/schema/mysql.sql
Expand Up @@ -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';

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand All @@ -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';

Expand All @@ -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';

Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand All @@ -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';
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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';

Expand All @@ -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';
Expand Down
14 changes: 14 additions & 0 deletions components/db_ido_pgsql/schema/pgsql.sql
Expand Up @@ -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)
) ;

Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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)
) ;
Expand Down Expand Up @@ -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)
) ;
Expand Down Expand Up @@ -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)
) ;
Expand All @@ -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)
) ;

Expand All @@ -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)
) ;

Expand Down Expand Up @@ -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)
) ;

Expand Down Expand Up @@ -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)
) ;

Expand All @@ -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)
) ;
Expand Down Expand Up @@ -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)
) ;

Expand Down Expand Up @@ -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)
) ;

Expand Down Expand Up @@ -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)
) ;

Expand All @@ -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)
) ;
Expand Down
11 changes: 11 additions & 0 deletions lib/db_ido/servicedbobject.cpp
Expand Up @@ -30,6 +30,7 @@
#include "icinga/eventcommand.h"
#include "icinga/externalcommandprocessor.h"
#include "icinga/compatutility.h"
#include "icinga/icingaapplication.h"
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -793,6 +797,7 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati

fields1->Set("escalated", 0);
fields1->Set("contacts_notified", static_cast<long>(users.size()));
fields1->Set("icinga_node", IcingaApplication::GetInstance()->GetIcingaNodeName());
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */

query1.Fields = fields1;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down

0 comments on commit 4aeaf9a

Please sign in to comment.