Module: check_mk
Branch: master
Commit: 98aa29bad7b8cbd17ea86275ac0fc96f68ac8fbd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=98aa29bad7b8cb…
Author: Götz Golla <gg(a)mathias-kettner.de>
Date: Mon Jan 27 17:55:12 2014 +0100
fileinfo.groups: new feature to include current date in file pattern
---
.werks/576 | 8 ++++++++
ChangeLog | 1 +
checkman/fileinfo.groups | 26 ++++++++++++++++----------
checks/fileinfo | 17 ++++++++++++++---
4 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/.werks/576 b/.werks/576
new file mode 100644
index 0000000..dd07b64
--- /dev/null
+++ b/.werks/576
@@ -0,0 +1,8 @@
+Title: fileinfo.groups: new feature to include current date in file pattern
+Level: 1
+Component: checks
+Version: 1.2.5i1
+Date: 1390841625
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 1838d2e..7ecc087 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -75,6 +75,7 @@
* 0265 mpre_include: run additional mrpe configs within user context...
* 0266 windows_agent: now supports mrpe include files...
* 0574 if64: check now supports clustering...
+ * 0576 fileinfo.groups: new feature to include current date in file pattern
* 0103 FIX: services: Fixed bug with service inventory defined in main.mk...
* 0299 FIX: borcade_mlx_fan: Prettified output, handling "other" state now
* 0300 FIX: cisco_fru_power: Trying not to inventorize not plugged in FRUs...
diff --git a/checkman/fileinfo.groups b/checkman/fileinfo.groups
index 04d3b03..50d1b96 100644
--- a/checkman/fileinfo.groups
+++ b/checkman/fileinfo.groups
@@ -13,31 +13,37 @@ description:
know the information about which files need to be sent. Please refer to
fileinfos manpage for information about setting up the agent.
- The check also needs a configured file grouping pattern. File grouping
- patterns combine a simple pattern based on {*} and {?} to join a subset
- of the file names send by the agent into a file group. In addition an
- {exclude} pattern may be define to exclude certain filenames.
- The name of the file group is referenced in the check configuration
- as the item.
+ The check also needs a configured file grouping pattern. The name of the
+ file group is referenced in the check configuration as the item.
+
+ File grouping patterns combine a simple pattern based on {*} and {?} to
+ join a subset of the file names send by the agent into a file group. In
+ addition an {exclude} pattern may be defined to exclude certain filenames.
+
+ Furthermore, the current time/date in a configurable format may be
+ included in the pattern. The syntax is as follows: {$DATE:format-spec$},
+ where {format-spec} is a list of time format directives of the unix date
+ command. Example: {$DATE:%Y%m%d$} is todays date, e.g. 20140127. A pattern
+ of {/var/tmp/backups/$DATE:%Y%m%d$.txt} would search for .txt files with
+ todays date as name in the directory /var/tmp/backups.
item:
Configured name of the file group
examples:
-
-# old syntax of file group patterns, still valid
+ # old syntax of file group patterns, still valid
fileinfo_groups = [
([("Auth_group",r"/var/log/auth*")], ALL_HOSTS),
([("Message_group", r"/var/log/messages*")], ['test2'],
ALL_HOSTS),
]
-# new syntax of file group patterns, including exclude pattern
+ # new syntax of file group patterns, including exclude pattern
fileinfo_groups = [
([("Auth_group",
("/var/log/auth*","/var/log/*.debug"))], ALL_HOSTS),
([("Message_group", ("/var/log/messages*",""))],
['test2'], ALL_HOSTS),
]
-# syntax of check
+ # syntax of check
check_parameters = [
({
"minsize": (200.0, 300.0),
diff --git a/checks/fileinfo b/checks/fileinfo
index 7907fdf..59b1c43 100644
--- a/checks/fileinfo
+++ b/checks/fileinfo
@@ -125,11 +125,20 @@ def check_fileinfo_groups(item, params, info):
size_all = 0
size_smallest = None
size_largest = 0
- # Start counting all values
+ date_inclusion = ""
+ # Start counting values on all files
for line in info[1:]:
for pattern in params['precompiled_patterns']:
- if fnmatch.fnmatch(line[0], pattern[0]) and str(line[1]) != 'missing'
\
- and not fnmatch.fnmatch(line[0], pattern[1]):
+ 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
+ if fnmatch.fnmatch(line[0], inclusion) and str(line[1]) != 'missing'
\
+ and not fnmatch.fnmatch(line[0], exclusion):
size = int(line[1])
size_all += size
if size_smallest == None:
@@ -163,6 +172,8 @@ def check_fileinfo_groups(item, params, info):
check_definition.append(("size_smallest", size_smallest,
get_filesize_human_readable))
if size_largest != 0:
check_definition.append(("size_largest", size_largest,
get_filesize_human_readable))
+ if date_inclusion:
+ check_definition.append(("date pattern", date_inclusion, str ))
return fileinfo_check_function(check_definition, params)