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 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.
41 $SIG{'__DIE__'} = sub {
43 exit $CODE{'UNKNOWN'};
48 $cmd = "sudo hpacucli $cmd";
49 open(FH, $cmd."|") or die ("Cannot run $cmd: $!");
52 die ("no results from $cmd\n") if (scalar @lines == 0);
58 die "code $newexit not defined\n" unless defined $CODE{$newexit};
60 if ($CODE{$newexit} > $CODE{$EXITCODE}) {
66 my $ctrlallshow = runcmd("controller all show");
71 if (/in Slot ([0-9]+) /) {
72 push @controllers, $1;
75 die ("Cannot read line '$_' gotten from hpacucli controller all show\n");
78 if (scalar @controllers == 0) {
79 print "UNKNONW: No smartarray controllers found with hpacucli\n";
85 for my $slot (sort @controllers) {
86 my $pds = runcmd("controller slot=$slot pd all show");
92 next if /^ *array [A-Z]$/;
93 next if (/^\S.*in Slot $slot/);
94 if (/^Error: The specified controller does not have any physical drives on it.$/) {
96 } elsif (/^ *physicaldrive (\S+) .* (OK|Predictive Failure|Failed|Rebuilding)(?:, spare)?\)$/) {
99 push @{$status{$status}}, $drive;
100 if ($status eq 'OK') {
101 } elsif ($status eq 'Predictive Failure' ||
102 $status eq 'Rebuilding') {
104 } elsif ($status eq 'Failed') {
110 die ("Cannot read line '$_' gotten from hpacucli controller slot=$slot pd all show\n");
114 if ($nodrives && scalar keys %status > 0) {
115 push @resultstr, "Slot $slot: have no drives but status results?";
118 } elsif ($nodrives) {
119 push @resultstr, "Slot $slot: no drives";
123 my $cst = runcmd("controller slot=$slot show status");
127 next if (/^\S.*in Slot $slot/);
128 if (/^ *(.*) Status: (.*)$/) {
131 push @{$status{$status}}, $system;
132 if ($status ne 'OK') {
136 die ("Cannot read line '$_' gotten from hpacucli controller slot=$slot show status\n");
140 my $status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status));
141 push @resultstr, "Slot $slot: $status";
144 print "$EXITCODE: ", join(" --- ", @resultstr), "\n";
145 exit $CODE{$EXITCODE};