From e7214174b1aa48c35ff20d6b97e521a1a9e44564 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 9 Aug 2013 13:55:04 +0200 Subject: [PATCH] compat: Add CompatUtility::GetCustomVariableConfig(). --- lib/icinga/compatutility.cpp | 38 ++++++++++++++++++++++++++++++++++++ lib/icinga/compatutility.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index a5237823b..44c5a7022 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -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 #include +#include #include #include #include @@ -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(object)->GetCustom(); + } else if (object->GetType() == DynamicType::GetByName("Service")) { + custom = static_pointer_cast(object)->GetCustom(); + } else if (object->GetType() == DynamicType::GetByName("User")) { + custom = static_pointer_cast(object)->GetCustom(); + } else { + Log(LogDebug, "compatutility", "unknown object type for custom vars"); + return Dictionary::Ptr(); + } + + Dictionary::Ptr customvars = boost::make_shared(); + + 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; diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index 5ca9593ee..e301504ff 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -24,6 +24,7 @@ #include "icinga/service.h" #include "icinga/checkcommand.h" #include "base/dictionary.h" +#include "base/dynamicobject.h" #include 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: