6 # This Nagios plugin was created to check Oracle status
10 PROGPATH
=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
11 REVISION
=`echo '$Revision$' | sed -e 's/[^0-9.]//g'`
18 echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
19 echo " $PROGNAME --db <ORACLE_SID>"
20 echo " $PROGNAME --login <ORACLE_SID>"
21 echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>"
22 echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
23 echo " $PROGNAME --oranames <Hostname>"
24 echo " $PROGNAME --help"
25 echo " $PROGNAME --version"
29 print_revision
$PROGNAME $REVISION
33 echo "Check Oracle status"
35 echo "--tns SID/IP Address"
36 echo " Check remote TNS server"
38 echo " Check local database (search /bin/ps for PMON process) and check"
39 echo " filesystem for sgadefORACLE_SID.dbf"
41 echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
43 echo " Check local database for library and buffer cache hit ratios"
44 echo " ---> Requires Oracle user/password and SID specified."
45 echo " ---> Requires select on v_$sysstat and v_$librarycache"
47 echo " Check local database for tablespace capacity in ORACLE_SID"
48 echo " ---> Requires Oracle user/password specified."
49 echo " ---> Requires select on dba_data_files and dba_free_space"
50 echo "--oranames Hostname"
51 echo " Check remote Oracle Names server"
53 echo " Print this help screen"
55 echo " Print version and license information"
57 echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
58 echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
59 echo "tnsnames.ora file is locatable and is properly configured."
61 echo "When checking local database status your ORACLE_SID is case sensitive."
63 echo "If you want to use a default Oracle home, add in your oratab file:"
64 echo "*:/opt/app/oracle/product/7.3.4:N"
92 print_revision
$PROGNAME $REVISION
96 print_revision
$PROGNAME $REVISION
101 # Hunt down a reasonable ORACLE_HOME
102 if [ -z "$ORACLE_HOME" ] ; then
104 for oratab
in /var
/opt
/oracle
/oratab
/etc
/oratab
106 [ ! -f $oratab ] && continue
108 while read SID ORACLE_HOME junk;
110 if [ "$SID" = "$2" -o "$SID" = "*" ] ; then
115 [ -n "$ORACLE_HOME" ] && break
119 [ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle
] && ORACLE_HOME
=$PROGPATH/oracle
121 if [ "$cmd" != "--db" ]; then
122 if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
123 echo "Cannot determine ORACLE_HOME for sid $2"
127 PATH
=$PATH:$ORACLE_HOME/bin
128 LD_LIBRARY_PATH
=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
129 export ORACLE_HOME PATH LD_LIBRARY_PATH
134 tnschk2
=` echo $tnschk | grep -c OK`
135 if [ ${tnschk2} -eq 1 ] ; then
136 tnschk3
=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
137 echo "OK - reply time ${tnschk3} from $2"
140 echo "No TNS Listener on $2"
145 namesctl status
$2 |
awk '
146 /Server has been running for:/ {
148 for (i = 6; i <= NF; i++) {
154 msg = "CRITICAL: " $0
155 status = '$STATE_CRITICAL'
163 pmonchk
=`ps -ef | grep -v grep | grep -c "ora_pmon_${2}$"`
164 if [ ${pmonchk} -ge 1 ] ; then
165 echo "${2} OK - ${pmonchk} PMON process(es) running"
167 #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
168 #if [ ${pmonchk} -eq 1 ] ; then
169 #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
170 #echo "${2} OK - running since ${utime}"
174 echo "${2} Database is DOWN"
179 loginchk
=`sqlplus dummy/user@$2 < /dev/null`
180 loginchk2
=` echo $loginchk | grep -c ORA-01017`
181 if [ ${loginchk2} -eq 1 ] ; then
182 echo "OK - dummy login connected"
185 loginchk3
=` echo "$loginchk" | grep "ORA-" | head -1`
186 echo "CRITICAL - $loginchk3"
191 if [ ${5} -gt ${6} ] ; then
192 echo "UNKNOWN - Warning level is less then Crit"
195 result
=`sqlplus -s ${3}/${4}@${2} << EOF
197 set numf '9999999.99'
198 select (1-(pr.value/(dbg.value+cg.value)))*100
199 from v\\$sysstat pr, v\\$sysstat dbg, v\\$sysstat cg
200 where pr.name='physical reads'
201 and dbg.name='db block gets'
202 and cg.name='consistent gets';
205 if [ -n "`echo $result | grep ORA-`" ] ; then
206 error
=` echo "$result" | grep "ORA-" | head -1`
207 echo "CRITICAL - $error"
211 buf_hr
=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'`
212 buf_hrx
=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'`
213 result
=`sqlplus -s ${3}/${4}@${2} << EOF
215 set numf '9999999.99'
216 select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100
217 from v\\$librarycache lc;
220 if [ -n "`echo $result | grep ORA-`" ] ; then
221 error
=` echo "$result" | grep "ORA-" | head -1`
222 echo "CRITICAL - $error"
226 lib_hr
=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'`
227 lib_hrx
=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'`
229 if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then
230 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"
233 if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then
234 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"
237 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"
242 if [ ${6} -lt ${7} ] ; then
243 echo "UNKNOWN - Warning level is more then Crit"
246 result
=`sqlplus -s ${3}/${4}@${2} << EOF
248 set numf '9999999.99'
249 select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc
251 select tablespace_name,sum(bytes)/1024/1024 total
252 from dba_data_files group by tablespace_name) A
254 ( select tablespace_name,sum(bytes)/1024/1024 free
255 from dba_free_space group by tablespace_name) B
256 ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}';
259 if [ -n "`echo $result | grep ORA-`" ] ; then
260 error
=` echo "$result" | grep "ORA-" | head -1`
261 echo "CRITICAL - $error"
265 ts_free
=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'`
266 ts_total
=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'`
267 ts_pct
=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'`
268 ts_pctx
=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'`
269 if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then
270 echo "No data returned by Oracle - tablespace $5 not found?"
273 if [ "$ts_pct" -ge ${6} ] ; then
274 echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
277 if [ "$ts_pct" -ge ${7} ] ; then
278 echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
281 echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"