Module: check_mk
Branch: master
Commit: 3fb44b4973714e2b78a8aac65994e45c073bf083
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3fb44b4973714e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 11 16:23:40 2017 +0100
4269 FIX Verifying unexpected keys in check_info while loading checks
When a check registers an unexpected key in the check_info dictionary,
Check_MK is now detecting that and terminating with an error message.
Change-Id: Id832caa485037dfc5e2a1dd7fd2850cc1b4d0c50
---
.werks/4269 | 10 ++++++++++
ChangeLog | 3 +++
modules/check_mk_base.py | 31 +++++++++++++++++++++----------
3 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/.werks/4269 b/.werks/4269
new file mode 100644
index 0000000..dbde193
--- /dev/null
+++ b/.werks/4269
@@ -0,0 +1,10 @@
+Title: Verifying unexpected keys in check_info while loading checks
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.4.0i4
+Date: 1484148162
+Class: fix
+
+When a check registers an unexpected key in the check_info dictionary,
+Check_MK is now detecting that and terminating with an error message.
diff --git a/ChangeLog b/ChangeLog
index da54f85..8a225ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
1.4.0i4:
+ Core & Setup:
+ * 4269 FIX: Verifying unexpected keys in check_info while loading checks...
+
Checks & Agents:
* 4104 veeam_tapejobs: New check to monitor Veeam tape jobs
* 4170 local: local check is now clusteraware. Best or worst state in cluster mode
can be configured...
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index b7282cc..244ad62 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1611,6 +1611,19 @@ def check_unimplemented(checkname, params, info):
# FIXME: Clear / unset all legacy variables to prevent confusions in other code trying
to
# use the legacy variables which are not set by newer checks.
def convert_check_info():
+ check_info_defaults = {
+ "inventory_function" : None,
+ "parse_function" : None,
+ "group" : None,
+ "snmp_info" : None,
+ "snmp_scan_function" : None,
+ "handle_empty_info" : False,
+ "handle_real_time_checks" : False,
+ "default_levels_variable" : None,
+ "node_info" : False,
+ "extra_sections" : [],
+ }
+
for check_type, info in check_info.items():
basename = check_type.split(".")[0]
@@ -1641,18 +1654,16 @@ def convert_check_info():
"extra_sections" : [],
}
else:
+ # Ensure that there are only the known keys set. Is meant to detect typos
etc.
+ for key in info.keys():
+ if key not in check_info_defaults:
+ raise MKGeneralException("The check '%s' declares an
unexpected key '%s' in 'check_info'." %
+
(check_type, key))
+
# Check does already use new API. Make sure that all keys are present,
# extra check-specific information into file-specific variables.
- info.setdefault("inventory_function", None)
- info.setdefault("parse_function", None)
- info.setdefault("group", None)
- info.setdefault("snmp_info", None)
- info.setdefault("snmp_scan_function", None)
- info.setdefault("handle_empty_info", False)
- info.setdefault("handle_real_time_checks", False)
- info.setdefault("default_levels_variable", None)
- info.setdefault("node_info", False)
- info.setdefault("extra_sections", [])
+ for key, val in check_info_defaults.items():
+ info.setdefault(key, val)
# Include files are related to the check file (= the basename),
# not to the (sub-)check. So we keep them in check_includes.