From 8c997255a9171289c71e0db403921ebc4ccb241e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 24 Sep 2015 11:45:44 +0200 Subject: [PATCH] DB IDO: Fix modified custom attribute update query problems fixes #10190 --- lib/db_ido/dbconnection.cpp | 30 ------------------------------ lib/db_ido/dbobject.cpp | 10 ++++++++-- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index eca07b802..ad7153f11 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -171,36 +171,6 @@ void DbConnection::ProgramStatusHandler(void) InsertRuntimeVariable("total_scheduled_services", std::distance(ConfigType::GetObjectsByType().first, ConfigType::GetObjectsByType().second)); InsertRuntimeVariable("total_hosts", std::distance(ConfigType::GetObjectsByType().first, ConfigType::GetObjectsByType().second)); InsertRuntimeVariable("total_scheduled_hosts", std::distance(ConfigType::GetObjectsByType().first, ConfigType::GetObjectsByType().second)); - - Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars(); - - if (!vars) - return; - - Log(LogDebug, "DbConnection", "Dumping global vars for icinga application"); - - ObjectLock olock(vars); - - BOOST_FOREACH(const Dictionary::Pair& kv, vars) { - if (!kv.first.IsEmpty()) { - Log(LogDebug, "DbConnection") - << "icinga application customvar key: '" << kv.first << "' value: '" << kv.second << "'"; - - Dictionary::Ptr fields4 = new Dictionary(); - fields4->Set("varname", Convert::ToString(kv.first)); - fields4->Set("varvalue", Convert::ToString(kv.second)); - fields4->Set("config_type", 1); - fields4->Set("has_been_modified", 0); - fields4->Set("instance_id", 0); /* DbConnection class fills in real ID */ - - DbQuery query4; - query4.Table = "customvariables"; - query4.Type = DbQueryInsert; - query4.Category = DbCatConfig; - query4.Fields = fields4; - DbObject::OnQuery(query4); - } - } } void DbConnection::CleanUpHandler(void) diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index 3cb247056..c1aebbcb9 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -198,9 +198,15 @@ void DbObject::SendVarsConfigUpdate(void) DbQuery query; query.Table = "customvariables"; - query.Type = DbQueryInsert; + query.Type = DbQueryInsert | DbQueryUpdate; query.Category = DbCatConfig; query.Fields = fields; + + query.WhereCriteria = new Dictionary(); + query.WhereCriteria->Set("object_id", obj); + query.WhereCriteria->Set("varname", kv.first); + query.Object = this; + OnQuery(query); } } @@ -259,7 +265,7 @@ void DbObject::SendVarsStatusUpdate(void) query.WhereCriteria = new Dictionary(); query.WhereCriteria->Set("object_id", obj); - query.WhereCriteria->Set("varname", Convert::ToString(kv.first)); + query.WhereCriteria->Set("varname", kv.first); query.Object = this; OnQuery(query); -- 2.40.0