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[2] ne 'Yes') {
116 $message = sprintf("FAN%d: status=%s ", $fan_num, $line[2]);
118 } elsif ($line[3] ne 'NORMAL') {
119 $message = sprintf("FAN%d: speed=%s ", $fan_num, $line[3]);
121 } elsif ($line[5] ne 'Yes') {
122 $message = sprintf("FAN%d: redundant=%s ",$fan_num, $line[5]);
125 } elsif ($line =~ /($prompt|^\s*$)/) {
129 $return .= $message if ($message);
132 return "FANS OK ($num_fans) ";
140 my $ps_num = my $return = my $message = '';
141 my $header_seen = my $num_ps = 0;
143 for my $line (@output) {
145 unless ($header_seen) {
146 next until ($line eq "$prompt SHOW POWERSUPPLY");
151 if ($line =~ /^Power supply #(\d+)/) {
153 $return .= $message if ($message);
158 } elsif ($line =~ /\s+Present\s*:\s+(.*)/) {
160 if ($present ne 'Yes') {
161 $message = sprintf("PS%d missing ", $ps_num);
164 } elsif ($line =~ /\s+Condition\s*:\s+(.*)/) {
166 if ($status ne 'Ok') {
167 $message = sprintf("PS%d: %s ", $ps_num, $status);
170 } elsif ($line =~ /\s+Redundant\s*:\s+(.*)/) {
172 if ($redundant ne 'Yes') {
173 $message = sprintf("PS%d not redundant ", $ps_num);
176 } elsif ($line =~ /($prompt|^\s*$)/) {
180 $return .= $message if ($message);
183 return "POWER OK ($num_ps) ";
191 my $temp_num = my $return = my $message = '';
192 my $header_seen = my $num_temp = 0;
194 for my $line (@output) {
196 unless ($header_seen) {
197 next until ($line eq "$prompt SHOW TEMP");
202 if ($line =~ /^#(\d+)/) {
204 $return .= $message if ($message);
209 my @line = split /\s+/, $line;
212 my $current_temp = $line[2];
213 my $threshold = $line[3];
215 $current_temp =~ s/(.*)C.*/$1/;
216 $threshold =~ s/(.*)C.*/$1/;
217 next if ($threshold eq '-');
220 my $off = $threshold - $current_temp;
222 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
224 } elsif ($off < ($threshold/10)) {
225 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
228 } elsif ($line =~ /($prompt|^\s*$)/) {
232 $return .= $message if ($message);
234 return "TEMP OK ($num_temp) ";
240 my @output = `echo "$command"|sudo hpasmcli 2>&1`;
241 if (($? >> 8) != 0) {
242 print "UNKNOWN: Can't exec hpasmcli: @output\n";
246 for my $line (@output) {
248 for my $check (sort keys %callbacks) {
249 if ($line eq "$prompt $check") {
250 $ret .= &{$callbacks{$check}}(@output);
255 if ($exit_status & 2) {
256 print "CRTICAL: $ret\n";
258 } elsif ($exit_status & 1) {
259 print "WARNING: $ret\n";