[icinga-checkins] icinga.org: icinga2/master: StatusDataWriter: Encode custom attr arrays&dictionaries as json string

git at icinga.org git at icinga.org
Tue Nov 4 18:09:35 CET 2014


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue Nov  4 18:08:26 2014 +0100

StatusDataWriter: Encode custom attr arrays&dictionaries as json string

refs #7560

---

 doc/9-appendix.md               |    2 ++
 lib/compat/statusdatawriter.cpp |   13 ++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/doc/9-appendix.md b/doc/9-appendix.md
index d00ece3..30765d9 100644
--- a/doc/9-appendix.md
+++ b/doc/9-appendix.md
@@ -147,6 +147,8 @@ Icinga 2 specific extensions:
 * host and service objects support 'check_source' (added in Classic UI 1.10.0)
 * command objects support custom variables (added in Classic UI 1.11.2)
 * host and service objects support 'is_reachable' (added in Classic UI 1.11.3)
+* 2.2 adds custom attributes with arrays and dictionaries. They are dumped as JSON encoded string and `_is_json`
+is set as additional custom variable in `objects.cache`.
 
 ### <a id="schema-db-ido"></a> DB IDO Schema
 
diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp
index 73f5e48..df57ce3 100644
--- a/lib/compat/statusdatawriter.cpp
+++ b/lib/compat/statusdatawriter.cpp
@@ -30,6 +30,7 @@
 #include "icinga/dependency.hpp"
 #include "base/dynamictype.hpp"
 #include "base/objectlock.hpp"
+#include "base/json.hpp"
 #include "base/convert.hpp"
 #include "base/logger.hpp"
 #include "base/exception.hpp"
@@ -514,6 +515,8 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const CustomVarObj
 	if (!vars)
 		return;
 
+	bool is_json = false;
+
 	ObjectLock olock(vars);
 	BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
 		if (kv.first.IsEmpty())
@@ -521,9 +524,10 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const CustomVarObj
 
 		String value;
 
-		if (kv.second.IsObjectType<Array>())
-			value = Utility::Join(kv.second, ';');
-		else
+		if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>()) {
+			value = JsonEncode(kv.second);
+			is_json = true;
+		} else
 			value = kv.second;
 
 		fp << "\t";
@@ -533,6 +537,9 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const CustomVarObj
 
 		fp << kv.first << "\t" << value << "\n";
 	}
+
+	if (is_json)
+		fp << "\t" "_is_json" "\t" "1" "\n";
 }
 
 void StatusDataWriter::UpdateObjectsCache(void)



More information about the icinga-checkins mailing list