Module: check_mk
Branch: master
Commit: 12e233d0dbfe4d1f0efc5f1a12c80fe33993d1de
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=12e233d0dbfe4d…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Sep 18 15:50:19 2018 +0200
6599 FIX HW/SW Inventory: Only count the real entries
The active check {{Check_MK HW/SW Inventory}}, the
inventory history and the shell commands <tt>cmk -vi</tt>
and <tt>cmk -vii</tt> show the number of found entries.
This number also includes the amount of nodes. Example:
<tt>Hardware > System > Family: Thinkpad</tt>
gives 3 entries. This may be confusing.
Now only the real entries are counted. Example:
<tt>Hardware > System > Family: Thinkpad</tt>
gives 1 entry.
Change-Id: I3c9e2c218ee6a4f12f4a2d82f67711cea5517881
---
.werks/6599 | 20 ++++++++++++++++++++
cmk/structured_data.py | 6 +++---
cmk_base/inventory.py | 2 +-
.../unit/cmk/structured_data/test_structured_data.py | 6 +++---
4 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/.werks/6599 b/.werks/6599
new file mode 100644
index 0000000..a10c047
--- /dev/null
+++ b/.werks/6599
@@ -0,0 +1,20 @@
+Title: HW/SW Inventory: Only count the real entries
+Level: 1
+Component: inv
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1537278111
+
+The active check {{Check_MK HW/SW Inventory}}, the
+inventory history and the shell commands <tt>cmk -vi</tt>
+and <tt>cmk -vii</tt> show the number of found entries.
+This number also includes the amount of nodes. Example:
+<tt>Hardware > System > Family: Thinkpad</tt>
+gives 3 entries. This may be confusing.
+
+Now only the real entries are counted. Example:
+<tt>Hardware > System > Family: Thinkpad</tt>
+gives 1 entry.
diff --git a/cmk/structured_data.py b/cmk/structured_data.py
index 1155342..dea409d 100644
--- a/cmk/structured_data.py
+++ b/cmk/structured_data.py
@@ -412,7 +412,7 @@ class Container(NodeAttribute):
def count_entries(self):
- return 1 + sum([child.count_entries() for _, __, child in self.get_children()])
+ return sum([child.count_entries() for _, __, child in self.get_children()])
def compare_with(self, old, keep_identical=False):
@@ -769,7 +769,7 @@ class Numeration(Leaf):
def count_entries(self):
- return 1 + sum(map(len, self._numeration))
+ return sum(map(len, self._numeration))
def compare_with(self, old, keep_identical=False):
@@ -991,7 +991,7 @@ class Attributes(Leaf):
def count_entries(self):
- return 1 + len(self._attributes)
+ return len(self._attributes)
def compare_with(self, old, keep_identical=False):
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index f58fe0d..6363a17 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -193,8 +193,8 @@ def _do_inv_for(sources, multi_host_sections, hostname, ipaddress,
do_status_dat
console.section_success("Found %s%s%d%s inventory entries" %
(tty.bold, tty.yellow, inventory_tree.count_entries(), tty.normal))
+ status_data_tree.normalize_nodes()
if do_status_data_inv:
- status_data_tree.normalize_nodes()
_save_status_data_tree(hostname, status_data_tree)
console.section_success("Found %s%s%d%s status entries" %
diff --git a/tests/unit/cmk/structured_data/test_structured_data.py
b/tests/unit/cmk/structured_data/test_structured_data.py
index 4a9fbca..14fc040 100644
--- a/tests/unit/cmk/structured_data/test_structured_data.py
+++ b/tests/unit/cmk/structured_data/test_structured_data.py
@@ -142,7 +142,7 @@ def test_structured_data_NodeAttribute_is_equal(na_x, na_y):
@pytest.mark.parametrize("node_attribute,result", zip(
node_attributes,
- [12, 24]
+ [0, 12]
))
def test_structured_data_NodeAttribute_count_entries(node_attribute, result):
assert node_attribute.count_entries() == result
@@ -353,8 +353,8 @@ def
test_structured_data_StructuredDataTree_is_equal_save_and_load(tree, tmpdir)
@pytest.mark.parametrize("tree,result", zip(
trees,
- [33, 12, 19, 6304, 5, 16676,
- 35, 11, 19, 6205, 5, 16675,]
+ [21, 9, 10, 6284, 2, 16654,
+ 23, 8, 10, 6185, 2, 16653,]
))
def test_structured_data_StructuredDataTree_count_entries(tree, result):
assert tree.count_entries() == result