Module: check_mk
Branch: master
Commit: 7c9e82ba1702dfd60facc6b00f381b2ab23ac25d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7c9e82ba1702df…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 25 16:27:31 2018 +0200
6173 FIX Fixed possible crash in Check_MK and Check_MK HW/SW Inventory
When using pretty outdated "Do hardware/software Inventory" rules which
have been saved before 1.4, this could lead to crashing Check_MK and
Check_MK HW/SW inventory services with errors like this:
'NoneType' object has no attribute 'get'
Workaround: Open this ruleset and save the rules in the relevant folders.
The configs will then be transformed and rewritten in the current format
which prevents this crash.
Change-Id: I74bac63ac280caddf95b19e141519e7be32b20ae
---
.werks/6173 | 19 +++++++++++++++++++
cmk_base/checks.py | 14 ++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/.werks/6173 b/.werks/6173
new file mode 100644
index 0000000..a611c59
--- /dev/null
+++ b/.werks/6173
@@ -0,0 +1,19 @@
+Title: Fixed possible crash in Check_MK and Check_MK HW/SW Inventory
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1527258292
+
+When using pretty outdated "Do hardware/software Inventory" rules which
+have been saved before 1.4, this could lead to crashing Check_MK and
+Check_MK HW/SW inventory services with errors like this:
+
+'NoneType' object has no attribute 'get'
+
+Workaround: Open this ruleset and save the rules in the relevant folders.
+The configs will then be transformed and rewritten in the current format
+which prevents this crash.
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index 288483a..08d7b3e 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -797,12 +797,18 @@ def do_status_data_inventory_for(hostname):
rules = config.active_checks.get('cmk_inv')
if rules is None:
return False
+
# 'host_extra_conf' is already cached thus we can
# use it after every check cycle.
- params = rulesets.host_extra_conf(hostname, rules)
- if params:
- return params[0].get('status_data_inventory', False)
- return False
+ entries = rulesets.host_extra_conf(hostname, rules)
+
+ if not entries:
+ return False # No matching rule -> disable
+
+ # Convert legacy rules to current dict format (just like the valuespec)
+ params = {} if entries[0] is None else entries[0]
+
+ return params.get('status_data_inventory', False)
def filter_by_management_board(hostname, found_check_plugin_names,