From af621214d4596cf63b3b2948d5ae2512c2d6ae56 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 4 Apr 2014 16:53:03 +0200 Subject: [PATCH] DB IDO: Dump application and command vars. Refs #5855 --- lib/db_ido/commanddbobject.cpp | 36 ++++++++++++++++++++++++++++++++++ lib/db_ido/commanddbobject.h | 3 +++ lib/db_ido/dbconnection.cpp | 30 ++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/lib/db_ido/commanddbobject.cpp b/lib/db_ido/commanddbobject.cpp index 771507689..c5cbb04a8 100644 --- a/lib/db_ido/commanddbobject.cpp +++ b/lib/db_ido/commanddbobject.cpp @@ -23,6 +23,7 @@ #include "icinga/command.h" #include "icinga/compatutility.h" #include "base/objectlock.h" +#include "base/convert.h" #include using namespace icinga; @@ -49,3 +50,38 @@ Dictionary::Ptr CommandDbObject::GetStatusFields(void) const { return Empty; } + +void CommandDbObject::OnConfigUpdate(void) +{ + Command::Ptr command = static_pointer_cast(GetObject()); + + Dictionary::Ptr vars = command->GetVars(); + + if (!vars) + return; + + Log(LogDebug, "db_ido", "Dumping command vars for '" + command->GetName() + "'"); + + ObjectLock olock(vars); + + BOOST_FOREACH(const Dictionary::Pair& kv, vars) { + if (!kv.first.IsEmpty()) { + Log(LogDebug, "db_ido", "command customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); + + Dictionary::Ptr fields1 = make_shared(); + fields1->Set("varname", Convert::ToString(kv.first)); + fields1->Set("varvalue", Convert::ToString(kv.second)); + fields1->Set("config_type", 1); + fields1->Set("has_been_modified", 0); + fields1->Set("object_id", command); + fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ + + DbQuery query1; + query1.Table = "customvariables"; + query1.Type = DbQueryInsert; + query1.Category = DbCatConfig; + query1.Fields = fields1; + OnQuery(query1); + } + } +} \ No newline at end of file diff --git a/lib/db_ido/commanddbobject.h b/lib/db_ido/commanddbobject.h index c236e4550..7e3816eda 100644 --- a/lib/db_ido/commanddbobject.h +++ b/lib/db_ido/commanddbobject.h @@ -40,6 +40,9 @@ public: virtual Dictionary::Ptr GetConfigFields(void) const; virtual Dictionary::Ptr GetStatusFields(void) const; + +protected: + virtual void OnConfigUpdate(void); }; } diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 6e6372961..b80e87c6a 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -24,6 +24,7 @@ #include "icinga/service.h" #include "base/dynamictype.h" #include "base/convert.h" +#include "base/objectlock.h" #include "base/utility.h" #include "base/initialize.h" #include "base/logger_fwd.h" @@ -114,6 +115,35 @@ void DbConnection::ProgramStatusHandler(void) InsertRuntimeVariable("total_scheduled_services", static_cast(DynamicType::GetObjects().size())); InsertRuntimeVariable("total_hosts", static_cast(DynamicType::GetObjects().size())); InsertRuntimeVariable("total_scheduled_hosts", static_cast(DynamicType::GetObjects().size())); + + Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars(); + + if (!vars) + return; + + Log(LogDebug, "db_ido", "Dumping global vars for icinga application"); + + ObjectLock olock(vars); + + BOOST_FOREACH(const Dictionary::Pair& kv, vars) { + if (!kv.first.IsEmpty()) { + Log(LogDebug, "db_ido", "icinga application customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); + + Dictionary::Ptr fields4 = make_shared(); + 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) -- 2.40.0