Module: check_mk
Branch: master
Commit: 7b469142248e95111b762f41665b74d8df28b910
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7b469142248e95…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Sep 30 16:06:13 2013 +0200
Began WATOization of check_sql
---
checks/check_sql | 57 ++++++++++++++++++++++++
doc/treasures/active_checks/check_sql | 22 +++++-----
web/plugins/wato/active_checks.py | 77 ++++++++++++++++++++-------------
3 files changed, 115 insertions(+), 41 deletions(-)
diff --git a/checks/check_sql b/checks/check_sql
new file mode 100644
index 0000000..d391c78
--- /dev/null
+++ b/checks/check_sql
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+def check_sql_arguments(params):
+ args = " -H '$HOSTNAME$'"
+ args += " --dbms %s" % quote_shell_string(params["dbms"])
+ args += " --name %s" % quote_shell_string(params["name"])
+
+ if "levels" in params:
+ upper = params["levels"]
+ else:
+ upper = "", ""
+
+ if "levels_low" in params:
+ lower = params["levels_low"]
+ else:
+ lower = "", ""
+
+ 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])
+
+ args += " %s" % quote_shell_string(params["sql"])
+
+ return args
+
+
+active_check_info['sql'] = {
+ "command_line" : '$USER1$/check_sql $ARG1$',
+ "argument_function" : check_sql_arguments,
+ "service_description" : lambda args: args["description"],
+ "has_perfdata" : True,
+}
+
diff --git a/doc/treasures/active_checks/check_sql
b/doc/treasures/active_checks/check_sql
index 47a7212..4b9954e 100755
--- a/doc/treasures/active_checks/check_sql
+++ b/doc/treasures/active_checks/check_sql
@@ -30,8 +30,8 @@ import sys, getopt
def usage():
sys.stderr.write("""Check_MK SQL Test
-USAGE: check-sql [OPTIONS] SQL-Statement
- check-sql -h
+USAGE: check_sql [OPTIONS] SQL-Statement
+ check_sql -h
ARGUMENTS:
SQL-Statement Valid SQL-Statement for the selected database
@@ -40,17 +40,17 @@ ARGUMENTS:
OPTIONS:
-h, --help Show this help message and exit
- -u USER, --user USER Username for database access
- -p PASS, --password PASS Password for database access
- -d DBMS, --dbms DBMS Name of the database management system.
+ -u USER, --user USER Username for database access
+ -p PASS, --password PASS Password for database access
+ -d DBMS, --dbms DBMS Name of the database management system.
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'
- -n NAME, --name NAME Name of the database on the DBMS
- -w RANGE, --warning RANGE lower and upper level for the warning state
- -c RANGE, --critical RANGE lower and upper level for the critical state
+ -H HOST, --hostname HOST Hostname or IP-Address where the database lives. Default
is '127.0.0.1'
+ -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
--debug Debug mode: let Python exceptions come through
- -v, --verbose Verbose mode: print sql statement and levels
+ -v, --verbose Verbose mode: print SQL statement and levels
""")
@@ -116,7 +116,7 @@ try:
if args:
opt_sql = ' '.join(map(str,args))
else:
- print "UNKNOWN - no sql statement given"
+ print "UNKNOWN - no SQL statement given"
sys.exit(3)
except Exception, e:
diff --git a/web/plugins/wato/active_checks.py b/web/plugins/wato/active_checks.py
index 1ca1dae..1ee64a0 100644
--- a/web/plugins/wato/active_checks.py
+++ b/web/plugins/wato/active_checks.py
@@ -89,41 +89,58 @@ register_rule(group,
register_rule(group,
"active_checks:sql",
- Tuple(
- title = _("Check SQL DB"),
- help = _("This check connects to the specified database, sends a custom
sql-statement "
+ Dictionary(
+ title = _("Check SQL Database"),
+ help = _("This check connects to the specified database, sends a custom
SQL-statement "
"and checks that the result has a defined format containing three
columns, a "
"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" ],
elements = [
- TextAscii(title = _("Hostname"), allow_empty = False,
- help = _('The hostname or address you want to query')),
- TextAscii(title = _("DBMS"), allow_empty = False,
- help = _('The database management system you want to
query')),
- TextAscii(title = _("DB-Name"), allow_empty = False,
- help = _('The name of the database on the DBMS')),
- TextAscii(title = _("SQL-Statement"), allow_empty = False,
- help = _('The SQL-Statement which is sent to the DBMS')),
- Dictionary(
- title = _("Optional parameters"),
- elements = [
- ( "upperlevels",
- Tuple(
- title = _("Upper levels for first output item"),
- elements = [
- Float( title = _("Warning if above")),
- Float( title = _("Critical if above"))
- ])
- ),
- ( "lowerlevels",
- Tuple(
- title = _("Lower levels for first output item"),
- elements = [
- Float( title = _("Warning if below")),
- Float( title = _("Critical if below"))
- ])),
- ]),
+ ( "description",
+ TextUnicode(title = _("Service Description"),
+ help = _("The name of this active service to be displayed."),
+ allow_empty = False,
+ )),
+ ( "dbms",
+ DropdownChoice(
+ title = _("Type of Database"),
+ choices = [
+ ( "mysql", _("MySQL") ),
+ ( "postgres", _("PostgreSQL") ),
+ ( "oracle", _("Oracle") ),
+ ],
+ default_value = "mysql",
+ ),
+ ),
+ ( "name",
+ TextAscii(title = _("Database Name"), allow_empty = False,
+ help = _('The name of the database on the DBMS'))
+ ),
+ ( "sql",
+ TextAscii(title = _("SQL-Statement"), allow_empty = False,
+ help = _('The SQL-Statement which is sent to the DBMS'))
+ ),
+ ( "levels",
+ Tuple(
+ title = _("Upper levels for first output item"),
+ elements = [
+ Float( title = _("Warning if above")),
+ Float( title = _("Critical if above"))
+ ])
+ ),
+ ( "levels_low",
+ Tuple(
+ title = _("Lower levels for first output item"),
+ elements = [
+ Float( title = _("Warning if below")),
+ Float( title = _("Critical if below"))
+ ])
+ ),
+ ( "perfdata",
+ FixedValue(True, totext=_("Store output value into RRD
database"), title = _("Performance Data"), ),
+ )
]
),
match = 'all')