#!/bin/sh # # Paolo Seghetti # spegghy69@yahoo.it # 01/06/2006 # # This Nagios plugin was created to check Oracle standby status # Pass the user/pass and sid of active and standby db # to check the differences # # The plugin execute a query on the v$log_history table of the DBs # and compare two values. # The predefined range of differences are: # 0-4 ok # 5-10 warning # 10- critical PROGNAME=`basename $0` PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` REVISION=`echo '$Revision: 1.0 $' | sed -e 's/[^0-9.]//g'` export LD_LIBRARY_PATH=/home/instantclient export PATH=/home/instantclient:${PATH} export TNS_ADMIN=/home/instantclient warnlev=4 critlev=10 # # END OF CUSTOMIZATION # . $PROGPATH/utils.sh print_usage() { echo "Usage:" echo " $PROGNAME --oa " echo " $PROGNAME --os " echo " $PROGNAME --warn " echo " $PROGNAME --crit " echo " $PROGNAME --help" echo " $PROGNAME --version" } print_help() { print_revision $PROGNAME $REVISION echo "" print_usage echo "" echo "Check Oracle Standby DB status" echo "" echo "--oa" echo " The login data of Oracle active DB" echo "--os" echo " The login data of Oracle standby DB" echo "--warn" echo " The warning level" echo "--crit" echo " The critical level" echo "--help" echo " Print this help screen" echo "--version" echo " Print version and license information" echo "" support } oa=0 os=0 while test -n "$1"; do case "$1" in --help) print_help exit $STATE_OK ;; -h) print_help exit $STATE_OK ;; --version) print_revision $PROGNAME $VERSION exit $STATE_OK ;; -V) print_revision $PROGNAME $VERSION exit $STATE_OK ;; --oa) oa=1 ua=$2 pa=$3 sa=$4 shift shift shift ;; --os) os=1 us=$2 ps=$3 ss=$4 shift shift shift ;; --warn) warnlev=$2 shift ;; --crit) critlev=$2 shift ;; *) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN ;; esac shift done if [ ${oa} -eq 0 -a ${os} -eq 0 ] ; then print_help exit $STATE_UNKNOWN fi if [ ${oa} -eq 0 ] ; then echo "UNKNOWN - Active DB not set" exit $STATE_UNKNOWN fi if [ ${os} -eq 0 ] ; then echo "UNKNOWN - Standby DB not set" exit $STATE_UNKNOWN fi if [ ${critlev} -lt ${warnlev} ] ; then echo "UNKNOWN - Warning level is more then Crit" exit $STATE_UNKNOWN fi seq1=`/home/instantclient/sqlplus -s ${ua}/${pa}@${sa} as sysdba < <${seq2}>" exit $STATE_CRITICAL fi expr $seq1 - $seq2 > /dev/null 2>&1 if [ $? = 2 ] ; then echo "CRITICAL ${sa} Script error - b - <${seq1}> <${seq2}>" exit $STATE_CRITICAL fi difference=`expr $seq1 - $seq2` if [ -z $difference ] ; then echo "CRITICAL ${sa} Script error -c - <${difference}>" exit $STATE_CRITICAL fi if [ $difference -gt $critlev ] ; then echo "CRITICAL ${sa} Standby with $difference difference" exit $STATE_CRITICAL fi if [ $difference -gt $warnlev ] ; then echo "WARNING ${sa} Standby with $difference difference" exit $STATE_WARNING fi echo "OK ${sa} Standby with $difference difference" exit $STATE_OK