Module: check_mk
Branch: master
Commit: 9db80eb331300317174fa8b5fb38e083b33d0d0d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9db80eb3313003…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Jan 27 12:44:12 2011 +0100
mk_oracle: new oracle agent plugin and first check
---
ChangeLog | 5 +++-
agents/plugins/mk_oracle | 64 +++++++++++++++++++++++++++++++++++++++++++++
agents/plugins/sqlplus.sh | 22 +++++++++++++++
checkman/oracle_sessions | 42 +++++++++++++++++++++++++++++
checks/oracle_sessions | 52 ++++++++++++++++++++++++++++++++++++
5 files changed, 184 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 73bcea5..e6dd36f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,7 +19,10 @@
* hpux_serviceguard: new check for monitoring HP-UX Serviceguard
* drbd: Fixed var typo which prevented inventory of drbd general check
(Thanks to Andreas Behler)
-
+ * mk_oracle: new agent plugin for monitoring ORACLE (currently only
+ on Linux, but easily portable to other Unices)
+ * oracle_sessions: new check for monitoring the current number of active
+ database sessions.
1.1.9i5:
Multisite:
diff --git a/agents/plugins/mk_oracle b/agents/plugins/mk_oracle
new file mode 100644
index 0000000..3f080b0
--- /dev/null
+++ b/agents/plugins/mk_oracle
@@ -0,0 +1,64 @@
+#!/bin/sh
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2010 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.
+
+# Check_MK agent plugin for monitoring ORACLE databases
+
+# Get list of all running databases
+SIDS=$(UNIX95=true ps ax -o args | sed -n '/^ora_pmon_\([^ ]*\)/s//\1/p')
+if [ -z "$SIDS" ] ; then exit 0 ; fi
+
+# Make an sqlplus query, clean up the result and add an artificial
+# column with the SID at the front of each line. If the query fails,
+# no output at all is made.
+function sqlplus ()
+{
+ OUTPUT=$({ echo 'set pages 0' ; echo 'set lines 8000' ; cat ; } |
$MK_CONFDIR/sqlplus.sh $1) || return 1
+ echo "${OUTPUT}" | sed -e 's/[[:space:]]\+/ /g' -e
'/^[[:space:]]*$/d' -e "s/^/$1 /"
+}
+
+# Sessions
+echo '<<<oracle_sessions>>>'
+for SID in $SIDS
+do
+ echo "select count(*) from v"'$'"session where status =
'ACTIVE';" | sqlplus "$SID"
+done
+
+echo '<<<oracle_logswitches>>>'
+for SID in $SIDS
+do
+ sqlplus "$SID" <<EOF
+select count(*) from v\$loghist where first_time > sysdate - 1/24;
+EOF
+done
+
+# Tablespaces
+echo '<<<oracle_tablespaces>>>'
+for SID in $SIDS
+do
+ sqlplus "$SID" <<EOF
+select f.file_name, f.tablespace_name, f.status, f.AUTOEXTENSIBLE, f.blocks, f.maxblocks,
f.USER_BLOCKS, f.INCREMENT_BY, f.ONLINE_STATUS, t.BLOCK_SIZE, t.status from
dba_data_files f, dba_tablespaces t where f.tablespace_name = t.tablespace_name;
+EOF
+done
+
diff --git a/agents/plugins/sqlplus.sh b/agents/plugins/sqlplus.sh
new file mode 100755
index 0000000..929eab6
--- /dev/null
+++ b/agents/plugins/sqlplus.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# This script is called by the Check_MK ORACLE plugin in order to
+# execute an SQL query.
+
+# It is your task to adapt this script so that the ORACLE environment
+# is setup and the correct user chosen to execute sqlplus.
+
+# The script we get the query on stdin and shall output the
+# result on stdout. Error messages goes to stderr.
+
+ORACLE_SID=$1
+if [ -z "$ORACLE_SID" ] ; then
+ echo "Usage: $0 ORACLE_SID" >&2
+ exit 1
+fi
+
+su - nagios -c "
+ORACLE_SID=$ORACLE_SID
+ORAENV_ASK=NO
+. /usr/local/bin/oraenv
+sqlplus -s /"
diff --git a/checkman/oracle_sessions b/checkman/oracle_sessions
new file mode 100644
index 0000000..5f2571d
--- /dev/null
+++ b/checkman/oracle_sessions
@@ -0,0 +1,42 @@
+title: Check number of active sessions in ORACLE database
+agents: linux
+author: Mathias Kettner <mk(a)mathias-kettner.de>
+license: GPL
+distribution: check_mk
+description:
+ This check monitors the number of active sessions in an
+ ORACLE database. You can set warn/crit levels.
+
+ This check needs the Check_MK {mk_oracle}-plugin installed in
+ the agent. Please refer to the online documentation
+ for how to install that plugin.
+
+item:
+ The SID of the database (as appearing in the process
+ name of the pmon_... process).
+
+examples:
+ # Set global default values to 20 sessions for
+ # warning and 100 sessions for critical
+ oracle_sessions_default_levels = (20, 100)
+
+ # Set higher levels for productive systems
+ # (having the host tag 'prod')
+ check_parameters += [
+ ( (80, 160), [ 'prod' ], ALL_HOSTS, [ "ORA .* sessions" ])
+ ]
+
+perfdata:
+ One value: the current number of active sessions.
+
+inventory:
+ One separate check for each database found running will
+ be created.
+
+[parameters]
+warning(int): The number of active sessions triggering a warning
+critical(int): The number of active sessions making the check critical
+
+[configuration]
+oracle_sessions_default_levels(int, int): Global default levels used for all checks which
have no specific configuration. This is preset to {(50, 100)}.
+
diff --git a/checks/oracle_sessions b/checks/oracle_sessions
new file mode 100644
index 0000000..706f211
--- /dev/null
+++ b/checks/oracle_sessions
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2010 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.
+
+# <<<oracle_sessions>>>
+# pengt 15
+# hirni 22
+
+oracle_sessions_default_levels = (50, 100)
+
+def inventory_oracle_sessions(checkname, info):
+ return [ (line[0], "oracle_sessions_default_levels") for line in info if
len(line) >= 2 ]
+
+def check_oracle_sessions(item, params, info):
+ for line in info:
+ if line[0] == item:
+ warn, crit = params
+ sessions = int(line[1])
+ infotext = " - %d active sessions" % sessions
+ perfdata = [("sessions", sessions, warn, crit)]
+ if sessions >= crit:
+ return (2, "CRIT" + infotext, perfdata)
+ elif sessions >= warn:
+ return (1, "WARN" + infotext, perfdata)
+ else:
+ return (0, "OK" + infotext, perfdata)
+ return (2, "UNKNOWN - Database not existant or not running")
+
+check_info['oracle_sessions'] = (check_oracle_sessions, "ORA %s
Sessions", 1, inventory_oracle_sessions )
+