DB IDO: Dump application and command vars.

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-04 16:53:03 +02:00
parent 17b87c9b2a
commit af621214d4
3 changed files with 69 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "icinga/command.h"
#include "icinga/compatutility.h"
#include "base/objectlock.h"
#include "base/convert.h"
#include <boost/foreach.hpp>
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<Command>(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<Dictionary>();
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);
}
}
}

View File

@ -40,6 +40,9 @@ public:
virtual Dictionary::Ptr GetConfigFields(void) const;
virtual Dictionary::Ptr GetStatusFields(void) const;
protected:
virtual void OnConfigUpdate(void);
};
}

View File

@ -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<long>(DynamicType::GetObjects<Service>().size()));
InsertRuntimeVariable("total_hosts", static_cast<long>(DynamicType::GetObjects<Host>().size()));
InsertRuntimeVariable("total_scheduled_hosts", static_cast<long>(DynamicType::GetObjects<Host>().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<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)