Module: check_mk
Branch: master
Commit: d3fad386603f45f3afa2a1392969cc5606c1f0db
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d3fad386603f45…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jan 23 16:35:48 2015 +0100
Fix exception in inventory for diskstat checks
---
modules/check_mk_base.py | 50 +++++++++++++++++-----------------------------
modules/discovery.py | 42 +++++++++++++++++++++-----------------
2 files changed, 42 insertions(+), 50 deletions(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 5883c98..9071f29 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -257,32 +257,26 @@ class MKCheckTimeout(Exception):
# | Functions for getting monitoring data from TCP/SNMP agent. |
# '----------------------------------------------------------------------'
-# Collect information needed for one check. In case the check uses
-# extra sections (new feature since 1.2.7i1) only the main section
-# raises exceptions. Error in extra sections are silently ignored
-# and the info is replaced with None.
-def get_info_with_extra_sections(hostname, ipaddress, section_name, max_cachefile_age,
ignore_check_interval, info_func):
- if section_name in check_info:
- extra_sections = check_info[section_name]["extra_sections"]
- if extra_sections:
- info = [ info_func(hostname, ipaddress, section_name, max_cachefile_age,
ignore_check_interval) ]
- for es in extra_sections:
- try:
- info.append(info_func(hostname, ipaddress, es, max_cachefile_age,
ignore_check_interval=False))
- except:
- info.append(None)
- return info
-
- return info_func(hostname, ipaddress, section_name, max_cachefile_age,
ignore_check_interval)
+def apply_parse_function(info, section_name):
+ # Now some check types define a parse function. In that case the
+ # info is automatically being parsed by that function - on the fly.
+ if info != None and section_name in check_info:
+ parse_function = check_info[section_name]["parse_function"]
+ if parse_function:
+ return parse_function(info)
+ return info
def get_info_for_check(hostname, ipaddress, section_name, max_cachefile_age=None,
ignore_check_interval=False):
- return get_info_with_extra_sections(hostname, ipaddress, section_name,
- max_cachefile_age, ignore_check_interval,
info_func=get_host_info)
+ info = apply_parse_function(get_host_info(hostname, ipaddress, section_name,
max_cachefile_age, ignore_check_interval), section_name)
+ if section_name in check_info and
check_info[section_name]["extra_sections"]:
+ info = [ info ]
+ for es in check_info[section_name]["extra_sections"]:
+ try:
+ info.append(apply_parse_function(get_host_info(hostname, ipaddress, es,
max_cachefile_age, ignore_check_interval=False), es))
+ except:
+ info.append(None)
+ return info
-def get_info_for_inventory(hostname, ipaddress, section_name, use_caches):
- return get_info_with_extra_sections(hostname, ipaddress, section_name,
- use_caches and inventory_max_cachefile_age or 0,
- ignore_check_interval=True,
info_func=get_realhost_info)
# This is the main function for getting information needed by a
# certain check. It is called once for each check type. For SNMP this
@@ -357,14 +351,6 @@ def get_host_info(hostname, ipaddress, checkname,
max_cachefile_age=None, ignore
add_host = None
info = [ [add_host] + line for line in info ]
- # Now some check types define a parse function. In that case the
- # info is automatically being parsed by that function - on the fly.
- if checkname in check_info: # e.g. not the case for cpu (check is cpu.loads)
- parse_function = check_info[checkname]["parse_function"]
- if parse_function:
- parsed = parse_function(info)
- return parsed
-
return info
@@ -1370,7 +1356,7 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
try:
if is_tcp_host(hostname):
- version_info = get_host_info(hostname, ipaddress, 'check_mk')
+ version_info = get_info_for_check(hostname, ipaddress, 'check_mk')
agent_version = version_info[0][1]
else:
agent_version = None
diff --git a/modules/discovery.py b/modules/discovery.py
index ffd5eb0..b6bb015 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -213,6 +213,28 @@ def service_ignored(hostname, check_type, service_description):
return False
+def get_info_for_discovery(hostname, ipaddress, section_name, use_caches):
+ def add_nodeinfo(info, s):
+ if s in check_info and check_info[s]["node_info"]:
+ return [ [ None ] + l for l in info ]
+ else:
+ return info
+
+ max_cachefile_age = use_caches and inventory_max_cachefile_age or 0
+ info = apply_parse_function(add_nodeinfo(get_realhost_info(hostname, ipaddress,
section_name, max_cachefile_age, ignore_check_interval=True), section_name),
section_name)
+ if section_name in check_info and
check_info[section_name]["extra_sections"]:
+ info = [ info ]
+ for es in check_info[section_name]["extra_sections"]:
+ try:
+ bare_info = get_realhost_info(hostname, ipaddress, es, max_cachefile_age,
ignore_check_interval=True)
+ with_node_info = add_nodeinfo(bare_info, es)
+ parsed = apply_parse_function(with_node_info, es)
+ info.append(parsed)
+ except:
+ if opt_debug:
+ raise
+ info.append(None)
+ return info
#.
# .--Discovery-----------------------------------------------------------.
@@ -353,7 +375,7 @@ def discover_check_type(hostname, ipaddress, check_type, use_caches):
try:
info = None # default in case of exception
- info = get_info_for_inventory(hostname, ipaddress, section_name, use_caches)
+ info = get_info_for_discovery(hostname, ipaddress, section_name, use_caches)
except MKAgentError, e:
if str(e):
raise
@@ -364,24 +386,8 @@ def discover_check_type(hostname, ipaddress, check_type,
use_caches):
if info == None: # No data for this check type
return []
- # Add information about nodes if check wants this. Note:
- # in the node info we always put None, not the name of a node.
- # During inventory we behave like a non-cluster. We do not know
- # yet if the service is going to be clustered!
- if check_info[check_type]["node_info"]:
- if check_info[section_name]["extra_sections"]:
- info = [ sec and [ [None] + line for line in sec ] or None for sec in info ]
- else:
- info = [ [None] + line for line in info ]
-
# Now do the actual inventory
try:
- # Convert with parse function if available
- if section_name in check_info: # parse function must be define for base check
- parse_function = check_info[section_name]["parse_function"]
- if parse_function:
- info = check_info[section_name]["parse_function"](info)
-
# Check number of arguments of discovery function. Note: This
# check for the legacy API will be removed after 1.2.6.
if len(inspect.getargspec(discovery_function)[0]) == 2:
@@ -613,7 +619,7 @@ def get_check_preview(hostname, use_caches, do_snmp_scan):
try:
exitcode = None
perfdata = []
- info = get_host_info(hostname, ipaddress, infotype)
+ info = get_info_for_check(hostname, ipaddress, infotype)
# Handle cases where agent does not output data
except MKAgentError, e:
exitcode = 3