Module: check_mk
Branch: master
Commit: 48a20ff4676976e5f2166b2aac3df7d54b81f94b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=48a20ff4676976…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Feb 6 16:53:06 2018 +0100
Fixed handling of another numeration format
Change-Id: Id8d05793ada41f6b6781bbab405080a008a604f9
---
cmk/structured_data.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/cmk/structured_data.py b/cmk/structured_data.py
index af36fa2..52caf71 100644
--- a/cmk/structured_data.py
+++ b/cmk/structured_data.py
@@ -194,10 +194,15 @@ class StructuredDataTree(object):
# In the second case we have to deal with nested numerations
# We take a look at children which may be real numerations
# or sub trees.
- if self._is_numeration(v):
+ # May also be a flat list, thus we convert to expected
+ # numeration format: [{KEY: VAL,..},..]
+ entries_type = self._get_entries_type(v)
+ if isinstance(entries_type, Numeration):
sub_raw_tree.setdefault(k, v)
- else:
+ elif isinstance(entries_type, Container):
sub_raw_tree.setdefault(k, dict(enumerate(v)))
+ else:
+ sub_raw_tree.setdefault(k, [{"name": e} for e in v])
else:
# Here we collect all other values meaning simple
# attributes of this node.
@@ -205,12 +210,15 @@ class StructuredDataTree(object):
return sub_raw_tree, leaf_data
- def _is_numeration(self, entries):
+ def _get_entries_type(self, entries):
+ #TODO test
for entry in entries:
+ if not isinstance(entry, dict):
+ return
for k, v in entry.iteritems():
if isinstance(v, list):
- return False
- return True
+ return Container()
+ return Numeration()
# ---delegators-----------------------------------------------------------