Module: check_mk
Branch: master
Commit: ec41bd630e6698ff72ee018d1720fdd31d50ebbe
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec41bd630e6698…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 13 09:00:24 2012 +0100
Fix some problems with new check registration API
---
checks/cpu | 19 +++++++++++++++----
checks/df | 15 +++++++++------
checks/mem | 11 ++++++++---
modules/check_mk.py | 46 ++++++++++++++++++++++++++++------------------
modules/check_mk_base.py | 21 +++++++++++----------
5 files changed, 71 insertions(+), 41 deletions(-)
diff --git a/checks/cpu b/checks/cpu
index e2bb254..5a42b0a 100644
--- a/checks/cpu
+++ b/checks/cpu
@@ -74,8 +74,19 @@ def check_cpu_threads(item, params, info):
else:
return (0, "OK - %d threads" % (nthreads,), perfdata)
-check_info['cpu.loads'] = (check_cpu_load, "CPU load", 1,
inventory_cpu_load )
-checkgroup_of['cpu.loads'] = "cpu_load"
+check_info["cpu.loads"] = {
+ "check_function" : check_cpu_load,
+ "inventory_function" : inventory_cpu_load,
+ "service_description" : "CPU load",
+ "has_perfdata" : True,
+ "group" : "cpu_load",
+}
+
+check_info["cpu.threads"] = {
+ "check_function" : check_cpu_threads,
+ "inventory_function" : inventory_cpu_threads,
+ "service_description" : "Number of threads",
+ "has_perfdata" : True,
+ "group" : "threads",
+}
-check_info['cpu.threads'] = (check_cpu_threads, "Number of threads", 1,
inventory_cpu_threads)
-checkgroup_of['cpu.threads'] = "threads"
diff --git a/checks/df b/checks/df
index a53d4fc..7664b85 100644
--- a/checks/df
+++ b/checks/df
@@ -31,8 +31,6 @@
# /dev/sda1 reiserfs 256666 16052 227362 7% /boot
# /dev/mapper/mirrored-database ext3 20642428 1027112 19405604 6%
/mirrored/database
-check_includes['df'] = [ "df.include" ]
-
def inventory_df(info):
inventory = []
for line in info:
@@ -81,7 +79,12 @@ def check_df(mountpoint, params, info):
return df_check_filesystem(g_hostname, mountpoint, size_mb, avail_mb, params)
-
-check_info['df'] = (check_df, "fs_%s", 1, inventory_df)
-check_default_levels['df'] = "filesystem_default_levels"
-checkgroup_of['df'] = "filesystem"
+check_info['df'] = {
+ "check_function" : check_df,
+ "inventory_function" : inventory_df,
+ "service_description" : "fs_%s",
+ "has_perfdata" : True,
+ "group" : "df",
+ "default_levels_variable" : "filesystem_default_levels",
+ "includes" : [ "df.include" ],
+}
diff --git a/checks/mem b/checks/mem
index 92112aa..3e5c172 100644
--- a/checks/mem
+++ b/checks/mem
@@ -120,9 +120,14 @@ def check_mem_used(item, params, info):
return (0, 'OK - %s' % infotext, perfdata)
-check_info['mem.used'] = (check_mem_used, "Memory used", 1,
inventory_mem_used)
-check_config_variables.append("mem_extended_perfdata")
-checkgroup_of["mem.used"] = "memory"
+check_info['mem.used'] = {
+ "check_function" : check_mem_used,
+ "inventory_function" : inventory_mem_used,
+ "service_description" : "Memory used",
+ "has_perfdata" : True,
+ "group" : "memory",
+ "check_config_variables" : [ "mem_extended_perfdata" ],
+}
# +----------------------------------------------------------------------+
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 5bf4626..a8c246b 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -633,7 +633,7 @@ def get_snmp_character_encoding(hostname):
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]["snmp_info"] != None
+ check_info[base_check_name].get("snmp_info") != None
def is_snmp_host(hostname):
return in_binary_hostlist(hostname, snmp_hosts)
@@ -2395,15 +2395,17 @@ no_inventory_possible = None
# Do we need to load the SNMP module? This is the case, if the host
# has at least one SNMP based check. Also collect the needed check
- # types.
+ # types and sections.
need_snmp_module = False
- needed_types = set([])
- for checktype, item, param, descr, aggr in check_table:
- if checktype not in check_info:
- sys.stderr.write('Warning: Ignoring missing check %s.\n' %
checktype)
+ needed_check_types = set([])
+ needed_sections = set([])
+ for check_type, item, param, descr, aggr in check_table:
+ if check_type not in check_info:
+ sys.stderr.write('Warning: Ignoring missing check %s.\n' %
check_type)
continue
- needed_types.add(checktype.split(".")[0])
- if check_uses_snmp(checktype):
+ needed_sections.add(check_type.split(".")[0])
+ needed_check_types.add(check_type)
+ if check_uses_snmp(check_type):
need_snmp_module = True
if need_snmp_module:
@@ -2416,9 +2418,9 @@ no_inventory_possible = None
# We need to include all those plugins that are referenced in the host's
# check table
filenames = []
- for checktype in needed_types:
+ for check_type in needed_check_types:
# Add library files needed by check (also look in local)
- for lib in check_includes.get(checktype, []):
+ for lib in check_info[check_type].get("includes", []):
if local_checks_dir and os.path.exists(local_checks_dir + "/" +
lib):
to_add = local_checks_dir + "/" + lib
else:
@@ -2426,11 +2428,12 @@ no_inventory_possible = None
if to_add not in filenames:
filenames.append(to_add)
- # Now add check file itself
- path = find_check_plugin(checktype)
+ # Now add check file itself (convert check_type to section)
+ section = check_type.split(".")[0]
+ path = find_check_plugin(section)
if not path:
- raise MKGeneralException("Cannot find plugin for check type %s (missing
file %s/%s)\n" % \
- (checktype, checks_dir, checktype))
+ raise MKGeneralException("Cannot find check file %s needed for check
type %s" % \
+ (section, check_type))
if path not in filenames:
filenames.append(path)
@@ -2521,6 +2524,11 @@ no_inventory_possible = None
for var in check_config_variables:
output.write("%s = %r\n" % (var, eval(var)))
+ # The same for those checks that use the new API
+ for check_type in needed_check_types:
+ for var in check_info[check_type].get("check_config_variables", []):
+ output.write("%s = %r\n" % (var, eval(var)))
+
# perform actual check
output.write("do_check(%r, %r)\n" % (hostname, ipaddress))
output.close()
@@ -4000,8 +4008,10 @@ def read_config_files(with_autochecks=True, with_conf_d=True):
global vars_before_config, final_mk, local_mk, checks
# Initialize dictionary-type default levels variables
- for varname in check_default_levels.values():
- globals()[varname] = {}
+ for check in check_info.values():
+ def_var = check.get("default_levels_variable")
+ if def_var:
+ globals()[def_var] = {}
# Create list of all files to be included
if with_conf_d:
@@ -4090,7 +4100,7 @@ def read_config_files(with_autochecks=True, with_conf_d=True):
# at least those keys defined in the factory
# settings are present in the parameters
if type(params) == dict:
- def_levels_varname = check_default_levels.get(checktype)
+ def_levels_varname =
check_info[checktype].get("default_levels_variable")
if def_levels_varname:
for key, value in factory_settings.get(def_levels_varname,
{}).items():
if key not in params:
@@ -4159,7 +4169,7 @@ def read_config_files(with_autochecks=True, with_conf_d=True):
# the values code in autochecks (given as parameter params)
def compute_check_parameters(host, checktype, item, params):
# Handle dictionary based checks
- def_levels_varname = check_default_levels.get(checktype)
+ def_levels_varname = check_info[checktype].get("default_levels_variable")
if def_levels_varname:
vars_before_config.add(def_levels_varname)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index fbdccc4..54e9374 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -730,21 +730,22 @@ def check_unimplemented(checkname, params, info):
return (3, 'UNKNOWN - Check not implemented')
def convert_check_info():
- for checkname, info in check_info.items():
+ for check_type, info in check_info.items():
if type(info) != dict:
check_function, service_description, has_perfdata, inventory_function = info
if inventory_function == no_inventory_possible:
inventory_function = None
- check_info[checkname] = {
- "check_function" : check_function,
- "service_description" : service_description,
- "has_perfdata" : not not has_perfdata,
- "inventory_function" : inventory_function,
- "group" : checkgroup_of.get(checkname),
- "snmp_info" : snmp_info.get(checkname),
- "snmp_scan_function" : snmp_scan_functions.get(checkname),
- "includes" : check_includes.get(checkname, []),
+ check_info[check_type] = {
+ "check_function" : check_function,
+ "service_description" : service_description,
+ "has_perfdata" : not not has_perfdata,
+ "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),
+ "includes" : check_includes.get(check_type,
[]),
+ "default_levels_variable" :
check_default_levels.get(check_type),
}
# Loops over all checks for a host, gets the data, calls the check