--- check_oracle 2010-10-07 17:11:31.000000000 +0200 +++ check_oracle_tsmax 2011-07-22 15:12:42.000000000 +0200 @@ -8,7 +8,7 @@ PROGNAME=`basename $0` PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` -REVISION="1.4.15" +REVISION="1.4.15-tsmax" . $PROGPATH/utils.sh @@ -19,7 +19,7 @@ echo " $PROGNAME --db " echo " $PROGNAME --login " echo " $PROGNAME --cache " - echo " $PROGNAME --tablespace " + echo " $PROGNAME --tablespace [maxbytes]" echo " $PROGNAME --oranames " echo " $PROGNAME --help" echo " $PROGNAME --version" @@ -42,7 +42,7 @@ 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 " ---> 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." @@ -246,12 +246,12 @@ result=`sqlplus -s ${3}/${4}@${2} << EOF 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 +select ROUND(a.maxi,0) MAXI, ROUND(a.total,0) ALLOCATED, ROUND(a.total-b.free,0) USED, ROUND(b.free,0) FREE, ROUND(a.maxi-a.total+b.free,0) FREEMAXI from ( -select tablespace_name,sum(bytes)/1024/1024 total +select tablespace_name,sum(NVL(bytes,0))/1024/1024 total,sum(NVL(maxbytes,0))/1024/1024 maxi from dba_data_files group by tablespace_name) A LEFT OUTER JOIN -( select tablespace_name,sum(bytes)/1024/1024 free +( select tablespace_name,sum(NVL(bytes,0))/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` @@ -262,23 +262,42 @@ exit $STATE_CRITICAL fi - 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}'` + ts_total= + ts_used= + ts_free= + if [ "${8}" = "max" ]; then + ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'` + ts_used=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` + ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($5)}'` + else + ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'` + ts_used=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` + ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($4)}'` + fi + + compwarn=$7; compcrit=$6 + + if [ "$ts_total" = "" ]; then + echo "${2} : ${5} UNKNOWN - no data was returned|${5}=0%;$compwarn%;$compcrit%;0;100" + exit $STATE_UNKNOWN + fi + + ts_pctx=`echo "scale=2; $ts_used/$ts_total * 100" | bc -l` + ts_pct=`echo "scale=0; $ts_used/$ts_total * 100" | bc -l` + if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" exit $STATE_UNKNOWN fi 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" + echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;$compwarn%;$compcrit%;0;100" exit $STATE_CRITICAL fi 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" + echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;$compwarn%;$compcrit%;0;100" exit $STATE_WARNING fi - echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" + echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;$compwarn%;$compcrit%;0;100" exit $STATE_OK ;; *)