pkg-monitoring-plugins/plugins-scripts/check_oracle.sh

305 lines
9.1 KiB
Bash
Raw Normal View History

2013-11-26 22:53:19 +00:00
#!/bin/sh
#
# latigid010@yahoo.com
# 01/06/2000
#
2014-07-11 19:01:00 +00:00
# This Monitoring plugin was created to check Oracle status
2013-11-26 22:53:19 +00:00
#
2014-10-15 12:48:52 +00:00
PATH="@TRUSTED_PATH@"
export PATH
2022-10-19 15:24:24 +00:00
PROGNAME=$(basename "$0")
PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,')
REVISION="@NP_VERSION@"
2013-11-26 22:53:19 +00:00
2022-10-19 15:24:24 +00:00
. "$PROGPATH"/utils.sh
2013-11-26 22:53:19 +00:00
print_usage() {
echo "Usage:"
echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
echo " $PROGNAME --db <ORACLE_SID>"
echo " $PROGNAME --login <ORACLE_SID>"
echo " $PROGNAME --connect <ORACLE_SID>"
2013-11-26 22:53:19 +00:00
echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>"
echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
echo " $PROGNAME --oranames <Hostname>"
echo " $PROGNAME --help"
echo " $PROGNAME --version"
}
print_help() {
2022-10-19 15:24:24 +00:00
print_revision "$PROGNAME" "$REVISION"
2013-11-26 22:53:19 +00:00
echo ""
print_usage
echo ""
echo "Check Oracle 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 "--login SID"
echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
echo "--connect SID"
echo " Attempt a login and alert if an ORA- error is returned"
2013-11-26 22:53:19 +00:00
echo "--cache"
echo " Check local database for library and buffer cache hit ratios"
echo " ---> Requires Oracle user/password and SID specified."
echo " ---> Requires select on v_$sysstat and v_$librarycache"
echo "--tablespace"
echo " Check local database for tablespace capacity in ORACLE_SID"
echo " ---> Requires Oracle user/password specified."
echo " ---> Requires select on dba_data_files and dba_free_space"
echo "--oranames Hostname"
echo " Check remote Oracle Names server"
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 ""
echo "If you want to use a default Oracle home, add in your oratab file:"
echo "*:/opt/app/oracle/product/7.3.4:N"
echo ""
support
}
case "$1" in
1)
cmd='--tns'
;;
2)
cmd='--db'
;;
*)
cmd="$1"
;;
esac
# Information options
case "$cmd" in
--help)
print_help
2022-10-19 15:24:24 +00:00
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
;;
-h)
print_help
2022-10-19 15:24:24 +00:00
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
;;
--version)
2022-10-19 15:24:24 +00:00
print_revision "$PROGNAME" "$REVISION"
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
;;
-V)
2022-10-19 15:24:24 +00:00
print_revision "$PROGNAME" "$REVISION"
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
;;
esac
# Hunt down a reasonable ORACLE_HOME
if [ -z "$ORACLE_HOME" ] ; then
2022-10-19 15:24:24 +00:00
# Adjust to taste
for oratab in /var/opt/oracle/oratab /etc/oratab
do
[ ! -f $oratab ] && continue
ORACLE_HOME=`IFS=:
while read -r SID ORACLE_HOME junk;
do
if [ "$SID" = "$2" ] || [ "$SID" = "*" ] ; then
echo "$ORACLE_HOME";
exit;
fi;
done < $oratab`
[ -n "$ORACLE_HOME" ] && break
done
2013-11-26 22:53:19 +00:00
fi
# Last resort
2022-10-19 15:24:24 +00:00
[ -z "$ORACLE_HOME" ] && [ -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle
2013-11-26 22:53:19 +00:00
2013-11-26 22:54:42 +00:00
if [ "$cmd" != "--db" ]; then
2022-10-19 15:24:24 +00:00
if [ -z "$ORACLE_HOME" ] || [ ! -d "$ORACLE_HOME" ] ; then
echo "Cannot determine ORACLE_HOME for sid $2"
exit "$STATE_UNKNOWN"
fi
2013-11-26 22:53:19 +00:00
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)
2022-10-19 15:24:24 +00:00
tnschk=$(tnsping "$2")
tnschk2=$(echo "$tnschk" | grep -c OK)
if [ "${tnschk2}" -eq 1 ] ; then
tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*}
echo "OK - reply time ${tnschk3} from $2"
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
else
2022-10-19 15:24:24 +00:00
echo "No TNS Listener on $2"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
;;
--oranames)
2022-10-19 15:24:24 +00:00
namesctl status "$2" | awk '
2013-11-26 22:53:19 +00:00
/Server has been running for:/ {
2022-10-19 15:24:24 +00:00
msg = "OK: Up"
for (i = 6; i <= NF; i++) {
msg = msg " " $i
}
status = '"$STATE_OK"'
2013-11-26 22:53:19 +00:00
}
/error/ {
2022-10-19 15:24:24 +00:00
msg = "CRITICAL: " $0
status = '"$STATE_CRITICAL"'
2013-11-26 22:53:19 +00:00
}
END {
2022-10-19 15:24:24 +00:00
print msg
exit status
2013-11-26 22:53:19 +00:00
}'
;;
--db)
2022-10-19 15:24:24 +00:00
pmonchk=$(pgrep -f "(asm|ora)_pmon_${2}$")
if [ "${pmonchk}" -ge 1 ] ; then
echo "${2} OK - ${pmonchk} PMON process(es) running"
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
#if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
2022-10-19 15:24:24 +00:00
#if [ ${pmonchk} -eq 1 ] ; then
2013-11-26 22:53:19 +00:00
#utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
2022-10-19 15:24:24 +00:00
#echo "${2} OK - running since ${utime}"
#exit $STATE_OK
#fi
2013-11-26 22:53:19 +00:00
else
2022-10-19 15:24:24 +00:00
echo "${2} Database is DOWN"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
;;
--login)
2022-10-19 15:24:24 +00:00
loginchk=$(sqlplus dummy/user@"$2" < /dev/null)
loginchk2=$(echo "$loginchk" | grep -c ORA-01017)
if [ "${loginchk2}" -eq 1 ] ; then
echo "OK - dummy login connected"
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
else
2022-10-19 15:24:24 +00:00
loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1)
echo "CRITICAL - $loginchk3"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
;;
--connect)
2022-10-19 15:24:24 +00:00
connectchk=$(sqlplus "$2" < /dev/null)
connectchk2=$(echo "$connectchk" | grep -c ORA-)
if [ "${connectchk2}" -eq 0 ] ; then
echo "OK - login successful"
exit "$STATE_OK"
else
2022-10-19 15:24:24 +00:00
connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1)
echo "CRITICAL - $connectchk3"
exit "$STATE_CRITICAL"
fi
;;
2013-11-26 22:53:19 +00:00
--cache)
2022-10-19 15:24:24 +00:00
if [ "${5}" -gt "${6}" ] ; then
echo "UNKNOWN - Warning level is less then Crit"
exit "$STATE_UNKNOWN"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF
2013-11-26 22:53:19 +00:00
set pagesize 0
set numf '9999999.99'
select (1-(pr.value/(dbg.value+cg.value)))*100
from v\\$sysstat pr, v\\$sysstat dbg, v\\$sysstat cg
where pr.name='physical reads'
and dbg.name='db block gets'
and cg.name='consistent gets';
EOF`
2022-10-19 15:24:24 +00:00
if echo "$result" | grep -q 'ORA-' ; then
error=$(echo "$result" | grep "ORA-" | head -1)
echo "CRITICAL - $error"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}')
buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}')
result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF
2013-11-26 22:53:19 +00:00
set pagesize 0
set numf '9999999.99'
select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100
from v\\$librarycache lc;
EOF`
2022-10-19 15:24:24 +00:00
if echo "$result" | grep -q 'ORA-' ; then
error=$(echo "$result" | grep "ORA-" | head -1)
echo "CRITICAL - $error"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}')
lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}')
2013-11-26 22:53:19 +00:00
2022-10-19 15:24:24 +00:00
if [ "$buf_hr" -le "${5}" ] || [ "$lib_hr" -le "${5}" ] ; then
echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
if [ "$buf_hr" -le "${6}" ] || [ "$lib_hr" -le "${6}" ] ; then
echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100"
exit "$STATE_WARNING"
2013-11-26 22:53:19 +00:00
fi
echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100"
2022-10-19 15:24:24 +00:00
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
;;
--tablespace)
2022-10-19 15:24:24 +00:00
if [ "${6}" -lt "${7}" ] ; then
echo "UNKNOWN - Warning level is more then Crit"
exit "$STATE_UNKNOWN"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF
2013-11-26 22:53:19 +00:00
set pagesize 0
set numf '9999999.99'
select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc
from (
select tablespace_name,sum(bytes)/1024/1024 total
from dba_data_files group by tablespace_name) A
LEFT OUTER JOIN
( select tablespace_name,sum(bytes)/1024/1024 free
from dba_free_space group by tablespace_name) B
ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}';
EOF`
2022-10-19 15:24:24 +00:00
if echo "$result" | grep -q 'ORA-' ; then
error=$(echo "$result" | grep "ORA-" | head -1)
echo "CRITICAL - $error"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
ts_free=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}')
ts_total=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}')
ts_pct=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}')
ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}')
if [ "$ts_free" -eq 0 ] && [ "$ts_total" -eq 0 ] && [ "$ts_pct" -eq 0 ] ; then
2013-11-26 22:53:19 +00:00
echo "No data returned by Oracle - tablespace $5 not found?"
2022-10-19 15:24:24 +00:00
exit "$STATE_UNKNOWN"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
if [ "$ts_pct" -ge "${6}" ] ; then
echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
exit "$STATE_CRITICAL"
2013-11-26 22:53:19 +00:00
fi
2022-10-19 15:24:24 +00:00
if [ "$ts_pct" -ge "${7}" ] ; then
echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
exit "$STATE_WARNING"
2013-11-26 22:53:19 +00:00
fi
echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
2022-10-19 15:24:24 +00:00
exit "$STATE_OK"
2013-11-26 22:53:19 +00:00
;;
*)
print_usage
2022-10-19 15:24:24 +00:00
exit "$STATE_UNKNOWN"
2013-11-26 22:53:19 +00:00
esac