[Nagiosplug-devel] improved check_oracle
Philip Brown
phil at bolthole.com
Mon Sep 9 16:23:02 CEST 2002
Improved version of check_oracle attached.
Allows actually logging in as a user, and doing
select * from dual;
which is a lot more definitive in saying "oracle is working", than
either checking the listener, or seeing if the oracle process is running.
new added syntax:
check_oracle --oralogin user/pw at ora.name
-------------- next part --------------
#! /bin/sh
#
# made by latigid010 at yahoo.com
# 01/06/2000
#
# This Nagios plugin was created to check remote or local TNS
# status and check local Database status.
#
# Updated by Philip Brown to allow doing a login with
# specified oracle loginstring, and do "select * from dual;"
#
# Sample configuration to add to checkcommands.cfg:
# command[check-oracle-tns]=/usr/local/nagios/libexec/check_oracle --tns $ARG$
# command[check-oracle-ps]=/usr/local/nagios/libexec/check_oracle --db $ARG$
# command[check-oracle-login]=/usr/local/nagios/libexec/check_oracle --oralogin $ARG$
#
#
# Usage:
# (See print_usage() function)
#
# I have the script checking for the Oracle PMON process and
# the sgadefORACLE_SID.dbf file.
#
#
# If you have any problems check that you have the $ORACLE_HOME
# enviroment variable set.
# The script will adjust its PATH and LD_LIBRARY_PATH based on that.
# Dont forget about your tnsnames.ora file.
# When checking Local Database status your ORACLE_SID is case sensitive.
#
# You may want to hardcode this here, so that your oracle client
# binaries will work. Otherwise, set in nagios's profile or something.
#
#export ORACLE_HOME PATH LD_LIBRARY_PATH
#ORACLE_HOME=/opt/oracle/product/8.1.7.3
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.2 $' | sed -e 's/[^0-9.]//g'`
. $PROGPATH/utils.sh
print_usage() {
echo "Usage:"
echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
echo " $PROGNAME --db <ORACLE_SID>"
echo " $PROGNAME --oranames <Hostname>"
echo " $PROGNAME --oralogin <connect/pw at string>"
echo " $PROGNAME --help"
echo " $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "Check remote or local TNS status and check local Database status"
echo ""
echo "--tns=SID/IP Address"
echo " Check remote TNS server"
echo "--db=SID"
echo " Check local database (search /bin/ps for PMON process and check"
echo " filesystem for sgadefORACLE_SID.dbf"
echo "--oranames=Hostname"
echo " Check remote Oracle Names server"
echo "--oralogin=user/pw at oracle_db.name"
echo " Try basic user login to oracle"
echo "--help"
echo " Print this help screen"
echo "--version"
echo " Print version and license information"
echo ""
echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
echo "tnsnames.ora file is locatable and is properly configured."
echo ""
echo "When checking Local Database status your ORACLE_SID is case sensitive."
echo ""
support
}
check_login() {
sqlplus $1 << EOF
select * from dual;
quit;
EOF
}
case "$1" in
1)
cmd='--tns'
;;
2)
cmd='--db'
;;
3)
cmd='--oralogin'
;;
*)
cmd="$1"
;;
esac
# Hunt down a reasonable ORACLE_HOME
if [ -z "$ORACLE_HOME" ] ; then
# Adjust to taste
for oratab in /var/opt/oracle/oratab /etc/oratab
do
[ ! -f $oratab ] && continue
ORACLE_HOME=`IFS=:
while read SID ORACLE_HOME junk;
do
if [ "$SID" = "$2" ] ; then
echo $ORACLE_HOME;
exit;
fi;
done < $oratab`
[ -n "$ORACLE_HOME" ] && break
done
fi
# Last resort
[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle
if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
echo "Cannot determine ORACLE_HOME for sid $2"
exit $STATE_UNKNOWN
fi
PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export ORACLE_HOME PATH LD_LIBRARY_PATH
case "$cmd" in
--tns)
tnschk=` tnsping $2`
tnschk2=` echo $tnschk | grep -c OK`
if [ ${tnschk2} -eq 1 ] ; then
tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
echo "OK - reply time ${tnschk3} from $2"
exit $STATE_OK
else
echo "No TNS Listener on $2"
exit $STATE_CRITICAL
fi
;;
--oralogin)
# we COULD do a somewhat more stringent check of output, but I think
# this should be "good enough" ?
check_login $2 | grep ERROR >/dev/null
if [ $? -eq 0 ] ; then
# we saw "ERROR"
echo "Error doing select from dual. Check login to database manually"
exit $STATE_CRITICAL
fi
echo "OK - select statement succeeded"
exit $STATE_OK
EOF
tnschk=` tnsping $2`
tnschk2=` echo $tnschk | grep -c OK`
if [ ${tnschk2} -eq 1 ] ; then
tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
echo "OK - reply time ${tnschk3} from $2"
exit $STATE_OK
else
echo "No TNS Listener on $2"
exit $STATE_CRITICAL
fi
;;
--oranames)
namesctl status $2 | awk '
/Server has been running for:/ {
msg = "OK: Up"
for (i = 6; i <= NF; i++) {
msg = msg " " $i
}
status = '$STATE_OK'
}
/error/ {
msg = "CRITICAL: " $0
status = '$STATE_CRITICAL'
}
END {
print msg
exit status
}'
;;
--db)
pmonchk=`ps -ef | grep -v grep | grep ${2} | grep -c pmon`
if [ ${pmonchk} -ge 1 ] ; then
echo "${2} OK - ${pmonchk} PMON process(es) running"
exit $STATE_OK
#if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
#if [ ${pmonchk} -eq 1 ] ; then
#utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
#echo "${2} OK - running since ${utime}"
#exit $STATE_OK
#fi
else
echo "${2} Database is DOWN"
exit $STATE_CRITICAL
fi
;;
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PLUGIN $REVISION
exit $STATE_OK
;;
-V)
print_revision $PLUGIN $REVISION
exit $STATE_OK
;;
*)
print_usage
exit $STATE_UNKNOWN
esac
More information about the Devel
mailing list