mirror of https://github.com/Icinga/icinga2.git
StatusDataWriter: Encode custom attr arrays&dictionaries as json string
refs #7560
This commit is contained in:
parent
eeb6facdac
commit
c4ba3f6691
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue