[Nagiosplug-devel] new plugin for oracle

Gilles THOMAS tom at persofrance.dyndns.org
Fri Feb 20 11:40:03 CET 2004


Hi

I make this plugin for nagios, the plugin enable to monitor an oracle
database.
indeed to be sure oracle allow a connection and so running nice, the plugin
connect to oracle and do à request.

it compare the string that must match the globale database name and return
the Uptime.

the command arguments are : -s SID -u user -p passwd -c global_database_name

here the script :

----------------------- cut here -------------------------------------------

#!/bin/sh
#
# This script is intended to be executed by Nagios
# Before use it and install in Nagios, you must configure the $DIR variable
# at line 18
#
# The Oracle client must be install on the nagios/station...
# And the system must be configured with :
# ORACLE_HOME and ORACLE_SID
# You can test with ' set | grep ORACLE_SID ' and ' set | grep ORACLE_HOME '
#
# Any hints on errors or bugs aswell as recommendations for additions are
always welcome
#
#
# Tom tom at persofrance.dyndns.org
# =======================================================( Header /
Syntax )===

DIR=/usr/local/nagios/libexec

if [ -z "$1" ]; then
  SCRIPT=${0##*/}
  echo Bad arguments...
  echo
============================================================================
  echo "${SCRIPT} v 0.1 beta       (c) 2004 by tom
(tom at persofrance.dyndns.org)"


echo -----------------------------------------------------------------------
-----
  echo This script is intended to be executed by Nagios...


echo -----------------------------------------------------------------------
-----
  echo "Syntax: ${SCRIPT} <ORACLE_SID> <Options>"
  echo "  Options:"
  echo "     -s <ORACLE_SID/Connection String for Target DB>"
  echo "     -p <Password>"
  echo "     -u <username>"
  echo "     -c <chaine>"
  echo "  Example: "
  echo "   ${SCRIPT} -s SID -u user -p passwd -c global_database_name"
  echo
============================================================================
  echo
  exit 3
fi

# ------------------------------------------( process command line
options )---
while [ "$1" != "" ] ; do
  case "$1" in
    -s) shift; ORACLE_CONNECT=$1;;
    -u) shift; username=$1;;
    -p) shift; passwd=$1;;
    -c) shift; chaine=$1;;
  esac
  shift
done

if [ -z "$ORACLE_CONNECT" ]; then
  ORACLE_CONNECT=$ORACLE_SID
fi
if [ -n "$username" ]; then
  user=$username
fi
if [ -n "$passwd" ]; then
  password=$passwd
fi
if [ -n "$chaine" ]; then
  cherche_chaine=$chaine
fi

SQLSET=$DIR/orasnap_sqlset_$ORACLE_SID.$$
TMPOUT=$DIR/orasnap_tmpout_$ORACLE_SID.$$

cd $DIR

echo | pwd > $DIR/log.log
echo | whoami >> $DIR/log.log

ORACLE__HOME=`set |grep ORACLE_HOME | awk -F "=" '{print $2}'`
echo $ORACLE__HOME >> $DIR/log.log
export ORACLE_HOME=$ORACLE__HOME
# ------------------------------------------( Start the Run of the
Scripts )---
cat >$SQLSET<<ENDSQL
CONNECT $user/$password@$ORACLE_CONNECT as sysdba
Set TERMOUT OFF
Set SCAN OFF
Set SERVEROUTPUT On Size 1000000
Set LINESIZE 300
Set TRIMSPOOL On
Set FEEDBACK OFF
Set Echo Off
Set PAGESIZE 0
SPOOL $TMPOUT
select NAME,STARTUP_TIME,
trunc(SYSDATE-(STARTUP_TIME) ) || ' day(s), ' ||
         trunc(24*((SYSDATE-STARTUP_TIME) - trunc(SYSDATE-STARTUP_TIME)))||'
hour(s), ' ||
         mod(trunc(1440*((SYSDATE-STARTUP_TIME) -
trunc(SYSDATE-STARTUP_TIME))), 60) ||' minute(s), ' ||
         mod(trunc(86400*((SYSDATE-STARTUP_TIME) -
trunc(SYSDATE-STARTUP_TIME))), 60) ||' seconds'
from sys.v_\$database, sys.v_\$instance;
ENDSQL
cat $SQLSET | $ORACLE__HOME/bin/sqlplus -s /NOLOG >>$DIR/log.log
# You can see log.log" to debug....
cherch=`cat $TMPOUT | awk '{print $1}'`
char=`cat $TMPOUT`
if [ "$cherch" = "$cherche_chaine" ]; then
  echo OK - Connected, result of the query : $char
  rm -f $SQLSET $TMPOUT
  exit 0
else
  err=`cat $TMPOUT | awk '{print $1}'`
  if [ "$err" = SP2-0640: ]; then
    echo CRITICAL - Not connected !
    rm -f $SQLSET $TMPOUT
    exit 2
  else
    echo Warning - Bad result  : $cherch ... You try to search for
$cherche_chaine
    rm -f $SQLSET $TMPOUT
    exit 1
  fi
fi
exit 3

----------------------- cut here -------------------------------------------

you can see it in action at
http://persofrance.dyndns.org/modules.php?name=NukeFrame&page=http://persofrance.dyndns.org/nagios/cgi-bin/status.cgi?host=all&style=hostdetail
guest/guest

tom





More information about the Devel mailing list