-
Notifications
You must be signed in to change notification settings - Fork 6
/
check_common_ups
executable file
·462 lines (436 loc) · 19.7 KB
/
check_common_ups
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#!/bin/bash
# this file: /usr/lib64/nagios/plugins/check_common_ups
# Mel - 2016-09-15 - icinga2 check apc ups
# Mel - 2016-09-19 - add cyber power ups checks - Note: CyberPower has some
# "Wrong Type" errors in their MIB file. These are made
# functional by using OID numerics and not OID strings,
# and also not referencing their their MIB file. So I have
# removed the OID strings for APC and removed the -mALL
# variable for consistency.
# Mel - 2016-09-20 - fix cyberpower reports voltage in tenths of volts
# Mel - 2016-09-29 - add bash version check, change sysName to numeric MIB
# for consistency
# Mel - 2017-04-11 - added option to skip battery replace flag check, since
# cyber power 202 and 303 cards (and maybe others) do not
# have this OID. Recommend 205/305 cards instead. However,
# this OID is really just a calculation of last battery
# replace date + 3 years, and battery replace date can
# be manually reset through the web interface.
# Mel - 2017-04-13 - change upstype to autodetect.
# Mel - 2017-04-18 - removed model detect attempt using sysObjectID
# Note: For sysDescr CyberPower always returns "UPS SNMP Card"
# across all cards tested. APC returns full details, example:
# APC Web/SNMP Management Card (MB:v4.0.1 PF:v6.1.1 PN:apc_hw05_aos_611.bin AF1:v6.1.1 AN1:apc_hw05_sumx_611.bin MN:AP9630 HR:05 SN: ZA1425004783 MD:06/18/2014) (Embedded PowerNet SNMP Agent SW v2.2 compatible)
# Mel - 2017-04-28 - Fix calibration/diagnostic days result in perfdata when
# they have not been run
# Mel - 2017-05-10 - Typo: unsuppoted
# !!!!!!!!!!!!!!!!!!!!!!!!!!! REQUIRES BASH 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# THE PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT
# ANY WARRANTY. IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
# EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION. IN NO EVENT WILL THE AUTHOR BE LIABLE TO YOU FOR
# DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
# LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED
# BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGES.
version="2017-05-10"
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]];then
echo "Requires bash version >= 4"
exit 1
fi
requiredsoftware="snmpget:net-snmp-utils bc:bc"
for x in $requiredsoftware;do
if [[ "$(which ${x%%:*} 2>/dev/null)" == "" ]];then
stillneeded="$stillneeded ${x##*:}"
echo "Missing software: ${x%%:*}"
fi
done
if [[ ! -z $stillneeded ]];then
echo "Install missing software with:"
echo "yum -y install $stillneeded"
exit 1
fi
usage(){
cat << MEL
Usage:
$(basename $0) [OPTION]... [OPTION]...
Options:
-b, --onbattcrit Set CRITICAL any time ups is on battery. Without this
"on battery" is only warning. In that case final status would only
be warning until run time falls below critical level (set by -R)
-B, --noreplaceck, Do not check battery replace status. The battery
replace status is just a calculation the battery replaced date plus
3 years. The battery replace date can be set in the web interface.
The cyber 202 and 303 cards (and maybe others) do not have this OID.
-C STRING, --community STRING, The SNMP community string. Defaults to
"public".
-d CHAR, --degrees CHAR, Accepted values are C, c, F, or f. For celsius or
fahrenheit. Invalid values or not set will default to fahrenheit. This
setting is also used by -t and -T to determine default values.
-h, --help Show this help message.
-H HOSTNAME, --host HOST, Set HOSTNAME or IP to check.
-i INTEGER, --inlow INTEGER, Set WARNING status if input voltage is less
than INTEGER. Values are not checked for sanity, except inlow must be
less than inhigh. Defaults to 106.
-I INTEGER, --inhigh INTEGER, Set WARNING status if input voltage is
greater than INTEGER. Values are not checked for sanity, except inlow
must be less than inhigh. Defaults to 133. (Note: inlow and inhigh
can result in CRITICAL status if -v flag is set)
-l INTEGER, --warnload INTEGER, Set WARNING status if ups load is greater
than INTEGER. loadwarn values should be less than loadcrit values.
Defaults to 70.
-L INTEGER, --critload INTEGER, Set CRITICAL status if ups load is greater
than INTEGER. loadcrit values less than loadwarn values will be set to
loadwarn +1. Defaults to 80.
-r INTEGER, --warnrun INTEGER, Set WARNING status if runtime is less than
INTEGER minutes. If not set, defaults to 10. Minimum value is 2.
-R INTEGER, --critrun INTEGER, Set CRITICAL status if runtime is less than
INTEGER minutes. If not set, defaults to 8. critrun values greater than
warnrun values will be set to warnrun -1. Minimum value is 1.
-t INTEGER, --warntemp INTEGER, Set WARNING status if battery temperature
is more than INTEGER degrees. Celsius or fahrenheit is set by -d.
If not set, defaults to 45 celsius, or 113 fahrenheit (see -d)
-T INTEGER, --crittemp INTEGER, Set CRITICAL status if battery temperature
is more than INTEGER degrees Celsius or fahrenheit is set by -d.
Crit values not greater than warn values will be set to warn value +1.
If not set, defaults to 50 celsius, or 122 fahrenheit. (see -d)
-v, --voltcrit Set CRITICAL for input voltage low or high results. (-i
and -I)
-V --version Show version information.
-w INTEGER, --diagwarn INTEGER, Set WARNING status if number of days since
last diagnostic is more than INTEGER days. Default is 15. This test may
be disabled with -x.
-W INTEGER, --diagcrit INTEGER, Set CRITICAL status if number of days since
last diagnostic is more than INTEGER days. Default is 20. This test may
be disabled with -x.
-x, --nodiagck Disables test for number of days since last diagnostic.
Implies -z.
-X, --nocalibck Disables test for number of days since last calibration.
-y INTEGER, --calibwarn INTEGER, Set WARNING status if number of days since
last calibration is more than INTEGER days. This test may be disabled
with -X. Default is 365.
-Y INTEGER, --calibcrit INTEGER, Set CRITICAL status if number of days since
last calibration is more than INTEGER days. This test may be disabled
with -X. Default is 400.
-z, --nodiagdata Disables diagnostic days performance data.
-Z, --nocalibdata Disables calibration days performance data.
Example:
$(basename $0) -H 10.1.2.3 -C public -b -d c -i 105 -I 133 -l 20 -L 40 -r 15 -R 10 -t 44 -T 51 -w 14 -W 21 -X
MEL
}
# FIXME replace below with some test for snmp version, and ummm... add support for other versions (user, password, etc)
SNMPget="snmpget -v1"
showver(){
echo "$(basename $0) version $version"
}
# sets variable snmpresult
snmpPoll(){
snmpresult="$($SNMPget -c $community $MALL $upsip $1 2>/dev/null)"
if [[ $? -ne 0 ]];then
echo "CRITICAL: $upsip $upsmodel not responding to $2 SNMP poll. snmpresult=$snmpresult"
exit 2
fi
}
# set some defaults here that may get changed by arguments below
community="public"
voltcrit="WARN"
onbatt="WARN"
# run time
runwarn=10
runcrit=8
# Input Voltage
inlow=106
inhigh=133
# Output Load
loadcrit=80
loadwarn=70
# diagnostic days
diagwarn=15
diagcrit=20
# calibration days
calibwarn=365
calibcrit=400
while getopts "bBC:d:hH:i:I:l:L:r:R:t:T-:u:vVw:W:xXy:Y:zZ" opt; do
case $opt in
b) onbatt="CRIT" ;;
B) ckreplc="no" ;;
C) community="$OPTARG" ;;
d) degrees="${OPTARG:0:1}" ;;
h) usage;exit ;;
H) upsip="$OPTARG" ;;
i) inlow=$OPTARG ;;
I) inhigh=$OPTARG ;;
l) loadwarn=$OPTARG ;;
L) loadcrit=$OPTARG ;;
r) runwarn=$OPTARG ;;
R) runcrit=$OPTARG ;;
t) tempwarn=$OPTARG ;;
T) tempcrit=$OPTARG ;;
u) upstype=$OPTARG ;;
v) voltcrit="CRIT" ;;
V) showver;exit ;;
w) diagwarn=$OPTARG ;;
W) diagcrit=$OPTARG ;;
x) diagtest="no";diagdata="no" ;;
X) calibtest="no";calibdata="no" ;;
y) calibwarn=$OPTARG ;;
Y) calibcrit=$OPTARG ;;
z) diagdata="no" ;;
Z) calibdata="no" ;;
-)
# long args for official compatibility...
case $OPTARG in
help) usage;exit ;;
version) showver;exit ;;
community) community="${!OPTIND}";shift $OPTIND;OPTIND=1;;
degrees) degrees="${OPTARG:0:1}" ;;
crittemp) tempcrit=${!OPTIND};shift $OPTIND;OPTIND=1;;
warntemp) tempwarn=${!OPTIND};shift $OPTIND;OPTIND=1;;
critrun) runcrit=${!OPTIND};shift $OPTIND;OPTIND=1;;
warnrun) runwarn=${!OPTIND};shift $OPTIND;OPTIND=1;;
critload) loadcrit=${!OPTIND};shift $OPTIND;OPTIND=1;;
warnload) loadwarn=${!OPTIND};shift $OPTIND;OPTIND=1;;
inhigh) inhigh=${!OPTIND};shift $OPTIND;OPTIND=1;;
inlow) inlow=${!OPTIND};shift $OPTIND;OPTIND=1;;
host) upsip="${!OPTIND}";shift $OPTIND;OPTIND=1;;
onbattcrit) onbatt="CRIT" ;;
noreplaceck)ckreplc="no";shift $OPTIND;OPTIND=1;;
upstype) upstype="${!OPTIND}";shift $OPTIND;OPTIND=1;;
voltcrit) voltcrit="CRIT" ;;
diagwarn) diagwarn=${!OPTIND};shift $OPTIND;OPTIND=1;;
diagcrit) diagcrit=${!OPTIND};shift $OPTIND;OPTIND=1;;
nodiagck) diagtest="no";diagdata="no" ;;
nocalibck) calibtest="no";calibdata="no" ;;
calibwarn) calibwarn=${!OPTIND};shift $OPTIND;OPTIND=1;;
calibcrit) calibcrit=${!OPTIND};shift $OPTIND;OPTIND=1;;
nodiagdata) diagdata="no" ;;
nocalibdata) calibdata="no" ;;
*)
echo "Invalid long argument: --$OPTARG";usage;exit 1;;
esac ;;
\?) echo "Invalid short argument: -$OPTARG";usage;exit 1 ;;
esac
done
sysName="1.3.6.1.2.1.1.5.0"
sysObjectID="1.3.6.1.2.1.1.2.0"
# check which brand of ups
snmpPoll "$sysObjectID" sysObjectID
upsvendorID="${snmpresult##*:}"
upsvendorID="${upsvendorID#*.}"
upsvendorID="${upsvendorID%%.*}"
case ${upsvendorID} in
318) upstype="apc";upsvendorPrettyName="APC";;
3808) upstype="cyber";upsvendorPrettyName="CyberPower";;
*) upstype="unsupported";upsvendorPrettyName="Unsupported";;
esac
case ${upstype} in
cyber)
MIBmodel="1.3.6.1.4.1.3808.1.1.1.1.1.1.0"
MIBbatTemp="1.3.6.1.4.1.3808.1.1.1.2.2.3.0"
MIBinVolts="1.3.6.1.4.1.3808.1.1.1.3.2.1.0"
MIBoutLoad="1.3.6.1.4.1.3808.1.1.1.4.2.3.0"
MIBrunTime="1.3.6.1.4.1.3808.1.1.1.2.2.4.0"
MIBbatReplc="1.3.6.1.4.1.3808.1.1.1.2.2.5.0"
MIBtimeOnBat="1.3.6.1.4.1.3808.1.1.1.2.1.2.0"
MIBcalibResult="1.3.6.1.4.1.3808.1.1.1.7.2.7.0"
MIBdiagResult="1.3.6.1.4.1.3808.1.1.1.7.2.3.0"
MIBlastDiag="1.3.6.1.4.1.3808.1.1.1.7.2.4.0"
MIBcalibDate="1.3.6.1.4.1.3808.1.1.1.7.2.8.0"
;;
apc)
MIBmodel="1.3.6.1.4.1.318.1.1.1.1.1.1.0"
MIBbatTemp="1.3.6.1.4.1.318.1.1.1.2.2.2.0"
MIBinVolts="1.3.6.1.4.1.318.1.1.1.3.2.1.0"
MIBoutLoad="1.3.6.1.4.1.318.1.1.1.4.2.3.0"
MIBrunTime="1.3.6.1.4.1.318.1.1.1.2.2.3.0"
MIBbatReplc="1.3.6.1.4.1.318.1.1.1.2.2.4.0"
MIBtimeOnBat="1.3.6.1.4.1.318.1.1.1.2.1.2.0"
MIBcalibResult="1.3.6.1.4.1.318.1.1.1.7.2.6.0"
MIBdiagResult="1.3.6.1.4.1.318.1.1.1.7.2.3.0"
MIBlastDiag="1.3.6.1.4.1.318.1.1.1.7.2.4.0"
MIBcalibDate="1.3.6.1.4.1.318.1.1.1.7.2.7.0"
;;
*)
echo "Unsupported upstype: $upstype";exit 1;;
esac
if [[ -z $upsip ]];then
echo "CRITICAL: Hostname or IP not given"
exit 2
fi
# set any unset values
degrees="${degrees,,}"
[[ $degrees != "f" ]] && [[ $degrees != "c" ]] && degrees="f"
if [[ $degrees == "f" ]];then
[[ -z $tempwarn ]] && tempwarn=113
[[ -z $tempcrit ]] && tempcrit=122
else
[[ -z $tempwarn ]] && tempwarn=45
[[ -z $tempcrit ]] && tempcrit=50
fi
[[ $tempwarn -gt $tempcrit ]] && tempcrit=$((10#${tempwarn}+1))
# run time
[[ $runwarn -lt 2 ]] && runwarn=2
[[ $runcrit -lt 1 ]] && runcrit=1
[[ $runcrit -lt $runwarn ]] || runcrit=$((10#${runwarn}-1))
exitstatus=0
snmpPoll "$sysName" sysName
upshostname="${snmpresult##* }"
upshostname="${upshostname//\"/}"
# to show UPS model in output
snmpPoll "$MIBmodel" upsModel
upsmodel="${snmpresult#*\"}"
upsmodel="${upsmodel//\"/}"
snmpPoll "$MIBtimeOnBat" OnBattery
onbattime="${snmpresult##* }"
if [[ $onbattime != "0:00:00.00" ]];then
[[ $onbatt == "CRIT" ]] && exitstatus=2 || exitstatus=1
exitstring="$onbatt: on battery"
fi
snmpPoll "$MIBdiagResult" DiagnosticResult
diagnostic="${snmpresult##* }"
if [[ $diagnostic != "ok(1)" ]] && [[ $diagnostic != "1" ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: diagnostics error" || exitstring="$exitstring, CRIT: diagnostics error"
fi
if [[ $diagtest != "no" ]];then
snmpPoll "$MIBlastDiag" DiagnosticDate
diagdate="${snmpresult#*\"}"
diagdate="${diagdate//\"/}"
if [[ $diagdate =~ [0-9]{2}/[0-9]{2}/[0-9]{4} ]];then
lastdiagsecs="$(date -d "$diagdate" +%s)"
nowsecs="$(date +%s)"
diagdays=$(((nowsecs-lastdiagsecs)/86400))
if [[ $diagdays -gt $diagwarn ]];then
if [[ $diagdays -gt $diagcrit ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: diagnostic overdue: $diagdays > $diagcrit days" || exitstring="$exitstring, CRIT: diagnostic overdue: $diagdays > $diagcrit days"
else
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ -z $exitstring ]] && exitstring="WARN: diagnostic overdue: $diagdays > $diagwarn days" || exitstring="$exitstring, WARN: diagnostic overdue: $diagdays > $diagwarn days"
fi
fi
else
diagdays=$diagcrit
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: invalid diagnostic date" || exitstring="$exitstring, CRIT: invalid diagnostic date"
fi
fi
snmpPoll "$MIBcalibResult" CalibrationResult
calibration="${snmpresult##* }"
if [[ $calibration != "ok(1)" ]] && [[ $calibration != "1" ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: calibration error" || exitstring="$exitstring, CRIT: calibration error"
fi
if [[ $calibtest != "no" ]];then
snmpPoll "$MIBcalibDate" CalibrationDate
calibdate="${snmpresult#*\"}"
calibdate="${calibdate//\"/}"
if [[ $calibdate =~ [0-9]{2}/[0-9]{2}/[0-9]{4} ]];then
lastcalibsecs="$(date -d "$calibdate" +%s)"
nowsecs="$(date +%s)"
calibdays=$(((nowsecs-lastcalibsecs)/86400))
if [[ $calibdays -gt $calibwarn ]];then
if [[ $calibdays -gt $calibcrit ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: calibration overdue: $calibdays > $calibcrit days" || exitstring="$exitstring, CRIT: calibration overdue: $calibdays > $calibcrit days"
else
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ -z $exitstring ]] && exitstring="WARN: calibration overdue: $calibdays > $calibwarn days" || exitstring="$exitstring, WARN: calibration overdue: $calibdays > $calibwarn days"
fi
fi
else
calibdays=$calibcrit
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: invalid calibration date" || exitstring="$exitstring, CRIT: invalid calibration date"
fi
fi
if [[ $ckreplc != "no" ]];then
snmpPoll "$MIBbatReplc" BatteryReplace
battstat="${snmpresult##* }"
if [[ ! $battstat =~ ^noBatteryNeedsReplacing.* ]] && [[ $battstat != "1" ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: battery needs replaced" || exitstring="$exitstring, CRIT: battery needs replaced"
fi
fi
snmpPoll "$MIBrunTime" RunTime
rtfull="${snmpresult##* }"
rthrs="${rtfull%%:*}"
rtmin="${rtfull%:*}"
rtmin="${rtmin#*:}"
runtime=$(((10#${rthrs}*60)+10#${rtmin}))
if [[ $runtime -lt $runwarn ]];then
if [[ $runtime -lt $runcrit ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: runtime: $runtime < $runcrit" || exitstring="$exitstring, CRIT: runtime: $runtime < $runcrit"
else
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ -z $exitstring ]] && exitstring="WARN: runtime: $runtime < $runwarn" || exitstring="$exitstring, WARN: runtime: $runtime < $runwarn"
fi
fi
snmpPoll "$MIBoutLoad" Load
load="${snmpresult##* }"
if [[ $load -gt $loadwarn ]];then
if [[ $load -gt $loadcrit ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: load: $load > $loadcrit" || exitstring="$exitstring, CRIT: load: $load > $loadcrit"
else
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ -z $exitstring ]] && exitstring="WARN: load $load > $loadwarn" || exitstring="$exitstring, WARN: load $load > $loadwarn"
fi
fi
snmpPoll "$MIBinVolts" LineVoltage
involts="${snmpresult##* }"
# cyberpower reports tenths of volts
if [[ ${upstype} == "cyber" ]];then
involtsdata="${involts:0:3}.${involts:3}"
involts="${involts:0:3}"
else
involtsdata=$involts
fi
if [[ $involts -lt $inlow ]];then
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ $voltcrit == "CRIT" ]] && exitstatus=2
[[ -z $exitstring ]] && exitstring="$voltcrit: line voltage: $involt < $inlow" || exitstring="$exitstring, $voltcrit: line voltage: $involt < $inlow"
elif [[ $involts -gt $inhigh ]];then
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ $voltcrit == "CRIT" ]] && exitstatus=2
[[ -z $exitstring ]] && exitstring="$voltcrit: line voltage: $involt > $inhigh" || exitstring="$exitstring, $voltcrit: line voltage: $involt > $inhigh"
fi
snmpPoll "$MIBbatTemp" BatteryTemperature
tempc="${snmpresult##* }"
tempf="$(echo "(9*$tempc/5)+32"|bc)"
if [[ $degrees == "c" ]];then
temp=$tempc
temppref="${tempc}c"
tempalt="${tempf}f"
else
temp=$tempf
temppref="${tempf}f"
tempalt="${tempc}c"
fi
if [[ $temp -gt $tempwarn ]];then
if [[ $temp -gt $tempcrit ]];then
exitstatus=2
[[ -z $exitstring ]] && exitstring="CRIT: temp $temppref($tempalt) > $tempcrit$degrees" || exitstring="$exitstring, CRIT: temp $temppref($tempalt) > $tempcrit$degrees"
else
[[ $exitstatus -lt 1 ]] && exitstatus=1
[[ -z $exitstring ]] && exitstring="WARN: temp $temppref($tempalt) > $tempwarn$degrees" || exitstring="$exitstring, WARN: temp $temppref($tempalt) > $tempwarn$degrees"
fi
fi
perfdata=";| Temp=$temp;$tempwarn;$tempcrit;0 Line_Voltage=$involtsdata;$inhigh;;$inlow Load=$load;$loadwarn;$loadcrit;0 RunTime=$runtime;$runwarn;$runcrit;0"
[[ $diagdata == "no" ]] || perfdata="$perfdata Diagnostic=${diagdays:-0};$diagwarn;$diagcrit;0"
[[ $calibdata == "no" ]] || perfdata="$perfdata Calibration=${calibdays:-0};$calibwarn;$calibcrit;0"
[[ -z $exitstring ]] && exitstring="OK"
exitstring="host: $upshostname: $upsvendorPrettyName ${upsmodel:-(Unknown Model)}: $exitstring$perfdata"
case $exitstatus in
0) echo "OK: $exitstring";;
1) echo "WARNING: $exitstring";;
2) echo "CRITICAL: $exitstring";;
*) echo "UNKNOWN: $exitstring";;
esac
exit $exitstatus