]> granicus.if.org Git - icinga2/commitdiff
compat: Add CompatUtility::GetCustomVariableConfig().
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 9 Aug 2013 11:55:04 +0000 (13:55 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 9 Aug 2013 11:55:44 +0000 (13:55 +0200)
lib/icinga/compatutility.cpp
lib/icinga/compatutility.h

index a5237823b94eb028e4766e5af7cce9571f1a0222..44c5a7022bd12b8e10ec39dca6f2baa3d49f33a5 100644 (file)
 #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;
index 5ca9593ee3b8d8186586e1251c5ac9345563b7ce..e301504ff9e169c881b58e8508d798bb360c0001 100644 (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: