Module: check_mk
Branch: master
Commit: d860b2df886d56bc62eca641f3e415fc02bc0e61
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d860b2df886d56…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Feb 16 13:21:12 2012 +0100
Fixed problem with snmp_scan_functions of subchecks
---
modules/check_mk.py | 12 ++++++++----
modules/check_mk_base.py | 27 +++++++++++++++++++++++++--
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index b34e3af..e283474 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -630,9 +630,7 @@ def get_snmp_character_encoding(hostname):
return entries[0]
def check_uses_snmp(check_type):
- base_check_name = check_type.split(".")[0]
- return base_check_name in check_info and \
- check_info[base_check_name].get("snmp_info") != None
+ return snmp_info.get(check_type.split(".")[0]) != None
def is_snmp_host(hostname):
return in_binary_hostlist(hostname, snmp_hosts)
@@ -741,7 +739,13 @@ def snmp_scan(hostname, ipaddress):
continue
elif not check_uses_snmp(check_type):
continue
- scan_function = check["snmp_scan_function"]
+ basename = check_type.split(".")[0]
+ # The scan function should be assigned to the basename, because
+ # subchecks sharing the same SNMP info of course should have
+ # an identical scan function. But some checks do not do this
+ # correctly
+ scan_function = snmp_scan_functions.get(check_type,
+ snmp_scan_functions.get(basename))
if scan_function:
try:
if scan_function(lambda oid: get_single_oid(hostname, ipaddress, oid)):
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 54e9374..e617656 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -305,7 +305,7 @@ def get_realhost_info(hostname, ipaddress, check_type,
max_cache_age):
# Is this an SNMP table check? Then snmp_info specifies the OID to fetch
# Please note, that if the check_type is foo.bar then we lookup the
# snmp info for "foo", not for "foo.bar".
- oid_info = check_info.get(check_type, {}).get("snmp_info")
+ oid_info = snmp_info.get(check_type.split(".")[0])
if oid_info:
content = read_cache_file(cache_relpath, max_cache_age)
if content:
@@ -735,6 +735,7 @@ def convert_check_info():
check_function, service_description, has_perfdata, inventory_function = info
if inventory_function == no_inventory_possible:
inventory_function = None
+ basename = check_type.split(".")[0]
check_info[check_type] = {
"check_function" : check_function,
@@ -743,10 +744,32 @@ def convert_check_info():
"inventory_function" : inventory_function,
"group" : checkgroup_of.get(check_type),
"snmp_info" : snmp_info.get(check_type),
- "snmp_scan_function" :
snmp_scan_functions.get(check_type),
+ # Sometimes the scan function is assigned to the check_type
+ # rather than to the base name.
+ "snmp_scan_function" :
+ snmp_scan_functions.get(check_type,
+ snmp_scan_functions.get(basename)),
"includes" : check_includes.get(check_type,
[]),
"default_levels_variable" :
check_default_levels.get(check_type),
}
+ else:
+ # Make sure that all keys are present
+ info.setdefault("inventory_function", None)
+ info.setdefault("group", None)
+ info.setdefault("snmp_info", None)
+ info.setdefault("snmp_scan_function", None)
+ info.setdefault("includes", [])
+ info.setdefault("default_levels_variable", None)
+
+ # Now gather snmp_info and snmp_scan_function back to the
+ # original arrays. Note: these information is tied to a "agent section",
+ # not to a check. Several checks may use the same SNMP info and scan function.
+ for info in check_info.values():
+ basename = check_type.split(".")[0]
+ if info["snmp_info"] and basename not in snmp_info:
+ snmp_info[basename] = info["snmp_info"]
+ if info["snmp_scan_function"] and basename not in snmp_scan_functions:
+ snmp_scan_functions[basename] = info["snmp_scan_function"]
# Loops over all checks for a host, gets the data, calls the check
# function that examines that data and sends the result to Nagios