6 # check status of various hardware devices (fans, temp, dimms, powersupply)
9 # Copyright (c) 2009 Stephen Gran <steve@lobefin.net>
11 # Permission is hereby granted, free of charge, to any person obtaining
12 # a copy of this software and associated documentation files (the
13 # "Software"), to deal in the Software without restriction, including
14 # without limitation the rights to use, copy, modify, merge, publish,
15 # distribute, sublicense, and/or sell copies of the Software, and to
16 # permit persons to whom the Software is furnished to do so, subject to
17 # the following conditions:
19 # The above copyright notice and this permission notice shall be
20 # included in all copies or substantial portions of the Software.
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 'SHOW DIMM' => \&do_dimm,
40 'SHOW FANS' => \&do_fans,
41 'SHOW POWERSUPPLY' => \&do_powersupply,
42 'SHOW TEMP' => \&do_temp,
45 my $prompt = "hpasmcli>";
51 my $dimm_num = my $status = my $return = my $message = '';
52 my $in_block = my $header_seen = my $num_dimms = 0;
54 for my $line (@output) {
56 unless ($header_seen) {
57 next until ($line eq "$prompt SHOW DIMM");
62 if ($line =~ /(^\s*$|-----)/) {
64 if ($status ne 'Ok') {
65 $message = sprintf("DIMM%d: %s ", $dimm_num, $status);
68 $return .= $message if ($message);
69 $message = $status = '';
75 if ($line =~ /^Module #:\s+(\d)/) {
78 } elsif ($line =~ /Status:\s+(\S+(\s*(.*)?))/) {
80 } elsif ($line =~ /$prompt/) {
86 return "DIMMS OK ($num_dimms) ";
94 my $fan_num = my $status = my $present = my $return = my $message = '';
95 my $header_seen = my $num_fans = 0;
97 for my $line (@output) {
99 unless ($header_seen) {
100 next until ($line eq "$prompt SHOW FANS");
105 if ($line =~ /^#(\d+)/) {
107 $return .= $message if ($message);
113 my @line = split /\s+/, $line;
115 if ($line[1] eq 'VIRTUAL') { # blade, etc
116 $message = 'FAN1: (virtual) OK ';
120 if ($line[2] ne 'Yes') {
121 $message = sprintf("FAN%d: status=%s ", $fan_num, $line[2]);
123 } elsif ($line[3] ne 'NORMAL') {
124 $message = sprintf("FAN%d: speed=%s ", $fan_num, $line[3]);
126 } elsif ($line[5] ne 'Yes') {
127 $message = sprintf("FAN%d: redundant=%s ",$fan_num, $line[5]);
130 } elsif ($line =~ /($prompt|^\s*$)/) {
134 $return .= $message if ($message);
137 return "FANS OK ($num_fans) ";
145 my $ps_num = my $return = my $message = '';
146 my $header_seen = my $num_ps = 0;
148 for my $line (@output) {
150 unless ($header_seen) {
151 next until ($line eq "$prompt SHOW POWERSUPPLY");
156 if ($line =~ /^Power supply #(\d+)/) {
158 $return .= $message if ($message);
163 } elsif ($line =~ /\s+Present\s*:\s+(.*)/) {
165 if ($present ne 'Yes') {
166 $message = sprintf("PS%d missing ", $ps_num);
169 } elsif ($line =~ /\s+Condition\s*:\s+(.*)/) {
171 if ($status ne 'Ok') {
172 $message = sprintf("PS%d: %s ", $ps_num, $status);
175 } elsif ($line =~ /\s+Redundant\s*:\s+(.*)/) {
177 if ($redundant ne 'Yes') {
178 $message = sprintf("PS%d not redundant ", $ps_num);
181 } elsif ($line =~ /($prompt|^\s*$)/) {
185 $return .= $message if ($message);
188 return "POWER OK ($num_ps) ";
196 my $temp_num = my $return = my $message = '';
197 my $header_seen = my $num_temp = 0;
199 for my $line (@output) {
201 unless ($header_seen) {
202 next until ($line eq "$prompt SHOW TEMP");
207 if ($line =~ /^#(\d+)/) {
209 $return .= $message if ($message);
214 my @line = split /\s+/, $line;
217 my $current_temp = $line[2];
218 my $threshold = $line[3];
220 $current_temp =~ s/(.*)C.*/$1/;
221 $threshold =~ s/(.*)C.*/$1/;
222 next if ($threshold eq '-');
225 if ($current_temp ne '-') {
226 my $off = $threshold - $current_temp;
228 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
230 } elsif ($off < ($threshold/10)) {
231 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
235 } elsif ($line =~ /($prompt|^\s*$)/) {
239 $return .= $message if ($message);
241 return "TEMP OK ($num_temp) ";
247 my @output = `echo "$command"|sudo hpasmcli 2>&1`;
248 if (($? >> 8) != 0) {
249 print "UNKNOWN: Can't exec hpasmcli: @output\n";
253 for my $line (@output) {
255 for my $check (sort keys %callbacks) {
256 if ($line eq "$prompt $check") {
257 $ret .= &{$callbacks{$check}}(@output);
262 if ($exit_status & 2) {
263 print "CRTICAL: $ret\n";
265 } elsif ($exit_status & 1) {
266 print "WARNING: $ret\n";