summaryrefslogtreecommitdiffstats
path: root/web/attachments/56241-check_oracle.jjm
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/56241-check_oracle.jjm')
-rw-r--r--web/attachments/56241-check_oracle.jjm590
1 files changed, 590 insertions, 0 deletions
diff --git a/web/attachments/56241-check_oracle.jjm b/web/attachments/56241-check_oracle.jjm
new file mode 100644
index 0000000..3142511
--- /dev/null
+++ b/web/attachments/56241-check_oracle.jjm
@@ -0,0 +1,590 @@
1#!/bin/sh
2#
3# latigid010@yahoo.com
4# 01/06/2000
5#
6# This Nagios plugin was created to check Oracle status
7#
8
9PROGNAME=`basename $0`
10PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
11REVISION=`echo '$Revision: 1.6 $' | sed -e 's/[^0-9.]//g'`
12
13. $PROGPATH/utils.sh
14
15
16function init_var() {
17RETURN_MSG=""
18CHECK_CACHE=no
19CHECK_DB=no
20CHECK_EXTENTS=no
21CHECK_LOGIN=no
22CHECK_NAMES=no
23CHECK_TS=no
24CHECK_TNS=no
25CRIT_LVL=-1
26WARN_LVL=-1
27ORACLE_SID=${ORACLE_SID}
28ORA_USER=""
29ORA_PASS=""
30ORA_TS=""
31ORA_HOST=""
32ORA_NAMES=""
33
34
35# Hunt down a reasonable ORACLE_HOME
36if [ -z "$ORACLE_HOME" ] ; then
37 # Adjust to taste
38 for oratab in /var/opt/oracle/oratab /etc/oratab
39 do
40 [ ! -f $oratab ] && continue
41 ORACLE_HOME=`IFS=:
42 while read SID ORACLE_HOME junk;
43 do
44 if [ "$SID" = "$2" -o "$SID" = "*" ] ; then
45 echo $ORACLE_HOME;
46 exit;
47 fi;
48 done < $oratab`
49 [ -n "$ORACLE_HOME" ] && break
50 done
51fi
52# Last resort
53[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle
54
55if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
56 echo "Cannot determine ORACLE_HOME for sid ${ORACLE_SID}"
57 exit ${STATE_UNKNOWN}
58fi
59PATH=$PATH:$ORACLE_HOME/bin
60LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
61export ORACLE_HOME PATH LD_LIBRARY_PATH
62}
63
64
65print_usage() {
66 echo "This check_oracle provides a new argument handling scheme."
67 echo " To use the old scheme - add a "--" before any arguments"
68 echo "Old Usage:"
69 echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
70 echo " $PROGNAME --db <ORACLE_SID>"
71 echo " $PROGNAME --login <ORACLE_SID>"
72 echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>"
73 echo " $PROGNAME --extents <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
74 echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
75 echo " $PROGNAME --oranames <Hostname>"
76 echo " $PROGNAME --help"
77 echo " $PROGNAME --version"
78 echo "The new argument handling takes shorter args + allows chaining of checks"
79 echo "New Usage:"
80 echo " $PROGNAME [args...]"
81 echo " -c Cache Check -C <ARG> Critical level"
82 echo " -d DB Check -W <ARG> Warning level"
83 echo " -e Extent Check"
84 echo " -l Listener Check -u <ARG> User"
85 echo " -n Oranames check -p <ARG> Password"
86 echo " -t tns names check -s <ARG> oracle SID"
87 echo " -T Tablespace check -H <ARG> Host check"
88 echo " -h Help"
89}
90
91print_help() {
92 print_revision $PROGNAME $REVISION
93 echo ""
94 print_usage
95 echo ""
96 echo "Check Oracle status"
97 echo ""
98 echo "--tns SID/IP Address"
99 echo " Check remote TNS server"
100 echo "--db SID"
101 echo " Check local database (search /bin/ps for PMON process) and check"
102 echo " filesystem for sgadefORACLE_SID.dbf"
103 echo "--login SID"
104 echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
105 echo "--cache"
106 echo " Check local database for library and buffer cache hit ratios"
107 echo " ---> Requires Oracle user/password and SID specified."
108 echo " ---> Requires select on v_$sysstat and v_$librarycache"
109 echo "--extents"
110 echo " Check to see if there are extents unable to be extended."
111 echo "--tablespace"
112 echo " Check local database for tablespace capacity in ORACLE_SID"
113 echo " ---> Requires Oracle user/password specified."
114 echo " ---> Requires select on dba_data_files and dba_free_space"
115 echo "--oranames Hostname"
116 echo " Check remote Oracle Names server"
117 echo "--help"
118 echo " Print this help screen"
119 echo "--version"
120 echo " Print version and license information"
121 echo ""
122 echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
123 echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
124 echo "tnsnames.ora file is locatable and is properly configured."
125 echo ""
126 echo "When checking local database status your ORACLE_SID is case sensitive."
127 echo ""
128 echo "If you want to use a default Oracle home, add in your oratab file:"
129 echo "*:/opt/app/oracle/product/7.3.4:N"
130 echo ""
131 support
132}
133
134
135check_cache() {
136 if [ ${CRIT_LVL} -gt ${WARN_LVL} ] ; then
137 RETURN_MSG="UNKNOWN - Warning level is less then Crit"
138 return ${STATE_UNKNOWN}
139 fi
140 result=`sqlplus -s ${ORA_USER}/${ORA_PASS}@${ORACLE_SID} << EOF
141set pagesize 0
142select (1-(pr.value/(dbg.value+cg.value)))*100
143from v\\$sysstat pr, v\\$sysstat dbg, v\\$sysstat cg
144where pr.name='physical reads'
145and dbg.name='db block gets'
146and cg.name='consistent gets';
147EOF`
148
149 if [ -n "`echo $result | grep ORA-`" ] ; then
150 error=` echo "$result" | grep "ORA-" | head -1`
151 echo "CRITICAL - $error"
152 exit $STATE_CRITICAL
153 fi
154
155
156 buf_hr=`echo $result | awk '{print int($1)}'`
157 result=`sqlplus -s ${ORA_USER}/${ORA_PASS}@${ORACLE_SID} << EOF
158set pagesize 0
159select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100
160from v\\$librarycache lc;
161EOF`
162
163 if [ -n "`echo $result | grep ORA-`" ] ; then
164 error=` echo "$result" | grep "ORA-" | head -1`
165 echo "CRITICAL - $error"
166 exit $STATE_CRITICAL
167 fi
168
169 lib_hr=`echo $result | awk '{print int($1)}'`
170
171 if [ $buf_hr -le ${CRIT_LVL} -o $lib_hr -le ${CRIT_LVL} ] ; then
172 export RETURN_MSG="${ORACLE_SID} CRITICAL - Cache Hit Rates: $lib_hr% Lib -- $buf_hr% Buff"
173 exit $STATE_CRITICAL
174 fi
175 if [ $buf_hr -le ${WARN_LVL} -o $lib_hr -le ${WARN_LVL} ] ; then
176 export RETURN_MSG="${ORACLE_SID} WARNING - Cache Hit Rates: $lib_hr% Lib -- $buf_hr% Buff"
177 exit $STATE_WARNING
178 fi
179 export RETURN_MSG="${ORACLE_SID} OK - Cache Hit Rates: $lib_hr% Lib -- $buf_hr% Buff"
180
181 return ${STATE_OK}
182
183
184}
185
186check_extents() {
187 if [ ${CRIT_LVL} -lt ${WARN_LVL} ] ; then
188 RETURN_MSG="UNKNOWN - Warning level is higher then Crit"
189 return ${STATE_UNKNOWN}
190 fi
191 result=`sqlplus -s ${ORA_USER}/${ORA_PASS}@${ORACLE_SID} << EOF
192set pagesize 200
193column Sname form a40 heading 'Object Name'
194column Size form 99,999 heading 'Size'
195column Next form 99,999 heading 'Next'
196column Tname form a15 heading 'TsName'
197
198select a.owner||'.'||a.segment_name "Sname",
199 a.bytes/1024/1024 "Size",
200 a.next_extent/1024/1024 "Next",
201 a.tablespace_name "TName"
202from sys.dba_segments a
203where a.tablespace_name not like 'T%MP' -- Exclude TEMP tablespaces
204and a.tablespace_name like '%${ORA_TS}%'
205and next_extent * 1 > ( -- Cannot extend 1x, can change to 2x...
206 select max(b.bytes)
207 from dba_free_space b
208 where a.tablespace_name = b.tablespace_name)
209order by 3 desc;
210EOF`
211
212 if [ -n "`echo $result | grep ORA-`" ] ; then
213 error=` echo "$result" | grep "ORA-" | head -1`
214 echo "CRITICAL - $error"
215 exit $STATE_CRITICAL
216 fi
217
218 if [ `echo $result | grep -c "no rows selected"` -eq 1 ]
219 then
220 export RETURN_MSG="${ORACLE_SID} : ${ORA_TS} OK - Extents. Extensible"
221 return ${STATE_OK}
222 else
223 nn=`expr \`echo "$result" | wc -l\` - 3`
224 export RETURN_MSG="CRIT: Result: $nn objects can't extend"
225 return $STATE_CRITICAL
226 fi
227}
228
229check_tablespace() {
230 if [ ${CRIT_LVL} -lt ${WARN_LVL} ] ; then
231 RETURN_MSG="UNKNOWN - Warning level is more then Crit"
232 return ${STATE_UNKNOWN}
233 fi
234 result=`sqlplus -s ${ORA_USER}/${ORA_PASS}@${ORACLE_SID} << EOF
235set pagesize 0
236select b.free,a.total,100 - trunc(b.free/a.total * 1000) / 10 prc
237from (
238select tablespace_name,sum(bytes)/1024/1024 total
239from dba_data_files group by tablespace_name) A,
240( select tablespace_name,sum(bytes)/1024/1024 free
241from dba_free_space group by tablespace_name) B
242where a.tablespace_name=b.tablespace_name and a.tablespace_name='${ORA_TS}';
243EOF`
244
245 if [ -n "`echo $result | grep ORA-`" ] ; then
246 error=` echo "$result" | grep "ORA-" | head -1`
247 echo "CRITICAL - $error"
248 exit $STATE_CRITICAL
249 fi
250
251
252 ts_free=`echo $result | awk '{print int($1)}'`
253 ts_total=`echo $result | awk '{print int($2)}'`
254 ts_pct=`echo $result | awk '{print int($3)}'`
255
256 ce_ret=${STATE_OK}
257 ce_ret_msg=""
258 if [ ${CHECK_EXTENTS} == "yes" ]
259 then
260 check_extents
261 ce_ret=${?}
262 ce_ret_msg=${RETURN_MSG}
263 fi
264 if [ ${ts_pct} -ge ${CRIT_LVL} ] || [ ${ce_ret} -eq ${STATE_CRITICAL} ]
265 then
266 RETURN_MSG="${ORACLE_SID} : ${ORA_TS} CRITICAL - $ts_pct% used [ $ts_free / $ts_total MB available ] || ${ce_ret_msg}"
267 return ${STATE_CRITICAL}
268 fi
269 if [ ${ts_pct} -ge ${WARN_LVL} ] || [ ${ce_ret} -eq ${STATE_WARNING} ]
270 then
271 RETURN_MSG="${ORACLE_SID} : ${ORA_TS} WARNING - $ts_pct% used [ $ts_free / $ts_total MB available ] || ${ce_ret_msg}"
272 return ${STATE_WARNING}
273 fi
274 if [ $ts_free -eq 0 -a $ts_total -eq 0 -a $ts_pct -eq 0 ] || \
275 [ ${ce_ret} -eq ${STATE_UNKNOWN} ]
276 then
277 RETURN_MSG="No data returned by Oracle - tablespace ${ORA_TS} not found? || ${ce_ret_msg}"
278 return ${STATE_UNKNOWN}
279 fi
280 RETURN_MSG="${ORACLE_SID} : ${ORA_TS} OK - $ts_pct% used [ $ts_free / $ts_total MB available ] || ${ce_ret_msg}"
281 return ${STATE_OK}
282}
283
284check_tns() {
285 tnstarg=""
286 if [ -n "${ORA_HOST}" -a "${ORA_HOST}" != "" ]
287 then
288 tnstarg=${ORA_HOST}
289 elif [ -n "${ORACLE_SID}" ] #-a "${ORACLE_SID}" != "" ]
290 then
291 tnstarg=${ORACLE_SID}
292 RETURN_MSG="set tnstarg = $tnstarg (ORACLE_SID = ${ORACLE_SID})"
293 else
294 RETURN_MSG="Could not determine destination"
295 return $STATE_WARNING
296 fi
297
298 tnschk=` tnsping ${tnstarg}`
299 tnschk2=` echo $tnschk | grep -c OK`
300 if [ ${tnschk2} -eq 1 ] ; then
301 tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
302 export RETURN_MSG="OK - reply time ${tnschk3} from ${tnstarg}"
303 return ${STATE_OK}
304 else
305 export RETURN_MSG="No TNS Listener on ${tnstarg}"
306 return $STATE_CRITICAL
307 fi
308}
309
310
311check_oranames() {
312 namesctl status ${ORA_NAMES} | awk '
313 /Server has been running for:/ {
314 msg = "OK: Up"
315 for (i = 6; i <= NF; i++) {
316 msg = msg " " $i
317 }
318 status = '${STATE_OK}'
319 }
320 /error/ {
321 msg = "CRITICAL: " $0
322 status = '$STATE_CRITICAL'
323 }
324 END {
325 print msg
326 RETURN status
327 }'
328}
329
330check_db() {
331 pmonchk=`ps -ef | grep -v grep | grep ${ORACLE_SID} | grep -c pmon`
332 if [ ${pmonchk} -ge 1 ] ; then
333 export RETURN_MSG="${ORACLE_SID} OK - ${pmonchk} PMON process(es) running"
334 return ${STATE_OK}
335 else
336 export RETURN_MSG="${2} Database is DOWN"
337 return $STATE_CRITICAL
338 fi
339}
340
341check_login() {
342 loginchk=`sqlplus dummy/user@${ORACLE_SID} < /dev/null`
343 loginchk2=` echo ${loginchk} | grep -c ORA-01017`
344 if [ ${loginchk2} -eq 1 ] ; then
345 export RETURN_MSG="OK - dummy login connected"
346 return ${STATE_OK}
347 else
348 loginchk3=` echo "${loginchk}" | grep "ORA-" | head -1`
349 export RETURN_MSG="CRITICAL - ${loginchk3}"
350 return $STATE_CRITICAL
351 fi
352}
353#begin our "main"
354#
355
356init_var
357
358
359while getopts ":cC:dehH:ln:p:s:tT:u:W:" arg ; do
360 case ${arg} in
361
362 c ) #echo "Cache Received"
363 CHECK_CACHE=yes
364 ;;
365 C ) #echo "Critical lvl = ${OPTARG}"
366 CRIT_LVL=${OPTARG}
367 ;;
368 d ) #echo "DB Received"
369 CHECK_DB=yes
370 ;;
371 e ) #echo "Extents Received"
372 CHECK_EXTENTS=yes
373 ;;
374 H ) #echo "Host Received = ${OPTARG}"
375 ORA_HOST=${OPTARG}
376 ;;
377 h ) #echo "Help Received"
378 print_help
379 exit ${STATE_UNKNOWN}
380 ;;
381 l ) #echo "Login Received"
382 CHECK_LOGIN=yes
383 ;;
384 n ) #echo "oranames Received = $OPTARG}"
385 CHECK_NAMES=yes
386 ORA_NAMES=${OPTARG}
387 ;;
388 p ) #echo "Passwd Received = ${OPTARG}"
389 ORA_PASS=${OPTARG}
390 ;;
391 s ) #echo "SID Received = ${OPTARG}"
392 ORACLE_SID=${OPTARG}
393 ;;
394 t ) #echo "tnsnames Received"
395 CHECK_TNS=yes
396 ;;
397 T ) #echo "Tablespace Received = ${OPTARG}"
398 ORA_TS=${OPTARG}
399 CHECK_TS=yes
400 ;;
401 u ) #echo "User Received = ${OPTARG}"
402 ORA_USER=${OPTARG}
403 ;;
404 W ) #echo "Warning lvl = ${OPTARG}"
405 WARN_LVL=${OPTARG}
406 ;;
407 \?) print_usage
408 exit ${STATE_UNKNOWN}
409 ;;
410 esac
411done
412
413
414shift $(($OPTIND - 1))
415
416if [ "$1" == "--help" ]
417then
418 print_help
419fi
420
421# "This is where new options can be used - working on compat first
422# "step through following:"
423if [ -z $1 ]
424then
425
426if [ -n ${ORACLE_SID} ] && [ "${ORACLE_SID}" != "" ]
427then
428 if [ -n ${ORA_PASS} -a "${ORA_PASS}" != "" ] || \
429 [ -n ${ORA_USER} -a "${ORA_USER}" != "" ] || \
430 [ -n ${CRIT_LVL} >= 0 ] || [ ${WARN_LVL} >= 0 ]
431 then
432 if [ ${CHECK_CACHE} == "yes" ] && [ ${CHECK_TS} == "no" ]
433 then
434 check_cache
435 ret=${?}
436 echo ${RETURN_MSG}
437 exit ${ret}
438 fi
439 if [ ${CHECK_EXTENTS} == "yes" ] && [ ${CHECK_TS} == "no" ]
440 then
441 echo "call check_Extents"
442 check_extents
443 ret=${?}
444 echo ${RETURN_MSG}
445 exit ${RET}
446 fi
447 else
448 echo "error - not proper args"
449 fi
450 if [ -n ${ORA_TS} ] && [ "${ORA_TS}" != "" ]
451 then
452 if [ ${CHECK_TS} == "yes" ] && [ ${CHECK_CACHE} == "no" ]
453 then
454 check_tablespace
455 ret=${?}
456 echo ${RETURN_MSG}
457 exit ${ret}
458 fi
459 if [ ${CHECK_TS} == "yes" ] && [ ${CHECK_CACHE} == "yes" ]
460 then
461 RETURN_MSG="INVALID: Currently Cache and tablespace checks don't mesh"
462 echo ${RETURN_MSG}
463 exit ${STATE_UNKNOWN}
464 fi
465 fi
466 if [ ${CHECK_LOGIN} == "yes" ]
467 then
468 check_login
469 ret=${?}
470 echo ${RETURN_MSG}
471 exit ${ret}
472 fi
473 if [ ${CHECK_DB} == "yes" ]
474 then
475 check_db
476 ret=${?}
477 echo ${RETURN_MSG}
478 exit ${ret}
479 fi
480fi
481else
482 echo "Using old Invocation Methods: \"$*\""
483fi
484
485case "$1" in
4861)
487 cmd='--tns'
488 ;;
4892)
490 cmd='--db'
491 ;;
492*)
493 cmd="$1"
494 ;;
495esac
496
497# Information options
498case "$cmd" in
499--help)
500 print_help
501 exit ${STATE_OK}
502 ;;
503-h)
504 print_help
505 exit ${STATE_OK}
506 ;;
507--db)
508 CHECK_DB=yes
509 ORACLE_SID=$2
510 check_db
511 ret=${?}
512 echo ${RETURN_MSG}
513 exit $ret
514 ;;
515--cache)
516 CHECK_CACHE=yes
517 ORACLE_SID=$2
518 ORA_USER=$3
519 ORA_PASS=$4
520 CRIT_LVL=$5
521 WARN_LVL=$6
522 check_cache
523 ret=${?}
524 echo ${RETURN_MSG}
525 exit $ret
526 ;;
527--extents)
528 CHECK_EXTENTS=yes
529 ORACLE_SID=$2
530 ORA_USER=$3
531 ORA_PASS=$4
532 CRIT_LVL=$5
533 WARN_LVL=$6
534 check_extents
535 ret=${?}
536 echo ${RETURN_MSG}
537 exit $ret
538 ;;
539--login)
540 CHECK_LOGIN=yes
541 ORACLE_SID=$2
542 check_login
543 ret=${?}
544 echo ${RETURN_MSG}
545 exit $ret
546 ;;
547--oranames)
548 CHECK_NAMES=yes
549 ORA_NAMES=$2
550 check_oranames
551 exit ${?}
552 ;;
553--tablespace)
554 CHECK_TS=yes
555 ORACLE_SID=$2
556 ORA_USER=$3
557 ORA_PASS=$4
558 ORA_TS=$5
559 CRIT_LVL=$6
560 WARN_LVL=$7
561 check_tablespace
562 ret=${?}
563 echo ${RETURN_MSG}
564 exit $ret
565 ;;
566--tns)
567 CHECK_TNS=yes
568 export ORACLE_SID=$2
569 echo "--tns ${ORACLE_SID} "
570 check_tns
571 ret=${?}
572 echo ${RETURN_MSG}
573 exit $ret
574 ;;
575--version)
576 print_revision $PLUGIN $REVISION
577 exit ${STATE_OK}
578 ;;
579-V)
580 print_revision $PLUGIN $REVISION
581 exit ${STATE_OK}
582 ;;
583*)
584 print_usage
585 exit ${STATE_UNKNOWN}
586 ;;
587esac
588
589
590exit ${STATE_UNKNOWN}