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.
38 $ENV{'LD_LIBRARY_PATH'} = '/home/sgran/lib';
41 'SHOW DIMM' => \&do_dimm,
42 'SHOW FANS' => \&do_fans,
43 'SHOW POWERSUPPLY' => \&do_powersupply,
44 'SHOW TEMP' => \&do_temp,
47 my $prompt = "hpasmcli>";
53 my $dimm_num = my $status = my $return = my $message = '';
54 my $in_block = my $header_seen = my $num_dimms = 0;
56 for my $line (@output) {
58 unless ($header_seen) {
59 next until ($line eq "$prompt SHOW DIMM");
64 if ($line =~ /(^\s*$|-----)/) {
66 if ($status ne 'Ok') {
67 $message = sprintf("DIMM%d: %s ", $dimm_num, $status);
70 $return .= $message if ($message);
71 $message = $status = '';
77 if ($line =~ /^Module #:\s+(\d)/) {
80 } elsif ($line =~ /Status:\s+(\S+(\s*(.*)?))/) {
82 } elsif ($line =~ /$prompt/) {
88 return "All DIMMS OK ($num_dimms)";
96 my $fan_num = my $status = my $present = my $return = my $message = '';
97 my $header_seen = my $num_fans = 0;
99 for my $line (@output) {
101 unless ($header_seen) {
102 next until ($line eq "$prompt SHOW FANS");
107 if ($line =~ /^#(\d+)/) {
109 $return .= $message if ($message);
115 my @line = split /\s+/, $line;
117 if ($line[2] ne 'Yes') {
118 $message = sprintf("FAN%d: status=%s ", $fan_num, $line[2]);
120 } elsif ($line[3] ne 'NORMAL') {
121 $message = sprintf("FAN%d: speed=%s ", $fan_num, $line[3]);
123 } elsif ($line[5] ne 'Yes') {
124 $message = sprintf("FAN%d: redundant=%s ",$fan_num, $line[5]);
127 } elsif ($line =~ /($prompt|^\s*$)/) {
131 $return .= $message if ($message);
134 return "FANS OK ($num_fans) ";
142 my $ps_num = my $return = my $message = '';
143 my $header_seen = my $num_ps = 0;
145 for my $line (@output) {
147 unless ($header_seen) {
148 next until ($line eq "$prompt SHOW POWERSUPPLY");
153 if ($line =~ /^Power supply #(\d+)/) {
155 $return .= $message if ($message);
160 } elsif ($line =~ /\s+Present\s*:\s+(.*)/) {
162 if ($present ne 'Yes') {
163 $message = sprintf("PS%d missing ", $ps_num);
166 } elsif ($line =~ /\s+Condition\s*:\s+(.*)/) {
168 if ($status ne 'Ok') {
169 $message = sprintf("PS%d: %s ", $ps_num, $status);
172 } elsif ($line =~ /\s+Redundant\s*:\s+(.*)/) {
174 if ($redundant ne 'Yes') {
175 $message = sprintf("PS%d not redundant ", $ps_num);
178 } elsif ($line =~ /($prompt|^\s*$)/) {
182 $return .= $message if ($message);
185 return "POWER OK ($num_ps) ";
193 my $temp_num = my $return = my $message = '';
194 my $header_seen = my $num_temp = 0;
196 for my $line (@output) {
198 unless ($header_seen) {
199 next until ($line eq "$prompt SHOW TEMP");
204 if ($line =~ /^#(\d+)/) {
206 $return .= $message if ($message);
212 my @line = split /\s+/, $line;
215 my $current_temp = $line[2];
216 my $threshold = $line[3];
218 $current_temp =~ s/(.*)C.*/$1/;
219 $threshold =~ s/(.*)C.*/$1/;
221 my $off = $threshold - $current_temp;
223 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
225 } elsif ($off < ($threshold/10)) {
226 $message = sprintf("TEMP zone=%s %sC/%sC ", $zone, $current_temp, $threshold);
229 } elsif ($line =~ /($prompt|^\s*$)/) {
233 $return .= $message if ($message);
235 return "TEMP OK ($num_temp) ";
241 my @output = `echo "$command"|hpasmcli 2>&1`;
242 if (($? >> 8) != 0) {
243 print "UNKNOWN: Can't exec hpasmcli: @output\n";
247 for my $line (@output) {
249 for my $check (sort keys %callbacks) {
250 if ($line eq "$prompt $check") {
251 $ret .= &{$callbacks{$check}}(@output);
256 if ($exit_status & 2) {
257 print "CRTICAL: $ret\n";
259 } elsif ($exit_status & 1) {
260 print "WARNING: $ret\n";