-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_snmp_huawei_oceanstore.sh
1586 lines (1462 loc) · 35.1 KB
/
check_snmp_huawei_oceanstore.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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#################################################################################
# Script: check_snmp_huawei_ocaeanstore
# Author: Michael Geschwinder (Maerkischer-Kreis)
# Description: Plugin for Nagios to Monitor Huawei Oceanstore (tested with 5500 v3)
# storage units with snmp
#
# Version: 1.0
#
# History:
# 20170222 Created plugin
# 20170223 Added types: diskhealth, controllerhealth, powerhealth, fanhealth, bbuhealth, enclosurehealth
# 20170224 Added types: diskdomainhealth, stragepoolhealth & Added hadnling if there is no result from SNMP
# 20170224 Added types: sashealth, fchealth
# 20170227 Fixed enclosurehealth not detected as snmp table. Wuerying every column by hand.
#
#################################################################################################################
# Usage: ./check_snmp_huawei_oceanstore.sh -H host -C community -t type [-w warning] [-c critical] [-D debug]
##################################################################################################################
help="check_snmp_huawei_oceanstore (c) 2017 Michael Geschwinder published under GPL license
\nUsage: ./check_snmp_huawei_oceanstore.sh -H host -C community -t type [-w warning] [-c critical] [-D debug]
\nRequirements: snmpget, awk, sed, grep\n
\nOptions: \t-H hostname\n\t\t-C Community (to be defined in snmp settings)\n\t\t-D enable Debug messages\n\t\t-t Type to check, see list below
\t\t-w Warning Threshold (optional)\n\t\t-c Critical Threshold (optional)\n
\nTypes:\t\t
\t\tdiskhealth -> Checks the physical disks
\t\tcontrollerhealth -> Checks the controlle health
\t\tpowerhealth -> Checks the health of the powersupplys
\t\tfanhealth -> Checks the health of the fans
\t\tbbuhealth -> Checks the health of the Backup Battery Units
\t\tenclosurehealth -> Checks the health of the enclosures
\t\tdiskdomainhealth -> Checks the health of the diskdomain
\t\tstoragepoolhealth -> Checks the health of the storagepool
\t\tsashealth -> Checks the health of the SAS ports
\t\tfchealth -> Checks the health of the Fibre Channel ports"
##########################################################
# Nagios exit codes and PATH
##########################################################
STATE_OK=0 # define the exit code if status is OK
STATE_WARNING=1 # define the exit code if status is Warning
STATE_CRITICAL=2 # define the exit code if status is Critical
STATE_UNKNOWN=3 # define the exit code if status is Unknown
PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/icinga/libexec: # Set path
##########################################################
# Debug Ausgabe aktivieren
##########################################################
DEBUG=0
##########################################################
# Debug output function
##########################################################
function debug_out {
if [ $DEBUG -eq "1" ]
then
datestring=$(date +%d%m%Y-%H:%M:%S)
echo -e $datestring DEBUG: $1
fi
}
###########################################################
# Check if programm exist $1
###########################################################
function check_prog {
if ! `which $1 1>/dev/null`
then
echo "UNKNOWN: $1 does not exist, please check if command exists and PATH is correct"
exit ${STATE_UNKNOWN}
else
debug_out "OK: $1 does exist"
fi
}
############################################################
# Check Script parameters and set dummy values if required
############################################################
function check_param {
if [ ! $host ]
then
echo "No Host specified... exiting..."
exit $STATE_UNKNOWN
fi
if [ ! $community ]
then
debug_out "Setting default community (public)"
community="public"
fi
if [ ! $type ]
then
echo "No check type specified... exiting..."
exit $STATE_UNKNOWN
fi
if [ ! $warning ]
then
debug_out "Setting dummy warn value "
warning=999
fi
if [ ! $critical ]
then
debug_out "Setting dummy critical value "
critical=999
fi
}
############################################################
# Get SNMP Value
############################################################
function get_snmp {
oid=$1
snmpret=$(snmpget -v2c -c $community $host $oid) # | awk '{print $4}'
echo "snmpget -v2c -c $community $host $oid"
if [ $? == 0 ]
then
echo $snmpret #| awk '{print $4}'
else
exit $STATE_UNKNOWN
fi
}
############################################################
# Get SNMP Walk
############################################################
function get_snmp_walk {
oid=$1
snmpret=$(snmpwalk -v2c -c $community $host $oid -Oqv) # | awk '{print $4}'
i=0
IFS=$'\n'
if [ $? == 0 ]
then
for line in $snmpret
do
line=$(echo $line | sed 's/\"/ /g')
retval[$i]=$line
let "i+=1"
done;
else
exit $STATE_UNKNOWN
fi
IFS=$IFSold
}
############################################################
# Get SNMP Table
############################################################
function get_snmp_table {
oid=$1
snmpret=$(snmptable2csv $host --community=$community $oid)
IFSold=$IFS
IFS=$'\n'
if [ $? == 0 ]
then
for line in $snmpret
do
echo $line
done;
else
exit $STATE_UNKNOWN
fi
IFS=$IFSold
}
############################################################
# Huawei specific mappings
############################################################
function get_healthstat {
stat=$1
case ${stat} in
1)
echo "Normal;$STATE_OK"
;;
2)
echo "Fault;$STATE_CRITICAL"
;;
3)
echo "Pre-fail;$STATE_CRITICAL"
;;
4)
echo "Parity broken;$STATE_CRITICAL"
;;
5)
echo "Degraded;$STATE_WARNING"
;;
6)
echo "Bad sectors found;$STATE_CRITICAL"
;;
7)
echo "Bit errors found;$STATE_CRITICAL"
;;
8)
echo "Consistent;$STATE_OK"
;;
9)
echo "Inconsistent;$STATE_CRITICAL"
;;
10)
echo "Busy;$STATE_WARNING"
;;
11)
echo "No input;$STATE_UNKNOWN"
;;
12)
echo "Low Battery;$STATE_WARNING"
;;
13)
echo "Single Link fault;$STATE_CRITICAL"
;;
14)
echo "Invalid;$STATE_CRITICAL"
;;
15)
echo "Write protect;$STATE_CRITICAL"
;;
*)
esac
}
function get_runningstat {
stat=$1
case ${stat} in
1)
echo Normal
;;
2)
echo Running
;;
3)
echo Not running
;;
4)
echo Not existed
;;
5)
echo Sleep in high temperature
;;
6)
echo Starting
;;
7)
echo Power failure rotection
;;
8)
echo Spin down
;;
9)
echo Started
;;
10)
echo Link Up
;;
11)
echo Link Down
;;
12)
echo Powering on
;;
13)
echo Powered off
;;
14)
echo Pre-copy
;;
15)
echo Copyback
;;
16)
echo Reconstruction
;;
17)
echo Expansion
;;
18)
echo Unformatted
;;
19)
echo Formatting
;;
20)
echo Unmapped
;;
21)
echo Initial synchronizing
;;
22)
echo Consistent
;;
23)
echo Synchronizing
;;
24)
echo Synchronized
;;
25)
echo Unsynchronized
;;
26)
echo Split
;;
27)
echo Online
;;
28)
echo Offline
;;
29)
echo Locked
;;
30)
echo Enabled
;;
31)
echo Disabled
;;
32)
echo Balancing
;;
33)
echo To be recovered
;;
34)
echo Interrupted
;;
35)
echo Invalid
;;
36)
echo Not start
;;
37)
echo Queuing
;;
38)
echo Stopped
;;
39)
echo Copying
;;
40)
echo Completed
;;
41)
echo Paused
;;
42)
echo Reverse synchronizing
;;
43)
echo Activated
;;
44)
echo Restore
;;
45)
echo Inactive
;;
46)
echo Idle
;;
47)
echo Powering off
;;
48)
echo Charging
;;
49)
echo Charging completed
;;
50)
echo Discharging
;;
51)
echo Upgrading
;;
52)
echo Power Lost
;;
53)
echo Initializing
;;
54)
echo Apply change
;;
55)
echo Online disable
;;
56)
echo Offline disable
;;
57)
echo Online frozen
;;
58)
echo Offline frozen
;;
59)
echo Closed
;;
60)
echo Removing
;;
61)
echo In service
;;
62)
echo Out of service
;;
63)
echo Running normal
;;
64)
echo Running fail
;;
65)
echo Running success
;;
66)
echo Running success
;;
67)
echo Running failed
;;
68)
echo Waiting
;;
69)
echo Canceling
;;
70)
echo Canceled
;;
71)
echo About to synchronize
;;
72)
echo Synchronizing data
;;
73)
echo Failed to synchronize
;;
74)
echo Fault
;;
75)
echo Migrating
;;
76)
echo Migrated
;;
77)
echo Activating
;;
78)
echo Deactivating
;;
79)
echo Start failed
;;
80)
echo Stop failed
;;
81)
echo Decommissioning
;;
82)
echo Decommissioned
;;
83)
echo Recommissioning
;;
84)
echo Replacing node
;;
85)
echo Scheduling
;;
86)
echo Pausing
;;
87)
echo Suspending
;;
88)
echo Suspended
;;
89)
echo Overload
;;
90)
echo To be switch
;;
91)
echo Switching
;;
92)
echo To be cleanup
;;
93)
echo Forced start
;;
94)
echo Error
;;
95)
echo Job completed
;;
96)
echo Partition Migrating
;;
97)
echo Mount
;;
98)
echo Umount
;;
99)
echo INSTALLING
;;
100)
echo To Be Synchronized
;;
101)
echo Connecting
;;
102)
echo Service Switching
;;
103)
echo Power-on failed
;;
104)
echo REPAIRING
;;
105)
echo abnormal
;;
106)
echo Deleting
;;
107)
echo Modifying
;;
108)
echo "Running (clearing data)"
;;
109)
echo "Running(synchronizing data)"
;;
*)
echo UNKNOWN
esac
}
function get_disktype
{
dtype=$1
case ${dtype} in
0)
echo FC
;;
1)
echo SAS
;;
2)
echo SATA
;;
3)
echo SSD
;;
4)
echo NL_SAS
;;
5)
echo SLC SSD
;;
6)
echo MLC SSD
;;
7)
echo FC_SED
;;
8)
echo SAS_SED
;;
9)
echo SATA_SED
;;
10)
echo SSD_SED
;;
11)
echo NL_SAS_SED
;;
12)
echo SLC_SSD_SED
;;
13)
echo MLC_SSD_SED
;;
*)
echo UNKNOWN
esac
}
function get_diskrole
{
drole=$1
case ${drole} in
1)
echo FREE
;;
2)
echo MEMBER
;;
3)
echo SPARE
;;
4)
echo CACHE
;;
*)
echo UNKNOWN
esac
}
function get_controllerrole
{
crole=$1
case ${crole} in
0)
echo Normal
;;
1)
echo Master
;;
2)
echo Slave
;;
*)
echo UNKNOWN
esac
}
function get_enclogictype
{
enctype=$1
case ${enctype} in
0)
echo EXP
;;
1)
echo CTRL
;;
2)
echo DSW
;;
3)
echo MSW
;;
4)
echo SVP
;;
*)
echo UNKNOWN
esac
}
function get_enctype
{
enctype=$1
case ${enctype} in
0)
echo "BMC Controller"
;;
1)
echo "2U 2 Controllers and 12 Slot 3.5 SAS Disks Enclosure"
;;
2)
echo "2U 2 Controllers and 24 Slot 2.5 SAS Disks Enclosure"
;;
16)
echo "2U 12 Slot 3.5 SAS Disks Enclosure"
;;
17)
echo "2U 24 Slot 2.5 SAS Disks Enclosure"
;;
18)
echo "4U 24 Slot 3.5 SAS Disks Enclosure"
;;
19)
echo "4U 24 Slot 3.5 FC Disks Enclosure"
;;
20)
echo "1U PCIE Switch Enclosure"
;;
21)
echo "4U 75 Slot 3.5 SAS Disks Enclosure"
;;
22)
echo "Service Processor Enclosure"
;;
23)
echo "2U 2 Controllers and 12 Slot 3.5 SAS Disks Enclosure"
;;
24)
echo "2U 25 Slot 2.5 SAS Disks Enclosure"
;;
25)
echo "4U 24 Slot 3.5 SAS Disks Enclosure"
;;
26)
echo "2U 2 Controllers and 25 Slot 2.5 SAS Disks Enclosure"
;;
37)
echo "2U 2 Controllers and 12 Slot 3.5 SAS Disks Enclosure"
;;
38)
echo "2U 2 Controllers and 25 Slot 2.5 SAS Disks Enclosure"
;;
96)
echo "3U 2 Controllers Enclosure "
;;
97)
echo "6U 4 Controllers Enclosure"
;;
*)
echo UNKNOWN
esac
}
function get_relocationstatus
{
alocstat=$1
case ${alocstat} in
1)
echo Ready
;;
2)
echo Migrating
;;
3)
echo Paused
;;
*)
echo UNKNOWN
esac
}
function get_portrole
{
srole=$1
case ${srole} in
2)
echo INI
;;
3)
echo TGT
;;
4)
echo INI_AND_TGT
;;
4294967295)
echo Invalid
;;
*)
echo UNKNOWN
esac
}
function get_portlogictype
{
plogtype=$1
case ${plogtype} in
0)
echo HOST
;;
1)
echo EXP
;;
2)
echo MNGT
;;
3)
echo INNER
;;
4)
echo MAINTENANCE
;;
5)
echo MNGT_SRV
;;
6)
echo MAINTENANCE_SRV
;;
7)
echo BACKUP_MGR
;;
8)
echo PRODUCT_STORAGE
;;
9)
echo BACKUP_STORAGE
;;
10)
echo ETH_NOT_CONFIG
;;
11)
echo IP_SCALE_OUT
;;
*)
echo UNKNOWN
esac
}
function get_sfpstatus
{
val=$1
case ${val} in
0)
echo Not Exist
;;
1)
echo Offline
;;
2)
echo Online
;;
4294967295)
echo Invalid
;;
*)
echo UNKNOWN
esac
}
function get_fcmode
{
val=$1
case ${val} in
0)
echo Fabric
;;
1)
echo FC-ALe
;;
2)
echo Point to Point
;;
3)
echo Auto
;;
4294967295)
echo Invalid
;;
*)
echo UNKNOWN
esac
}
function get_noyes
{
val=$1
case ${val} in
0)
echo No
;;
1)
echo Yes
;;
*)
echo UNKNOWN
esac
}
function check_ret
{
if [ "$1" == "" ]
then
echo "No data received!"
exit $STATE_UNKNOWN
fi
}
#################################################################################
# Display Help screen
#################################################################################
if [ "${1}" = "--help" -o "${#}" = "0" ];
then
echo -e "${help}";
exit $STATE_UNKNOWN;
fi
################################################################################
# check if requiered programs are installed
################################################################################
for cmd in snmpget snmpwalk snmptable2csv awk sed grep;do check_prog ${cmd};done;
################################################################################
# Get user-given variables
################################################################################
while getopts "H:C:t:w:c:o:D" Input;
do
case ${Input} in
H) host=${OPTARG};;
C) community=${OPTARG};;
t) type=${OPTARG};;
w) warning=${OPTARG};;
c) critical=${OPTARG};;
o) moid=${OPTARG};;
D) DEBUG=1;;
*) echo "Wrong option given. Please use options -H for host, -c for SNMP-Community, -t for type, -w for warning and -c for critical"
exit 1
;;
esac
done
debug_out "Host=$host, Community=$community, Type=$type, Warning=$warning, Critical=$critical"
check_param
#################################################################################
# Switch Case for different check types
#################################################################################
case ${type} in
#manual oid
manual)
declare -A retval
set -e
get_snmp_walk $moid
a=("${retval[@]}")
echo "length:"
echo ${#a[@]}
echo ${a[@]}
set +e
exit
;;
diskhealth)
set -e
#echo -e "id\thealthstat\trunningstat\tlocation\ttype\tcapacity\tdiskrole\tdiskspeed\ttemp\tmodel\t\t\tfwversion=\tmanufacturer\t\tserial\t\tdomain\truntime"
ret=$(get_snmp_table .1.3.6.1.4.1.34774.4.1.23.5.1.1)
check_ret $ret
IFSold=$IFS
IFS=$'\n'
messagetext="disks "
for line in $ret
do
line=$(echo $line | sed 's/\"//g')
id=$(echo $line | cut -d "," -f1)
healthstat=$(echo $line | cut -d "," -f2)
runningstat=$(echo $line | cut -d "," -f3)
location=$(echo $line | cut -d "," -f4)
type=$(echo $line | cut -d "," -f5)
capacity=$(echo $line | cut -d "," -f6)
diskrole=$(echo $line | cut -d "," -f7)
diskspeed=$(echo $line | cut -d "," -f8)
temp=$(echo $line | cut -d "," -f11)
model=$(echo $line | cut -d "," -f12)
fwversion=$(echo $line | cut -d "," -f13)
manufacturer=$(echo $line | cut -d "," -f14)
serial=$(echo $line | cut -d "," -f15)
domain=$(echo $line | cut -d "," -f18)
runtime=$(echo $line | cut -d "," -f21)
healthstatret=$(get_healthstat $healthstat)
nagret=$(echo $healthstatret | cut -d ";" -f2)
healthstat=$(echo $healthstatret | cut -d ";" -f1)
runningstat=$(get_runningstat $runningstat)
type=$(get_disktype $type)
capacity=$(echo "scale=0 ; $capacity / 1024" | bc -l)
capacity=$(echo "${capacity}GB")
diskrole=$(get_diskrole $diskrole)
outtext="id=$id\thealthstatus=$healthstat\trunningstatus=$runningstat\tlocation=$location\ttype=$type\tcapacity=$capacity\trole=$diskrole\tspeed=$diskspeed rpm\t\ttemp=$temp\tmodel=$model\t\tfwversion=$fwversion\tmanufacturer=$manufacturer\tserial=$serial\tdomain=$domain\truntime=$runtime days\n"
if [ "$nagret" == "$STATE_CRITICAL" ]
then
crittext=$(echo "$crittext $outtext")
CRIT=true
elif [ "$nagret" == "$STATE_WARNING" ]
then
warntext=$(echo "$warntext $outtext")
WARN=true
elif [ "$nagret" == "$SATE_UNKNOWN" ]
then
unknowntext=$(echo "$unknowntext $outtext")
UNKNOWN=true
else
oktext=$(echo "$oktext $outtext")