3 # Copyright (c) 2008,2009 Peter Palfrader <peter@palfrader.org>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 use File::Temp qw/ tempdir /;
37 $SIG{'__DIE__'} = sub {
39 exit $CODE{'UNKNOWN'};
44 $cmd = "sudo arcconf $cmd";
45 open(FH, $cmd."|") or die ("Cannot run $cmd: $!");
48 die ("no results from $cmd\n") if (scalar @lines == 0);
54 die "code $newexit not defined\n" unless defined $CODE{$newexit};
56 if ($CODE{$newexit} > $CODE{$EXITCODE}) {
61 # arcconf puts crap into a $PWD/UcliEvt.log file.
62 my $dir = tempdir( "/tmp/check-aacraid-XXXXXXX", CLEANUP => 1 );
63 chdir ($dir) or die ("Cannot chdir $dir: $!\n");
67 my $numcontrollers = 1;
68 while ($ctrl <= $numcontrollers) {
69 my $lds = runcmd("GETCONFIG $ctrl LD");
75 if (/^Controllers found: *([0-9]+)/) {
77 } elsif (/^Logical device number (.*)/) {
79 } elsif (/^ *Status of logical device *: *(.*)/) {
81 if ($status ne 'Optimal') {
84 push @{$status{$status}}, $ld;
88 my $adi = runcmd("GETCONFIG $ctrl AD");
91 if (/^ *Controller Status *: *(.*)/) {
93 if ($status ne 'Optimal') {
96 push @{$status{$status}}, "controller";
97 } elsif (/^ *Defunct disk drive count *: *(.*)/) {
101 push @extrastatus, "$count defunct drives";
103 } elsif (m#^ *Logical devices/Failed/Degraded *: (.*)/(.*)/(.*)#) {
107 push @extrastatus, "$total/$failed/$degraded LDs total/failed/degraded";
110 } elsif ($degraded > 0) {
113 } elsif (/.*Controller Battery Information/) {
117 # in Controller Battery Information
120 if (/^ *Status *: *(.*)/) {
122 if ($status eq 'Not Installed') {
124 } elsif ($status ne 'Optimal' && $status ne 'ZMM Optimal') {
127 push @{$status{$status}}, 'Battery';
131 my $status = join(" - ", (map { $_.": ".join(", ", @{$status{$_}}) } keys %status));
132 if (scalar @extrastatus > 0) {
133 $status .= ", ".join(", ", @extrastatus);
135 push @resultstr, "Ctrl $ctrl: $status";
139 if ( -e 'UcliEvt.log' ) {
140 unlink('UcliEvt.log') or die ("Cannot unlink UcliEvt.log: $!\n");
142 print "$EXITCODE: ", join(" --- ", @resultstr), "\n";
143 exit $CODE{$EXITCODE};