3 # check enclosure status
5 # Copyright (c) 2008,2009,2010 Peter Palfrader <peter@palfrader.org>
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be
16 # included in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 $SIG{'__DIE__'} = sub {
42 exit $CODE{'UNKNOWN'};
47 $cmd = "sudo hpacucli $cmd";
48 open(FH, $cmd."|") or die ("Cannot run $cmd: $!");
51 die ("no results from $cmd\n") if (scalar @lines == 0);
57 die "code $newexit not defined\n" unless defined $CODE{$newexit};
59 if ($CODE{$newexit} > $CODE{$EXITCODE}) {
64 my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME <controller slot> <enclosure>\n";
66 Getopt::Long::Configure('bundling');
68 '--help' => \$params->{'help'},
72 if ($params->{'help'}) {
76 die ($usage) unless (scalar @ARGV == 2);
82 my $status = runcmd("controller slot=$slot enclosure $enc show detail");
86 next if (/^\S.*in Slot $slot/);
87 next if (/^ \S.*at Port/);
90 if (m/^ (Fan Status|Temperature Status):\s*(.*?)\s*$/) {
93 push @{$status{$status}}, $system;
94 if ($status ne 'OK') {
97 } elsif (m/^ (Power Supply Status):\s*(.*?)\s*$/) {
100 push @{$status{$status}}, $system;
101 if ($status ne 'Redundant') {
104 } elsif (m/^ (Active Path|Standby Path):\s*(.*?),\s*(.*?)\s*$/) {
108 push @{$status{$status}}, $system."($detail)";
109 if ($status ne 'OK') {
115 $status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status));
116 push @resultstr, "Slot $slot: $status";
118 print "$EXITCODE: ", join(" --- ", @resultstr), "\n";
119 exit $CODE{$EXITCODE};