8 # check status of various hardware devices (fans, temp, dimms, powersupply)
11 # Copyright (c) 2009 Stephen Gran <steve@lobefin.net>
12 # Copyright (c) 2009,2010,2012 Peter Palfrader
14 # Permission is hereby granted, free of charge, to any person obtaining
15 # a copy of this software and associated documentation files (the
16 # "Software"), to deal in the Software without restriction, including
17 # without limitation the rights to use, copy, modify, merge, publish,
18 # distribute, sublicense, and/or sell copies of the Software, and to
19 # permit persons to whom the Software is furnished to do so, subject to
20 # the following conditions:
22 # The above copyright notice and this permission notice shall be
23 # included in all copies or substantial portions of the Software.
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 'SHOW DIMM' => \&do_dimm,
43 'SHOW FANS' => \&do_fans,
44 'SHOW POWERSUPPLY' => \&do_powersupply,
45 'SHOW TEMP' => \&do_temp,
51 my $USAGE = "PROGRAM_NAME: Usage: $PROGRAM_NAME [--help] [--ps-no-redundant] [--fan-no-redundant] [--fan-high] [--dimm-na] [--fan-ignore-not-present]\n";
52 Getopt::Long::config('bundling');
54 '--help' => \$params->{'help'},
55 '--ps-no-redundant' => \$params->{'ps-no-redundant'},
56 '--fan-no-redundant' => \$params->{'fan-no-redundant'},
57 '--fan-high' => \$params->{'fan-high'},
58 '--dimm-na' => \$params->{'dimm-na'},
59 '--fan-ignore-not-present' => \$params->{'fan-ignore-not-present'},
63 if ($params->{'help'}) {
65 print "Checks hp hardware health.\n";
70 my $prompt = "hpasmcli>";
76 my $dimm_num = my $status = my $return = my $message = '';
77 my $in_block = my $header_seen = my $num_dimms = 0;
79 for my $line (@output) {
81 unless ($header_seen) {
82 next until ($line eq "$prompt SHOW DIMM");
87 if ($line =~ /(^\s*$|-----)/) {
89 unless (($status eq 'Ok') ||
90 ($params->{'dimm-na'} && $status eq 'N/A')) {
91 $message = sprintf("DIMM%d: %s ", $dimm_num, $status);
94 $return .= $message if ($message);
95 $message = $status = '';
101 if ($line =~ /^Module #:\s+(\d)/) {
104 } elsif ($line =~ /Status:\s+(\S+(\s*(.*)?))/) {
106 } elsif ($line =~ /$prompt/) {
112 return "DIMMS OK ($num_dimms) ";
120 my $fan_num = my $status = my $present = my $return = my $message = '';
121 my $header_seen = my $num_fans = 0;
123 for my $line (@output) {
125 unless ($header_seen) {
126 next until ($line eq "$prompt SHOW FANS");
131 if ($line =~ /^#(\d+)/) {
133 $return .= $message if ($message);
139 my @line = split /\s+/, $line;
141 if ($line[1] eq 'VIRTUAL') { # blade, etc
142 $message = 'FAN1: (virtual) OK ';
146 if ($line[2] ne 'Yes') {
147 $message = sprintf("FAN%d: status=%s ", $fan_num, $line[2]);
148 $exit_status |= 2 unless ($params->{'fan-ignore-not-present'});
149 } elsif ($line[3] ne 'NORMAL') {
150 $message = sprintf("FAN%d: speed=%s ", $fan_num, $line[3]);
151 $exit_status |= 1 unless ($line[3] eq 'HIGH' && $params->{'fan-high'});
152 } elsif ($line[5] ne 'Yes') {
153 $message = sprintf("FAN%d: redundant=%s ",$fan_num, $line[5]);
154 $exit_status |= 1 unless ($params->{'fan-no-redundant'});
156 } elsif ($line =~ /($prompt|^\s*$)/) {
160 $return .= $message if ($message);
163 return "FANS OK ($num_fans) ";
171 my $ps_num = my $return = my $message = '';
172 my $header_seen = my $num_ps = 0;
174 for my $line (@output) {
176 unless ($header_seen) {
177 next until ($line eq "$prompt SHOW POWERSUPPLY");
182 if ($line =~ /^Power supply #(\d+)/) {
184 $return .= $message if ($message);
189 } elsif ($line =~ /\s+Present\s*:\s+(.*)/) {
191 if ($present ne 'Yes') {
192 $message = sprintf("PS%d missing ", $ps_num);
195 } elsif ($line =~ /\s+Condition\s*:\s+(.*)/) {
197 if ($status ne 'Ok') {
198 $message = sprintf("PS%d: %s ", $ps_num, $status);
201 } elsif ($line =~ /\s+Redundant\s*:\s+(.*)/) {
203 if ($redundant ne 'Yes') {
204 $message = sprintf("PS%d not redundant ", $ps_num);
205 $exit_status |= 1 unless ($params->{'ps-no-redundant'});
207 } elsif ($line =~ /($prompt|^\s*$)/) {
211 $return .= $message if ($message);
214 return "POWER OK ($num_ps) ";
222 my $temp_num = my $return = my $message = '';
223 my $header_seen = my $num_temp = 0;
225 for my $line (@output) {
227 unless ($header_seen) {
228 next until ($line eq "$prompt SHOW TEMP");
233 if ($line =~ /^#(\d+)/) {
235 $return .= $message if ($message);
240 my @line = split /\s+/, $line;
243 my $current_temp = $line[2];
244 my $threshold = $line[3];
246 $current_temp =~ s/(.*)C.*/$1/;
247 $threshold =~ s/(.*)C.*/$1/;
248 next if ($threshold eq '-');
251 if ($current_temp ne '-') {
252 my $off = $threshold - $current_temp;
254 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
256 } elsif ($off < ($threshold/10)) {
257 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
261 } elsif ($line =~ /($prompt|^\s*$)/) {
265 $return .= $message if ($message);
267 return "TEMP OK ($num_temp) ";
273 my @output = `echo "$command"|sudo hpasmcli 2>&1`;
274 if (($? >> 8) != 0) {
275 print "UNKNOWN: Can't exec hpasmcli: @output\n";
279 for my $line (@output) {
281 for my $check (sort keys %callbacks) {
282 if ($line eq "$prompt $check") {
283 $ret .= &{$callbacks{$check}}(@output);
288 if ($exit_status & 2) {
289 print "CRITICAL: $ret\n";
291 } elsif ($exit_status & 1) {
292 print "WARNING: $ret\n";