Module: check_mk
Branch: master
Commit: 8f258a6bea1d496f4640359fe6a42bf36f1b3371
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8f258a6bea1d49…
Author: Götz Golla <gg(a)mathias-kettner.de>
Date: Mon Sep 16 14:05:04 2013 +0200
man page for new sql check
---
checkman/check_sql | 30 ++++++++++++++++++++++++++++++
doc/treasures/active_checks/check_sql | 21 ++++++++++++++-------
2 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/checkman/check_sql b/checkman/check_sql
new file mode 100644
index 0000000..e57b67d
--- /dev/null
+++ b/checkman/check_sql
@@ -0,0 +1,30 @@
+title: SQL database request check
+agents: active
+catalog: agentless
+license: GPL
+distribution: check_mk
+description:
+ This is an active check that connects to a database server, sends an sql
+ statement to that server, and checks for the following result:
+
+ The query must return two columns, a number and a text, plus
+ optional performance data.
+ If upper and lower levels are given, the number is being checked
+ against these levels and the according state is being computed.
+ Otherwise the number ist treated as a Nagios state (0,1,2,3).
+ State, text and the optional performance data are being returned
+
+ The check works with mysql, postgres and oracle databases using the
+ python drivers MySQLdb, psycopg2 and cx_Oracle. For cx_oracle the
+ oracle-instantclient needs to be installed as well, and the
+ LD_LIBRARY_PATH needs to be modified to point to the libclntsh.so of
+ that package.
+
+ This check can be configured by Wato.
+
+perfdata:
+ Optionally one value: the third field of the database response..
+
+installation:
+
+
diff --git a/doc/treasures/active_checks/check_sql
b/doc/treasures/active_checks/check_sql
index e97848b..47a7212 100755
--- a/doc/treasures/active_checks/check_sql
+++ b/doc/treasures/active_checks/check_sql
@@ -143,12 +143,12 @@ try:
db_connection = db.connect(host=opt_hostname, db=opt_name, \
user=opt_user, passwd=opt_password )
- elif opt_dbms == "odbc":
- import pyodbc # odbc driver
- db = odbc
- db_connection = db.connect(DRIVER=opt_dbms, SERVER=opt_hostname,
DATABASE=opt_name, \
- UID=opt_user, PWD=opt_password, CHARSET='UTF8' )
-
+ elif opt_dbms == "oracle":
+ sys.path.append('/usr/lib/python2.7/site-packages')
+ import cx_Oracle
+ db = cx_Oracle
+ cstring =
opt_user+"/"+opt_password+"@"+opt_hostname+"/"+opt_name
+ db_connection = db.connect(cstring)
else:
print "UNKNOWN - dbms not found"
sys.exit(3)
@@ -199,6 +199,13 @@ try:
row = rows[0]
number = float(row[0])
text = str(row[1])
+ try:
+ perf = row[2]
+ except IndexError:
+ if opt_debug:
+ raise
+ perf = "" # no perf data
+
state = 0
if warn != [ None, None] or crit != [ None, None ]:
if (warn[0] != None and warn[0] > number) or \
@@ -221,6 +228,6 @@ except Exception, e:
sys.exit(3)
result = ["OK", "WARN", "CRIT", "UNKNOWN"
][state]
-print "%s - %s %s" % (result, number, text)
+print "%s - %s %s %s" % (result, number, text, perf)
sys.exit(state)