compat: Add CompatUtility::GetCustomVariableConfig().

This commit is contained in:
Michael Friedrich 2013-08-09 13:55:04 +02:00
parent d562e98779
commit e7214174b1
2 changed files with 41 additions and 0 deletions

View File

@ -21,10 +21,12 @@
#include "icinga/compatutility.h"
#include "icinga/checkcommand.h"
#include "icinga/eventcommand.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/utility.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
@ -450,6 +452,42 @@ Dictionary::Ptr CompatUtility::GetCommandConfigAttributes(const Command::Ptr& co
return attr;
}
Dictionary::Ptr CompatUtility::GetCustomVariableConfig(DynamicObject::Ptr const& object)
{
Dictionary::Ptr custom;
if (object->GetType() == DynamicType::GetByName("Host")) {
custom = static_pointer_cast<Host>(object)->GetCustom();
} else if (object->GetType() == DynamicType::GetByName("Service")) {
custom = static_pointer_cast<Service>(object)->GetCustom();
} else if (object->GetType() == DynamicType::GetByName("User")) {
custom = static_pointer_cast<User>(object)->GetCustom();
} else {
Log(LogDebug, "compatutility", "unknown object type for custom vars");
return Dictionary::Ptr();
}
Dictionary::Ptr customvars = boost::make_shared<Dictionary>();
if (!custom)
return Dictionary::Ptr();
ObjectLock olock(custom);
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), custom) {
if (key != "notes" && key != "action_url" && key != "notes_url" &&
key != "icon_image" && key != "icon_image_alt" && key != "statusmap_image" && "2d_coords")
continue;
customvars->Set(key, value);
}
return customvars;
}
String CompatUtility::EscapeString(const String& str)
{
String result = str;

View File

@ -24,6 +24,7 @@
#include "icinga/service.h"
#include "icinga/checkcommand.h"
#include "base/dictionary.h"
#include "base/dynamicobject.h"
#include <vector>
namespace icinga
@ -52,6 +53,8 @@ public:
static Dictionary::Ptr GetServiceConfigAttributes(const Service::Ptr& service);
static Dictionary::Ptr GetCommandConfigAttributes(const Command::Ptr& command);
static Dictionary::Ptr GetCustomVariableConfig(DynamicObject::Ptr const& object);
static String EscapeString(const String& str);
private: