3 # check _physical_ disk status of disks on Smart Array controllers
4 # requires hpssacli or ssacli
6 # does _not_ check raid status. use arrayprobe for that.
8 # Copyright (c) 2008,2009,2010,2011 Peter Palfrader <peter@palfrader.org>
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be
19 # included in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 $SIG{'__DIE__'} = sub {
45 exit $CODE{'UNKNOWN'};
48 # support both the older hpssacli and the newer ssacli
50 if ($0 =~ /hpssacli/) {
58 $cmd = "sudo $BIN $cmd";
59 open(FH, $cmd."|") or die ("Cannot run $cmd: $!");
62 die ("no results from $cmd\n") if (scalar @lines == 0);
68 die "code $newexit not defined\n" unless defined $CODE{$newexit};
70 if ($CODE{$newexit} > $CODE{$EXITCODE}) {
75 my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--no-battery] [--ignore-cache] [--ignore-controller=<regex>] [--no-controller-ok] [--ignore-transfer-speed=<pd> [--ignore-transfer-speed=<pd> ...]]\n";
77 Getopt::Long::Configure('bundling');
79 '--help' => \$params->{'help'},
80 '--no-battery' => \$params->{'no-battery'},
81 '--no-controller-ok' => \$params->{'no-controller-ok'},
82 '--ignore-cache' => \$params->{'ignore-cache'},
83 '--ignore-controller=s' => \$params->{'ignore-controller'},
84 '--ignore-transfer-speed=s@' => \$params->{'ignore-transfer-speed'},
88 if ($params->{'help'}) {
92 die ($usage) unless (scalar @ARGV == 0);
94 my $ctrlallshow = runcmd("controller all show detail");
100 next if ($params->{'ignore-controller'} && /$params->{'ignore-controller'}/);
101 if (/in Slot ([0-9a-z]+)/) {
103 $controllers{$slot} = ();
104 } elsif (/^ *(Controller|Cache|Battery\/Capacitor) Status: (.*)$/) {
108 if ($system eq 'Cache') {
111 # - 'Not Configured' (for e.g. HP SSD Smart Path)
112 # - 'Permanently Disabled'
114 next if $status =~ /^(OK|Not Configured)$/;
115 if ($params->{'ignore-cache'}) {
116 push @{$controllers{$slot}}, "$system: $status (ignored)";
121 push @{$controllers{$slot}}, "$system: $status";
122 if ($status ne 'OK') {
123 next if ($params->{'no-battery'} && $system eq 'Battery/Capacitor');
126 } elsif (/^ *(Cache Status Details): (Cable Error)/) {
127 push @{$controllers{$slot}}, $2;
129 } elsif (/^ *(Battery\/Capacitor Count): (.*)/) {
130 next if $params->{'no-battery'} || int($2) > 0;
131 push @{$controllers{$slot}}, "Battery count: $2";
136 if (scalar keys %controllers == 0) {
137 if ($params->{'no-controller-ok'}) {
138 print "No Smart Array controllers found with $BIN\n";
141 print "UNKNOWN: No Smart Array controllers found with $BIN\n";
142 exit $CODE{'UNKNOWN'}
148 for my $slot (sort keys %controllers) {
152 # check logicaldrives
155 my $lds = runcmd("controller slot=$slot ld all show detail");
159 if (/Logical Drive: ([0-9a-z]+)/) {
161 push @logicaldrives, $logicaldrive;
162 } elsif (/^Error: The specified device does not have any logical drives.$/) {
164 } elsif (/^ *Parity Initialization Status: (Initialization Completed|Initialization Failed|Rebuilding)$/) {
166 if ($status eq 'Initialization Completed') {
167 push @{$status{'OK'}}, "Parity LD$logicaldrive";
168 } elsif ($status eq 'Rebuilding') {
169 push @{$status{'Failed'}}, "Parity LD$logicaldrive";
171 } elsif ($status eq 'Initialization Failed') {
172 push @{$status{'Failed'}}, "Parity LD$logicaldrive";
177 } elsif (/^ *LD Acceleration Method: (.*)$/) {
179 # can at least be "Controller Cache" or HP SSD Smart Path", both OK
180 if ($status eq 'All disabled') {
181 push @{$status{'Acceleration method'}}, "LD$logicaldrive disabled";
187 if (!$nodrives && scalar @logicaldrives == 0) {
188 push @resultstr, "Slot $slot: unexpectedly, found no logical drives in list.";
190 } elsif ($nodrives && scalar keys %status > 0) {
191 push @resultstr, "Slot $slot: have no logical drives but status results?";
194 } elsif ($nodrives) {
195 push @resultstr, "Slot $slot: no logical drives";
198 my $pds = runcmd("controller slot=$slot pd all show detail");
204 next if (/^\S.*in Slot $slot/);
205 next if /^ *Array [A-Z]$/i;
206 next if /^ *unassigned/;
207 if (/^ *HBA Drives/) {
208 # HBA mode implies no logical drives, thus reset the "drives found" check and proceed with
209 # checking physical drives.
213 if (/^ *(Array [A-Z]) \(Failed\)$/i) {
215 push @{$status{'Failed'}}, $1;
216 } elsif (/^Error: The specified controller does not have any physical drives on it.$/) {
218 } elsif (/^ *physicaldrive (\S+)/) {
220 $drives{$drive} = {};
221 } elsif (defined $drive && m/^\s*(.*?):\s*(.*?)\s*$/) {
222 $drives{$drive}{$1} = $2;
224 die ("Cannot read line '$_' gotten from $BIN controller slot=$slot pd all show\n");
228 # Check that all drives have the proper transfer speed.
229 # sometimes stuff breaks and they fall back to 10mb/sec.
230 for my $drive (sort keys %drives) {
231 my $value = $drives{$drive};
232 my $status = $value->{'Status'};
233 push @{$status{$status}}, $drive;
234 if ($status eq 'OK') {
235 } elsif ($status eq 'Predictive Failure' ||
236 $status eq 'Rebuilding') {
238 } elsif ($status eq 'Failed') {
240 # skip drives that are known to have failed
247 if ($drive =~ /^[0-9]+:[0-9]+$/) { # scsi drives
249 } elsif ($drive =~ /^[0-9]+[EI]:[0-9]+:[0-9]+$/) { # SAS
251 } elsif ($drive =~ /^[0-9]+[C]:[0-9]+:[0-9]+$/) { # New 6GBPS SAS
254 warn ("Unknown diskdrive ID $drive\n");
260 if ($type eq 'SCSI') {
261 $key = 'Transfer Speed';
262 if (!defined $value->{'Transfer Mode'}) {
264 push @{$status{'unknown transfer mode'}}, $drive;
266 } elsif ($value->{'Transfer Mode'} eq 'Ultra 3 Wide') {
267 $expected = '160 MB/Sec';
268 } elsif ($value->{'Transfer Mode'} eq 'Ultra 320 Wide') {
269 $expected = '320 MB/Sec';
272 push @{$status{'unknown transfer mode'}}, $drive."(".$value->{'Transfer Mode'}.")";
275 } elsif ($type eq 'SAS' || $type eq 'SAS+') {
276 $key = 'PHY Transfer Rate';
277 if ($value->{'Interface Type'} eq 'SATA') {
278 $expected = [ '1.5Gbps', '3.0Gbps', '6.0Gbps' ];
279 } elsif ($value->{'PHY Count'} eq '2') {
280 if (defined($value->{'Redundant Path(s)'})) {
281 $expected = [ '3.0GBPS, 3.0GBPS', '6.0GBPS, 6.0GBPS',
282 '12.0GBPS, 12.0GBPS' ];
284 $expected = [ '3.0GBPS, Unknown', 'Unknown, 3.0GBPS',
285 '6.0GBPS, Unknown', 'Unknown, 6.0GBPS',
286 '12.0GBPS, Unknown', 'Unknown, 12.0GBPS' ];
289 $expected = [ '3.0GBPS', '6.0GBPS', '12.0GBPS' ];
292 warn "Should not be here. Do not know what to do with type '$type'\n";
296 if ($params->{'ignore-transfer-speed'}) {
297 if (grep { $drive eq $_ } @{$params->{'ignore-transfer-speed'}}) {
298 push @{$status{'ignored transfer speed'}}, $drive."(".$value->{$key}.")";
302 if (!defined $value->{$key}) {
304 push @{$status{'unknown transfer speed'}}, $drive;
305 } elsif (ref($expected) eq 'ARRAY') {
306 if (scalar(grep { uc($value->{$key}) eq uc($_) } @$expected) == 0) {
308 push @{$status{'bad transfer speed'}}, $drive."(".$value->{$key}.")";
310 } elsif (uc($value->{$key}) ne uc($expected)) {
312 push @{$status{'bad transfer speed'}}, $drive."(".$value->{$key}.")";
316 if ($nodrives && scalar keys %status > 0) {
317 push @resultstr, "Slot $slot: have no drives but status results?";
320 } elsif ($nodrives) {
321 push @resultstr, "Slot $slot: no drives";
325 my $status = join(" - ", ((map { $_.": ".join(", ", @{$status{$_}}) } keys %status), @{$controllers{$slot}}));
327 push @resultstr, "Slot $slot: $status";
330 print "$EXITCODE: ", join(" --- ", @resultstr), "\n";
331 exit $CODE{$EXITCODE};