Module: check_mk
Branch: master
Commit: 095e64321cea2378531190b6161c24c9ab23e5ee
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=095e64321cea23…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Thu Feb 23 10:50:48 2017 +0100
4436 FIX check_sql: fixed thresholds and added missing options
Thresholds are now actually used when the options are activated and the number is added to
the output if Thresholds are set. Additionally the option "Performance Data" is
now actually used. If not activated no performance data will be added, even if it is given
by the result of the SQL statement.
Change-Id: Ifb3780f318f3a2bc81ade56007698bbc7fd43f16
---
.werks/4436 | 13 +++++++++++++
active_checks/check_sql | 28 +++++++++++++++++++---------
checks/check_sql | 3 +++
3 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/.werks/4436 b/.werks/4436
new file mode 100644
index 0000000..c03c4c8
--- /dev/null
+++ b/.werks/4436
@@ -0,0 +1,13 @@
+Title: check_sql: fixed thresholds and added missing options
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1487842750
+Class: fix
+
+Thresholds are now actually used when the options are activated and the
+number is added to the output if Thresholds are set. Additionally the option
+"Performance Data" is now actually used. If not activated no performance
+data will be added, even if it is given by the result of the SQL statement.
diff --git a/active_checks/check_sql b/active_checks/check_sql
old mode 100755
new mode 100644
index 6cac732..18a88b2
--- a/active_checks/check_sql
+++ b/active_checks/check_sql
@@ -64,6 +64,7 @@ OPTIONS:
-c RANGE, --critical RANGE lower and upper level for the critical state, separated
by a colon
-o, --procedure treat the main argument as a procedure instead of an
SQL-Statement
-i CSV, --inputvars CSV values of input variables if required by the procedure;
csv-list
+ -m, --metrics Add performance data to the output
--debug Debug mode: let Python exceptions come through
-v, --verbose Verbose mode: print SQL statement and levels
@@ -83,10 +84,10 @@ def bail_out(exit_code, output):
sys.exit(exit_code)
-short_options = 'hou:i:p:d:n:H:P:w:c:v'
+short_options = 'hou:i:p:d:n:H:P:w:c:v:m'
long_options = [
'help', 'user=', 'password=', 'dbms=',
'name=', 'warning=', 'critical=', 'hostname=',
- 'port=', 'debug', 'verbose', 'procedure',
'inputvars=']
+ 'port=', 'debug', 'verbose', 'procedure',
'inputvars=', 'metrics']
try:
@@ -106,10 +107,12 @@ opt_port = None
opt_sql = None
opt_input = []
opt_procedure = False
+opt_metrics = False
warn = [ None, None ]
crit = [ None, None ]
+
try:
for o,a in opts:
if o in [ '--debug' ]:
@@ -134,6 +137,8 @@ try:
crit = map(saverfloat,a.split(":",2))
elif o in [ '-o', '--procedure' ]:
opt_procedure = True
+ elif o in [ '-m', '--metrics' ]:
+ opt_metrics = True
elif o in [ '-i', '--inputvars' ]:
opt_input = a.split(",")
elif o in [ '-h', '--help' ]:
@@ -268,12 +273,13 @@ try:
else:
text = "%s" % result[1]
- try:
- perf = " | performance_data=%s" % str(result[2])
- except IndexError:
- if opt_debug:
- raise
- perf = ""
+ if opt_metrics:
+ try:
+ perf = " | performance_data=%s" % str(result[2])
+ except IndexError:
+ if opt_debug:
+ raise
+ perf = ""
state = 0
if warn != [ None, None ] or crit != [ None, None ]:
@@ -283,6 +289,7 @@ try:
if (crit[0] != None and crit[0] > number) or \
(crit[1] != None and crit[1] < number):
state = 2
+ text += ": %s" % number
else:
if number in [ 0, 1, 2, 3 ]:
state = int(number)
@@ -295,4 +302,7 @@ except Exception, e:
bail_out(3, "Error while processing result of SQL statement: %s" % e)
-bail_out(state, "%s%s" % (text, perf))
+if opt_metrics:
+ bail_out(state, "%s%s" % (text, perf))
+else:
+ bail_out(state, "%s" % text)
diff --git a/checks/check_sql b/checks/check_sql
index b689050..ac48882 100644
--- a/checks/check_sql
+++ b/checks/check_sql
@@ -65,6 +65,9 @@ def check_sql_arguments(params):
else:
lower = "", ""
+ if "perfdata" in params:
+ args += [ "--metrics" ]
+
if "levels" in params or "levels_low" in params:
args += [ "-w", "%s:%s" % (lower[0], upper[0]) ]
args += [ "-c", "%s:%s" % (lower[1], upper[1]) ]