Module: check_mk
Branch: master
Commit: 1f4156e7f53949665b2db530e848b6d82b0a3c92
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1f4156e7f53949…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 4 15:10:45 2013 +0100
local: New state type P for state computation based on perfdata
The section <tt><<<local>>></tt> now
allows a new state
marker <tt>P</tt> (next to <tt>0</tt>, <tt>1</tt>,
<tt>2</tt> and <tt>3</tt>).
When setting this marker, the check plugin computes the state according to the
levels contained in the performance data. Take the following example:
F+:
<<<local>>>
P Environment temp=30;28;35|humidity=33;40:60;35:70;0;100 This is a text
F-:
The check will first check the variable <tt>temp</tt>. It's current value
is <tt>30</tt>. The levels are at <tt>28</tt> and
<tt>35</tt> for warning and
critical, resp. Because 30 is greater then 28 this will trigger a warning.
The second performance value <tt>humidity</tt> has both lower and upper
levels for warning and critical - separated by a colon. The
current value is 33, which is lower than the lower critical level
of <tt>35</tt>. This will make this variable und thus the total check
critical.
H2:Notes
<ul>
<li>It is allowed to use fractional values like
<tt>35.12</tt>.</li>
<li>If the current value exactly matches a level, the <i>better</i>
state is being used. This
is not consistent with the usual levels in Check_MK checks, but is neccessary if you want
to have just one single value to be OK.</li>
<li>When using <tt>P</tt> then the current values of all variables are
appended to the plugin output.
If you want you can omit the your additional text at all in that case.</li>
<li>When you use <tt>P</tt> and do not supply performance data or do not
supply levels, the
status will always be <b>OK</b>.</li>
</ul>
Example for a <tt>local</tt> line without a text:
F+:
<<<local>>>
P Environment temp=30;28;35|humidity=33;40:60;35:70;0;100
F-:
The output will be:
C+:
Environment CRIT - temp 30.0 > 28.0(!), humidity 33.0 < 35.0(!!)
C-:
---
.werks/17 | 51 +++++++++++++++++++++++++++++++++++++
ChangeLog | 1 +
checkman/local | 2 +-
checks/local | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 124 insertions(+), 6 deletions(-)
diff --git a/.werks/17 b/.werks/17
new file mode 100644
index 0000000..9be5396
--- /dev/null
+++ b/.werks/17
@@ -0,0 +1,51 @@
+Title: local: New state type P for state computation based on perfdata
+Level: 1
+Component: checks
+Version: 1.2.3i7
+Date: 1386165155
+Class: feature
+
+The section <tt><<<local>>></tt>
now allows a new state
+marker <tt>P</tt> (next to <tt>0</tt>, <tt>1</tt>,
<tt>2</tt> and <tt>3</tt>).
+When setting this marker, the check plugin computes the state according to the
+levels contained in the performance data. Take the following example:
+
+F+:
+<<<local>>>
+P Environment temp=30;28;35|humidity=33;40:60;35:70;0;100 This is a text
+F-:
+
+The check will first check the variable <tt>temp</tt>. It's current
value
+is <tt>30</tt>. The levels are at <tt>28</tt> and
<tt>35</tt> for warning and
+critical, resp. Because 30 is greater then 28 this will trigger a warning.
+
+The second performance value <tt>humidity</tt> has both lower and upper
+levels for warning and critical - separated by a colon. The
+current value is 33, which is lower than the lower critical level
+of <tt>35</tt>. This will make this variable und thus the total check
critical.
+
+H2:Notes
+
+<ul>
+<li>It is allowed to use fractional values like
<tt>35.12</tt>.</li>
+<li>If the current value exactly matches a level, the <i>better</i>
state is being used. This
+is not consistent with the usual levels in Check_MK checks, but is neccessary if you
want
+to have just one single value to be OK.</li>
+<li>When using <tt>P</tt> then the current values of all variables are
appended to the plugin output.
+If you want you can omit the your additional text at all in that case.</li>
+<li>When you use <tt>P</tt> and do not supply performance data or do
not supply levels, the
+status will always be <b>OK</b>.</li>
+</ul>
+
+Example for a <tt>local</tt> line without a text:
+
+F+:
+<<<local>>>
+P Environment temp=30;28;35|humidity=33;40:60;35:70;0;100
+F-:
+
+The output will be:
+
+C+:
+Environment CRIT - temp 30.0 > 28.0(!), humidity 33.0 < 35.0(!!)
+C-:
diff --git a/ChangeLog b/ChangeLog
index bc9aa4b..69704a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -39,6 +39,7 @@
* 0013 Solaris Agent: implement cached async plugins and local checks...
* 0238 vsphere monitoring: new option to skip placeholder vms in agent output...
* 0016 Linux+Windows agent: allow spooling plugin outputs via files...
+ * 0017 local: New state type P for state computation based on perfdata...
* 0024 FIX: cisco_wlc: removed check configuration parameter ap_model...
* 0003 FIX: ps: Remove exceeding [ and ] in service description when using process
inventory...
* 0037 FIX: checkman browser (cmk -m) was not working properly in network subtree...
diff --git a/checkman/local b/checkman/local
index 2a57a7b..4c0c64d 100644
--- a/checkman/local
+++ b/checkman/local
@@ -1,4 +1,4 @@
-title: Integrate custom checks
+title: Integrate custom checks via arbitrary scripts on the agent
agents: linux, windows, aix, solaris, freebsd, netbsd, openbsd
catalog: generic
license: GPL
diff --git a/checks/local b/checks/local
index 2007fe2..605bd9a 100644
--- a/checks/local
+++ b/checks/local
@@ -24,22 +24,82 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+# Example output from agent:
+# 0 Service_FOO V=1 This Check is OK
+# 1 Bar_Service - This is WARNING and has no performance data
+# 2 NotGood V=120;50;100;0;1000 A critical check
+# P Some_other_Service value1=10;30;50|value2=20;10:20;0:50;0;100 Result is computed from
two values
+# P This_is_OK foo=18;20;50
+# P Some_yet_other_Service temp=40;30;50|humidity=28;50:100;0:50;0;100
+# P Has-no-var - This has no variable
+# P No-Text hirn=-8;-20
+
+
+# Compute state according to warn/crit levels contained in the
+# performance data.
+def local_compute_state(perfdata):
+ texts = []
+
+ def outof_levels(value, levels):
+ if levels == None:
+ return
+
+ if ':' in levels:
+ lower, upper = map(float, levels.split(':'))
+ else:
+ lower = None
+ upper = float(levels)
+ if value > upper:
+ return " %s > %s" % (value, upper)
+ elif lower != None and value < lower:
+ return " %s < %s" % (value, lower)
+
+ worst = 0
+ for entry in perfdata:
+ if len(entry) < 3:
+ continue # No levels attached
+ varname = entry[0]
+ value = float(entry[1])
+ warn = entry[2]
+ if len(entry) >= 4:
+ crit = entry[3]
+ else:
+ crit = None
+
+ text = outof_levels(value, crit)
+ if text:
+ worst = 2
+ text = "%s%s(!!)" % (varname, text)
+ texts.append(text)
+
+ else:
+ text = outof_levels(value, warn)
+ if text:
+ worst = max(worst, 1)
+ text = "%s%s(!)" % (varname, text)
+ texts.append(text)
+
+ else:
+ texts.append("%s is %s(.)" % (varname, value))
+
+ return worst, texts
def inventory_local(info):
inventory = []
# Ignore invalid lines, tolerate bugs in local checks
- # of unexperianced users
+ # of unexperianced users. Lines with P do not need to
+ # supply a text
for line in info:
- if len(line) >= 4:
+ if len(line) >= 4 or len(line) == 3 and line[0] == 'P':
inventory.append( (line[1], None) )
return inventory
def check_local(item, params, info):
for line in info:
# Ignore invalid lines, tolerate bugs in local checks
- # of unexperianced users
+ # of unexperienced users
if len(line) >= 2 and line[1] == item:
- state = int(line[0])
+ statechar = line[0]
perftxt = line[2]
output = " ".join(line[3:])
perfdata = []
@@ -49,11 +109,17 @@ def check_local(item, params, info):
varname, valuetxt = entry.split('=')
values = valuetxt.split(';')
perfdata.append(tuple( [varname] + values ))
+ if statechar == 'P':
+ state, texts = local_compute_state(perfdata)
+ if output:
+ texts = [output] + texts
+ output = ", ".join(texts)
+ else:
+ state = int(statechar)
return (state, output, perfdata)
return (3, "Check output not found in local checks")
-
check_info["local"] = {
'check_function': check_local,
'inventory_function': inventory_local,