use other sections
Message-ID: <54aa6b76.duYlKV0oaHQVBpik%mk(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 61b435c3c9651ad0c0275798f53d5a15c46c1def
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=61b435c3c9651a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jan 5 11:46:10 2015 +0100
New experimental feature for checks: use other sections
---
modules/automation.py | 2 +-
modules/check_mk.py | 15 +--------------
modules/check_mk_base.py | 40 +++++++++++++++++++++++++++++++++++-----
3 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/modules/automation.py b/modules/automation.py
index 354708e..d7af29f 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -358,7 +358,7 @@ def automation_try_inventory_node(hostname, leave_no_tcp=False,
with_snmp_scan=F
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
diff --git a/modules/check_mk.py b/modules/check_mk.py
index f5b6e1c..fa19744 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2859,20 +2859,7 @@ def make_inventory(checkname, hostnamelist, check_only=False,
include_state=Fals
checkname_base = checkname.split('.')[0] # make e.g. 'lsi'
from 'lsi.arrays'
try:
- info = get_realhost_info(hostname, ipaddress, checkname_base,
inventory_max_cachefile_age, True)
- # Add information about nodes if check wants this
- if check_info[checkname]["node_info"]:
- if clusters_of(hostname):
- add_host = hostname
- else:
- add_host = None
- info = [ [add_host] + line for line in info ]
-
- # Convert with parse function if available
- if checkname_base in check_info: # parse function must be define for base
check
- parse_function =
check_info[checkname_base]["parse_function"]
- if parse_function:
- info =
check_info[checkname_base]["parse_function"](info)
+ info = get_info_for_check(hostname, ipaddress, checkname_base,
inventory_max_cachefile_age, True)
except MKAgentError, e:
# This special handling is needed for the inventory check. It needs
special
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 2770fdb..bad296b 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -278,7 +278,7 @@ def submit_check_mk_aggregation(hostname, status, output):
# checks usually use existing cache files, if check_mk is not misconfigured,
# and thus do no network activity at all...
-def get_host_info(hostname, ipaddress, checkname):
+def get_host_info(hostname, ipaddress, checkname, max_cachefile_age,
ignore_check_interval=False):
# If the check want's the node info, we add an additional
# column (as the first column) with the name of the node
# or None (in case of non-clustered nodes). On problem arises,
@@ -299,7 +299,9 @@ def get_host_info(hostname, ipaddress, checkname):
# try the other nodes.
try:
ipaddress = lookup_ipaddress(node)
- new_info = get_realhost_info(node, ipaddress, checkname,
cluster_max_cachefile_age)
+ new_info = get_realhost_info(node, ipaddress, checkname,
+ max_cachefile_age == None and cluster_max_cachefile_age or
max_cache_age,
+ ignore_check_interval)
if new_info != None:
if add_nodeinfo:
new_info = [ [node] + line for line in new_info ]
@@ -323,9 +325,15 @@ def get_host_info(hostname, ipaddress, checkname):
raise MKAgentError(", ".join(exception_texts))
else:
- info = get_realhost_info(hostname, ipaddress, checkname,
check_max_cachefile_age)
+ info = get_realhost_info(hostname, ipaddress, checkname,
+ max_cachefile_age == None and check_max_cachefile_age or
max_cachefile_age,
+ ignore_check_interval)
if info != None and add_nodeinfo:
- info = [ [ None ] + line for line in info ]
+ if clusters_of(hostname):
+ add_host = hostname
+ else:
+ 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.
@@ -1149,6 +1157,7 @@ def convert_check_info():
"default_levels_variable" :
check_default_levels.get(check_type),
"node_info" : False,
"parse_function" : None,
+ "extra_sections" : [],
}
else:
# Check does already use new API. Make sure that all keys are present,
@@ -1160,6 +1169,7 @@ def convert_check_info():
info.setdefault("snmp_scan_function", None)
info.setdefault("default_levels_variable", None)
info.setdefault("node_info", False)
+ info.setdefault("extra_sections", [])
# Include files are related to the check file (= the basename),
# not to the (sub-)check. So we keep them in check_includes.
@@ -1284,11 +1294,12 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
if infotype in parsed_infos:
info = parsed_infos[infotype]
else:
- info = get_host_info(hostname, ipaddress, infotype)
+ info = get_info_for_check(hostname, ipaddress, infotype)
parsed_infos[infotype] = info
except MKSkipCheck, e:
continue
+
except MKSNMPError, e:
if str(e):
problems.append(str(e))
@@ -1399,6 +1410,25 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
return agent_version, num_success, error_sections, ", ".join(problems)
+# 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_for_check(hostname, ipaddress, infotype, max_cachefile_age=None,
ignore_check_interval=False):
+
+ if infotype in check_info:
+ extra_sections = check_info[infotype]["extra_sections"]
+ if extra_sections:
+ info = [ get_host_info(hostname, ipaddress, infotype, max_cachefile_age,
ignore_check_interval) ]
+ for es in extra_sections:
+ try:
+ info.append(get_host_info(hostname, ipaddress, es, max_cachefile_age,
ignore_check_interval=False))
+ except:
+ info.append(None)
+ return info
+
+ return get_host_info(hostname, ipaddress, infotype, max_cachefile_age,
ignore_check_interval)
+
def open_checkresult_file():
global checkresult_file_fd