forked from vita2/check_qnap4
/
check_qnap3.sh
executable file
·707 lines (621 loc) · 21.3 KB
/
check_qnap3.sh
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
#!/usr/bin/env bash
############################# Written and Manteined by Nicola Bandini ###############
############################# Created and written by Matthias Luettermann ###############
############################# finetuning by primator@gmail.com
############################# finetuning by n.bandini@gmail.com
############################# finetuning by vitamin.b@mailbox.org
############################# with code by Tom Lesniak and Hugo Geijteman
#
# copyright (c) 2008 Shahid Iqbal
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# contact the author directly for more information at: matthias@xcontrol.de
##########################################################################################
#Version 1.23
plgVer=1.24
usage() {
echo
echo "Check_QNAP3 $plgVer"
echo
echo "Warning: Wrong command line arguments."
echo
echo "Usage: ${0##*/} [-V protocol] -H <hostname> -C <community> -p <part> -w <warning> -c <critical>"
echo
echo "Where: -p|--part - part to check"
echo " -h - no human-readable output; do not use unit suffixes"
echo " -w|--warning - warning"
echo " -c|--critical - critical"
echo " --help - show this help"
echo
echo "SNMP specific"
echo " -H|--hostname - hostname or IP"
echo " -V - SNMP protocol version to use (1, 2c, 3); default: 2c"
echo " -P|--port - SNMP port; default: 161"
echo
echo "SNMP Version 1|2c specific"
echo " -C|--community - SNMP community name; default: public"
echo
echo "SNMP Version 3 specific"
echo " -l|--level - security level (noAuthNoPriv|authNoPriv|authPriv)"
echo " -u|--user - security name"
echo " -a|--authprotocol - authentication protocol (MD5|SHA)"
echo " -A|--authpassphrase - authentication protocol pass phrase"
echo " -x|--privprotocol - privacy protocol (DES|AES)"
echo " -X|--privpassphrase - privacy protocol pass phrase"
echo
echo "Parts are: status, sysinfo, systemuptime, temp, cpu, cputemp, freeram, powerstatus, fans, diskused, hdstatus, hd#status, hd#temp, volstatus (Raid Volume Status), vol#status"
echo
echo "hdstatus shows status & temp; volstatus checks all vols and vols space; powerstatus checks power supply"
echo "<#> is 1-8 for hd, 1-5 for vol"
echo
echo " Example for diskusage: ${0##*/} 127.0.0.1 public diskused 80 95"
echo
echo " Example for volstatus: ${0##*/} 127.0.0.1 public volstatus 15 10"
echo " critical and warning value are related to free disk space"
echo
echo " Example for fans: ${0##*/} 127.0.0.1 public fans 2000 1900"
echo " critical and warning are minimum speed in rpm for fans"
echo
exit 3
}
strProtocol="2c"
strCommunity="public"
strPort="161"
PARSED_OPTIONS=$(getopt -n "$0" -o V:H:C:p:hw:c:l:u:a:A:x:X:P: --long "hostname:,community:,part:,warning:,critical:,level:,user:,authprotocol:,authpassphrase:,privprotocol:,privpassphrase:,port:,help" -- "$@")
if [ $? -ne 0 ]; then
exit 1
fi
#if [ -n $1 ]; then
# usage
#fi
eval set -- "$PARSED_OPTIONS"
while true; do
case "$1" in
--help)
usage
shift
;;
-C|--community)
strCommunity="$2"
shift 2
;;
-P|--port)
strPort="$2"
shift 2
;;
-h)
inhuman=1
shift
;;
-H|--hostname)
strHostname="$2"
shift 2
;;
-p|--part)
strPart="$2"
shift 2
;;
-V)
if [ -n "$2" ]; then
strProtocol="$2"
case "$strProtocol" in
1|2c|3)
;;
*)
echo "ERROR: wrong protocol version" >&2
exit 3
;;
esac
fi
shift 2
;;
-w|--warning)
strWarning="$2"
shift 2
;;
-c|--critical)
strCritical="$2"
shift 2
;;
-l|--level)
if [ -n "$2" ]; then
strLevel="$2"
case "$strLevel" in
noAuthNoPriv|authNoPriv|authPriv)
;;
*)
echo "ERROR: wrong security level" >&2
exit 3
;;
esac
fi
shift 2
;;
-u|--user)
if [ -n "$2" ]; then
strUser="$2"
fi
shift 2
;;
-a|--authprotocol)
if [ -n "$2" ]; then
strAuthprotocol="${2,,}"
case "$strAuthprotocol" in
md5|sha)
;;
*)
echo "ERROR: wrong authentication protocol" >&2
exit 3
;;
esac
fi
shift 2
;;
-A|--authpassphrase)
if [ -n "$2" ]; then
strAuthpassphrase="$2"
else
echo "ERROR: authentification passphrase is missing" >&2
exit 3
fi
shift 2
;;
-x|--privprotocol)
if [ -n "$2" ]; then
strPrivprotocol="${2,,}"
case "$strPrivprotocol" in
des|aes)
;;
*)
echo "ERROR: wrong privacy protocol" >&2
exit 3
;;
esac
fi
shift 2
;;
-X|--privpassphrase)
if [ -n "$2" ]; then
strPrivpassphrase="$2"
else
echo "ERROR: privacy passphrase is missing" >&2
exit 3
fi
shift 2
;;
--)
shift
break
;;
esac
done
function _cmdparam() {
case "$strProtocol" in
1|2c)
cmd="-v $strProtocol -c $strCommunity"
;;
3)
cmd="-v $strProtocol -u $strUser -l $strLevel -a $strAuthprotocol -A $strAuthpassphrase -x $strPrivprotocol -X $strPrivpassphrase"
;;
esac
if [ -n "$strPort" ]; then
cmd="$cmd $strHostname:$strPort"
else
cmd="$cmd $strHostname"
fi
echo "$cmd"
}
function _snmpget() {
snmpget $(_cmdparam) "$@"
}
function _snmpgetval() {
snmpget $(_cmdparam) -Oqv "$@"
}
function _snmpstatus() {
snmpstatus $(_cmdparam) "$@"
}
function _get_exp() {
case "$1" in
PB) echo "50" ;;
TB) echo "40" ;;
GB) echo "30" ;;
MB) echo "20" ;;
KB) echo "10" ;;
'') echo "0" ;;
*) echo "ERROR: unknown unit '$1'" ;;
esac
}
# Check if QNAP is online
TEST="$(_snmpstatus -t 5 -r 0 2>&1)"
if [ "$TEST" == "Timeout: No Response from $strHostname" ]; then
echo "CRITICAL: SNMP to $strHostname is not available or wrong community string";
exit 2;
fi
# STATUS ---------------------------------------------------------------------------------------------------------------------------------------
if [ "$strPart" == "status" ]; then
echo "$TEST";
# DISKUSED ---------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "diskused" ]; then
diskStr="$(_snmpget 1.3.6.1.4.1.24681.1.2.17.1.4.1)"
freeStr="$(_snmpget 1.3.6.1.4.1.24681.1.2.17.1.5.1)"
diskSize="$(echo "$diskStr" | awk '{print $4}' | sed 's/.\(.*\)/\1/')"
freeSize="$(echo "$freeStr" | awk '{print $4}' | sed 's/.\(.*\)/\1/')"
diskUnit="$(echo "$diskStr" | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')"
freeUnit="$(echo "$freeStr" | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')"
diskExp="$(_get_exp "$diskUnit")"
freeExp="$(_get_exp "$freeUnit")"
disk="$(echo "scale=0; $diskSize*(2^$diskExp)" | bc -l)"
free="$(echo "scale=0; $freeSize*(2^$freeExp)" | bc -l)"
used="$(echo "scale=0; $disk-$free" | bc -l)"
perc="$(echo "scale=0; $used*100/$disk" | bc -l)"
diskH="$(echo "scale=2; $disk/(2^$diskExp)" | bc -l)"
freeH="$(echo "scale=2; $free/(2^$freeExp)" | bc -l)"
usedH="$(echo "scale=2; $used/(2^$diskExp)" | bc -l)"
if [ "${inhuman:-0}" -eq 1 ]; then
diskF="$disk"
freeF="$free"
usedF="$used"
else
diskF="$diskH$diskUnit"
freeF="$freeH$freeUnit"
usedF="$usedH$diskUnit"
fi
#wdisk=$(echo "scale=0; $strWarning*$disk/100" | bc -l)
#cdisk=$(echo "scale=0; $strCritical*$disk/100" | bc -l)
OUTPUT="Total:$diskF - Used:$usedF - Free:$freeF - Used Space: $perc%|Used=$perc;$strWarning;$strCritical;0;100"
if [ $perc -ge $strCritical ]; then
echo "CRITICAL: $OUTPUT"
exit 2
elif [ $perc -ge $strWarning ]; then
echo "WARNING: $OUTPUT"
exit 1
else
echo "OK: $OUTPUT"
exit 0
fi
# CPU ----------------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "cpu" ]; then
CPU="$(_snmpgetval 1.3.6.1.4.1.24681.1.2.1.0 | sed -E 's/"([0-9.]+) ?%"/\1/')"
OUTPUT="CPU Load=$CPU%|CPU load=$CPU%;$strWarning;$strCritical;0;100"
if (( $(echo "$CPU > $strCritical" | bc -l) )); then
echo "CRITICAL: $OUTPUT"
exit 2
elif (( $(echo "$CPU > $strWarning" | bc -l) )); then
echo "WARNING: $OUTPUT"
exit 1
else
echo "OK: $OUTPUT"
exit 0
fi
# CPUTEMP ----------------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "cputemp" ]; then
TEMP0="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.5.0 | sed -E 's/"([0-9.]+) ?C.*/\1/')"
OUTPUT="CPU Temperature=${TEMP0}C|NAS CPUtemperature=${TEMP0}C;$strWarning;$strCritical;0;90"
if [ "$TEMP0" -ge 89 ]; then
echo "CPU temperature too high!: $OUTPUT"
exit 3
else
if [ "$TEMP0" -ge "$strCritical" ]; then
echo "CRITICAL: $OUTPUT"
exit 2
fi
if [ "$TEMP0" -ge "$strWarning" ]; then
echo "WARNING: $OUTPUT"
exit 1
fi
echo "OK: $OUTPUT"
exit 0
fi
# Free RAM---------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "freeram" ]; then
totalMemStr="$(_snmpgetval 1.3.6.1.4.1.24681.1.2.2.0)"
freeMemStr="$(_snmpgetval 1.3.6.1.4.1.24681.1.2.3.0)"
totalMemSize="$(echo "$totalMemStr" | sed -E 's/"([0-9.]+) ?.?B"/\1/')"
freeMemSize="$(echo "$freeMemStr" | sed -E 's/"([0-9.]+) ?.?B"/\1/')"
totalMemUnit="$(echo "$totalMemStr" | sed -E 's/"[0-9.]+ ?(.?B)"/\1/')"
freeMemUnit="$(echo "$freeMemStr" | sed -E 's/"[0-9.]+ ?(.?B)"/\1/')"
totalMemExp="$(_get_exp "$totalMemUnit")"
freeMemExp="$(_get_exp "$freeMemUnit")"
totalMem="$(echo "scale=0; $totalMemSize*(2^$totalMemExp)" | bc -l)"
freeMem="$(echo "scale=0; $freeMemSize*(2^$freeMemExp)" | bc -l)"
usedMem="$(echo "scale=0; $totalMem-$freeMem" | bc -l)"
percMem="$(echo "scale=0; $usedMem*100/$totalMem" | bc -l)"
totalMemH="$(echo "scale=1; $totalMem/(2^$totalMemExp)" | bc -l)"
freeMemH="$(echo "scale=1; $freeMem/(2^$freeMemExp)" | bc -l)"
usedMemH="$(echo "scale=1; $usedMem/(2^$freeMemExp)" | bc -l)"
if [ "${inhuman:-0}" -eq 1 ]; then
totalMemF="$totalMem"
freeMemF="$freeMem"
usedMemF="$usedMem"
else
totalMemF="$totalMemH$totalMemUnit"
freeMemF="$freeMemH$freeMemUnit"
usedMemF="$usedMemH$freeMemUnit"
fi
OUTPUT="Total:$totalMemF - Used:$usedMemF - Free:$freeMemF = $percMem%|Memory usage=$percMem%;$strWarning;$strCritical;0;100"
if [ $percMem -ge $strCritical ]; then
echo "CRITICAL: $OUTPUT"
exit 2
elif [ $percMem -ge $strWarning ]; then
echo "WARNING: $OUTPUT"
exit 1
else
echo "OK: $OUTPUT"
exit 0
fi
# System Temperature---------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "temp" ]; then
TEMP0="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.6.0 | sed -E 's/"([0-9.]+) ?C.*/\1/')"
OUTPUT="Temperature=${TEMP0}C|NAS temperature=${TEMP0}C;$strWarning;$strCritical;0;80"
if [ "$TEMP0" -ge 89 ]; then
echo "System temperature too high!: $OUTPUT"
exit 3
else
if [ "$TEMP0" -ge "$strCritical" ]; then
echo "CRITICAL: $OUTPUT"
exit 2
fi
if [ "$TEMP0" -ge "$strWarning" ]; then
echo "WARNING: $OUTPUT"
exit 1
fi
echo "OK: $OUTPUT"
exit 0
fi
# HD# Temperature---------------------------------------------------------------------------------------------------------------------------------------
elif [[ "$strPart" == hd?temp ]]; then
hdnum="$(echo "$strPart" | sed -E 's/hd([0-9]+)temp/\1/')"
TEMPHD="$(_snmpgetval "1.3.6.1.4.1.24681.1.2.11.1.3.$hdnum" | sed -E 's/"([0-9.]+) ?C.*/\1/')"
OUTPUT="Temperature=${TEMPHD}C|HDD$hdnum temperature=${TEMPHD}C;$strWarning;$strCritical;0;60"
if [ "$(echo "$TEMPHD" | sed -E 's/[0-9.]+//g')" != "" ]; then
echo "ERROR: $TEMPHD"
exit 4
fi
if [ "$TEMPHD" -ge "59" ]; then
echo "HDD$hdnum temperature too high!: $OUTPUT"
exit 3
else
if [ "$TEMPHD" -ge "$strCritical" ]; then
echo "CRITICAL: $OUTPUT"
exit 2
fi
if [ "$TEMPHD" -ge "$strWarning" ]; then
echo "WARNING: $OUTPUT"
exit 1
fi
echo "OK: $OUTPUT"
exit 0
fi
# Volume # Status----------------------------------------------------------------------------------------------------------------------------------------
elif [[ "$strPart" == vol?status ]]; then
volnum="$(echo "$strPart" | sed -E 's/vol([0-9]+)status/\1/')"
Vol_Status="$(_snmpgetval "1.3.6.1.4.1.24681.1.2.17.1.6.$volnum" | sed 's/^"\(.*\).$/\1/')"
if [[ "$Vol_Status" == 'No Such Instance'* ]]; then
echo "ERROR: $Vol_Status"
exit 4
elif [ "$Vol_Status" == "Ready" ]; then
echo "OK: $Vol_Status"
exit 0
elif [ "$Vol_Status" == "Rebuilding..." ]; then
echo "WARNING: $Vol_Status"
exit 1
else
echo "CRITICAL: $Vol_Status"
exit 2
fi
# HD# Status----------------------------------------------------------------------------------------------------------------------------------------
elif [[ "$strPart" == hd?status ]]; then
hdnum="$(echo "$strPart" | sed -E 's/hd([0-9]+)status/\1/')"
HDstat="$(_snmpgetval "1.3.6.1.4.1.24681.1.2.11.1.7.$hdnum" | sed 's/^"\(.*\).$/\1/')"
if [[ "$HDstat" == 'No Such Instance'* ]]; then
echo "ERROR: $HDstat"
exit 4
elif [ "$HDstat" == "GOOD" ]; then
echo "OK: GOOD"
exit 0
else
echo "CRITICAL: ERROR"
exit 2
fi
# HD Status----------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "hdstatus" ]; then
hdnum="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.10.0)"
hdok=0
hdnop=0
output_crit=""
for (( c=1; c<=$hdnum; c++ ))
do
HD="$(_snmpgetval "1.3.6.1.4.1.24681.1.2.11.1.7.$c" | sed 's/^"\(.*\).$/\1/')"
if [ "$HD" == "GOOD" ]; then
((hdok+=1))
elif [ "$HD" == "--" ]; then
((hdnop+=1))
else
output_crit="${output_crit} Disk ${c}"
fi
done
if [ -n "$output_crit" ]
then
echo "CRITICAL: ${output_crit}"
exit 2
else
echo "OK: Online Disk $hdok, Free Slot $hdnop"
exit 0
fi
# Volume Status----------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "volstatus" ]; then
ALLOUTPUT=""
PERFOUTPUT=""
WARNING=0
CRITICAL=0
VOL=1
VOLCOUNT="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.16.0)"
if [ "$strWarning" -lt "$strCritical" ]; then
echo "Warning threshold ($strWarning) is less than critical threshold ($strCritical) ! -- Are you sure ?"
fi
while [ "$VOL" -le "$VOLCOUNT" ]; do
Vol_Status="$(_snmpgetval ".1.3.6.1.4.1.24681.1.2.17.1.6.$VOL" | sed 's/^"\(.*\).$/\1/')"
if [ "$Vol_Status" == "Ready" ]; then
VOLSTAT="OK: $Vol_Status"
elif [ "$Vol_Status" == "Rebuilding..." ]; then
VOLSTAT="WARNING: $Vol_Status"
WARNING=1
else
VOLSTAT="CRITICAL: $Vol_Status"
CRITICAL=1
fi
volCpctStr="$(_snmpget ".1.3.6.1.4.1.24681.1.2.17.1.4.$VOL")"
volFreeStr="$(_snmpget ".1.3.6.1.4.1.24681.1.2.17.1.5.$VOL")"
volCpctSize="$(echo "$volCpctStr" | awk '{print $4}' | sed 's/.\(.*\)/\1/')"
volFreeSize="$(echo "$volFreeStr" | awk '{print $4}' | sed 's/.\(.*\)/\1/')"
volCpctUnit="$(echo "$volCpctStr" | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')"
volFreeUnit="$(echo "$volFreeStr" | awk '{print $5}' | sed 's/.*\(.B\).*/\1/')"
volCpctExp="$(_get_exp "$volCpctUnit")"
volFreeExp="$(_get_exp "$volFreeUnit")"
volCpct="$(echo "scale=0; $volCpctSize*(2^$volCpctExp)" | bc -l)"
volFree="$(echo "scale=0; $volFreeSize*(2^$volFreeExp)" | bc -l)"
volUsed="$(echo "scale=0; $volCpct-$volFree" | bc -l)"
volFreePct="$(echo "scale=0; $volFree*100/$volCpct" | bc -l)"
volUsedPct="$(echo "scale=0; $volUsed*100/$volCpct" | bc -l)"
volCpctH="$(echo "scale=2; $volCpct/(2^$volCpctExp)" | bc -l)"
volFreeH="$(echo "scale=2; $volFree/(2^$volFreeExp)" | bc -l)"
volUsedH="$(echo "scale=2; $volUsed/(2^$volFreeExp)" | bc -l)"
if [ "${inhuman:-0}" -eq 1 ]; then
volCpctF="$volCpct"
volFreeF="$volFree"
volUsedF="$volUsed"
else
volCpctF="$volCpctH $volCpctUnit"
volFreeF="$volFreeH $volFreeUnit"
volUsedF="$volUsedH $volFreeUnit"
fi
if [ "$volFreePct" -le "$strCritical" ]; then
volFreePct="CRITICAL: $volFreePct"
CRITICAL=1
elif [ "$volFreePct" -le "$strWarning" ]; then
volFreePct="WARNING: $volFreePct"
WARNING=1
fi
ALLOUTPUT="${ALLOUTPUT}Volume #$VOL: $VOLSTAT, Total Size (bytes): $volCpctF, Free: $volFreeF (${volFreePct}%)"
if [ "$VOL" -lt "$VOLCOUNT" ]; then
ALLOUTPUT="${ALLOUTPUT}, "
fi
#Performance Data
if [ $VOL -gt 1 ]; then
PERFOUTPUT="$PERFOUTPUT "
fi
PERFOUTPUT="${PERFOUTPUT}FreeSize_Volume-$VOL=${volFreePct}%;$strWarning;$strCritical;0;100"
VOL="`expr $VOL + 1`"
done
echo "$ALLOUTPUT|$PERFOUTPUT"
if [ $CRITICAL -eq 1 ]; then
exit 2
elif [ $WARNING -eq 1 ]; then
exit 1
else
exit 0
fi
# Power Supply Status ----------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "powerstatus" ]; then
ALLOUTPUT=""
WARNING=0
CRITICAL=0
PS=1
COUNT="$(_snmpgetval .1.3.6.1.4.1.24681.1.4.1.1.1.1.3.1.0)"
if [[ "$COUNT" == 'No Such Object'* ]]; then
echo "ERROR: $COUNT"
exit 4
fi
while [ "$PS" -le "$COUNT" ]; do
STATUS="$(_snmpgetval ".1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.4.$PS")"
if [ "$STATUS" -eq 0 ]; then
PSSTATUS="OK: GOOD"
else
PSSTATUS="CRITICAL: ERROR"
CRITICAL=1
fi
ALLOUTPUT="${ALLOUTPUT}Power Supply #$PS - $PSSTATUS"
if [ "$PS" -lt "$COUNT" ]; then
ALLOUTPUT="$ALLOUTPUT\n"
fi
PS="`expr $PS + 1`"
done
echo "$ALLOUTPUT"
if [ $CRITICAL -eq 1 ]; then
exit 2
elif [ $WARNING -eq 1 ]; then
exit 1
else
exit 0
fi
# Fan Status----------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "fans" ]; then
ALLOUTPUT=""
PERFOUTPUT=""
WARNING=0
CRITICAL=0
FAN=1
FANCOUNT="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.14.0)"
if [ "$strWarning" -lt "$strCritical" ]; then
echo "Warning threshold ($strWarning) is less than critical threshold ($strCritical) ! -- Are you sure ?"
fi
while [ "$FAN" -le "$FANCOUNT" ]; do
FANSPEED="$(_snmpgetval ".1.3.6.1.4.1.24681.1.2.15.1.3.$FAN" | sed -E 's/"([0-9]+) ?RPM"/\1/')"
#Performance data
if [ $FAN -gt 1 ]; then
PERFOUTPUT="$PERFOUTPUT "
fi
PERFOUTPUT="${PERFOUTPUT}Fan-$FAN=$FANSPEED;$strWarning;$strCritical"
if [ "$FANSPEED" == "" ]; then
FANSTAT="CRITICAL: $FANSPEED RPM"
CRITICAL=1
elif [ "$FANSPEED" -le "$strCritical" ]; then
FANSTAT="CRITICAL: $FANSPEED RPM"
CRITICAL=1
elif [ "$FANSPEED" -le "$strWarning" ]; then
FANSTAT="WARNING: $FANSPEED RPM"
WARNING=1
else
FANSTAT="OK: $FANSPEED RPM"
fi
ALLOUTPUT="${ALLOUTPUT}Fan #${FAN}: $FANSTAT"
if [ "$FAN" -lt "$FANCOUNT" ]; then
ALLOUTPUT="${ALLOUTPUT}, "
fi
FAN="`expr $FAN + 1`"
done
echo "$ALLOUTPUT|$PERFOUTPUT"
if [ $CRITICAL -eq 1 ]; then
exit 2
elif [ $WARNING -eq 1 ]; then
exit 1
else
exit 0
fi
# System Uptime----------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "systemuptime" ]; then
netuptime="$(_snmpget .1.3.6.1.2.1.1.3.0 | awk '{print $5, $6, $7, $8}')"
sysuptime="$(_snmpget .1.3.6.1.2.1.25.1.1.0 | awk '{print $5, $6, $7, $8}')"
echo "System Uptime $sysuptime - Network Uptime $netuptime"
exit 0
# System Info------------------------------------------------------------------------------------------------------------------------------------------
elif [ "$strPart" == "sysinfo" ]; then
model="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.12.0 | sed 's/^"\(.*\).$/\1/')"
hdnum="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.10.0)"
VOLCOUNT="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.16.0)"
name="$(_snmpgetval .1.3.6.1.4.1.24681.1.2.13.0 | sed 's/^"\(.*\)$/\1/')"
firmware="$(_snmpgetval .1.3.6.1.2.1.47.1.1.1.1.9.1 | sed 's/^"\(.*\)$/\1/')"
echo "NAS $name, Model $model, Firmware $firmware, Max HD number $hdnum, No. Volume $VOLCOUNT"
exit 0
#----------------------------------------------------------------------------------------------------------------------------------------------------
else
echo "Unknown Part!" && exit 3
fi
exit 0