Module: check_mk
Branch: master
Commit: dd44b1bd3d6cb8323ebc1c222b2c67a80603281b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dd44b1bd3d6cb8…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Mon Oct 14 16:16:44 2013 +0200
check_sql: Database port can now be explicitly set; Wato fields for Username and Password
added
---
ChangeLog | 1 +
checks/check_sql | 7 ++++++-
doc/treasures/active_checks/check_sql | 26 ++++++++++++++++++--------
web/plugins/wato/active_checks.py | 14 +++++++++++++-
4 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1ebc0c5..c3b6959 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@
* ucd_cpu_load: support predictive levels
* hpux_cpu, blade_bx_load: support predictive levels, add perf-o-meter,
make WATO-configable
+ * check_sql: Database port can now be explicitly set
WATO:
* You can now have site-specific global settings when using
diff --git a/checks/check_sql b/checks/check_sql
index 9018cf3..54a1bca 100644
--- a/checks/check_sql
+++ b/checks/check_sql
@@ -25,9 +25,14 @@
# Boston, MA 02110-1301 USA.
def check_sql_arguments(params):
- args = " -H '$HOSTNAME$'"
+ args = " --hostname '$HOSTNAME$'"
args += " --dbms %s" % quote_shell_string(params["dbms"])
args += " --name %s" % quote_shell_string(params["name"])
+ args += " --user '%s'" % params["user"]
+ args += " --password '%s'" % params["password"]
+
+ if "port" in params:
+ args += " --port %s" % params["port"]
if "levels" in params:
upper = params["levels"]
diff --git a/doc/treasures/active_checks/check_sql
b/doc/treasures/active_checks/check_sql
index 4b9954e..3e90ba5 100755
--- a/doc/treasures/active_checks/check_sql
+++ b/doc/treasures/active_checks/check_sql
@@ -46,6 +46,7 @@ OPTIONS:
Default is 'postgres', other valid values are
'mysql' and 'oracle'
-H HOST, --hostname HOST Hostname or IP-Address where the database lives. Default
is '127.0.0.1'
+ -P PORT, --port PORT Port used to connect to the database
-n NAME, --name NAME Name of the database on the DBMS
-w RANGE, --warning RANGE lower and upper level for the warning state, separated by
a colon
-c RANGE, --critical RANGE lower and upper level for the critical state, separated
by a colon
@@ -65,10 +66,10 @@ def saverfloat(f):
#
# defining and collection input parameters
#
-short_options = 'hu:p:d:n:H:w:c:v'
+short_options = 'hu:p:d:n:H:P:w:c:v'
long_options = [
'help', 'user=', 'password=', 'dbms=',
'name=', 'warning=', 'critical=', 'hostname=',
- 'debug', 'verbose'
+ 'port=', 'debug', 'verbose'
]
try:
@@ -85,6 +86,7 @@ opt_name = None
opt_user = opt_dbms
opt_password = None
opt_hostname = "127.0.0.1"
+opt_port = None
opt_sql = None
warn = [ None, None ]
crit = [ None, None ]
@@ -105,6 +107,8 @@ try:
opt_password = a
elif o in [ '-H', '--hostname' ]:
opt_hostname = a
+ elif o in [ '-P', '--port' ]:
+ opt_port = int(a)
elif o in [ '-w', '--warning' ]:
warn = map(saverfloat,a.split(":",2))
elif o in [ '-c', '--critical' ]:
@@ -134,20 +138,26 @@ try:
if opt_dbms == "postgres":
import psycopg2 # postgres driver
db = psycopg2
- db_connection = db.connect(host=opt_hostname, database=opt_name, \
- user=opt_user, password=opt_password )
+ if opt_port == None:
+ opt_port=5432
+ db_connection = db.connect(host=opt_hostname, port=opt_port, \
+ database=opt_name, user=opt_user, password=opt_password )
elif opt_dbms == "mysql":
import MySQLdb # mysql driver
db = MySQLdb
- db_connection = db.connect(host=opt_hostname, db=opt_name, \
- user=opt_user, passwd=opt_password )
+ if opt_port == None:
+ opt_port=3306
+ db_connection = db.connect(host=opt_hostname, port=opt_port, \
+ db=opt_name, user=opt_user, passwd=opt_password )
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
+ if opt_port == None:
+ opt_port=1521
+ cstring =
opt_user+"/"+opt_password+"@"+opt_hostname+":"+opt_port+"/"+opt_name
db_connection = db.connect(cstring)
else:
print "UNKNOWN - dbms not found"
@@ -216,7 +226,7 @@ try:
state = 2
else:
if number in [ 0 ,1 ,2 ,3 ]:
- state = number
+ state = int(number)
else:
print "UNKNOWN - <%s> is not a state, and no levels given" %
str(number)
sys.exit(3)
diff --git a/web/plugins/wato/active_checks.py b/web/plugins/wato/active_checks.py
index a622d4f..c25ccc7 100644
--- a/web/plugins/wato/active_checks.py
+++ b/web/plugins/wato/active_checks.py
@@ -160,7 +160,7 @@ register_rule(group,
"number, a text, and performance data. Upper or lower levels may be
defined "
"here. If they are not defined the number is taken as the state of
the check."
"This check uses the active check
<tt>check_sql</tt>."),
- optional_keys = [ "levels", "levels_low",
"perfdata" ],
+ optional_keys = [ "levels", "levels_low",
"perfdata", "port" ],
elements = [
( "description",
TextUnicode(title = _("Service Description"),
@@ -178,6 +178,10 @@ register_rule(group,
default_value = "mysql",
),
),
+ ( "port",
+ Integer(title = _("Database Port"), allow_empty = True,
+ help = _('The port the DBMS listens to'))
+ ),
( "name",
TextAscii(title = _("Database Name"), allow_empty = False,
help = _('The name of the database on the DBMS'))
@@ -186,6 +190,14 @@ register_rule(group,
TextAscii(title = _("SQL-Statement"), allow_empty = False,
help = _('The SQL-Statement which is sent to the DBMS'))
),
+ ( "user",
+ TextAscii(title = _("Database User"), allow_empty = False,
+ help = _('The username used to connect to the database'))
+ ),
+ ( "password",
+ Password(title = _("Database Password"), allow_empty = False,
+ help = _('The password used to connect to the database'))
+ ),
( "levels",
Tuple(
title = _("Upper levels for first output item"),