8 # check status of various hardware devices (fans, temp, dimms, powersupply)
11 # Copyright (c) 2009 Stephen Gran <steve@lobefin.net>
13 # Permission is hereby granted, free of charge, to any person obtaining
14 # a copy of this software and associated documentation files (the
15 # "Software"), to deal in the Software without restriction, including
16 # without limitation the rights to use, copy, modify, merge, publish,
17 # distribute, sublicense, and/or sell copies of the Software, and to
18 # permit persons to whom the Software is furnished to do so, subject to
19 # the following conditions:
21 # The above copyright notice and this permission notice shall be
22 # included in all copies or substantial portions of the Software.
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 'SHOW DIMM' => \&do_dimm,
42 'SHOW FANS' => \&do_fans,
43 'SHOW POWERSUPPLY' => \&do_powersupply,
44 'SHOW TEMP' => \&do_temp,
50 Getopt::Long::config('bundling');
52 '--help' => \$params->{'help'},
53 '--ps-no-redundant' => \$params->{'ps-no-redundant'},
54 '--fan-no-redundant' => \$params->{'fan-no-redundant'},
56 die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help] [--ps-no-redundant] [--fan-no-redundant]\n");
58 if ($params->{'help'}) {
59 print "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help] [--ps-no-redundant] [--fan-no-redundant]\n";
60 print "Checks hp hardware health.\n";
65 my $prompt = "hpasmcli>";
71 my $dimm_num = my $status = my $return = my $message = '';
72 my $in_block = my $header_seen = my $num_dimms = 0;
74 for my $line (@output) {
76 unless ($header_seen) {
77 next until ($line eq "$prompt SHOW DIMM");
82 if ($line =~ /(^\s*$|-----)/) {
84 if ($status ne 'Ok') {
85 $message = sprintf("DIMM%d: %s ", $dimm_num, $status);
88 $return .= $message if ($message);
89 $message = $status = '';
95 if ($line =~ /^Module #:\s+(\d)/) {
98 } elsif ($line =~ /Status:\s+(\S+(\s*(.*)?))/) {
100 } elsif ($line =~ /$prompt/) {
106 return "DIMMS OK ($num_dimms) ";
114 my $fan_num = my $status = my $present = my $return = my $message = '';
115 my $header_seen = my $num_fans = 0;
117 for my $line (@output) {
119 unless ($header_seen) {
120 next until ($line eq "$prompt SHOW FANS");
125 if ($line =~ /^#(\d+)/) {
127 $return .= $message if ($message);
133 my @line = split /\s+/, $line;
135 if ($line[1] eq 'VIRTUAL') { # blade, etc
136 $message = 'FAN1: (virtual) OK ';
140 if ($line[2] ne 'Yes') {
141 $message = sprintf("FAN%d: status=%s ", $fan_num, $line[2]);
143 } elsif ($line[3] ne 'NORMAL') {
144 $message = sprintf("FAN%d: speed=%s ", $fan_num, $line[3]);
146 } elsif ($line[5] ne 'Yes') {
147 $message = sprintf("FAN%d: redundant=%s ",$fan_num, $line[5]);
148 $exit_status |= 1 unless ($params->{'fan-no-redundant'});
150 } elsif ($line =~ /($prompt|^\s*$)/) {
154 $return .= $message if ($message);
157 return "FANS OK ($num_fans) ";
165 my $ps_num = my $return = my $message = '';
166 my $header_seen = my $num_ps = 0;
168 for my $line (@output) {
170 unless ($header_seen) {
171 next until ($line eq "$prompt SHOW POWERSUPPLY");
176 if ($line =~ /^Power supply #(\d+)/) {
178 $return .= $message if ($message);
183 } elsif ($line =~ /\s+Present\s*:\s+(.*)/) {
185 if ($present ne 'Yes') {
186 $message = sprintf("PS%d missing ", $ps_num);
189 } elsif ($line =~ /\s+Condition\s*:\s+(.*)/) {
191 if ($status ne 'Ok') {
192 $message = sprintf("PS%d: %s ", $ps_num, $status);
195 } elsif ($line =~ /\s+Redundant\s*:\s+(.*)/) {
197 if ($redundant ne 'Yes') {
198 $message = sprintf("PS%d not redundant ", $ps_num);
199 $exit_status |= 1 unless ($params->{'ps-no-redundant'});
201 } elsif ($line =~ /($prompt|^\s*$)/) {
205 $return .= $message if ($message);
208 return "POWER OK ($num_ps) ";
216 my $temp_num = my $return = my $message = '';
217 my $header_seen = my $num_temp = 0;
219 for my $line (@output) {
221 unless ($header_seen) {
222 next until ($line eq "$prompt SHOW TEMP");
227 if ($line =~ /^#(\d+)/) {
229 $return .= $message if ($message);
234 my @line = split /\s+/, $line;
237 my $current_temp = $line[2];
238 my $threshold = $line[3];
240 $current_temp =~ s/(.*)C.*/$1/;
241 $threshold =~ s/(.*)C.*/$1/;
242 next if ($threshold eq '-');
245 if ($current_temp ne '-') {
246 my $off = $threshold - $current_temp;
248 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
250 } elsif ($off < ($threshold/10)) {
251 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
255 } elsif ($line =~ /($prompt|^\s*$)/) {
259 $return .= $message if ($message);
261 return "TEMP OK ($num_temp) ";
267 my @output = `echo "$command"|sudo hpasmcli 2>&1`;
268 if (($? >> 8) != 0) {
269 print "UNKNOWN: Can't exec hpasmcli: @output\n";
273 for my $line (@output) {
275 for my $check (sort keys %callbacks) {
276 if ($line eq "$prompt $check") {
277 $ret .= &{$callbacks{$check}}(@output);
282 if ($exit_status & 2) {
283 print "CRTICAL: $ret\n";
285 } elsif ($exit_status & 1) {
286 print "WARNING: $ret\n";