[icinga-checkins] icinga.org: icinga2/master: Implement support for custom variables.

git at icinga.org git at icinga.org
Mon Jul 1 13:47:05 CEST 2013


Module: icinga2
Branch: master
Commit: 23c87f6eaf16ac8f0b3044d790e14d66a9719b3d
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=23c87f6eaf16ac8f0b3044d790e14d66a9719b3d

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Jul  1 13:46:50 2013 +0200

Implement support for custom variables.

Fixes #4344

---

 components/compat/compatcomponent.cpp |   33 ++++++++++++++++++++++++++++++---
 components/compat/compatcomponent.h   |    2 ++
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp
index e87395a..0f13e4e 100644
--- a/components/compat/compatcomponent.cpp
+++ b/components/compat/compatcomponent.cpp
@@ -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.
  */
diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h
index 135907d..fd91421 100644
--- a/components/compat/compatcomponent.h
+++ b/components/compat/compatcomponent.h
@@ -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);
 };
 





More information about the icinga-checkins mailing list