]> granicus.if.org Git - icinga2/commitdiff
Implement support for custom variables.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 1 Jul 2013 11:46:50 +0000 (13:46 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 1 Jul 2013 11:46:50 +0000 (13:46 +0200)
Fixes #4344

components/compat/compatcomponent.cpp
components/compat/compatcomponent.h

index e87395a425231b6046baa503469b13a7eba34a4e..0f13e4e8b4f20752b6378b8bce5d609ee36ebf96 100644 (file)
@@ -25,6 +25,7 @@
 #include "icinga/servicegroup.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
+#include "base/convert.h"
 #include "base/logger_fwd.h"
 #include "base/exception.h"
 #include "base/application.h"
@@ -328,6 +329,8 @@ void CompatComponent::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
 
        }
 
+       DumpCustomAttributes(fp, host);
+
        fp << "\t" << "}" << "\n"
           << "\n";
 }
@@ -471,11 +474,14 @@ void CompatComponent::DumpServiceObject(std::ostream& fp, const Service::Ptr& se
                   << "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
                   << "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
                   << "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n"
-                  << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n"
-                  << "\t" << "}" << "\n"
-                  << "\n";
+                  << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n";
        }
 
+       DumpCustomAttributes(fp, service);
+
+       fp << "\t" << "}" << "\n"
+          << "\n";
+
        BOOST_FOREACH(const Service::Ptr& parent, service->GetParentServices()) {
                Host::Ptr host = service->GetHost();
 
@@ -499,6 +505,27 @@ void CompatComponent::DumpServiceObject(std::ostream& fp, const Service::Ptr& se
        }
 }
 
+void CompatComponent::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object)
+{
+       Dictionary::Ptr custom = object->Get("custom");
+
+       if (!custom)
+               return;
+
+       ObjectLock olock(custom);
+       String key;
+       Value value;
+       BOOST_FOREACH(boost::tie(key, value), custom) {
+               fp << "\t";
+
+               if (key != "action_url" && key != "notes_url" && key != "icon_image" &&
+                   key != "icon_image_alt" && key != "statusmap_image" && "2d_coords")
+                       fp << "_";
+
+               fp << key << "\t" << Convert::ToString(value) << "\n";
+       }
+}
+
 /**
  * Periodically writes the status.dat and objects.cache files.
  */
index 135907d5f1835b51b13cf114ee6bbf315f43fe9f..fd91421290a5598c23be8fed9a1d1bdbafebbb04 100644 (file)
@@ -106,6 +106,8 @@ private:
        void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service);
        void DumpServiceObject(std::ostream& fp, const Service::Ptr& service);
 
+       void DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object);
+
        void StatusTimerHandler(void);
 };