Module: check_mk
Branch: master
Commit: 6dd32b7e62e4bd609c1d1d63d33ebea51a58b3b6
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6dd32b7e62e4bd…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 18 12:03:31 2013 +0100
ps: Allow %1, %2, .. instead of %s in process_inventory.
---
ChangeLog | 2 ++
checkman/ps | 4 ++++
checks/ps | 5 +++++
web/plugins/wato/check_parameters.py | 11 +++++++----
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c759304..a1ee131 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,8 @@
1.2.2b4:
Checks & Agents:
* Linux agent: limit netstat to 10 seconds
+ * ps: Allow %1, %2, .. instead of %s in process_inventory. That allows
+ reordering of matched groups
BI:
* FIX: fixed invalid links to hosts and services in BI tree view
diff --git a/checkman/ps b/checkman/ps
index 84f423a..65d2c69 100644
--- a/checkman/ps
+++ b/checkman/ps
@@ -44,6 +44,10 @@ inventory:
are used for the service descriptions. The matched substrings corresponding
to the remaining groups are copied into the regular expression, nevertheless.
+ New in version 1.2.2: As an alternative to {%s} you may also use {%1}, {%2},
+ etc. These will be replaced by the first, second, ... matching group. This
+ allows you to reorder things.
+
Wildcards not enclosed by brackets are simply copied verbatim to the created
checks. Please refer to the examples for more details.
diff --git a/checks/ps b/checks/ps
index fb2aa8c..4b62529 100644
--- a/checks/ps
+++ b/checks/ps
@@ -120,6 +120,11 @@ def inventory_ps_common(invdata, info, handle_perfdata = False):
i_userspec = userspec
i_servicedesc = servicedesc
+ # New in 1.2.2b4: Alle %1, %2, etc. to be replaced with first, second, ...
+ # group. This allows a reordering of the matched groups
+ for nr, group in enumerate(matches):
+ i_servicedesc = i_servicedesc.replace("%%%d" % (nr+1), group)
+
# It is allowed (1.1.4) that the pattern contains more subexpressions then the
# service description. In that case only the first subexpressions are used as
# item.
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index fc2ebb5..334a725 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -293,14 +293,17 @@ register_rule(group + '/' + subgroup_inventory,
elements = [
('descr', TextAscii(
title = _('Service Description'),
- help = _('<p>The service description may contain one or more occurances of %s. If you do this, then the pattern must be a regular '
+ help = _('<p>The service description may contain one or more occurances of <tt>%s</tt>. If you do this, then the pattern must be a regular '
'expression and be prefixed with ~. For each %s in the description, the expression has to contain one "group". A group '
- 'is a subexpression enclosed in brackets, for example (.*) or ([a-zA-Z]+) or (...). When the inventory finds a process '
+ 'is a subexpression enclosed in brackets, for example <tt>(.*)</tt> or <tt>([a-zA-Z]+)</tt> or <tt>(...)</tt>. When the inventory finds a process '
'matching the pattern, it will substitute all such groups with the actual values when creating the check. That way one '
'rule can create several checks on a host.</p>'
- '<p>If the pattern contains more groups thenoccurrances of %s in the service description then only the first matching '
+ '<p>If the pattern contains more groups then occurrances of <tt>%s</tt> in the service description then only the first matching '
'subexpressions are used for the service descriptions. The matched substrings corresponding to the remaining groups '
- 'are copied into the regular expression, nevertheless.</p>'),
+ 'are copied into the regular expression, nevertheless.</p>'
+ '<p>As an alternative to <tt>%s</tt> you may also use <tt>%1</tt>, <tt>%2</tt>, etc. '
+ 'These will be replaced by the first, second, ... matching group. This allows you to reorder things.</p>'
+ ),
)),
('match', Alternative(
title = _("Process Matching"),