Module: check_mk
Branch: master
Commit: dd7a4cc90a5916331cc44ee182a8b36ac5fc0a66
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dd7a4cc90a5916…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 20 14:38:39 2012 +0100
ps: output node a process is running on
This is only done if the check is run on a cluster
---
ChangeLog | 1 +
checks/ps | 53 +++++++++++++++++++++++++++++++----------
modules/check_mk.py | 7 +++++
web/plugins/views/painters.py | 21 +++++++++++----
4 files changed, 63 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2f0d46a..0e7fdf6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,6 +40,7 @@
is needed on Cisco WLC 21xx series (thanks to Ralf Ertzinger)
* FIX: fix inventory of f5_bigip_temp
* mk_oracle (lnx+win): Fixed TEMP tablespace size calculations
+ * ps: output node process is running on (only for clusters)
Multisite:
* Added several missing localization stringsw
diff --git a/checks/ps b/checks/ps
index aa3c799..e2ce176 100644
--- a/checks/ps
+++ b/checks/ps
@@ -40,13 +40,14 @@ inventory_processes_perf = []
ANY_USER = None
GRAB_USER = False
+def inventory_ps(info):
+ return inventory_ps_common(inventory_processes, info)
-def inventory_ps(check_name, info):
+def inventory_ps_perf(info):
+ return inventory_ps_common(inventory_processes_perf, info)
+
+def inventory_ps_common(invdata, info):
inventory = []
- if check_name == "ps":
- invdata = inventory_processes
- else:
- invdata = inventory_processes_perf
for inventry in invdata:
# New in 1.1.7i1: inventory_processes may be prefixed with list of
@@ -69,7 +70,9 @@ def inventory_ps(check_name, info):
servicedesc, pattern, userspec, warnmin, okmin, okmax, warnmax = inventry
num_perc_s = servicedesc.count("%s")
- for ps in info:
+ for line in info:
+ # First entry in line is the node name or None for non-clusters
+ ps = line[1:]
l_user = [userspec]
matches = process_matches(ps, pattern, l_user)
if matches != False:
@@ -171,9 +174,14 @@ def check_procs(item, params, info, with_perfdata):
percent_cpu = 0.0
extended_perfdata = False
- for ps in info:
+ running_on = set([]) # collect information about nodes the processes run on
+ for line in info:
+ node_name = line[0]
+ ps = line[1:]
if process_matches(ps, procname, [user]) != False:
count += 1
+ if node_name != None:
+ running_on.add(node_name)
if ps[0][0] == '(':
addinfo = ps[0][1:-1].split(",")
if len(addinfo) >= 4: # extended performance data
@@ -201,12 +209,31 @@ def check_procs(item, params, info, with_perfdata):
else:
perfdata = []
+ infotext = " - %d processes" % count
+ if running_on:
+ infotext += " [running on %s]" % ", ".join(running_on)
+
if count > warnmax or count < warnmin:
- return (2, "CRIT - %d processes (ok from %d to %d)" % (count, okmin,
okmax), perfdata)
+ return (2, "CRIT" + infotext + " (ok from %d to %d)" %
(okmin, okmax), perfdata)
elif count > okmax or count < okmin:
- return (1, "WARN - %d processes (ok from %d to %d)" % (count, okmin,
okmax), perfdata)
+ return (1, "WARN" + infotext + " (ok from %d to %d)" %
(okmin, okmax), perfdata)
else:
- return (0, "OK - %d processes" % count, perfdata)
-
-check_info['ps'] = (lambda i,p,n: check_procs(i,p,n,False),
"proc_%s", 0, inventory_ps)
-check_info['ps.perf'] = (lambda i,p,n: check_procs(i,p,n,True),
"proc_%s", 1, inventory_ps)
+ return (0, "OK" + infotext, perfdata)
+
+check_info['ps'] = {
+ "check_function" : lambda i,p,n: check_procs(i,p,n,False),
+ "inventory_function" : inventory_ps,
+ "service_description" : "proc_%s",
+ "has_perfdata" : False,
+ "node_info" : True, # add first column with actual host name
+ "group" : "ps",
+}
+
+check_info['ps.perf'] = {
+ "check_function" : lambda i,p,n: check_procs(i,p,n,True),
+ "inventory_function" : inventory_ps_perf,
+ "service_description" : "proc_%s",
+ "has_perfdata" : True,
+ "node_info" : True, # add first column with actual host name
+ "group" : "ps",
+}
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 73a27e9..9a7e5ed 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2032,6 +2032,13 @@ def make_inventory(checkname, hostnamelist, check_only=False,
include_state=Fals
checkname_base = checkname.split('.')[0] # make e.g. 'lsi'
from 'lsi.arrays'
try:
info = get_realhost_info(hostname, ipaddress, checkname_base,
inventory_max_cachefile_age)
+ # Add information about nodes if check wants this
+ if check_info[checkname]["node_info"]:
+ if cluster_of(hostname):
+ add_host = hostname
+ else:
+ add_host = None
+ info = [ [add_host] + line for line in info ]
except MKAgentError, e:
# This special handling is needed for the inventory check. It needs
special
# handling for WATO.
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 2aa0991..bc6e828 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -308,16 +308,25 @@ warn_marker = '<b class="stmark
state1">WARN</b>'
crit_marker = '<b class="stmark state2">CRIT</b>'
unknown_marker = '<b class="stmark state3">UNKN</b>'
-def format_plugin_output(output):
- return output.replace("(!)", warn_marker) \
- .replace("(!!)", crit_marker) \
- .replace("(?)", unknown_marker)
+def format_plugin_output(row, output):
+ output = output.replace("(!)", warn_marker) \
+ .replace("(!!)", crit_marker) \
+ .replace("(?)", unknown_marker)
+ if "[running on" in output:
+ a = output.index("[running on")
+ e = output.index("]", a)
+ hosts = output[a+12:e].replace(" ","").split(",")
+ css, h = paint_host_list(row["site"], hosts)
+ output = output[:a] + "running on " + h + output[e+1:]
+
+ return output
+
multisite_painters["svc_plugin_output"] = {
"title" : _("Output of check plugin"),
"short" : _("Status detail"),
"columns" : ["service_plugin_output"],
- "paint" : lambda row: ("",
format_plugin_output(row["service_plugin_output"])),
+ "paint" : lambda row: ("", format_plugin_output(row,
row["service_plugin_output"])),
"sorter" : 'svcoutput',
}
multisite_painters["svc_long_plugin_output"] = {
@@ -1549,7 +1558,7 @@ multisite_painters["log_plugin_output"] = {
"title" : _("Log: output of check plugin"),
"short" : _("Check output"),
"columns" : ["log_plugin_output"],
- "paint" : lambda row: ("",
format_plugin_output(row["log_plugin_output"])),
+ "paint" : lambda row: ("", format_plugin_output(row,
row["log_plugin_output"])),
}
multisite_painters["log_attempt"] = {