Skip to content

Instantly share code, notes, and snippets.

@gardart
Created January 24, 2017 11:22
Show Gist options
  • Save gardart/e880d5fee8e0adc111a3e6d9ca74b76e to your computer and use it in GitHub Desktop.
Save gardart/e880d5fee8e0adc111a3e6d9ca74b76e to your computer and use it in GitHub Desktop.
nagios check sql query plugin using sqlplus
#!/bin/bash
PROGNAME=`/bin/basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
. $PROGPATH/utils.sh
#export PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins:/usr/lib/oracle/11.2/client64/bin
#export ORACLE_HOME=/usr/lib/oracle/11.2
#export TNS_ADMIN=/etc
#export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
USER=$1
PASS=$2
ORATNS=$3
WARNING=$4
CRITICAL=$5
OUTPUT=$(sqlplus -s $USER/$PASS@$ORATNS <<END
set pagesize 0
set feedback off
set verify off
set heading off
set echo off;
select count(*) from testtable;
END
)
# Clean up output - remove leading and trailing whitespaces
COUNT=${OUTPUT//[[:space:]]/}
if (( "$COUNT" >= $CRITICAL )) ; then
echo "CRITICAL - Value is $COUNT"
exit $STATE_CRITICAL
elif (( "$COUNT" >= $WARNING )) ; then
echo "WARNING - Value is $COUNT"
exit $STATE_WARNING
elif (( "$COUNT" == 0 )) ; then
echo "OK! Current Value: $COUNT"
exit $STATE_OK
else
echo "UNKNOWN! Company Group Check (QV). Current Value: $COUNT"
exit $STATE_UNKNOWN
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment