Module: check_mk
Branch: master
Commit: e2ff95cf65ce2088ced8b6b47f481276cb25b743
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e2ff95cf65ce20…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Sep 18 13:38:06 2018 +0200
6596 FIX Do status data inventory: Check "HW/SW Inventory" and shell commands
behave the same way
If <tt>Status data inventory</tt> is enabled in the ruleset
<tt>Do hardware/software Inventory</tt> the active check
<tt>Check_MK HW/SW Inventory</tt> and the shell commands
<tt>cmk -vii</tt> and <tt>cmk -v</tt> behave the same way.
Change-Id: I41016a6491549d166b77991c7fc3ae01f4608994
---
.werks/6596 | 16 ++++++++++++++++
cmk_base/inventory.py | 25 ++++++++++++++-----------
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/.werks/6596 b/.werks/6596
new file mode 100644
index 0000000..08846d5
--- /dev/null
+++ b/.werks/6596
@@ -0,0 +1,16 @@
+Title: Do status data inventory: Check "HW/SW Inventory" and shell commands
behave the same way
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1537270279
+Class: fix
+
+If <tt>Status data inventory</tt> is enabled in the ruleset
+<tt>Do hardware/software Inventory</tt> the active check
+<tt>Check_MK HW/SW Inventory</tt> and the shell commands
+<tt>cmk -vii</tt> and <tt>cmk -vi</tt> behave the same way.
+
+The same result should also be displayed if <tt>cmk -v</tt>
+is executed if <tt>Status data inventory</tt> is enabled.
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index a368510..f58fe0d 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -83,7 +83,8 @@ def do_inv(hostnames):
ipaddress = ip_lookup.lookup_ip_address(hostname)
sources = data_sources.DataSources(hostname, ipaddress)
- do_inv_for(sources, multi_host_sections=None, hostname=hostname,
ipaddress=ipaddress)
+ _do_inv_for(sources, multi_host_sections=None, hostname=hostname,
ipaddress=ipaddress,
+
do_status_data_inv=config.do_status_data_inventory_for(hostname))
except Exception, e:
if cmk.debug.enabled():
raise
@@ -108,8 +109,10 @@ def do_inv_check(hostname, options):
status, infotexts, long_infotexts, perfdata = 0, [], [], []
sources = data_sources.DataSources(hostname, ipaddress)
- old_timestamp, inventory_tree, status_data_tree = do_inv_for(sources,
multi_host_sections=None,
- hostname=hostname,
ipaddress=ipaddress)
+ old_timestamp, inventory_tree, status_data_tree =\
+ _do_inv_for(sources, multi_host_sections=None,
+ hostname=hostname, ipaddress=ipaddress,
+ do_status_data_inv=config.do_status_data_inventory_for(hostname))
if inventory_tree.is_empty() and status_data_tree.is_empty():
infotexts.append("Found no data")
@@ -157,17 +160,18 @@ def do_status_data_inventory(sources, multi_host_sections, hostname,
ipaddress):
import cmk_base.inventory_plugins as inventory_plugins
# cmk_base/modes/check_mk.py loads check plugins but not inventory plugins
do_inv = False
+ section_names = multi_host_sections.get_host_sections().get((hostname,
ipaddress)).sections.keys()
inventory_plugins.load_plugins(check_api.get_check_api_context,
get_inventory_context)
- for plugin in inventory_plugins.inv_info.values():
- if plugin.get("has_status_data"):
+ for plugin_name, plugin in inventory_plugins.inv_info.iteritems():
+ if plugin_name in section_names and plugin.get("has_status_data"):
do_inv = True
break
if do_inv:
- do_inv_for(sources, multi_host_sections=multi_host_sections, hostname=hostname,
- ipaddress=ipaddress, do_status_data_inventory=True)
+ _do_inv_for(sources, multi_host_sections=multi_host_sections, hostname=hostname,
+ ipaddress=ipaddress, do_status_data_inv=True)
-def do_inv_for(sources, multi_host_sections, hostname, ipaddress,
do_status_data_inventory=False):
+def _do_inv_for(sources, multi_host_sections, hostname, ipaddress, do_status_data_inv):
_initialize_inventory_tree()
inventory_tree = g_inv_tree
status_data_tree = StructuredDataTree()
@@ -189,7 +193,7 @@ def do_inv_for(sources, multi_host_sections, hostname, ipaddress,
do_status_data
console.section_success("Found %s%s%d%s inventory entries" %
(tty.bold, tty.yellow, inventory_tree.count_entries(), tty.normal))
- if do_status_data_inventory:
+ if do_status_data_inv:
status_data_tree.normalize_nodes()
_save_status_data_tree(hostname, status_data_tree)
@@ -219,7 +223,7 @@ def _do_inv_for_realhost(sources, multi_host_sections, hostname,
ipaddress,
source.set_check_plugin_name_filter(_gather_snmp_check_plugin_names_inventory)
if multi_host_sections is not None:
# Status data inventory already provides filled multi_host_sections
object.
- # SNMP data source: If do_status_data_inventory is enabled there may be
+ # SNMP data source: If 'do_status_data_inv' is enabled there may
be
# sections for inventory plugins which were not fetched yet.
source.enforce_check_plugin_names(None)
host_sections = multi_host_sections.add_or_get_host_sections(hostname,
ipaddress)
@@ -236,7 +240,6 @@ def _do_inv_for_realhost(sources, multi_host_sections, hostname,
ipaddress,
for section_name, plugin in inventory_plugins.inv_info.items():
section_content = multi_host_sections.get_section_content(hostname, ipaddress,
section_name,
for_discovery=False)
-
if section_content is None: # No data for this check type
continue