Module: check_mk
Branch: master
Commit: b6e78726694f0ebd2b087c520d01d514fc4d049e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b6e78726694f0e…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Mon Oct 27 14:46:00 2014 +0100
#1193 ps: Manual Checks can now use RegEx for user matching
If you start the username with a tilde, the string will be interpreted as RegEx.
When using Wato just choice RegEx in the Dropdown.
---
.werks/1193 | 11 +++++++++++
ChangeLog | 1 +
checks/ps.include | 6 +++++-
web/plugins/wato/check_parameters.py | 26 +++++++++++++++++++++++---
4 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/.werks/1193 b/.werks/1193
new file mode 100644
index 0000000..1db3401
--- /dev/null
+++ b/.werks/1193
@@ -0,0 +1,11 @@
+Title: ps: Manual Checks can now use RegEx for user matching
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.5i6
+Date: 1414417457
+Class: feature
+
+If you start the username with a tilde, the string will be interpreted as RegEx.
+When using Wato just choice RegEx in the Dropdown.
+
diff --git a/ChangeLog b/ChangeLog
index 82f1df8..ff01a77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -80,6 +80,7 @@
* 1190 statgrab_cpu: Check can now handle parameters
* 1191 Linux agent now also sends information about tmpfs...
* 1424 mknotifyd: now able to check if its still listening for telegrams...
+ * 1193 ps: Manual Checks can now use RegEx for user matching...
* 1051 FIX: tcp_conn_stats: fix missing performance data...
* 1142 FIX: winperf_ts_sessions: fix computation, check has never really worked
* 1090 FIX: zfsget: fixed exception which happened on incomplete zfs entries
diff --git a/checks/ps.include b/checks/ps.include
index 22e5336..6b12e90 100644
--- a/checks/ps.include
+++ b/checks/ps.include
@@ -165,7 +165,11 @@ def process_matches(ps, procname, l_user):
if ps[0].startswith("(") and ps[0].endswith(")") and len(ps) >
1:
addinfo = ps[0][1:-1].split(",")
user = addinfo[0]
- if userspec and userspec != user:
+ if userspec and userspec.startswith('~'):
+ if not re.match(userspec[1:], user):
+ return False
+
+ elif userspec and userspec != user:
return False
l_user[0] = user # return actual user that way
ps = ps[1:]
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 6cc3199..800c8aa 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -6034,10 +6034,30 @@ register_check_parameters(
title = _("Maximum number of matched process for WARNING
state"),
default_value = 1,
)),
- ( "user", TextAscii(
+ ( "user", Alternative(
title = _("Name of operating system user"),
- help = _("Leave this empty, if the user does not matter"),
- none_is_empty = True,
+ style = "dropdown",
+ elements = [
+ TextAscii(
+ title = _("Exact name of the oeprating system
user")
+ ),
+ Transform(
+ RegExp(size = 50),
+ title = _("Regular expression matching username"),
+ help = _("This regex must match the
<i>beginning</i> of the complete "
+ "username"),
+ forth = lambda x: x[1:], # remove ~
+ back = lambda x: "~" + x, # prefix ~
+ ),
+ FixedValue(
+ None,
+ totext = "",
+ title = _("Match all users"),
+ )
+
+ ],
+ match = lambda x: (not x and 2) or (x[0] == '~' and 1 or 0)
+
)),
( "cpulevels",
Tuple(