Module: check_mk
Branch: master
Commit: 08109beb12c45921dbba287b2e66f17aa645a71a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=08109beb12c459…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Oct 24 19:15:55 2010 +0200
ps: inventory with GRAB_USER replaces %u in service desc
---
ChangeLog | 3 +++
LIESMICH.zutun | 4 ----
checkman/ps | 31 +++++++++++++++++--------------
checks/ps | 17 ++++++++++++-----
4 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c2c1892..834a353 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,9 @@
* logwatch: Fixed typo in 'too many unacknowledged logs' error message
* ps: fix bug: inventory with fixed user name now correctly puts
that user name into the resulting check - not None.
+ * ps: inventory with GRAB_USER: require service description to contain
+ %u. That will be replaced with the user name and thus makes the
+ service description unique.
Livestatus:
* Prohibit { and } in regular expressions. This avoids a segmentation
diff --git a/LIESMICH.zutun b/LIESMICH.zutun
index 17a17bc..9b25838 100644
--- a/LIESMICH.zutun
+++ b/LIESMICH.zutun
@@ -12,10 +12,6 @@ BUGS beheben bis => 1.1.8
--------------------------------------------------------------------------------
CHECK_MK:
-inventory_processes: Wenn man mit GRAB_USER arbeitet und sich die
-Prozesse nur im Benutzer unterscheiden, dann muss der Benutzer in
-der Servicedescription auftauchen, sonst heissen alle Services gleich.
-
akcp_sensor_temp -> Man-Page ist kaputt
doc/ aufräumen und komplett 1:1 installieren.
diff --git a/checkman/ps b/checkman/ps
index d1a43a1..01fd674 100644
--- a/checkman/ps
+++ b/checkman/ps
@@ -44,17 +44,19 @@ inventory:
are used for the service descriptions. The matched substrings corresponding
to the remaining groups are copied into the regular expression, nevertheless.
- Wildcards not enclosed by brackets are simply copied verbatim to the
- created checks. Please refer to the examples for more details.
-
+ Wildcards not enclosed by brackets are simply copied verbatim to the created
+ checks. Please refer to the examples for more details.
+
The {user specification} can either be a user name (string). The inventory
- will then trigger only if that user matches the user the process
- is running as and the resulting check will require that user.
- Alternatively you can specify {ANY_USER} or {GRAB_USER}.
- If you specify {ANY_USER} then the user field will simply be ignored.
- The created check will not check for a specific user. Specifying {GRAB_USER}
- makes the created check expect the process to run as the same user as
- during inventory: the user name will be hardcoded into the check.
+ will then trigger only if that user matches the user the process is running as
+ and the resulting check will require that user. Alternatively you can specify
+ {ANY_USER} or {GRAB_USER}. If you specify {ANY_USER} then the user field
+ will simply be ignored. The created check will not check for a specific user.
+
+ Specifying {GRAB_USER} makes the created check expect the process to run
+ as the same user as during inventory: the user name will be hardcoded into
+ the check. In that case you need to put {%u} into the service description,
+ which will be replace by the actual user name during inventory.
The {warning and critical levels} are simply copied to the created
checks.
@@ -100,7 +102,7 @@ examples:
# alternative(3): do the same, but make sure, ntpd is always
# running as the user under which we found it first:
- ( "NTPD2", "/usr/sbin/ntpd", GRAB_USER, 1, 1, 1, 1),
+ ( "NTPD2 %u", "/usr/sbin/ntpd", GRAB_USER, 1, 1, 1, 1),
# if we find Apache2, monitor it and make sure it's running
# as the user 'www-data'! Make also sure, that the number
@@ -112,10 +114,11 @@ examples:
# For each NIC there might by one dhclient. We monitor the
# processes separately for each NIC at which we find a dhclient
# running.
- ( "DHCP-Client NIC %s", "~dhclient.* ([a-z]+[0-9]-*)$", GRAB_USER,
1, 1, 1, 1) ,
+ ( "DHCP-Client NIC %s", "~dhclient.* ([a-z]+[0-9]-*)$", ANY_USER,
1, 1, 1, 1) ,
- # SAP: Search for SAP processes, extract three components
- ( "SCS %s/%s/%s", "~(..)\.sap(...)_SCS([0-9]+) pf=", ANY_USER, 1,
1, 1, 1 ),
+ # SAP: Search for SAP processes, extract three components, add the
+ # user name the process was running as to the service description
+ ( "SCS %s/%s/%s %u", "~(..)\.sap(...)_SCS([0-9]+) pf=", GRAB_USER,
1, 1, 1, 1 ),
]
[configuration]
inventory_processes (list): A list of 7-tuples. See {INVENTORY} for details.
diff --git a/checks/ps b/checks/ps
index 7b13972..bb7a163 100644
--- a/checks/ps
+++ b/checks/ps
@@ -77,18 +77,25 @@ def inventory_ps(check_name, info):
raise MKGeneralException("Invalid entry in inventory_processes:
service description '%s' contains "
"%d times '%%s', but regular expression
'%s' contains only %d subexpression(s)." % \
(servicedesc, num_perc_s, pattern, len(matches)))
- # 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.
- i_servicedesc = servicedesc % (matches[:num_perc_s])
+
if userspec == GRAB_USER:
i_userspec = l_user[0]
+ if '%u' not in servicedesc:
+ raise MKGeneralException("Invalid entry in
inventory_processes: if you use GRAB_USER, you need to put %%u into the service
description. Your description is '%s'" % servicedesc)
+ i_servicedesc = servicedesc.replace("%u", l_user[0])
else:
i_userspec = userspec
+ i_servicedesc = servicedesc
+
+ # 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.
+ i_servicedesc = i_servicedesc % (matches[:num_perc_s])
+
# Problem here: We need to instantiate all subexpressions
# with their actual values of the found process.
i_pattern = instantiate_regex_pattern(pattern, matches)
- inv = ( i_servicedesc, "matched by \"%s\"" % pattern,
( i_pattern, i_userspec, warnmin, okmin, okmax, warnmax ) )
+ inv = ( i_servicedesc, ( i_pattern, i_userspec, warnmin, okmin, okmax,
warnmax ) )
if inv not in inventory:
inventory.append(inv)