From a26df23e3d55abee4d0bd3c34da49d63702d209f Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 20 Mar 2014 18:02:45 +0100 Subject: [PATCH] DB IDO: Add check_source_object_id reference to endpoint objects. Refs #5810 Refs #5636 --- components/db_ido_mysql/schema/mysql.sql | 4 ++++ .../db_ido_mysql/schema/upgrade/0.0.9.sql | 4 ++++ components/db_ido_pgsql/schema/pgsql.sql | 3 +++ .../db_ido_pgsql/schema/upgrade/0.0.9.sql | 5 +++++ lib/db_ido/servicedbobject.cpp | 18 ++++++++++++++++-- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 components/db_ido_mysql/schema/upgrade/0.0.9.sql create mode 100644 components/db_ido_pgsql/schema/upgrade/0.0.9.sql diff --git a/components/db_ido_mysql/schema/mysql.sql b/components/db_ido_mysql/schema/mysql.sql index 080898dcd..545e6fa52 100644 --- a/components/db_ido_mysql/schema/mysql.sql +++ b/components/db_ido_mysql/schema/mysql.sql @@ -1398,6 +1398,10 @@ ALTER TABLE icinga_servicechecks ADD COLUMN endpoint_object_id bigint default NU ALTER TABLE icinga_statehistory ADD COLUMN endpoint_object_id bigint default NULL; ALTER TABLE icinga_systemcommands ADD COLUMN endpoint_object_id bigint default NULL; +ALTER TABLE icinga_servicestatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_hoststatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_statehistory ADD COLUMN check_source_object_id bigint default NULL; + -- ----------------------------------------- -- add index (delete) diff --git a/components/db_ido_mysql/schema/upgrade/0.0.9.sql b/components/db_ido_mysql/schema/upgrade/0.0.9.sql new file mode 100644 index 000000000..5786c74ca --- /dev/null +++ b/components/db_ido_mysql/schema/upgrade/0.0.9.sql @@ -0,0 +1,4 @@ + +ALTER TABLE icinga_servicestatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_hoststatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_statehistory ADD COLUMN check_source_object_id bigint default NULL; diff --git a/components/db_ido_pgsql/schema/pgsql.sql b/components/db_ido_pgsql/schema/pgsql.sql index c30e9e50d..ed96d8c18 100644 --- a/components/db_ido_pgsql/schema/pgsql.sql +++ b/components/db_ido_pgsql/schema/pgsql.sql @@ -1426,6 +1426,9 @@ ALTER TABLE icinga_servicechecks ADD COLUMN endpoint_object_id bigint default NU ALTER TABLE icinga_statehistory ADD COLUMN endpoint_object_id bigint default NULL; ALTER TABLE icinga_systemcommands ADD COLUMN endpoint_object_id bigint default NULL; +ALTER TABLE icinga_servicestatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_hoststatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_statehistory ADD COLUMN check_source_object_id bigint default NULL; -- ----------------------------------------- -- add index (delete) diff --git a/components/db_ido_pgsql/schema/upgrade/0.0.9.sql b/components/db_ido_pgsql/schema/upgrade/0.0.9.sql new file mode 100644 index 000000000..0d6b0de87 --- /dev/null +++ b/components/db_ido_pgsql/schema/upgrade/0.0.9.sql @@ -0,0 +1,5 @@ + +ALTER TABLE icinga_servicestatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_hoststatus ADD COLUMN check_source_object_id bigint default NULL; +ALTER TABLE icinga_statehistory ADD COLUMN check_source_object_id bigint default NULL; + diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 208e516fa..4d00620e7 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -145,7 +145,14 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields(void) const fields->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr)); - fields->Set("check_source", cr->GetCheckSource()); + + String check_source = cr->GetCheckSource(); + fields->Set("check_source", check_source); + + Endpoint::Ptr check_endpoint = Endpoint::GetByName(check_source); + + if(check_endpoint) + fields->Set("check_source_object_id", check_endpoint); } fields->Set("current_state", CompatUtility::GetServiceCurrentState(service)); @@ -887,7 +894,14 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const C if (cr) { fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - fields1->Set("check_source", cr->GetCheckSource()); + + String check_source = cr->GetCheckSource(); + fields1->Set("check_source", check_source); + + Endpoint::Ptr check_endpoint = Endpoint::GetByName(check_source); + + if(check_endpoint) + fields1->Set("check_source_object_id", check_endpoint); } fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ -- 2.40.0