Module: check_mk
Branch: master
Commit: 2f8fa0673858c90857d9db6dfc02c6278634a770
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2f8fa0673858c9…
Author: Götz Golla <gg(a)mathias-kettner.de>
Date: Fri Jan 31 13:44:27 2014 +0100
FIX fileinfo.groups: new date pattern is now available for inventory check as well
---
.werks/577 | 8 +++++++
ChangeLog | 1 +
checks/fileinfo | 62 ++++++++++++++++++++++++++++++++-----------------------
3 files changed, 45 insertions(+), 26 deletions(-)
diff --git a/.werks/577 b/.werks/577
new file mode 100644
index 0000000..2ead16f
--- /dev/null
+++ b/.werks/577
@@ -0,0 +1,8 @@
+Title: fileinfo.groups: new date pattern is now available for inventory check as well
+Level: 1
+Component: checks
+Version: 1.2.5i1
+Date: 1391172155
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 47c4cd9..9419a1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -147,6 +147,7 @@
* 0262 FIX: ps: Now able to skip disabled "Process Inventory" rules...
* 0264 FIX: printer_supply_ricoh: now reports correct filling levels...
* 0575 FIX: cmciii_lcp_airin, cmciii_lcp_airout, cmciii_lcp_waterin,
cmciii_lcp_waterout: improved handling of warning state...
+ * 0577 FIX: fileinfo.groups: new date pattern is now available for inventory check as
well
Multisite:
* 0371 Added log class filter to hostsvcevents view
diff --git a/checks/fileinfo b/checks/fileinfo
index 59b1c43..662176a 100644
--- a/checks/fileinfo
+++ b/checks/fileinfo
@@ -45,11 +45,13 @@ fileinfo_groups = []
def inventory_fileinfo(info, case):
inventory = []
added_groups = []
+ if info:
+ reftime = int(info[0][0])
for line in info:
if len(line) >= 3:
if line[1] == "missing":
continue
- groups = fileinfo_groups_of_file(line[0])
+ groups = fileinfo_groups_of_file(line[0], reftime)
if case == 'single' and not groups:
inventory.append((line[0], {}));
@@ -60,15 +62,26 @@ def inventory_fileinfo(info, case):
inventory.append((group, {}))
return inventory
-def fileinfo_groups_of_file(check_filename):
+def fileinfo_process_date(pattern,reftime):
+ disect = re.match('(/.*/)\$DATE:((?:%\w.?){1,})\$(.*)',pattern)
+ if disect:
+ prefix = disect.group(1)
+ datepattern = time.strftime(disect.group(2),time.localtime(reftime))
+ postfix = disect.group(3)
+ pattern = prefix+datepattern+postfix
+ return pattern
+
+def fileinfo_groups_of_file(check_filename,reftime):
import fnmatch
groups = []
for line in host_extra_conf(g_hostname, fileinfo_groups):
for group_name, pattern in line:
- if type(pattern) == str:
+ if type(pattern) == str: # support old format
pattern = ( pattern, '' )
- if fnmatch.fnmatch(check_filename, pattern[0]) \
- and not fnmatch.fnmatch(check_filename, pattern[1]):
+ inclusion, exclusion = pattern
+ inclusion = fileinfo_process_date(inclusion,reftime)
+ if fnmatch.fnmatch(check_filename, inclusion) \
+ and not fnmatch.fnmatch(check_filename, exclusion):
groups.append(group_name)
return groups
@@ -100,7 +113,7 @@ def fileinfo_groups_precompile(hostname, item, params):
for line in host_extra_conf(hostname, fileinfo_groups):
for group_name, pattern in line:
if group_name == item:
- if type(pattern) == str:
+ if type(pattern) == str: # support old format
pattern = ( pattern, '' )
patterns.append(pattern)
params['precompiled_patterns'] = patterns
@@ -130,13 +143,10 @@ def check_fileinfo_groups(item, params, info):
for line in info[1:]:
for pattern in params['precompiled_patterns']:
inclusion, exclusion = pattern
- disect = re.match('(/.*/)\$DATE:((?:%\w.?){1,})\$(.*)',inclusion)
- if disect:
- prefix = disect.group(1)
- datepattern = time.strftime(disect.group(2),time.localtime(reftime))
- postfix = disect.group(3)
- inclusion = prefix+datepattern+postfix
- date_inclusion = inclusion
+ inclusion_tmp = fileinfo_process_date(inclusion,reftime)
+ if inclusion != inclusion_tmp:
+ inclusion = inclusion_tmp
+ date_inclusion = inclusion_tmp
if fnmatch.fnmatch(line[0], inclusion) and str(line[1]) != 'missing'
\
and not fnmatch.fnmatch(line[0], exclusion):
size = int(line[1])
@@ -154,7 +164,6 @@ def check_fileinfo_groups(item, params, info):
else:
age_oldest = max(age_oldest, age)
age_newest = min(age_newest, age)
-
count_all += 1
if age_oldest == None:
@@ -184,18 +193,19 @@ def fileinfo_check_function(check_definition, params):
perfdata = []
for what, val, verbfunc in check_definition:
infos.append("%s is %s" % (what, verbfunc(val)))
- warn, crit = "", ""
- for how, comp, cfunc in [ ("min", "<", operator.lt),
("max", ">", operator.gt) ]:
- p = params.get(how + what)
- if p:
- warn, crit = p
- if cfunc(val, crit):
- state = 2
- infos[-1] += " (%s %s)(!!)" % (comp, verbfunc(crit))
- elif cfunc(val, warn):
- state = max(state, 1)
- infos[-1] += " (%s %s)(!)" % (comp, verbfunc(warn))
- perfdata.append((what, val, warn, crit))
+ if type(val) == int: # because strings go into infos but not into perfdata
+ warn, crit = "", ""
+ for how, comp, cfunc in [ ("min", "<", operator.lt),
("max", ">", operator.gt) ]:
+ p = params.get(how + what)
+ if p:
+ warn, crit = p
+ if cfunc(val, crit):
+ state = 2
+ infos[-1] += " (%s %s)(!!)" % (comp, verbfunc(crit))
+ elif cfunc(val, warn):
+ state = max(state, 1)
+ infos[-1] += " (%s %s)(!)" % (comp, verbfunc(warn))
+ perfdata.append((what, val, warn, crit))
infotext = ", ".join(infos)
return (state, infotext, perfdata)