summaryrefslogtreecommitdiffstats
path: root/web/attachments/419187-check_oracle_negativewarncrit.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/419187-check_oracle_negativewarncrit.patch')
-rw-r--r--web/attachments/419187-check_oracle_negativewarncrit.patch201
1 files changed, 201 insertions, 0 deletions
diff --git a/web/attachments/419187-check_oracle_negativewarncrit.patch b/web/attachments/419187-check_oracle_negativewarncrit.patch
new file mode 100644
index 0000000..2319b8b
--- /dev/null
+++ b/web/attachments/419187-check_oracle_negativewarncrit.patch
@@ -0,0 +1,201 @@
1--- check_oracle 2010-10-07 17:11:31.000000000 +0200
2+++ check_oracle_negativewarncrit 2011-07-22 19:28:28.000000000 +0200
3@@ -8,10 +8,15 @@
4
5 PROGNAME=`basename $0`
6 PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
7-REVISION="1.4.15"
8+REVISION="1.4.15-negativewarncrit"
9
10 . $PROGPATH/utils.sh
11
12+dflt_cachwarn="85%"
13+dflt_cachcrit="95%"
14+dflt_tswarn="85%"
15+dflt_tscrit="95%"
16+
17
18 print_usage() {
19 echo "Usage:"
20@@ -40,11 +45,11 @@
21 echo "--login SID"
22 echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
23 echo "--cache"
24- echo " Check local database for library and buffer cache hit ratios"
25+ echo " Check local database for library and buffer cache hit ratios (default warn:$dflt_cachwarn,crit:$dflt_cachcrit)"
26 echo " ---> Requires Oracle user/password and SID specified."
27 echo " ---> Requires select on v_$sysstat and v_$librarycache"
28 echo "--tablespace"
29- echo " Check local database for tablespace capacity in ORACLE_SID"
30+ echo " Check local database for tablespace capacity in ORACLE_SID (default warn:$dflt_tswarn,crit:$dflt_tscrit)"
31 echo " ---> Requires Oracle user/password specified."
32 echo " ---> Requires select on dba_data_files and dba_free_space"
33 echo "--oranames Hostname"
34@@ -54,6 +59,10 @@
35 echo "--version"
36 echo " Print version and license information"
37 echo ""
38+ echo " <WARNING>/<CRITICAL> can either be a percentage (ie. '15%') or a size in Mega/Giga/Terabyte (ie. '2G'; dflt: M)"
39+ echo " Prepend the size with minus to be notified for a certain level below the maximum value,"
40+ echo " ie. '-2G' to be warned 2G before 'SIZE' (-t) or 'MAXBYTES' (-T) tablespace runs out."
41+ echo ""
42 echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
43 echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
44 echo "tnsnames.ora file is locatable and is properly configured."
45@@ -66,6 +75,54 @@
46 support
47 }
48
49+
50+# convert_warncrit_val( warnlevel/critlevel ): returns in either % or units of M, no matter what input the user provided
51+ReturnVal=
52+ReturnUnit=
53+convert_warncrit_val() {
54+ input=$1; totalsize=$2
55+ tmp=""; tmpunit=""
56+ [ `expr index "$input" "%"` -gt 1 ] && tmp=`echo "scale=0; ${input%*%} * $totalsize" | bc | sed 's/\.[0-9]*$//g'` && tmpunit="%"
57+ if [ "$tmp" = "" ]; then
58+ [ `expr index "$input" "G"` -gt 1 ] && tmp=$[ ${input%*G}*1000 ] && tmpunit="M"
59+ [ `expr index "$input" "T"` -gt 1 ] && tmp=$[ ${input%*T}*1000*1000 ] && tmpunit="M"
60+ if [ "$tmp" = "" ]; then # default: M
61+ foo=$input
62+ [ `expr index "$input" "M"` -gt 1 ] && foo=$[ ${input%*M} ] && tmpunit="M"
63+ tmp=$foo
64+ fi
65+ fi
66+
67+ [ $tmp -lt 0 ] && tmp=$[ $totalsize + $tmp ] # ie. -2G
68+ [ $tmp -lt 0 ] && tmp=0 # ie. the result of the line before was below zero => set to zero.
69+
70+ ReturnVal=$tmp
71+ ReturnUnit=$tmpunit
72+ return
73+}
74+
75+
76+# do_warncrit_test(warnlevel, critlevel)
77+do_warncrit_test() {
78+ convert_warncrit_val $1 100; tmpwarn=$ReturnVal # use "100" as "size" for percentile checks, since we don't have that already
79+ convert_warncrit_val $2 100; tmpcrit=$ReturnVal
80+
81+ if [ $tmpwarn -lt 0 ]; then # ie. -2G
82+ if [ $tmpwarn -gt $tmpcrit ]; then
83+ echo "UNKNOWN - Warning level is less than Crit"
84+ exit $STATE_UNKNOWN
85+ fi
86+ else
87+ if [ $tmpwarn -gt $tmpcrit ]; then
88+ echo "UNKNOWN - Warning level is more than Crit"
89+ exit $STATE_UNKNOWN
90+ fi
91+ fi
92+}
93+
94+
95+
96+
97 case "$1" in
98 1)
99 cmd='--tns'
100@@ -188,10 +245,14 @@
101 fi
102 ;;
103 --cache)
104- if [ ${5} -gt ${6} ] ; then
105- echo "UNKNOWN - Warning level is less then Crit"
106- exit $STATE_UNKNOWN
107+
108+ do_warncrit_test "$6" "$5"
109+
110+ if [ `expr index "$6" "%"` -lt 1 ]; then
111+ echo "${2} UNKNOWN - cache check can only use % value for warn/crit level."
112+ exit $STATE_UNKNOWN
113 fi
114+
115 result=`sqlplus -s ${3}/${4}@${2} << EOF
116 set pagesize 0
117 set numf '9999999.99'
118@@ -226,23 +287,32 @@
119 lib_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'`
120 lib_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'`
121
122- if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then
123- 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"
124+ # for actually usable warn/crit levels with higher precision number
125+ convert_warncrit_val "$6" 10000; compwarn=$ReturnVal # $ReturnUnit is being used directly, should be of same type.
126+ convert_warncrit_val "$5" 10000; compcrit=$ReturnVal
127+ # just snip of the % of the input to get perfdata
128+ perfwarn=${6%*%}
129+ perfcrit=${5%*%}
130+
131+ newbufhr=`echo "$buf_hrx * 10000" | bc -l | sed 's/\.[0-9]*$//g'`
132+ newlibhr=`echo "$lib_hrx * 10000" | bc -l | sed 's/\.[0-9]*$//g'`
133+
134+ if [ $newbufhr -le $compcrit -o $newlibhr -le $compcrit ] ; then
135+ echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;100 buffer=$buf_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;100"
136 exit $STATE_CRITICAL
137 fi
138- if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then
139- 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"
140+ if [ $newbufhr -le $compwarn -o $newlibhr -le $compwarn ] ; then
141+ echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;100 buffer=$buf_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;100"
142 exit $STATE_WARNING
143 fi
144- 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"
145+ echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;100 buffer=$buf_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;100"
146
147 exit $STATE_OK
148 ;;
149 --tablespace)
150- if [ ${6} -lt ${7} ] ; then
151- echo "UNKNOWN - Warning level is more then Crit"
152- exit $STATE_UNKNOWN
153- fi
154+
155+ do_warncrit_test "$7" "$6"
156+
157 result=`sqlplus -s ${3}/${4}@${2} << EOF
158 set pagesize 0
159 set numf '9999999.99'
160@@ -258,7 +328,7 @@
161
162 if [ -n "`echo $result | grep ORA-`" ] ; then
163 error=` echo "$result" | grep "ORA-" | head -1`
164- echo "CRITICAL - $error"
165+ echo "${2} : ${5} CRITICAL - $error"
166 exit $STATE_CRITICAL
167 fi
168
169@@ -266,19 +336,26 @@
170 ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'`
171 ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'`
172 ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'`
173+
174+ convert_warncrit_val "$7" $ts_total; compwarn=$ReturnVal # $ReturnUnit is either % or M for the perfdata
175+ convert_warncrit_val "$6" $ts_total; compcrit=$ReturnVal
176+
177+ perfused=$ts_pctx
178+ [ "$ReturnUnit" != "%" ] && perfused=$[ $ts_total - $ts_free ] && ReturnUnit="M"
179+
180 if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then
181- echo "No data returned by Oracle - tablespace $5 not found?"
182+ echo "${2} : ${5} UNKNOWN - No data returned by Oracle - tablespace $5 not found?"
183 exit $STATE_UNKNOWN
184 fi
185- if [ "$ts_pct" -ge ${6} ] ; then
186- echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
187+ if [ "$ts_pct" -ge "$compcrit" ] ; then
188+ echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$perfused$ReturnUnit;$compwarn$ReturnUnit;$compcrit$ReturnUnit;0;100"
189 exit $STATE_CRITICAL
190 fi
191- if [ "$ts_pct" -ge ${7} ] ; then
192- echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
193+ if [ "$ts_pct" -ge "$compwarn" ] ; then
194+ echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$perfused$ReturnUnit;$compwarn$ReturnUnit;$compcrit$ReturnUnit;0;100"
195 exit $STATE_WARNING
196 fi
197- echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
198+ echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$perfused$ReturnUnit;$compwarn$ReturnUnit;$compcrit$ReturnUnit;0;100"
199 exit $STATE_OK
200 ;;
201 *)