Module: check_mk
Branch: master
Commit: 732c87d4bdcb7f68311740bd6470e249ec4d26b1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=732c87d4bdcb7f…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Oct 11 11:42:36 2016 +0200
3956 fileinfo.groups: now allows regular expressions within include and exclude patterns
each beginning with a tilde
---
.werks/3956 | 9 +++++++++
ChangeLog | 1 +
checks/fileinfo | 21 +++++++++++++++++----
web/plugins/wato/check_parameters.py | 6 ++++--
4 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/.werks/3956 b/.werks/3956
new file mode 100644
index 0000000..1d48cca
--- /dev/null
+++ b/.werks/3956
@@ -0,0 +1,9 @@
+Title: fileinfo.groups: now allows regular expressions within include and exclude
patterns each beginning with a tilde
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i2
+Date: 1476178717
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index b54045a..7b0cc4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
* 3913 gude_relayport, gude_temp, gude_humidity: new checks and relayport check now
monitors electricity
* 3954 postfix_mailq_status: new check which monitors the status of postfix mail
instances
* 3945 fortigate_node: Memory on fortigate clusters are now configurable by WATO...
+ * 3956 fileinfo.groups: now allows regular expressions within include and exclude
patterns each beginning with a tilde
* 3894 FIX: mkeventd_status: Fixed bug in case Event Console is not running
* 3907 FIX: oracle_tablespaces: simplyfied free space calculation depending on
version...
* 3819 FIX: windows agent: fixed 2 bugs related to mrpe...
diff --git a/checks/fileinfo b/checks/fileinfo
index ff5201a..5d52695 100644
--- a/checks/fileinfo
+++ b/checks/fileinfo
@@ -73,17 +73,30 @@ def fileinfo_process_date(pattern, reftime):
return pattern
-def fileinfo_groups_of_file(check_filename,reftime):
+def fileinfo_groups_of_file(check_filename, reftime):
groups = []
for line in host_extra_conf(g_hostname, fileinfo_groups):
for group_name, pattern in line:
if type(pattern) == str: # support old format
pattern = ( pattern, '' )
+
inclusion, exclusion = pattern
- inclusion = fileinfo_process_date(inclusion,reftime)
- if fnmatch.fnmatch(check_filename, inclusion) \
- and not fnmatch.fnmatch(check_filename, exclusion):
+ if inclusion.startswith("~"):
+ reg = regex(inclusion[1:])
+ incl_match = reg.match( check_filename )
+ else:
+ inclusion = fileinfo_process_date(inclusion, reftime)
+ incl_match = fnmatch.fnmatch(check_filename, inclusion)
+
+ if exclusion.startswith("~"):
+ reg = regex(exlusion[1:])
+ excl_match = reg.match( check_filename )
+ else:
+ excl_match = fnmatch.fnmatch(check_filename, exclusion)
+
+ if incl_match and not excl_match:
groups.append(group_name)
+
return groups
def fileinfo_check_timeranges(params):
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index eba58d5..8aa8c29 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -4300,7 +4300,9 @@ register_rule(group + '/' + subgroup_storage,
'not only for the total size and the age of the oldest/youngest
'
'file but also on the count. You can define one or several '
'patterns for a group containing <tt>*</tt> and
<tt>?</tt>, for example '
- '<tt>/var/log/apache/*.log</tt>. For files contained in
a group '
+ '<tt>/var/log/apache/*.log</tt>. If the pattern begins
with a tilde then '
+ 'this pattern is interpreted as a regular expression otherwise it
is a '
+ 'glob. For files contained in a group '
'the discovery will automatically create a group service instead
'
'of single services for each file. This rule also applies when
'
'you use manually configured checks instead of inventorized ones.
'
@@ -4314,7 +4316,7 @@ register_rule(group + '/' + subgroup_storage,
'The YESTERDAY syntax simply subtracts one day from the reference
time.'),
valuespec = ListOf(
Tuple(
- help = _("This defines one file grouping pattern"),
+ help = _("This defines one file grouping pattern."),
show_titles = True,
orientation = "horizontal",
elements = [