3 # check _physical_ disk status of disks on HP smart array controllers
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'};
50 $cmd = "sudo hpacucli $cmd";
51 open(FH, $cmd."|") or die ("Cannot run $cmd: $!");
54 die ("no results from $cmd\n") if (scalar @lines == 0);
60 die "code $newexit not defined\n" unless defined $CODE{$newexit};
62 if ($CODE{$newexit} > $CODE{$EXITCODE}) {
67 my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--no-battery] [--ignore-transfer-speed=<pd> [--ignore-transfer-speed=<pd> ...]]\n";
69 Getopt::Long::Configure('bundling');
71 '--help' => \$params->{'help'},
72 '--no-battery' => \$params->{'no-battery'},
73 '--ignore-transfer-speed=s@' => \$params->{'ignore-transfer-speed'},
77 if ($params->{'help'}) {
81 die ($usage) unless (scalar @ARGV == 0);
83 my $ctrlallshow = runcmd("controller all show");
88 if (/in Slot ([0-9a-z]+)/) {
89 push @controllers, $1;
92 die ("Cannot read line '$_' gotten from hpacucli controller all show\n");
95 if (scalar @controllers == 0) {
96 print "UNKNONW: No smartarray controllers found with hpacucli\n";
102 for my $slot (sort @controllers) {
103 my $pds = runcmd("controller slot=$slot pd all show");
110 next if (/^\S.*in Slot $slot/);
111 next if /^ *array [A-Z]$/;
112 next if /^ *unassigned/;
113 if (/^ *(array [A-Z]) \(Failed\)$/) {
115 push @{$status{'Failed'}}, $1;
116 } elsif (/^Error: The specified controller does not have any physical drives on it.$/) {
118 } elsif (/^ *physicaldrive (\S+) .* (OK|Predictive Failure|Failed|Rebuilding)(?:, (?:active )?spare)?\)$/) {
121 push @{$status{$status}}, $drive;
122 if ($status eq 'OK') {
123 } elsif ($status eq 'Predictive Failure' ||
124 $status eq 'Rebuilding') {
126 } elsif ($status eq 'Failed') {
131 push @drives, $drive;
133 die ("Cannot read line '$_' gotten from hpacucli controller slot=$slot pd all show\n");
137 # Check that all drives have the proper transfer speed.
138 # sometimes stuff breaks and they fall back to 10mb/sec.
139 for my $drive (@drives) {
140 # skip drives that are known to have failed
141 next if (exists $status{'Failed'} && grep {$drive eq $_} @{$status{'Failed'}});
143 if ($drive =~ /^[0-9]+:[0-9]+$/) { # scsi drives
145 } elsif ($drive =~ /^[0-9]+[EI]:[0-9]+:[0-9]+$/) { # SAS
147 } elsif ($drive =~ /^[0-9]+[C]:[0-9]+:[0-9]+$/) { # New 6GBPS SAS
150 # I'm not going to run pass arguments of unknown form to the shell..
151 warn ("Unknown diskdrive ID $drive\n");
155 my $pd = runcmd("controller slot=$slot pd $drive show");
156 while (defined $pd->[0] && !($pd->[0] =~ /physicaldrive/)) {
162 if (m/^\s*(.*?):\s*(.*?)\s*$/) {
169 if ($type eq 'SCSI') {
170 $key = 'Transfer Speed';
171 if (!defined $value{'Transfer Mode'}) {
173 push @{$status{'unknown transfer mode'}}, $drive;
175 } elsif ($value{'Transfer Mode'} eq 'Ultra 3 Wide') {
176 $expected = '160 MB/Sec';
177 } elsif ($value{'Transfer Mode'} eq 'Ultra 320 Wide') {
178 $expected = '320 MB/Sec';
181 push @{$status{'unknown transfer mode'}}, $drive."(".$value{'Transfer Mode'}.")";
184 } elsif ($type eq 'SAS' || $type eq 'SAS+') {
185 $key = 'PHY Transfer Rate';
186 if ($value{'PHY Count'} eq '2') {
187 if (defined($value{'Redundant Path(s)'})) {
188 $expected = [ '3.0GBPS, 3.0GBPS', '6.0GBPS, 6.0GBPS' ];
190 $expected = [ '3.0GBPS, Unknown', 'Unknown, 3.0GBPS',
191 '6.0GBPS, Unknown', 'Unknown, 6.0GBPS' ];
194 $expected = [ '3.0GBPS', '6.0GBPS' ];
197 warn "Should not be here. Do not know what to do with type '$type'\n";
201 if ($params->{'ignore-transfer-speed'}) {
202 if (grep { $drive eq $_ } @{$params->{'ignore-transfer-speed'}}) {
203 push @{$status{'ignored transfer speed'}}, $drive."(".$value{$key}.")";
207 if (!defined $value{$key}) {
209 push @{$status{'unknown transfer speed'}}, $drive;
210 } elsif (ref($expected) eq 'ARRAY') {
211 if (scalar(grep { $value{$key} eq $_ } @$expected) == 0) {
213 push @{$status{'bad transfer speed'}}, $drive."(".$value{$key}.")";
215 } elsif ($value{$key} ne $expected) {
217 push @{$status{'bad transfer speed'}}, $drive."(".$value{$key}.")";
221 if ($nodrives && scalar keys %status > 0) {
222 push @resultstr, "Slot $slot: have no drives but status results?";
225 } elsif ($nodrives) {
226 push @resultstr, "Slot $slot: no drives";
230 my $cst = runcmd("controller slot=$slot show status");
234 next if (/^\S.*in Slot $slot/);
235 if (/^ *(.*) Status: (.*)$/) {
238 push @{$status{$status}}, $system;
239 if ($status ne 'OK') {
240 next if ($params->{'no-battery'} && $system eq 'Cache');
241 next if ($params->{'no-battery'} && $system eq 'Battery/Capacitor');
245 die ("Cannot read line '$_' gotten from hpacucli controller slot=$slot show status\n");
249 my $status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status));
250 push @resultstr, "Slot $slot: $status";
253 print "$EXITCODE: ", join(" --- ", @resultstr), "\n";
254 exit $CODE{$EXITCODE};