Module: check_mk
Branch: master
Commit: 36a8dec80c62101895b7c17eb703a59289394c92
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=36a8dec80c6210…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 22 13:37:59 2015 +0200
Minor code cleanup
---
checks/fileinfo | 5 ++++-
modules/check_mk.py | 30 ++++++++++++++++++------------
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/checks/fileinfo b/checks/fileinfo
index ba91896..4650f26 100644
--- a/checks/fileinfo
+++ b/checks/fileinfo
@@ -144,6 +144,7 @@ def check_fileinfo_groups(item, params, info):
outof_range_txt = fileinfo_check_timeranges(params)
+ # TODO: import in check functions is not allowed
import fnmatch
reftime = int(info[0][0])
@@ -152,7 +153,8 @@ def check_fileinfo_groups(item, params, info):
# not been exectued yet. The precompile function creates an empty
# list when no rules/patterns are defined.
if 'precompiled_patterns' not in params:
- params = fileinfo_groups_precompile(g_hostname, item, params)
+ # TODO: it's not allowed to modify params!!
+ fileinfo_groups_precompile(g_hostname, item, params)
count_all = 0
age_oldest = None
@@ -212,6 +214,7 @@ def check_fileinfo_groups(item, params, info):
return fileinfo_check_function(check_definition, params, outof_range_txt)
def fileinfo_check_function(check_definition, params, outof_range_txt):
+ # TODO: use lambda a, b: a<b instead....
import operator
state = 0
infos = []
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 605bb96..4b4656c 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -316,7 +316,7 @@ check_info = {} # all known checks
inv_info = {} # inventory plugins
checkgroup_of = {} # groups of checks with compatible parametration
check_includes = {} # library files needed by checks
-precompile_params = {} # optional functions for parameter
precompilation, look at df for an example
+precompile_params = {} # optional functions for parameter
precompilation
check_default_levels = {} # dictionary-configured checks declare their
default level variables here
factory_settings = {} # factory settings for dictionary-configured
checks
check_config_variables = [] # variables (names) in checks/* needed for check
itself
@@ -3121,17 +3121,6 @@ def find_check_plugins(checktype):
return paths
-def get_precompiled_check_table(hostname):
- host_checks = get_sorted_check_table(hostname, remove_duplicates=True)
- precomp_table = []
- for checktype, item, params, description, deps in host_checks:
- aggr_name = aggregated_service_name(hostname, description)
- # some checks need precompilation of parameters
- precomp_func = precompile_params.get(checktype)
- if precomp_func:
- params = precomp_func(hostname, item, params)
- precomp_table.append((checktype, item, params, description, aggr_name)) # deps
not needed while checking
- return precomp_table
def precompile_hostchecks():
if not os.path.exists(precompiled_hostchecks_dir):
@@ -3145,6 +3134,7 @@ def precompile_hostchecks():
sys.stderr.write("Error precompiling checks for host %s: %s\n" %
(host, e))
sys.exit(5)
+
# read python file and strip comments
g_stripped_file_cache = {}
def stripped_python_file(filename):
@@ -3158,6 +3148,7 @@ def stripped_python_file(filename):
g_stripped_file_cache[filename] = a
return a
+# TODO: move this into a new module nagios.py (for creating Nagios config)
def precompile_hostcheck(hostname):
if opt_verbose:
sys.stderr.write("%s%s%-16s%s:" % (tty_bold, tty_blue, hostname,
tty_normal))
@@ -3482,6 +3473,21 @@ no_discovery_possible = None
if opt_verbose:
sys.stderr.write(" ==> %s.\n" % compiled_filename)
+
+def get_precompiled_check_table(hostname):
+ host_checks = get_sorted_check_table(hostname, remove_duplicates=True)
+ precomp_table = []
+ for checktype, item, params, description, deps in host_checks:
+ aggr_name = aggregated_service_name(hostname, description)
+ # some checks need precompilation of parameters
+ precomp_func = precompile_params.get(checktype)
+ if precomp_func:
+ params = precomp_func(hostname, item, params)
+ precomp_table.append((checktype, item, params, description, aggr_name)) # deps
not needed while checking
+ return precomp_table
+
+
+
#.
# .--Pack config---------------------------------------------------------.
# | ____ _ __ _ |