From fcec5c61a009057d9c7ffe736b3cebc5363174dc Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 21 Jan 2014 16:13:27 +0100 Subject: [PATCH] CompatUtility: Fix broken custom variable dump. Fixes #5547 --- lib/db_ido/hostdbobject.cpp | 34 ++++++++++++++++++---------------- lib/db_ido/servicedbobject.cpp | 34 ++++++++++++++++++---------------- lib/icinga/compatutility.cpp | 22 ++++++++++------------ 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 9cd68dad0..8c43ec315 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -276,8 +276,6 @@ void HostDbObject::OnConfigUpdate(void) } /* custom variables */ - Log(LogDebug, "ido", "host customvars for '" + host->GetName() + "'"); - Dictionary::Ptr customvars; { ObjectLock olock(host); @@ -285,25 +283,29 @@ void HostDbObject::OnConfigUpdate(void) } if (customvars) { + Log(LogDebug, "ido", "Dumping host customvars for '" + host->GetName() + "'"); + ObjectLock olock (customvars); BOOST_FOREACH(const Dictionary::Pair& kv, customvars) { - Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); + if (!kv.first.IsEmpty()) { + Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); - Dictionary::Ptr fields3 = make_shared(); - fields3->Set("varname", Convert::ToString(kv.first)); - fields3->Set("varvalue", Convert::ToString(kv.second)); - fields3->Set("config_type", 1); - fields3->Set("has_been_modified", 0); - fields3->Set("object_id", host); - fields3->Set("instance_id", 0); /* DbConnection class fills in real ID */ + Dictionary::Ptr fields3 = make_shared(); + fields3->Set("varname", Convert::ToString(kv.first)); + fields3->Set("varvalue", Convert::ToString(kv.second)); + fields3->Set("config_type", 1); + fields3->Set("has_been_modified", 0); + fields3->Set("object_id", host); + fields3->Set("instance_id", 0); /* DbConnection class fills in real ID */ - DbQuery query3; - query3.Table = "customvariables"; - query3.Type = DbQueryInsert; - query3.Category = DbCatConfig; - query3.Fields = fields3; - OnQuery(query3); + DbQuery query3; + query3.Table = "customvariables"; + query3.Type = DbQueryInsert; + query3.Category = DbCatConfig; + query3.Fields = fields3; + OnQuery(query3); + } } } } diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 953ac925d..1b45357dd 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -262,8 +262,6 @@ void ServiceDbObject::OnConfigUpdate(void) } /* custom variables */ - Log(LogDebug, "db_ido", "service customvars for '" + service->GetName() + "'"); - Dictionary::Ptr customvars; { @@ -272,25 +270,29 @@ void ServiceDbObject::OnConfigUpdate(void) } if (customvars) { + Log(LogDebug, "db_ido", "Dumping service customvars for '" + service->GetName() + "'"); + ObjectLock olock(customvars); BOOST_FOREACH(const Dictionary::Pair& kv, customvars) { - Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); + if (!kv.first.IsEmpty()) { + Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); - Dictionary::Ptr fields2 = make_shared(); - fields2->Set("varname", Convert::ToString(kv.first)); - fields2->Set("varvalue", Convert::ToString(kv.second)); - fields2->Set("config_type", 1); - fields2->Set("has_been_modified", 0); - fields2->Set("object_id", service); - fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ + Dictionary::Ptr fields2 = make_shared(); + fields2->Set("varname", Convert::ToString(kv.first)); + fields2->Set("varvalue", Convert::ToString(kv.second)); + fields2->Set("config_type", 1); + fields2->Set("has_been_modified", 0); + fields2->Set("object_id", service); + fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ - DbQuery query2; - query2.Table = "customvariables"; - query2.Type = DbQueryInsert; - query2.Category = DbCatConfig; - query2.Fields = fields2; - OnQuery(query2); + DbQuery query2; + query2.Table = "customvariables"; + query2.Type = DbQueryInsert; + query2.Category = DbCatConfig; + query2.Fields = fields2; + OnQuery(query2); + } } } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index ddc6d7828..bdee5351a 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -425,19 +425,17 @@ Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr& return Dictionary::Ptr(); ObjectLock olock(custom); - String key; - Value value; BOOST_FOREACH(const Dictionary::Pair& kv, custom) { - if (kv.first == "notes" || - kv.first == "action_url" || - kv.first == "notes_url" || - kv.first == "icon_image" || - kv.first == "icon_image_alt" || - kv.first == "statusmap_image" || - kv.first == "2d_coords") - continue; - - customvars->Set(key, value); + if (!kv.first.IsEmpty()) { + if (kv.first != "notes" && + kv.first != "action_url" && + kv.first != "notes_url" && + kv.first != "icon_image" && + kv.first != "icon_image_alt" && + kv.first != "statusmap_image" && + kv.first != "2d_coords") + customvars->Set(kv.first, kv.second); + } } return customvars;