diff options
Diffstat (limited to 'web/attachments/420075-check_oracle_1.4.15_tsmax_negwarncritlev_easymode_bugfixcache_bugfixperfdatatsmax.patch')
-rw-r--r-- | web/attachments/420075-check_oracle_1.4.15_tsmax_negwarncritlev_easymode_bugfixcache_bugfixperfdatatsmax.patch | 298 |
1 files changed, 298 insertions, 0 deletions
diff --git a/web/attachments/420075-check_oracle_1.4.15_tsmax_negwarncritlev_easymode_bugfixcache_bugfixperfdatatsmax.patch b/web/attachments/420075-check_oracle_1.4.15_tsmax_negwarncritlev_easymode_bugfixcache_bugfixperfdatatsmax.patch new file mode 100644 index 0000000..c4b1b19 --- /dev/null +++ b/web/attachments/420075-check_oracle_1.4.15_tsmax_negwarncritlev_easymode_bugfixcache_bugfixperfdatatsmax.patch | |||
@@ -0,0 +1,298 @@ | |||
1 | --- check_oracle 2010-10-07 17:11:31.000000000 +0200 | ||
2 | +++ co 2011-08-02 18:23:37.000000000 +0200 | ||
3 | @@ -8,18 +8,24 @@ | ||
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="95%" | ||
13 | +dflt_cachcrit="97%" | ||
14 | +dflt_tswarn="85%" | ||
15 | +dflt_tscrit="95%" | ||
16 | +dflt_tsname="SYSTEM" | ||
17 | + | ||
18 | |||
19 | print_usage() { | ||
20 | echo "Usage:" | ||
21 | echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>" | ||
22 | echo " $PROGNAME --db <ORACLE_SID>" | ||
23 | echo " $PROGNAME --login <ORACLE_SID>" | ||
24 | - echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>" | ||
25 | - echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>" | ||
26 | + echo " $PROGNAME --cache <ORACLE_SID> [USER] [PASS] [CRITICAL] [WARNING]" | ||
27 | + echo " $PROGNAME --tablespace <ORACLE_SID> [USER] [PASS] [TABLESPACE] [CRITICAL] [WARNING] [maxbytes]" | ||
28 | echo " $PROGNAME --oranames <Hostname>" | ||
29 | echo " $PROGNAME --help" | ||
30 | echo " $PROGNAME --version" | ||
31 | @@ -40,11 +46,11 @@ | ||
32 | echo "--login SID" | ||
33 | echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password" | ||
34 | echo "--cache" | ||
35 | - echo " Check local database for library and buffer cache hit ratios" | ||
36 | + echo " Check local database for library and buffer cache hit ratios (default warn:$dflt_cachwarn,crit:$dflt_cachcrit)" | ||
37 | echo " ---> Requires Oracle user/password and SID specified." | ||
38 | - echo " ---> Requires select on v_$sysstat and v_$librarycache" | ||
39 | + echo " ---> Requires select on v_\$sysstat and v_\$librarycache" | ||
40 | echo "--tablespace" | ||
41 | - echo " Check local database for tablespace capacity in ORACLE_SID" | ||
42 | + echo " Check local database for tablespace capacity in ORACLE_SID (default warn:$dflt_tswarn,crit:$dflt_tscrit,ts:$dflt_tsname)" | ||
43 | echo " ---> Requires Oracle user/password specified." | ||
44 | echo " ---> Requires select on dba_data_files and dba_free_space" | ||
45 | echo "--oranames Hostname" | ||
46 | @@ -54,6 +60,12 @@ | ||
47 | echo "--version" | ||
48 | echo " Print version and license information" | ||
49 | echo "" | ||
50 | + echo " <WARNING>/<CRITICAL> can either be a percentage (ie. '15%') or a size in Mega/Giga/Terabyte (ie. '2G'; dflt: M)" | ||
51 | + echo " Prepend the size with minus to be notified for a certain level below the maximum value," | ||
52 | + echo " ie. '-2G' to be warned 2G before 'SIZE' (-t) or 'MAXBYTES' (-T) tablespace runs out." | ||
53 | + echo "" | ||
54 | + echo "If <USER> and <PASS> are left blank, ie. \"\", \`sqlplus -s / as sysdba\` is tried instead." | ||
55 | + echo "" | ||
56 | echo "If the plugin doesn't work, check that the ORACLE_HOME environment" | ||
57 | echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the" | ||
58 | echo "tnsnames.ora file is locatable and is properly configured." | ||
59 | @@ -66,6 +78,54 @@ | ||
60 | support | ||
61 | } | ||
62 | |||
63 | + | ||
64 | +# convert_warncrit_val( warnlevel/critlevel ): returns in either % or units of M, no matter what input the user provided | ||
65 | +ReturnVal= | ||
66 | +ReturnUnit= | ||
67 | +convert_warncrit_val() { | ||
68 | + input=$1; totalsize=$2 | ||
69 | + tmp=0; tmpunit="" | ||
70 | + [ `expr index "$input" "%"` -gt 1 ] && tmp=`echo "scale=0; ${input%*%} * $totalsize" | bc | sed 's/\.[0-9]*$//g'` && tmpunit="%" | ||
71 | + if [ "$tmp" = "0" ]; then | ||
72 | + [ `expr index "$input" "G"` -gt 1 ] && tmp=$[ ${input%*G}*1000 ] && tmpunit="M" | ||
73 | + [ `expr index "$input" "T"` -gt 1 ] && tmp=$[ ${input%*T}*1000*1000 ] && tmpunit="M" | ||
74 | + if [ "$tmp" = "0" ]; then # default: M | ||
75 | + foo=$input | ||
76 | + [ `expr index "$input" "M"` -gt 1 ] && foo=$[ ${input%*M} ] && tmpunit="M" | ||
77 | + tmp=$foo | ||
78 | + fi | ||
79 | + fi | ||
80 | + | ||
81 | + [ $tmp -lt 0 ] && tmp=$[ $totalsize + $tmp ] # ie. -2G | ||
82 | + [ $tmp -lt 0 ] && tmp=0 # ie. the result of the line before was below zero => set to zero. | ||
83 | + | ||
84 | + ReturnVal=$tmp | ||
85 | + ReturnUnit=$tmpunit | ||
86 | + return | ||
87 | +} | ||
88 | + | ||
89 | + | ||
90 | +# do_warncrit_test(warnlevel, critlevel) | ||
91 | +do_warncrit_test() { | ||
92 | + convert_warncrit_val $1 100; tmpwarn=$ReturnVal # use "100" as "size" for percentile checks, since we don't have that already | ||
93 | + convert_warncrit_val $2 100; tmpcrit=$ReturnVal | ||
94 | + | ||
95 | + if [ $tmpwarn -lt 0 ]; then # ie. -2G | ||
96 | + if [ $tmpwarn -gt $tmpcrit ]; then | ||
97 | + echo "UNKNOWN - Warning level is less than Crit" | ||
98 | + exit $STATE_UNKNOWN | ||
99 | + fi | ||
100 | + else | ||
101 | + if [ $tmpwarn -gt $tmpcrit ]; then | ||
102 | + echo "UNKNOWN - Warning level is more than Crit" | ||
103 | + exit $STATE_UNKNOWN | ||
104 | + fi | ||
105 | + fi | ||
106 | +} | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + | ||
111 | case "$1" in | ||
112 | 1) | ||
113 | cmd='--tns' | ||
114 | @@ -171,8 +231,13 @@ | ||
115 | #exit $STATE_OK | ||
116 | #fi | ||
117 | else | ||
118 | - echo "${2} Database is DOWN" | ||
119 | - exit $STATE_CRITICAL | ||
120 | + if [ "${2}" != "" ]; then | ||
121 | + echo "${2} - Database is DOWN (or doesn't exist)" | ||
122 | + exit $STATE_CRITICAL | ||
123 | + else | ||
124 | + echo "UNKNOWN - Please supply a database name" | ||
125 | + exit $STATE_UNKNOWN | ||
126 | + fi | ||
127 | fi | ||
128 | ;; | ||
129 | --login) | ||
130 | @@ -188,11 +253,24 @@ | ||
131 | fi | ||
132 | ;; | ||
133 | --cache) | ||
134 | - if [ ${5} -gt ${6} ] ; then | ||
135 | - echo "UNKNOWN - Warning level is less then Crit" | ||
136 | - exit $STATE_UNKNOWN | ||
137 | + | ||
138 | + [ "$#" -lt 2 ] && print_usage && exit # use empty user/pass for default connection / as sysdba, use empty warncrit for dflt-warncrit | ||
139 | + | ||
140 | + realwarn=$dflt_cachwarn | ||
141 | + realcrit=$dflt_cachcrit | ||
142 | + [ "$6" != "" ] && realwarn=$6 | ||
143 | + [ "$5" != "" ] && realcrit=$5 | ||
144 | + | ||
145 | + do_warncrit_test "$realwarn" "$realcrit" | ||
146 | + | ||
147 | + if [ `expr index "$realwarn" "%"` -lt 1 ]; then | ||
148 | + echo "${2} UNKNOWN - cache check can only use % value for warn/crit level." | ||
149 | + exit $STATE_UNKNOWN | ||
150 | fi | ||
151 | - result=`sqlplus -s ${3}/${4}@${2} << EOF | ||
152 | + | ||
153 | + cmdsqlplus="sqlplus -s / as sysdba" | ||
154 | + [ "$3" != "" ] && [ "$4" != "" ] && cmdsqlplus="sqlplus -s ${3}/${4}@${2}" | ||
155 | + result=`$cmdsqlplus << EOF | ||
156 | set pagesize 0 | ||
157 | set numf '9999999.99' | ||
158 | select (1-(pr.value/(dbg.value+cg.value)))*100 | ||
159 | @@ -210,7 +288,7 @@ | ||
160 | |||
161 | buf_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` | ||
162 | buf_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` | ||
163 | - result=`sqlplus -s ${3}/${4}@${2} << EOF | ||
164 | + result=`$cmdsqlplus << EOF | ||
165 | set pagesize 0 | ||
166 | set numf '9999999.99' | ||
167 | select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 | ||
168 | @@ -226,59 +304,105 @@ | ||
169 | lib_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` | ||
170 | lib_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` | ||
171 | |||
172 | - if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then | ||
173 | - 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" | ||
174 | + # for actually usable warn/crit levels with higher precision number | ||
175 | + convert_warncrit_val "$realwarn" 10000; compwarn=$ReturnVal # $ReturnUnit is being used directly, should be of same type. | ||
176 | + convert_warncrit_val "$realcrit" 10000; compcrit=$ReturnVal | ||
177 | + # just snip of the % of the input to get perfdata | ||
178 | + perfwarn=${realwarn%*%} | ||
179 | + perfcrit=${realcrit%*%} | ||
180 | + | ||
181 | + newbufhr=`echo "$buf_hrx * 10000" | bc -l | sed 's/\.[0-9]*$//g'` | ||
182 | + newlibhr=`echo "$lib_hrx * 10000" | bc -l | sed 's/\.[0-9]*$//g'` | ||
183 | + | ||
184 | + if [ $newbufhr -le $compcrit -o $newlibhr -le $compcrit ] ; then | ||
185 | + echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0; buffer=$buf_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;" | ||
186 | exit $STATE_CRITICAL | ||
187 | fi | ||
188 | - if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then | ||
189 | - 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" | ||
190 | + if [ $newbufhr -le $compwarn -o $newlibhr -le $compwarn ] ; then | ||
191 | + echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0; buffer=$buf_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;" | ||
192 | exit $STATE_WARNING | ||
193 | fi | ||
194 | - 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" | ||
195 | + echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0; buffer=$buf_hrx$ReturnUnit;$perfwarn$ReturnUnit;$perfcrit$ReturnUnit;0;" | ||
196 | |||
197 | exit $STATE_OK | ||
198 | ;; | ||
199 | --tablespace) | ||
200 | - if [ ${6} -lt ${7} ] ; then | ||
201 | - echo "UNKNOWN - Warning level is more then Crit" | ||
202 | - exit $STATE_UNKNOWN | ||
203 | - fi | ||
204 | - result=`sqlplus -s ${3}/${4}@${2} << EOF | ||
205 | + | ||
206 | + [ "$#" -lt 2 ] && print_usage && exit # use empty user/pass for default connection / as sysdba, use empty warncrit for dflt-warncrit... | ||
207 | + | ||
208 | + tsname="$dflt_tsname" | ||
209 | + [ -n "$5" ] && tsname="$5" | ||
210 | + | ||
211 | + realwarn="$dflt_tswarn" | ||
212 | + realcrit="$dflt_tscrit" | ||
213 | + [ "$7" != "" ] && realwarn="$7" | ||
214 | + [ "$6" != "" ] && realcrit="$6" | ||
215 | + do_warncrit_test "$realwarn" "$realcrit" | ||
216 | + | ||
217 | + cmdsqlplus="sqlplus -s / as sysdba" | ||
218 | + [ "$3" != "" ] && [ "$4" != "" ] && cmdsqlplus="sqlplus -s ${3}/${4}@${2}" | ||
219 | + result=`$cmdsqlplus << EOF | ||
220 | set pagesize 0 | ||
221 | set numf '9999999.99' | ||
222 | -select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc | ||
223 | +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 | ||
224 | from ( | ||
225 | -select tablespace_name,sum(bytes)/1024/1024 total | ||
226 | +select tablespace_name,sum(NVL(bytes,0))/1024/1024 total,sum(NVL(maxbytes,0))/1024/1024 maxi | ||
227 | from dba_data_files group by tablespace_name) A | ||
228 | LEFT OUTER JOIN | ||
229 | -( select tablespace_name,sum(bytes)/1024/1024 free | ||
230 | +( select tablespace_name,sum(NVL(bytes,0))/1024/1024 free | ||
231 | from dba_free_space group by tablespace_name) B | ||
232 | -ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; | ||
233 | +ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${tsname}'; | ||
234 | EOF` | ||
235 | |||
236 | if [ -n "`echo $result | grep ORA-`" ] ; then | ||
237 | error=` echo "$result" | grep "ORA-" | head -1` | ||
238 | - echo "CRITICAL - $error" | ||
239 | + echo "${2} : ${tsname} CRITICAL - $error" | ||
240 | exit $STATE_CRITICAL | ||
241 | fi | ||
242 | |||
243 | - ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'` | ||
244 | - ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'` | ||
245 | - ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` | ||
246 | - ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'` | ||
247 | + ts_total= | ||
248 | + ts_used= | ||
249 | + ts_free= | ||
250 | + if [ "${8}" = "max" ]; then | ||
251 | + ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'` | ||
252 | + ts_used=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` | ||
253 | + ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($5)}'` | ||
254 | + else | ||
255 | + ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'` | ||
256 | + ts_used=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` | ||
257 | + ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($4)}'` | ||
258 | + fi | ||
259 | + | ||
260 | + if [ "$ts_total" = "" ]; then | ||
261 | + echo "${2} : ${tsname} UNKNOWN - no data was returned" | ||
262 | + exit $STATE_UNKNOWN | ||
263 | + fi | ||
264 | + | ||
265 | + ts_pctx=`echo "scale=2; $ts_used/$ts_total * 100" | bc -l` | ||
266 | + ts_pct=`echo "scale=0; $ts_used/$ts_total * 100" | bc -l` | ||
267 | + | ||
268 | + # if percentage supplied, use percentage in perfdata | ||
269 | + [ `expr index "%" "$realwarn"` -gt 0 ] && ts_total=1 | ||
270 | + | ||
271 | + convert_warncrit_val "$realwarn" $ts_total; compwarn=$ReturnVal # $ReturnUnit is either % or M for the perfdata | ||
272 | + convert_warncrit_val "$realcrit" $ts_total; compcrit=$ReturnVal | ||
273 | + | ||
274 | + perfused=$ts_pctx | ||
275 | + [ "$ReturnUnit" != "%" ] && perfused=$[ $ts_total - $ts_free ] && ReturnUnit="M" | ||
276 | + | ||
277 | if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then | ||
278 | - echo "No data returned by Oracle - tablespace $5 not found?" | ||
279 | + echo "${2} : ${tsname} UNKNOWN - No data returned by Oracle - tablespace ${tsname} not found?" | ||
280 | exit $STATE_UNKNOWN | ||
281 | fi | ||
282 | - if [ "$ts_pct" -ge ${6} ] ; then | ||
283 | - echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" | ||
284 | + if [ "$ts_pct" -ge "$compcrit" ] ; then | ||
285 | + echo "${2} : ${tsname} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${tsname}=$perfused$ReturnUnit;$compwarn$ReturnUnit;$compcrit$ReturnUnit;0;" | ||
286 | exit $STATE_CRITICAL | ||
287 | fi | ||
288 | - if [ "$ts_pct" -ge ${7} ] ; then | ||
289 | - echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" | ||
290 | + if [ "$ts_pct" -ge "$compwarn" ] ; then | ||
291 | + echo "${2} : ${tsname} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${tsname}=$perfused$ReturnUnit;$compwarn$ReturnUnit;$compcrit$ReturnUnit;0;" | ||
292 | exit $STATE_WARNING | ||
293 | fi | ||
294 | - echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" | ||
295 | + echo "${2} : ${tsname} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${tsname}=$perfused$ReturnUnit;$compwarn$ReturnUnit;$compcrit$ReturnUnit;0;" | ||
296 | exit $STATE_OK | ||
297 | ;; | ||
298 | *) | ||