This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheck_hardware_raid
executable file
·1383 lines (1203 loc) · 35.6 KB
/
check_hardware_raid
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
#!/usr/bin/perl -w
# vim:ts=4
# Nagios EPN Workaround:
# nagios: -epn
#
# Check RAID status. Look for any known types of RAID configurations, and check them all.
# Return CRITICAL if in a DEGRADED state, since if the whole array has failed you'll have already noticed it!
# Return UNKNOWN if there are no RAID configs that can be found.
# Return WARNING if rebuilding or initialising
#
# 2004-2006 Steve Shipway, university of auckland,
# http://www.steveshipway.org/forum/viewtopic.php?f=20&t=417&p=3211
# Steve Shipway Thanks M Carmier for megaraid section.
# 2009-2010 Elan Ruusamäe <[email protected]>
#
# $Id: check_raid,v 1.91 2011/04/18 07:54:12 glen Exp $
# Requires: perl 5.8 for the open(my $fh , '-|', @CMD) syntax
# you may workaround for earlier perl it as:
# open(my $fh , join(" ", @CMD, '|') or return;
# http://perldoc.perl.org/perl58delta.html#PerlIO-is-Now-The-Default
#
# License: GPL v2
#
# Supports:
# - Adaptec AAC RAID via aaccli or afacli or arcconf
# - AIX software RAID via lsvg
# - HP/Compaq Smart Array via cciss_vol_status
# - HP Smart Array Controllers and MSA Controllers via hpacucli (see hapacucli readme)
# - HP Smart Array (MSA1500) via serial line
# - Linux 3ware SATA RAID via tw_cli
# - Linux DPT/I2O hardware RAID controllers via /proc/scsi/dpt_i2o
# - Linux GDTH hardware RAID controllers via /proc/scsi/gdth
# - Linux LSI MegaRaid hardware RAID via CmdTool2
# - Linux LSI MegaRaid hardware RAID via megarc
# - Linux LSI MegaRaid hardware RAID via /proc/megaraid
# - Linux MegaIDE hardware RAID controllers via /proc/megaide
# - Linux MPT hardware RAID via mpt-status
# - Linux software RAID (md) via /proc/mdstat
# - LSI Logic MegaRAID SAS series via MegaCli
# - LSI MegaRaid via lsraid
# - Serveraid IPS via ipssend
# - Solaris software RAID via metastat
#
# Changes:
# Version 1.1 : IPS; Solaris, AIX, Linux software RAID; megaide
# Version 2.0 : Added megaraid, mpt (serveraid), aaccli (serveraid)
# Version 2.1 :
# - Made script more generic and secure
# - Added gdth
# - Added dpt_i2o
# - Added 3ware SATA RAID
# - Added Adaptec AAC-RAID via arcconf
# - Added LSI MegaRaid via megarc
# - Added LSI MegaRaid via CmdTool2
# - Added HP/Compaq Smart Array via cciss_vol_status
# - Added HP MSA1500 check via serial line
# - Added checks via HP hpacucli utility.
use strict;
use Getopt::Long;
use vars qw($opt_v $opt_d $opt_h $opt_W $opt_S);
my(%ERRORS) = (OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3);
my($VERSION) = "2.1";
my($message, $status);
my(@ignore);
my $sudo = which('sudo');
my $cat = which('cat');
# various RAID tools
my $mpt_status = which('mpt-status');
my $aaccli = which('aaccli');
my $afacli = which('afacli');
my $lsraid = which('lsraid');
my $megacli = which('MegaCli64') || which('MegaCli');
my $metastat = which('metastat');
my $lsvg = which('lsvg');
my $ipssend = which('ipssend');
my $tw_cli = which('tw_cli-9xxx') || which('tw_cli');
my $arcconf = which('arcconf');
my $megarc = which('megarc');
my $cmdtool2 = which('CmdTool2');
my $cciss_vol_status = which('cciss_vol_status');
my $hpacucli = which('hpacucli');
#####################################################################
sub print_usage () {
print "Usage: check_raid [list of devices to ignore]\n";
print " check_raid -v\n";
print " check_raid -h\n";
}
sub print_help () {
print "check_raid, v$VERSION\n";
print "Copyright (c) 2004-2006 Steve Shipway, Copyright (c) 2009-2010, Elan Ruusamäe <glen\@pld-linux.org>
This plugin reports the current server's RAID status
";
print_usage();
}
#####################################################################
# return true if parameter is not in ignore list
sub valid($) {
my($v) = lc $_[0];
foreach (@ignore) {
return 0 if lc $_ eq $v;
}
return 1;
}
# Solaris, software RAID
sub check_metastat {
my($d,$sd);
my @CMD = $metastat;
unshift(@CMD, $sudo) if $> and $sudo;
open(my $fh , '-|', @CMD) or return;
while (<$fh>) {
if (/^(\S+):/) { $d = $1; $sd = ''; next; }
if (/Submirror \d+:\s+(\S+)/) { $sd = $1; next; }
if (my($s) = /State: (\S.+)/) {
if ($sd and valid($sd) and valid($d)) {
if ($s =~ /Okay/i) {
# no worries...
} elsif ($s =~ /Resync/i) {
$status = $ERRORS{WARNING} unless $status;
} else {
$status = $ERRORS{CRITICAL};
}
$message .= "$d:$sd:$s ";
}
}
}
close $fh;
}
# MegaIDE RAID controller
sub check_megaide {
my $fh;
foreach my $f (</proc/megaide/*/status>) {
if (-r $f) {
open $fh, '<', $f or next;
} else {
my @CMD = ($cat, $f);
unshift(@CMD, $sudo) if $> and $sudo;
open($fh , '-|', @CMD) or next;
}
while (<$fh>) {
next unless (my($s, $n) = /Status\s*:\s*(\S+).*Logical Drive.*:\s*(\d+)/i);
next unless valid($n);
if ($s ne 'ONLINE') {
$status = $ERRORS{CRITICAL};
$message .= "Megaide:$n:$s ";
} else {
$message .= "Megaide:$n:$s ";
}
last;
}
close $fh;
}
}
# Linux Multi-Device (md)
# TODO: check linerar devices
sub check_mdstat {
open my $fh, '<', '/proc/mdstat' or return;
my ($md, $md_pers, $md_status, $resync_status);
my (@status, @failed_disks);
while (<$fh>) {
chomp;
if (my($s, $p) = /^(\S+)\s+:\s*(?:\S+)\s+(\S+)/) {
$md = $s;
$md_pers = $p;
@failed_disks = $_ =~ m/(\S+)\[\d+\]\(F\)/g;
undef $resync_status;
next;
}
# linux-2.6.33/drivers/md/dm-raid1.c, device_status_char
# A => Alive - No failures
# D => Dead - A write failure occurred leaving mirror out-of-sync
# S => Sync - A sychronization failure occurred, mirror out-of-sync
# R => Read - A read failure occurred, mirror data unaffected
# U => for the rest
if (my($s) = /^\s+.*\[([U_]+)\]/) {
$md_status = $s;
next;
}
# linux-2.6.33/drivers/md/md.c, md_seq_show
if (my($action) = m{(resync=(?:PENDING|DELAYED))}) {
$resync_status = $action;
next;
}
# linux-2.6.33/drivers/md/md.c, status_resync
# [==>..................] resync = 13.0% (95900032/732515712) finish=175.4min speed=60459K/sec
if (my($action, $perc, $eta, $speed) = m{(resync|recovery|check|reshape) = ([\d.]+%) \(\d+/\d+\) finish=([\d.]+min) speed=(\d+K/sec)}) {
$resync_status = "$action:$perc $speed ETA: $eta";
next;
}
# we need empty line denoting end of one md
next unless /^\s+$/;
next unless valid($md);
if ($md_status =~ /_/) {
$status = $ERRORS{CRITICAL};
push(@status, "$md($md_pers):@failed_disks:$md_status");
} elsif (scalar @failed_disks > 0) {
$status = $ERRORS{WARNING} unless $status;
push(@status, "$md($md_pers):hot-spare failure: @failed_disks:$md_status");
} elsif ($resync_status) {
$status = $ERRORS{WARNING} unless $status;
push(@status, "$md($md_pers):$md_status ($resync_status)");
undef $resync_status;
} else {
push(@status, "$md($md_pers):$md_status");
}
}
close $fh;
$message .= "md:[".join(', ', @status)."] " if @status;
}
# Linux, software RAID
sub check_lsraid {
my @CMD = ($lsraid, '-A', '-p');
unshift(@CMD, $sudo) if $> and $sudo;
open(my $fh , '-|', @CMD) or return;
while (<$fh>) {
next unless (my($n, $s) = m{/dev/(\S+) \S+ (\S+)});
next unless valid($n);
if ($s =~ /good|online/) {
# no worries
} elsif ($s =~ /sync/) {
$status = $ERRORS{WARNING} unless $status;
} else {
$status = $ERRORS{CRITICAL};
}
$message .= "md:$n:$s ";
}
close $fh;
}
# Linux, software RAID
# MegaRAID SAS 8xxx controllers
# based on info from here:
# http://www.bxtra.net/Articles/2008-09-16/Dell-Perc6i-RAID-Monitoring-Script-using-MegaCli-LSI-CentOS-52-64-bits
# TODO: http://www.techno-obscura.com/~delgado/code/check_megaraid_sas
sub check_megacli {
my @CMD = ($megacli, '-PDList', '-aALL', '-NoLog');
unshift(@CMD, $sudo) if $> and $sudo;
open(my $fh , '-|', @CMD) or return;
my (@status, @devs, %cur);
while (<$fh>) {
if (my($s) = /Device Id: (\S+)/) {
push(@devs, { %cur }) if %cur;
%cur = ( dev => $s, state => undef, name => undef );
next;
}
if (my($s) = /Firmware state: (.+)/) {
$cur{state} = $s;
next;
}
if (my($s) = /Inquiry Data: (.+)/) {
# trim some spaces
$s =~ s/\s+/ /g; $s =~ s/^\s+|\s+$//g;
$cur{name} = $s;
next;
}
}
close $fh;
push(@devs, { %cur }) if %cur;
foreach my $dev (@devs) {
push(@status, sprintf "Dev%02d (%s): %s", $dev->{dev}, $dev->{name}, $dev->{state});
if ($dev->{state} ne 'Online, Spun Up' and $dev->{state} ne 'Unconfigured(good), Spun Up') {
# TODO: process other statuses
$status = $ERRORS{CRITICAL};
#print $dev->{state};
#print "\n";
}
}
$message .= "MegaCli:".join(', ', @status) if @status;
}
# AIX LVM
sub check_lsvg {
my @CMD = $lsvg;
unshift(@CMD, $sudo) if $> and $sudo;
my @vg;
open(my $fh , '-|', @CMD) or return;
while (<$fh>) {
chomp;
push @vg, $_;
}
close $fh;
foreach my $vg (@vg) {
next unless valid($vg); # skip entire VG
open(my $fh , '-|', @CMD, '-l', $vg) or next;
while (<$fh>) {
my @f = split /\s/;
my ($n, $s) = ($f[0],$f[5]);
next if (!valid($n) or !$s);
next if ($f[3] eq $f[2]); # not a mirrored LV
if ($s =~ /open\/(\S+)/i) {
$s = $1;
if ($s ne 'syncd') {
$status = $ERRORS{CRITICAL};
}
$message .= "lvm:$n:$s ";
}
}
close $fh;
}
}
# Serveraid IPS
sub check_ipssend {
my @CMD = $ipssend;
unshift(@CMD, $sudo) if $> and $sudo;
my $n;
open(my $fh , '-|', @CMD, 'GETCONFIG', '1', 'LD') or return;
while (<$fh>) {
if (/drive number (\d+)/i){
$n=$1;
next;
}
next unless valid($n);
next unless (my($s, $c) = /Status .*: (\S+)\s+(\S+)/);
if ($c =~ /SYN|RBL/i ) { # resynching
$status = $ERRORS{WARNING} unless $status;
} elsif ($c !~ /OKY/i) { # not OK
$status = $ERRORS{CRITICAL};
}
$message .= "ips:$n:$s ";
}
close $fh;
}
# Adaptec ServeRAID
sub check_aaccli {
unless ($aaccli) {
$message .= "aac:aaccli program not found ";
$status = $ERRORS{CRITICAL};
return;
}
my @CMD = $aaccli;
unshift(@CMD, $sudo) if $> and $sudo;
use IPC::Open2;
my ($read, $write);
my $pid = open2($read, $write, @CMD) or return;
print $write "open aac0\n";
print $write "container list /full\n";
print $write "exit\n";
close $write;
#File foo receiving all output.
#
#AAC0>
#COMMAND: container list /full=TRUE
#Executing: container list /full=TRUE
#Num Total Oth Stripe Scsi Partition Creation
#Label Type Size Ctr Size Usage C:ID:L Offset:Size State RO Lk Task Done% Ent Date Time
#----- ------ ------ --- ------ ------- ------ ------------- ------- -- -- ------- ------ --- ------ --------
# 0 Mirror 74.5GB Open 0:02:0 64.0KB:74.5GB Normal 0 051006 13:48:54
# /dev/sda Auth 0:03:0 64.0KB:74.5GB Normal 1 051006 13:48:54
#
#
#AAC0>
#COMMAND: logfile end
#Executing: logfile end
while (<$read>) {
if (my ($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\S+\s+(\S+)/) {
next unless valid($dsk);
$dsk =~ s/:/\//g;
next unless valid($dsk);
$message .= "aac:$dsk:$stat ";
$status = $ERRORS{CRITICAL} if ($stat eq "Broken");
$status = $ERRORS{WARNING} if (!$status and $stat eq "Rebuild");
$status = $ERRORS{WARNING} if (!$status and $stat eq "Bld/Vfy");
$status = $ERRORS{CRITICAL} if ($stat eq "Missing");
$status = $ERRORS{WARNING} if (!$status and $stat eq "Verify");
$status = $ERRORS{WARNING} if (!$status and $stat eq "VfyRepl");
}
}
close $read;
}
# Adaptec AACRAID
sub check_afacli {
my @CMD = $afacli;
unshift(@CMD, $sudo) if $> and $sudo;
use IPC::Open2;
my ($read, $write);
my $pid = open2($read, $write, @CMD) or return;
print $write "open afa0\n";
print $write "container list /full\n";
print $write "exit\n";
close $write;
while (<$read>) {
# 0 Mirror 465GB Valid 0:00:0 64.0KB: 465GB Normal 0 032511 17:55:06
# /dev/sda root 0:01:0 64.0KB: 465GB Normal 1 032511 17:55:06
if (my($dsk, $stat) = /(\d:\d\d?:\d+)\s+\S+:\s?\S+\s+(\S+)/) {
next unless valid($dsk);
$dsk =~ s/:/\//g;
next unless valid($dsk);
$message .= "aac:$dsk:$stat ";
$status = $ERRORS{CRITICAL} if ($stat eq "Broken");
$status = $ERRORS{WARNING} if (!$status and $stat eq "Rebuild");
$status = $ERRORS{WARNING} if (!$status and $stat eq "Bld/Vfy");
$status = $ERRORS{CRITICAL} if ($stat eq "Missing");
$status = $ERRORS{WARNING} if (!$status and $stat eq "Verify");
$status = $ERRORS{WARNING} if (!$status and $stat eq "VfyRepl");
}
}
close $read;
}
# LSILogic MPT ServeRAID
sub check_mpt {
unless ($mpt_status) {
$message .= "mpt:mpt-status program not found ";
$status = $ERRORS{CRITICAL};
return;
}
# status messages pushed here
my @status;
my @CMD = $mpt_status;
unshift(@CMD, $sudo) if $> and $sudo;
open(my $fh, '-|', @CMD, '-s') or return;
while (<$fh>) {
if (my($d, $s) = /^log_id\s*(\d+)\s+(\S+)/) {
next unless valid($d);
if (!$status and $s =~ /INITIAL|INACTIVE|RESYNC/) {
$status = $ERRORS{WARNING} unless $status;
} elsif ($s =~ /DEGRADED/) {
$status = $ERRORS{CRITICAL};
} elsif (!$status and $s !~ /ONLINE|OPTIMAL/) {
$status = $ERRORS{UNKNOWN} unless $status;
}
push(@status, "Logical Volume $d:$s");
next;
}
if (my($d, $s) = /^phys_id\s*(\d+)\s+(\S+)/) {
next if ($s eq "ONLINE");
# TODO: process other statuses
$status = $ERRORS{CRITICAL};
push(@status, "Physical Disk $d:$s");
next;
}
}
close $fh;
$message .= "mpt:".join(', ', @status) if @status;
}
# MegaRAID
sub check_megaraid {
# status messages pushed here
my @status;
foreach my $f (</proc/megaraid/*/raiddrives*>) {
my $fh;
if (-r $f) {
open $fh, '<', $f or next;
} else {
my @CMD = ($cat, $f);
unshift(@CMD, $sudo) if $> and $sudo;
open($fh , '-|', @CMD) or next;
}
my ($n) = $f =~ m{/proc/megaraid/([^/]+)};
while (<$fh>) {
if (my($s) = /logical drive\s*:\s*\d+.*, state\s*:\s*(\S+)/i) {
if ($s ne 'optimal') {
$status = $ERRORS{CRITICAL};
}
push(@status, "$n: $s");
last;
}
}
close $fh;
}
$message .= "MegaRAID: ".join(', ', @status) if @status;
}
# Linux Gdth RAID
# based on check_gdth by Petter Reinholdtsen
# http://homepages.uni-paderborn.de/odenbach/projects/check_gdth/
sub check_gdth {
# Looking for this text block:
# Logical Drives:
# Number: 0 Status: ok
# Capacity [MB]: 17333 Type: RAID-1
# Slave Number: 15 Status: ok
# Missing Drv.: 0 Invalid Drv.: 0
# To Array Drv.: --
# status messages pushed here
my @status;
for my $file (</proc/scsi/gdth/*>) {
open my $fh, '<', $file or return;
my ($controller) = $file =~ m{([^/]+$)};
my @ld;
while (<$fh>) {
last if (/Array Drives:/); # Stop after the Logical Drive block
# Match items from Logical Drivers
if (my($num, $s) = m/^\s+Number:\s+(\d+)\s+Status:\s+(\S+)/) {
if ($s ne "ok") {
$status = $ERRORS{CRITICAL};
}
push(@ld, "$controller,$num:$s");
}
}
close($fh);
push(@status, "Logical Drive ".join(', ', @ld)) if @ld;
}
$message .= "gdth:".join(', ', @status) if @status;
}
sub check_dpt_i2o {
my @status;
for my $file (</proc/scsi/dpt_i2o/*>) {
open my $fh, '<', $file or return;
my ($controller) = $file =~ m{([^/]+$)};
while (<$fh>) {
if (my ($c, $t, $l, $s) = m/TID=\d+,\s+\(Channel=(\d+),\s+Target=(\d+),\s+Lun=(\d+)\)\s+\((\S+)\)/) {
if ($s ne "online") {
$status = $ERRORS{CRITICAL};
}
push(@status, "$c,$t,$l:$s");
}
}
close($fh);
}
$message .= "dpt_i2o:[".join(', ', @status)."] " if @status;
}
# 3ware SATA RAID
# check designed from check_3ware.sh by:
# Sander Klein <sander [AT] pictura [dash] dp [DOT] nl>
# http://www.pictura-dp.nl/
# Version 20070706
sub check_tw_cli {
my @CMD = $tw_cli;
unshift(@CMD, $sudo) if $> and $sudo;
# status messages pushed here
my @status;
my (@c, $fh);
# scan controllers
open($fh , '-|', @CMD, 'info') or return;
while (<$fh>) {
if (my($c, $model) = /^(c\d+)\s+(\S+)/) {
push(@c, [$c, $model]);
}
}
close $fh;
unless (@c) {
$status = $ERRORS{WARNING} unless $status;
$message .= "3ware: No Adapters were found on this machine";
return;
}
for my $i (@c) {
my ($c, $model) = @$i;
# check each unit on controllers
open($fh , '-|', @CMD, 'info', $c, 'unitstatus') or next;
my @cstatus;
while (<$fh>) {
next unless (my($u, $s, $p, $p2) = /^(u\d+)\s+\S+\s+(\S+)\s+(\S+)\s+(\S+)/);
if ($s eq 'OK') {
push(@cstatus, "$u:$s");
} elsif ($s eq 'INITIALIZING') {
$status = $ERRORS{WARNING} unless $status;
push(@cstatus, "$u:$s $p2");
} elsif ($s eq 'REBUILDING') {
$status = $ERRORS{WARNING} unless $status;
push(@cstatus, "$u:$s $p% ");
} elsif ($s eq 'DEGRADED') {
open(my $fh , '-|', @CMD, 'info', $c, 'drivestatus');
my @ds;
if ($fh) {
my @p;
while (<$fh>) {
next unless (my($p, $s) = /^(p\d+)\s+(\S+)\s+\Q$u\E/);
push(@ds, "$p:$s");
}
close $fh;
}
push(@cstatus, "$u:$s (disks: ".join(' ', @ds). ")");
$status = $ERRORS{CRITICAL};
} else {
push(@cstatus, "$u:$_");
$status = $ERRORS{UNKNOWN} unless $status;
}
}
push(@status, "$c($model): ". join(',', @cstatus));
close $fh;
}
$message .= "3ware: ".join(', ', @status) if @status;
}
# Adaptec AAC-RAID
# check designed from check-aacraid.py, Anchor System - <http://www.anchor.com.au>
# Oliver Hookins, Paul De Audney, Barney Desmond.
# Perl port (check_raid) by Elan Ruusamäe.
sub check_arcconf {
my @CMD = $arcconf;
unshift(@CMD, $sudo) if $> and $sudo;
# status messages pushed here
my @status;
# we chdir to /var/log, as tool is creating 'UcliEvt.log'
chdir('/var/log') || chdir('/');
my ($fh, $d);
open($fh , '-|', @CMD, 'GETCONFIG', '1', 'LD') or return;
while (<$fh>) {
$d = $1, next if /^Logical device number (\d+)/;
next unless (my ($s) = /^\s*Status of logical device\s+:\s+(.+)/);
push(@status, "Logical Device $d:$s");
}
close $fh;
open($fh , '-|', @CMD, 'GETCONFIG', '1', 'AD') or return;
while (<$fh>) {
if (my($s) = /Controller Status\s*:\s*(.*)/) {
if ($s ne 'Optimal') {
$status = $ERRORS{CRITICAL};
}
push(@status, "Controller:$s");
next;
}
if (my($s) = /Defunct disk drive count\s:\s*(\d+)/) {
$status = $ERRORS{CRITICAL};
push(@status, "Defunct drives:$s");
next;
}
if (my($td, $fd, $dd) = m{Logical devices/Failed/Degraded\s*:\s*(\d+)/(\d+)/(\d+)}) {
if (int($fd) > 0) {
$status = $ERRORS{CRITICAL};
push(@status, "Failed drives: $fd");
}
if (int($dd) > 0) {
$status = $ERRORS{CRITICAL};
push(@status, "Degraded drives: $dd");
}
next;
}
if (my($s) = /^\s*Status\s*:\s*(.*)$/) {
next if $s eq "Not Installed";
push(@status, "Battery Status: $s");
next;
}
if (my($s) = /^\s*Over temperature\s*:\s*(.*)$/) {
if ($s ne "No") {
$status = $ERRORS{CRITICAL};
push(@status, "Battery Overtemp: $s");
}
next;
}
if (my($s) = /\s*Capacity remaining\s*:\s*(\d+)\s*percent.*$/) {
push(@status, "Battery Capacity: $s%");
if (int($s) < 50) {
$status = $ERRORS{WARNING} unless $status;
}
if (int($s) < 25) {
$status = $ERRORS{CRITICAL};
}
next;
}
if (my($d, $h, $m) = /\s*Time remaining \(at current draw\)\s*:\s*(\d+) days, (\d+) hours, (\d+) minutes/) {
my $mins = int($d) * 1440 + int($h) * 60 + int($m);
if ($mins < 1440) {
$status = $ERRORS{WARNING} unless $status;
}
if ($mins < 720) {
$status = $ERRORS{CRITICAL};
}
if ($mins < 60) {
push(@status, "Battery Time: ${m}m");
} else {
push(@status, "Battery Time: ${d}d, ${h}h, ${m}m");
}
next;
}
}
close $fh;
$message .= "arcconf:".join(', ', @status) if @status;
}
# LSI MegaRaid or Dell Perc arrays
# Check the status of all arrays on all Lsi MegaRaid controllers on the local
# machine. Uses the megarc program written by Lsi to get the status of all
# arrays on all local Lsi MegaRaid controllers.
#
# check designed from check_lsi_megaraid:
# http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed/2416.html;d=1
# Perl port (check_raid) by Elan Ruusamäe.
sub check_megarc {
my @CMD = $megarc;
unshift(@CMD, $sudo) if $> and $sudo;
# status messages pushed here
my @status;
# get controllers
open(my $fh , '-|', @CMD, '-AllAdpInfo', '-nolog') or return;
my @lines = <$fh>;
close $fh;
if ($lines[11] =~ /No Adapters Found/) {
$status = $ERRORS{WARNING} unless $status;
$message .= "megarc: No LSI adapters were found on this machine";
return;
}
my @c;
foreach (@lines[12..$#lines]) {
if (my ($id) = /^\s*(\d+)/) {
push(@c, int($id));
}
}
unless (@c) {
$status = $ERRORS{WARNING} unless $status;
$message .= "megarc: No LSI adapters were found on this machine";
return;
}
foreach my $c (@c) {
open($fh , '-|', @CMD, '-dispCfg', "-a$c", '-nolog') or return;
my (%d, %s, $ld);
while (<$fh>) {
# Logical Drive : 0( Adapter: 0 ): Status: OPTIMAL
if (my($d, $s) = /Logical Drive\s+:\s+(\d+).+Status:\s+(\S+)/) {
$ld = $d;
$s{$ld} = $s;
next;
}
# SpanDepth :01 RaidLevel: 5 RdAhead : Adaptive Cache: DirectIo
if (my($s) = /RaidLevel:\s+(\S+)/) {
$d{$ld} = $s if defined $ld;
next;
}
}
close $fh;
# now process the details
unless (keys %d) {
push(@status, "No arrays found on controller $c");
$status = $ERRORS{WARNING} unless $status;
return;
}
while (my($d, $s) = each %s) {
if ($s ne 'OPTIMAL') {
# The Array number here is incremented by one because of the
# inconsistent way that the LSI tools count arrays.
# This brings it back in line with the view in the bios
# and from megamgr.bin where the array counting starts at
# 1 instead of 0
push(@status, "Array ".(int($d) + 1)." status is ".$s{$d}." (Raid-$s on adapter $c)");
$status = $ERRORS{CRITICAL};
next;
}
push(@status, "Logical Drive $d: $s");
}
}
$message .= "megarc: ".join(', ', @status) if @status;
}
sub check_cmdtool2 {
my @CMD = $cmdtool2;
unshift(@CMD, $sudo) if $> and $sudo;
# status messages pushed here
my @status;
# get adapters
open(my $fh , '-|', @CMD, '-AdpAllInfo', '-aALL', '-nolog') or return;
my @c;
while (<$fh>) {
if (my($c) = /^Adapter #(\d+)/) {
push(@c, $c);
}
}
close $fh;
unless (@c) {
$status = $ERRORS{WARNING} unless $status;
$message .= "CmdTool2: No LSI adapters were found on this machine";
return;
}
foreach my $c (@c) {
open($fh , '-|', @CMD, '-CfgDsply', "-a$c", '-nolog') or return;
my ($d);
while (<$fh>) {
# DISK GROUPS: 0
if (my($s) = /^DISK GROUPS: (\d+)/) {
$d = int($s);
next;
}
# State: Optimal
if (my($s) = /^State: (\S+)$/) {
if ($s ne 'Optimal') {
$status = $ERRORS{CRITICAL};
}
push(@status, "Logical Drive $c,$d: $s");
}
}
}
$message .= "CmdTool2: ".join(', ', @status) if @status;
}
sub check_cciss {
unless ($cciss_vol_status) {
$message .= "cciss:cciss_vol_status program not found";
$status = $ERRORS{CRITICAL};
return;
}
my @CMD = $cciss_vol_status;
unshift(@CMD, $sudo) if $> and $sudo;
# status messages pushed here
my @status;
# find controllers
# cciss0: HP Smart Array P400i Controller
# Board ID: 0x3235103c
# Firmware Version: 4.06
# IRQ: 98
# Logical drives: 1
# Current Q depth: 0
# Current # commands on controller: 0
# Max Q depth since init: 249
# Max # commands on controller since init: 275
# Max SG entries since init: 31
# Sequential access devices: 0
#
# cciss/c0d0: 220.12GB RAID 1(1+0)
my @c = "/dev/sg1";
unless (@c) {
$status = $ERRORS{WARNING} unless $status;
$message .= "cciss: No Smart Array Adapters were found on this machine";
return;
}
foreach my $c (@c) {
open(my $fh , '-|', @CMD, $c) or die $!;
while (<$fh>) {
chomp;
# strip for better pattern matching
s/\.\s*$//;
# /dev/cciss/c0d0: (Smart Array P400i) RAID 1 Volume 0 status: OK
if (my($s) = /status: (.*?)$/) {
if ($s ne 'OK') {
$status = $ERRORS{CRITICAL};
}
push(@status, $_);
}
}
close($fh);
}
$message .= "cciss: ".join(', ', @status) if @status;
}
sub check_hpacucli {
my @CMD = $hpacucli;
unshift(@CMD, $sudo) if $> and $sudo;
# status messages pushed here
my @status;
# TODO: allow target customize:
# hpacucli <target> is of format:
# [controller all|slot=#|wwn=#|chassisname="AAA"|serialnumber=#|chassisserialnumber=#|ctrlpath=#:# ]
# [array all|<id>]
# [physicaldrive all|allunassigned|[#:]#:#|[#:]#:#-[#:]#:#]
# [logicaldrive all|#]
# [enclosure all|#:#|serialnumber=#|chassisname=#]
# [licensekey all|<key>]
# Scan controllers
my (%targets, $fh);
open($fh , '-|', @CMD, 'controller', 'all', 'show', 'status') or return;
while (<$fh>) {
# Numeric slot
if (my($model, $slot) = /^(\S.+) in Slot (\d+)/) {
$targets{"slot=$slot"} = $model;
next;
}
# Named Entry
if (my($model, $cn) = /^(\S.+) in (.+)/) {
$targets{"chassisname=$cn"} = $cn;
next;
}
}
close $fh;
unless (%targets) {
$status = $ERRORS{WARNING} unless $status;
$message .= "hpacucli: No Controllers were found on this machine";
return;
}
# Scan logical drives
while (my($target, $model) = each %targets) {
# check each controllers
open($fh , '-|', @CMD, 'controller', $target, 'logicaldrive', 'all', 'show') or next;
my ($array, %array);
while (<$fh>) {
# "array A"
# "array A (Failed)"
# "array B (Failed)"
if (my($a, $s) = /^\s+array (\S+)(?:\s*\((\S+)\))?$/) {
$array = $a;
# Offset 0 is Array own status
# XXX: I don't like this one: undef could be false positive
$array{$array}[0] = $s || 'OK';
}
# skip if no active array yet
next unless $array;
# logicaldrive 1 (68.3 GB, RAID 1, OK)
# capture only status
if (my($drive, $s) = /^\s+logicaldrive (\d+) \([\d.]+ .B, [^,]+, (\S+)\)$/) {
# Offset 1 is each logical drive status
$array{$array}[1]{$drive} = $s;
}
}
close $fh;