Module: check_mk
Branch: master
Commit: 4dd57bd81690d59621188621fd806777ad41d7a1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4dd57bd81690d5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 6 17:57:12 2015 +0100
#2756 FIX SNMP: Generalized error handling of emtpy info for SNMP checks
This change changes the way empty data for SNMP checks is handled.
In previous version each SNMP check had to deal with the fact that
the SNMP agent could respond with an empty response (info = []).
This situation can better be handled in the Check_MK SNMP engine
which catches this issue now before calling the discovery/check
function of the check. The error is then reported as missing info
like for the Check_MK Agent based checks.
There might be some special SNMP checks which need to treat this
case of empty data on its own. These checks now need to declare
the attribute <tt>handle_empty_info</tt> in the
<tt>check_info</tt>.
---
.werks/2756 | 20 ++++++++++++++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 10 ++++++++++
modules/discovery.py | 7 +++++++
4 files changed, 38 insertions(+)
diff --git a/.werks/2756 b/.werks/2756
new file mode 100644
index 0000000..cc5219a
--- /dev/null
+++ b/.werks/2756
@@ -0,0 +1,20 @@
+Title: SNMP: Generalized error handling of emtpy info for SNMP checks
+Level: 2
+Component: core
+Compatible: compat
+Version: 1.2.7i4
+Date: 1446828681
+Class: fix
+
+This change changes the way empty data for SNMP checks is handled.
+In previous version each SNMP check had to deal with the fact that
+the SNMP agent could respond with an empty response (info = []).
+
+This situation can better be handled in the Check_MK SNMP engine
+which catches this issue now before calling the discovery/check
+function of the check. The error is then reported as missing info
+like for the Check_MK Agent based checks.
+
+There might be some special SNMP checks which need to treat this
+case of empty data on its own. These checks now need to declare
+the attribute <tt>handle_empty_info</tt> in the
<tt>check_info</tt>.
diff --git a/ChangeLog b/ChangeLog
index 01e4df1..8b952b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
* 2443 FIX: Fixed quoting of ! in classical nagios checks configured via WATO...
* 2718 FIX: Fixed agent timeouts not resulting in a crash report anympore...
* 2724 FIX: Discovery check: Fixed exception in simulation mode when no cache file
present
+ * 2756 FIX: SNMP: Generalized error handling of emtpy info for SNMP checks...
Checks & Agents:
* 2434 NetApp monitoring: Cluster-Mode is now supported, changes in existing 7Mode
checks...
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index a88b355..f13dee0 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1416,6 +1416,14 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
except MKParseFunctionError, e:
info = e
+ # In case of SNMP checks but missing agent response, skip this check.
+ # Special checks which still need to be called even with empty data
+ # may declare this.
+ if info == [] and check_uses_snmp(checkname) \
+ and not check_info[checkname]["handle_empty_info"]:
+ error_sections.add(infotype)
+ continue
+
if info or info == []:
num_success += 1
try:
@@ -1628,6 +1636,7 @@ def convert_check_info():
"snmp_scan_function" :
snmp_scan_functions.get(check_type,
snmp_scan_functions.get(basename)),
+ "handle_empty_info" : False,
"default_levels_variable" :
check_default_levels.get(check_type),
"node_info" : False,
"parse_function" : None,
@@ -1641,6 +1650,7 @@ def convert_check_info():
info.setdefault("group", None)
info.setdefault("snmp_info", None)
info.setdefault("snmp_scan_function", None)
+ info.setdefault("handle_empty_info", False)
info.setdefault("default_levels_variable", None)
info.setdefault("node_info", False)
info.setdefault("extra_sections", [])
diff --git a/modules/discovery.py b/modules/discovery.py
index 807527e..2e281f3 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -737,6 +737,13 @@ def discover_check_type(hostname, ipaddress, check_type, use_caches,
on_error):
if info == None: # No data for this check type
return []
+ # In case of SNMP checks but missing agent response, skip this check.
+ # Special checks which still need to be called even with empty data
+ # may declare this.
+ if not info and check_uses_snmp(check_type) \
+ and not check_info[check_type]["handle_empty_info"]:
+ return []
+
# Now do the actual inventory
try:
# Check number of arguments of discovery function. Note: This