Debian Codegraph @

check_hp_bladechassis/check_hp_bladechassis-1.0.1/check_hp_bladechassis

raw
1 #!/usr/bin/perl
2 #
3 # DESCRIPTION: Nagios plugin for checking the status of HP
4 # blade chassis via SNMP.
5 #
6 # AUTHOR: Trond H. Amundsen <[email protected]>
7 #
8 # $Id: check_hp_bladechassis 16304 2010-01-22 11:20:34Z trondham $
9 #
10 # Copyright (C) 2010 Trond H. Amundsen
11 #
12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #
25 # HP ASN.1 prefix: 1.3.6.1.4.1.232
26
27 use strict;
28 use warnings;
29 use POSIX qw(isatty);
30 use Getopt::Long qw(:config no_ignore_case);
31
32 # Global (package) variables used throughout the code
33 use vars qw( $NAME $VERSION $AUTHOR $CONTACT $E_OK $E_WARNING $E_CRITICAL
34 $E_UNKNOWN $USAGE $HELP $LICENSE $original_sigwarn
35 $snmp_session $snmp_error $linebreak $exit_code
36 $count_ioms $count_blades $global $total_wattage
37 %opt %reverse_exitcode %status2nagios %snmp_status %sysinfo
38 %nagios_alert_count %present_map
39 @reports @perfdata @perl_warnings
40 );
41
42 #---------------------------------------------------------------------
43 # Initialization and global variables
44 #---------------------------------------------------------------------
45
46 # Small subroutine to collect any perl warnings during execution
47 sub collect_perl_warning {
48 push @perl_warnings, [@_];
49 }
50
51 # Set the WARN signal to use our collect subroutine above
52 $original_sigwarn = $SIG{__WARN__};
53 $SIG{__WARN__} = \&collect_perl_warning;
54
55 # Version and similar info
56 $NAME = 'check_hp_bladechassis';
57 $VERSION = '1.0.1';
58 $AUTHOR = 'Trond H. Amundsen';
59 $CONTACT = '[email protected]';
60
61 # Exit codes
62 $E_OK = 0;
63 $E_WARNING = 1;
64 $E_CRITICAL = 2;
65 $E_UNKNOWN = 3;
66
67 # Usage text
68 $USAGE = <<"END_USAGE";
69 Usage: $NAME -H <HOSTNAME> [OPTION]...
70 END_USAGE
71
72 # Help text
73 $HELP = <<'END_HELP';
74
75 OPTIONS:
76 -H, --hostname Hostname or IP of the enclosure
77 -C, --community SNMP community string
78 -P, --protocol SNMP protocol version
79 --port SNMP port number
80 -p, --perfdata Output performance data
81 -t, --timeout Plugin timeout in seconds
82 -i, --info Prefix alerts with the enclosure's serial number
83 -v, --verbose Append extra info to alerts (part no. etc.)
84 -e, --extinfo Append system info to alerts
85 -s, --state Prefix alerts with alert state
86 --short-state Prefix alerts with alert state (abbreviated)
87 -d, --debug Debug output, reports everything
88 -h, --help Display this help text
89 -V, --version Display version info
90
91 For more information and advanced options, see the manual page or URL:
92 http://folk.uio.no/trondham/software/check_hp_bladechassis.html
93 END_HELP
94
95 # Version text
96 $LICENSE = <<"END_LICENSE";
97 $NAME $VERSION
98 Copyright (C) 2010 $AUTHOR
99 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
100 This is free software: you are free to change and redistribute it.
101 There is NO WARRANTY, to the extent permitted by law.
102
103 Written by $AUTHOR <$CONTACT>
104 END_LICENSE
105
106 # Options with default values
107 %opt
108 = (
109 'port' => 161, # default SNMP port
110 'hostname' => undef,
111 'community' => 'public', # SMNP v1 or v2c
112 'protocol' => 2, # default is SNMPv2c
113 'username' => undef, # SMNP v3
114 'authpassword' => undef, # SMNP v3
115 'authkey' => undef, # SMNP v3
116 'authprotocol' => undef, # SMNP v3
117 'privpassword' => undef, # SMNP v3
118 'privkey' => undef, # SMNP v3
119 'privprotocol' => undef, # SMNP v3
120 'timeout' => 30, # default timeout is 30 seconds
121 'verbose' => 0,
122 'info' => 0,
123 'extinfo' => 0,
124 'help' => 0,
125 'version' => 0,
126 'state' => 0,
127 'short-state' => 0,
128 'linebreak' => undef,
129 'perfdata' => undef,
130 'debug' => 0,
131 );
132
133 # Get options
134 GetOptions('H|hostname=s' => \$opt{hostname},
135 'C|community=s' => \$opt{community},
136 'P|protocol=i' => \$opt{protocol},
137 'port=i' => \$opt{port},
138 'U|username=s' => \$opt{username},
139 'authpassword=s' => \$opt{authpassword},
140 'authkey=s' => \$opt{authkey},
141 'authprotocol=s' => \$opt{authprotocol},
142 'privpassword=s' => \$opt{privpassword},
143 'privkey=s' => \$opt{privkey},
144 'privprotocol=s' => \$opt{privprotocol},
145 't|timeout=i' => \$opt{timeout},
146 'v|verbose' => \$opt{verbose},
147 'i|info' => \$opt{info},
148 'e|extinfo' => \$opt{extinfo},
149 'h|help' => \$opt{help},
150 'V|version' => \$opt{version},
151 's|state' => \$opt{state},
152 'short-state' => \$opt{shortstate},
153 'linebreak=s' => \$opt{linebreak},
154 'p|perfdata:s' => \$opt{perfdata},
155 'd|debug' => \$opt{debug},
156 ) or do { print $USAGE; exit $E_UNKNOWN; };
157
158 # If user requested help
159 if ($opt{'help'}) {
160 print $USAGE, $HELP;
161 exit $E_OK;
162 }
163
164 # If user requested version info
165 if ($opt{'version'}) {
166 print $LICENSE;
167 exit $E_OK;
168 }
169
170 # Error if hostname option is not present
171 if (!defined $opt{hostname}) {
172 print "ERROR: No hostname or address given on command line. Use the '-H' or '--hostname' option\n";
173 exit $E_UNKNOWN;
174 }
175
176 # Nagios error levels reversed
177 %reverse_exitcode
178 = (
179 0 => 'OK',
180 1 => 'WARNING',
181 2 => 'CRITICAL',
182 3 => 'UNKNOWN',
183 );
184
185 # HP SNMP status (condition)
186 %status2nagios
187 = (
188 'Other' => $E_CRITICAL,
189 'Ok' => $E_OK,
190 'Degraded' => $E_WARNING,
191 'Failed' => $E_CRITICAL,
192 );
193
194 # Status via SNMP
195 %snmp_status
196 = (
197 1 => 'Other',
198 2 => 'Ok',
199 3 => 'Degraded',
200 4 => 'Failed',
201 );
202
203 # Present map
204 %present_map
205 = (
206 1 => 'other',
207 2 => 'absent',
208 3 => 'present',
209 4 => 'OMG!WTF!BUG!', # for blades it can return 4, which is NOT spesified in MIB
210 );
211
212 # Reports (messages) are gathered in this array
213 @reports = ();
214
215 # Setting timeout
216 $SIG{ALRM} = sub {
217 print "PLUGIN TIMEOUT: $NAME timed out after $opt{timeout} seconds\n";
218 exit $E_UNKNOWN;
219 };
220 alarm $opt{timeout};
221
222 # Default line break
223 $linebreak = isatty(*STDOUT) ? "\n" : '<br/>';
224
225 # Line break from option
226 if (defined $opt{linebreak}) {
227 if ($opt{linebreak} eq 'REG') {
228 $linebreak = "\n";
229 }
230 elsif ($opt{linebreak} eq 'HTML') {
231 $linebreak = '<br/>';
232 }
233 else {
234 $linebreak = $opt{linebreak};
235 }
236 }
237
238 # System information gathered
239 %sysinfo
240 = (
241 'serial' => 'N/A', # serial number (service tag)
242 'model' => 'N/A', # system model
243 'firmware' => 'N/A', # firmware version
244 );
245
246 # Counter variable
247 %nagios_alert_count
248 = (
249 'OK' => 0,
250 'WARNING' => 0,
251 'CRITICAL' => 0,
252 'UNKNOWN' => 0,
253 );
254
255 # Number of blades
256 $count_blades = 0;
257
258 # Number of IO modules
259 $count_ioms = 0;
260
261 # Overall health status
262 $global = 'Ok';
263
264 # Initialize SNMP
265 snmp_initialize();
266
267 # Check that SNMP works
268 snmp_check();
269
270 #---------------------------------------------------------------------
271 # Functions
272 #---------------------------------------------------------------------
273
274 #
275 # Store a message in the message array
276 #
277 sub report {
278 my ($msg, $exval, $part, $spare, $serial) = @_;
279 return push @reports, [ $msg, $exval, $part, $spare, $serial ];
280 }
281
282 #
283 # Give an error and exit with unknown state
284 #
285 sub unknown_error {
286 my $msg = shift;
287 print "ERROR: $msg\n";
288 exit $E_UNKNOWN;
289 }
290
291 #
292 # Initialize SNMP
293 #
294 sub snmp_initialize {
295 # Legal SNMP v3 protocols
296 my $snmp_v3_privprotocol = qr{\A des|aes|aes128|3des|3desde \z}xms;
297 my $snmp_v3_authprotocol = qr{\A md5|sha \z}xms;
298
299 # Parameters to Net::SNMP->session()
300 my %param
301 = (
302 '-port' => $opt{port},
303 '-hostname' => $opt{hostname},
304 '-version' => $opt{protocol},
305 );
306
307 # Parameters for SNMP v3
308 if ($opt{protocol} == 3) {
309
310 # Username is mandatory
311 if (defined $opt{username}) {
312 $param{'-username'} = $opt{username};
313 }
314 else {
315 print "SNMP ERROR: With SNMPv3 the username must be specified\n";
316 exit $E_UNKNOWN;
317 }
318
319 # Authpassword is optional
320 if (defined $opt{authpassword}) {
321 $param{'-authpassword'} = $opt{authpassword};
322 }
323
324 # Authkey is optional
325 if (defined $opt{authkey}) {
326 $param{'-authkey'} = $opt{authkey};
327 }
328
329 # Privpassword is optional
330 if (defined $opt{privpassword}) {
331 $param{'-privpassword'} = $opt{privpassword};
332 }
333
334 # Privkey is optional
335 if (defined $opt{privkey}) {
336 $param{'-privkey'} = $opt{privkey};
337 }
338
339 # Privprotocol is optional
340 if (defined $opt{privprotocol}) {
341 if ($opt{privprotocol} =~ m/$snmp_v3_privprotocol/xms) {
342 $param{'-privprotocol'} = $opt{privprotocol};
343 }
344 else {
345 print "SNMP ERROR: Unknown privprotocol '$opt{privprotocol}', "
346 . "must be one of [des|aes|aes128|3des|3desde]\n";
347 exit $E_UNKNOWN;
348 }
349 }
350
351 # Authprotocol is optional
352 if (defined $opt{authprotocol}) {
353 if ($opt{authprotocol} =~ m/$snmp_v3_authprotocol/xms) {
354 $param{'-authprotocol'} = $opt{authprotocol};
355 }
356 else {
357 print "SNMP ERROR: Unknown authprotocol '$opt{authprotocol}', "
358 . "must be one of [md5|sha]\n";
359 exit $E_UNKNOWN;
360 }
361 }
362 }
363 # Parameters for SNMP v2c or v1
364 elsif ($opt{protocol} == 2 or $opt{protocol} == 1) {
365 $param{'-community'} = $opt{community};
366 }
367 else {
368 print "SNMP ERROR: Unknown SNMP version '$opt{protocol}'\n";
369 exit $E_UNKNOWN;
370 }
371
372 # Try to initialize the SNMP session
373 if ( eval { require Net::SNMP; 1 } ) {
374 ($snmp_session, $snmp_error) = Net::SNMP->session( %param );
375 if (!defined $snmp_session) {
376 printf "SNMP: %s\n", $snmp_error;
377 exit $E_UNKNOWN;
378 }
379 }
380 else {
381 print "ERROR: Required perl module Net::SNMP not found\n";
382 exit $E_UNKNOWN;
383 }
384 return;
385 }
386
387 #
388 # Checking if SNMP works by probing for "EnclosureModel", which all
389 # enclosures should have
390 #
391 sub snmp_check {
392 my $cpqRackCommonEnclosureModel = '1.3.6.1.4.1.232.22.2.3.1.1.1.3.1';
393 my $result = $snmp_session->get_request(-varbindlist => [$cpqRackCommonEnclosureModel]);
394
395 # Typically if remote host isn't responding
396 if (!defined $result) {
397 printf "SNMP CRITICAL: %s\n", $snmp_session->error;
398 exit $E_CRITICAL;
399 }
400
401 # If OpenManage isn't installed or is not working
402 if ($result->{$cpqRackCommonEnclosureModel} =~ m{\A noSuch (Instance|Object) \z}xms) {
403 print "SNMP ERROR: Can't determine model name\n";
404 exit $E_UNKNOWN;
405 }
406
407 # Store the model name
408 $sysinfo{model} = $result->{$cpqRackCommonEnclosureModel};
409 $sysinfo{model} =~ s{\s+\z}{}xms; # remove trailing whitespace
410
411 return;
412 }
413
414 # Gets the output from SNMP result according to the OIDs checked
415 sub get_snmp_output {
416 my ($result,$oidref) = @_;
417 my @output = ();
418
419 foreach my $oid (keys %{ $result }) {
420 my @dummy = split m{\.}xms, $oid;
421 my $id = pop @dummy;
422 --$id;
423 my $foo = join q{.}, @dummy;
424 if (exists $oidref->{$foo}) {
425 $output[$id]{$oidref->{$foo}} = $result->{$oid};
426 }
427 }
428 return \@output;
429 }
430
431 # Get enclosure status and firmware info
432 sub get_enclosure_status {
433 my @output = ();
434
435 my $part = undef; # part number
436 my $spare = undef; # spare part number
437 my $serial = undef; # serial
438 my $condition = undef; # enclosure condition
439
440 # OIDs we are interested in
441 my %oid
442 = (
443 '1.3.6.1.4.1.232.22.2.3.1.1.1.5' => 'cpqRackCommonEnclosurePartNumber', # part number
444 '1.3.6.1.4.1.232.22.2.3.1.1.1.6' => 'cpqRackCommonEnclosureSparePartNumber', # spare
445 '1.3.6.1.4.1.232.22.2.3.1.1.1.7' => 'cpqRackCommonEnclosureSerialNum', # serial no.
446 '1.3.6.1.4.1.232.22.2.3.1.1.1.8' => 'cpqRackCommonEnclosureFWRev', # firmware rev.
447 '1.3.6.1.4.1.232.22.2.3.1.1.1.16' => 'cpqRackCommonEnclosureCondition', # condition
448 );
449
450 my $result = $snmp_session->get_entries(-columns => [keys %oid]);
451
452 # Error if we don't get anything
453 if (!defined $result) {
454 printf "SNMP CRITICAL: [enclosure table] %s\n", $snmp_session->error;
455 exit $E_CRITICAL;
456 }
457
458 @output = @{ get_snmp_output($result, \%oid) };
459
460 ENCL:
461 foreach my $out (@output) {
462 $sysinfo{'serial'} = $out->{cpqRackCommonEnclosureSerialNum};
463 $sysinfo{'firmware'} = $out->{cpqRackCommonEnclosureFWRev};
464
465 $part = $out->{cpqRackCommonEnclosurePartNumber};
466 $spare = $out->{cpqRackCommonEnclosureSparePartNumber};
467 $serial = $out->{cpqRackCommonEnclosureSerialNum};
468 $condition = $out->{cpqRackCommonEnclosureCondition};
469 }
470
471 # report global enclosure condition
472 report( (sprintf q{Enclosure overall health condition is %s}, $snmp_status{$condition}),
473 $status2nagios{$snmp_status{$condition}}, $part, $spare, $serial );
474
475 $global = $snmp_status{$condition};
476
477 return;
478 }
479
480 # Check the enclosure managers
481 sub check_managers {
482 my @output = ();
483
484 my $index = undef; # index
485 my $part = undef; # part number
486 my $spare = undef; # spare part number
487 my $serial = undef; # serial number
488 my $role = undef; # manager role (primary / secondary)
489 my $condition = undef; # condition
490
491 # OIDs we are interested in
492 my %oid
493 = (
494 '1.3.6.1.4.1.232.22.2.3.1.6.1.3' => 'cpqRackCommonEnclosureManagerIndex',
495 '1.3.6.1.4.1.232.22.2.3.1.6.1.6' => 'cpqRackCommonEnclosureManagerPartNumber',
496 '1.3.6.1.4.1.232.22.2.3.1.6.1.7' => 'cpqRackCommonEnclosureManagerSparePartNumber',
497 '1.3.6.1.4.1.232.22.2.3.1.6.1.8' => 'cpqRackCommonEnclosureManagerSerialNum',
498 '1.3.6.1.4.1.232.22.2.3.1.6.1.9' => 'cpqRackCommonEnclosureManagerRole',
499 '1.3.6.1.4.1.232.22.2.3.1.6.1.12' => 'cpqRackCommonEnclosureManagerCondition',
500 );
501
502 my $default_timeout = $snmp_session->timeout(); # get existing session timeout
503 $snmp_session->timeout(20); # set new session timeout
504 my $result = $snmp_session->get_entries(-columns => [keys %oid]); # get entries
505 $snmp_session->timeout($default_timeout); # reset session timeout
506
507 # Error if we don't get anything
508 if (!defined $result) {
509 printf "ERROR: [manager table] %s\n", $snmp_session->error;
510 exit $E_UNKNOWN;
511 }
512
513 @output = @{ get_snmp_output($result, \%oid) };
514
515 my %map_role
516 = (
517 1 => 'Standby',
518 2 => 'Active',
519 );
520
521 MANAGER:
522 foreach my $out (@output) {
523 $index = $out->{cpqRackCommonEnclosureManagerIndex};
524 $part = $out->{cpqRackCommonEnclosureManagerPartNumber};
525 $spare = $out->{cpqRackCommonEnclosureManagerSparePartNumber};
526 $serial = $out->{cpqRackCommonEnclosureManagerSerialNum};
527 $role = $out->{cpqRackCommonEnclosureManagerRole};
528 $condition = $out->{cpqRackCommonEnclosureManagerCondition};
529
530 # report manager condition
531 if (exists $snmp_status{$condition}) {
532 report( (sprintf q{Enclosure management module %d is %s, status is %s},
533 $index, $map_role{$role}, $snmp_status{$condition}),
534 $status2nagios{$snmp_status{$condition}}, $part, $spare, $serial );
535 }
536 else {
537 report( (sprintf q{Enclosure management module %d is %s, status is Unknown},
538 $index, $map_role{$role}),
539 $E_OK, $part, $spare, $serial );
540 }
541 }
542
543 return;
544 }
545
546
547 # Check the enclosure fans
548 sub check_fans {
549 my @output = ();
550
551 my $index = undef; # index
552 my $present = undef; # if device is present
553 my $part = undef; # part number
554 my $spare = undef; # spare part number
555 my $condition = undef; # condition
556
557 # OIDs we are interested in
558 my %oid
559 = (
560 '1.3.6.1.4.1.232.22.2.3.1.3.1.3' => 'cpqRackCommonEnclosureFanIndex',
561 '1.3.6.1.4.1.232.22.2.3.1.3.1.6' => 'cpqRackCommonEnclosureFanPartNumber',
562 '1.3.6.1.4.1.232.22.2.3.1.3.1.7' => 'cpqRackCommonEnclosureFanSparePartNumber',
563 '1.3.6.1.4.1.232.22.2.3.1.3.1.8' => 'cpqRackCommonEnclosureFanPresent',
564 '1.3.6.1.4.1.232.22.2.3.1.3.1.11' => 'cpqRackCommonEnclosureFanCondition',
565 );
566
567 my $result = $snmp_session->get_entries(-columns => [keys %oid]);
568
569 # Error if we don't get anything
570 if (!defined $result) {
571 printf "SNMP ERROR: [fan table] %s\n", $snmp_session->error;
572 exit $E_UNKNOWN;
573 }
574
575 @output = @{ get_snmp_output($result, \%oid) };
576
577 FAN:
578 foreach my $out (@output) {
579 $index = $out->{cpqRackCommonEnclosureFanIndex};
580 $present = $out->{cpqRackCommonEnclosureFanPresent};
581 $part = $out->{cpqRackCommonEnclosureFanPartNumber};
582 $spare = $out->{cpqRackCommonEnclosureFanSparePartNumber};
583 $condition = $out->{cpqRackCommonEnclosureFanCondition};
584
585 next FAN if $present_map{$present} ne 'present';
586
587 # report fan condition
588 report( (sprintf q{Fan %d condition is %s}, $index, $snmp_status{$condition}),
589 $status2nagios{$snmp_status{$condition}}, $part, $spare, q{} );
590 }
591
592 return;
593 }
594
595
596 # Check the blades
597 sub check_blades {
598 my @output = ();
599
600 my $index = undef; # index
601 my $name = undef; # blade name
602 my $part = undef; # part number
603 my $spare = undef; # spare part number
604 my $serial = undef; # serial number
605 my $position = undef; # blade position
606 my $present = undef; # if device is present
607 my $product = undef; # product id
608 my $status = undef; # blade status
609 my $major = undef; # major fault
610 my $minor = undef; # minor fault
611 my $diag = undef; # blade fault diagnostic string
612 my $power = undef; # if blade is powered up
613
614 # OIDs we are interested in
615 my %oid
616 = (
617 '1.3.6.1.4.1.232.22.2.4.1.1.1.3' => 'cpqRackServerBladeIndex',
618 '1.3.6.1.4.1.232.22.2.4.1.1.1.4' => 'cpqRackServerBladeName',
619 '1.3.6.1.4.1.232.22.2.4.1.1.1.6' => 'cpqRackServerBladePartNumber',
620 '1.3.6.1.4.1.232.22.2.4.1.1.1.7' => 'cpqRackServerBladeSparePartNumber',
621 '1.3.6.1.4.1.232.22.2.4.1.1.1.8' => 'cpqRackServerBladePosition',
622 '1.3.6.1.4.1.232.22.2.4.1.1.1.12' => 'cpqRackServerBladePresent',
623 '1.3.6.1.4.1.232.22.2.4.1.1.1.16' => 'cpqRackServerBladeSerialNum',
624 '1.3.6.1.4.1.232.22.2.4.1.1.1.17' => 'cpqRackServerBladeProductId',
625 '1.3.6.1.4.1.232.22.2.4.1.1.1.21' => 'cpqRackServerBladeStatus',
626 '1.3.6.1.4.1.232.22.2.4.1.1.1.22' => 'cpqRackServerBladeFaultMajor',
627 '1.3.6.1.4.1.232.22.2.4.1.1.1.23' => 'cpqRackServerBladeFaultMinor',
628 '1.3.6.1.4.1.232.22.2.4.1.1.1.24' => 'cpqRackServerBladeFaultDiagnosticString',
629 '1.3.6.1.4.1.232.22.2.4.1.1.1.25' => 'cpqRackServerBladePowered',
630 );
631
632 my $result = $snmp_session->get_entries(-columns => [keys %oid]);
633
634 # Error if we don't get anything
635 if (!defined $result) {
636 printf "SNMP ERROR: [blade table] %s\n", $snmp_session->error;
637 exit $E_UNKNOWN;
638 }
639
640 @output = @{ get_snmp_output($result, \%oid) };
641
642 sub get {
643 my ($hash, $val) = @_;
644 return exists $hash->{$val} ? $hash->{$val} : undef;
645 }
646
647 BLADE:
648 foreach my $out (@output) {
649 $index = get($out, 'cpqRackServerBladeIndex');
650 $name = get($out, 'cpqRackServerBladeName');
651 $part = get($out, 'cpqRackServerBladePartNumber');
652 $spare = get($out, 'cpqRackServerBladeSparePartNumber');
653 $serial = get($out, 'cpqRackServerBladeSerialNum');
654 $position = get($out, 'cpqRackServerBladePosition');
655 $present = get($out, 'cpqRackServerBladePresent');
656 $product = get($out, 'cpqRackServerBladeProductId');
657 $status = get($out, 'cpqRackServerBladeStatus');
658 $major = get($out, 'cpqRackServerBladeFaultMajor');
659 $minor = get($out, 'cpqRackServerBladeFaultMinor');
660 $diag = get($out, 'cpqRackServerBladeFaultDiagnosticString');
661 $power = get($out, 'cpqRackServerBladePowered');
662
663 next BLADE if $present_map{$present} ne 'present';
664 ++$count_blades;
665
666 $part =~ s{\s+\z}{}xms; # remove trailing whitespace
667
668 # report blade condition
669 if (!defined $status) {
670 report( (sprintf q{Blade %d is a %s with name: %s},
671 $index, $product, $name),
672 $E_OK, $part, $spare, $serial );
673 }
674 else {
675 report( (sprintf q{Blade %d (%s, %s) status is %s},
676 $index, $name, $product, $snmp_status{$status}),
677 $status2nagios{$snmp_status{$status}}, $part, $spare, $serial );
678 }
679 }
680
681 return;
682 }
683
684
685 # Check the enclosure power supplies
686 sub check_psu {
687 my @output = ();
688
689 my $index = undef; # index
690 my $serial = undef; # serial number
691 my $present = undef; # if device is present
692 my $part = undef; # part number
693 my $spare = undef; # spare part number
694 my $currpwr = undef; # The current power output of the power supply in watts
695 my $status = undef; # The status of the power supply
696 my $inputline = undef; # The status of line input power
697 my $condition = undef; # The condition of the power supply
698
699 # OIDs we are interested in
700 my %oid
701 = (
702 '1.3.6.1.4.1.232.22.2.5.1.1.1.3' => 'cpqRackPowerSupplyIndex',
703 '1.3.6.1.4.1.232.22.2.5.1.1.1.5' => 'cpqRackPowerSupplySerialNum',
704 '1.3.6.1.4.1.232.22.2.5.1.1.1.6' => 'cpqRackPowerSupplyPartNumber',
705 '1.3.6.1.4.1.232.22.2.5.1.1.1.7' => 'cpqRackPowerSupplySparePartNumber',
706 '1.3.6.1.4.1.232.22.2.5.1.1.1.10' => 'cpqRackPowerSupplyCurPwrOutput',
707 '1.3.6.1.4.1.232.22.2.5.1.1.1.14' => 'cpqRackPowerSupplyStatus',
708 '1.3.6.1.4.1.232.22.2.5.1.1.1.15' => 'cpqRackPowerSupplyInputLineStatus',
709 '1.3.6.1.4.1.232.22.2.5.1.1.1.16' => 'cpqRackPowerSupplyPresent',
710 '1.3.6.1.4.1.232.22.2.5.1.1.1.17' => 'cpqRackPowerSupplyCondition',
711 );
712
713 my $result = $snmp_session->get_entries(-columns => [keys %oid]);
714
715 # Error if we don't get anything
716 if (!defined $result) {
717 printf "SNMP ERROR: [psu table] %s\n", $snmp_session->error;
718 exit $E_UNKNOWN;
719 }
720
721 @output = @{ get_snmp_output($result, \%oid) };
722
723 my %psu_status
724 = (
725 1 => 'noError',
726 2 => 'generalFailure',
727 3 => 'bistFailure',
728 4 => 'fanFailure',
729 5 => 'tempFailure',
730 6 => 'interlockOpen',
731 7 => 'epromFailed',
732 8 => 'vrefFailed',
733 9 => 'dacFailed',
734 10 => 'ramTestFailed',
735 11 => 'voltageChannelFailed',
736 12 => 'orringdiodeFailed',
737 13 => 'brownOut',
738 14 => 'giveupOnStartup',
739 15 => 'nvramInvalid',
740 16 => 'calibrationTableInvalid',
741 );
742
743 my %inputline_status
744 = (
745 1 => 'noError',
746 2 => 'lineOverVoltage',
747 3 => 'lineUnderVoltage',
748 4 => 'lineHit',
749 5 => 'brownOut',
750 6 => 'linePowerLoss',
751 );
752
753 $total_wattage = 0;
754
755 PSU:
756 foreach my $out (@output) {
757 $index = $out->{cpqRackPowerSupplyIndex};
758 $present = $out->{cpqRackPowerSupplyPresent};
759 $part = $out->{cpqRackPowerSupplyPartNumber};
760 $spare = $out->{cpqRackPowerSupplySparePartNumber};
761 $condition = $out->{cpqRackPowerSupplyCondition};
762 $serial = $out->{cpqRackPowerSupplySerialNum};
763 $currpwr = $out->{cpqRackPowerSupplyCurPwrOutput};
764 $status = $out->{cpqRackPowerSupplyStatus};
765 $inputline = $out->{cpqRackPowerSupplyInputLineStatus};
766
767 next PSU if $present_map{$present} ne 'present';
768
769 # Calculate total power consumption
770 $total_wattage += $currpwr;
771
772 # Report PSU condition
773 if ($snmp_status{$condition} eq 'Ok') {
774 report( (sprintf q{PSU %d is %s, output: %d W},
775 $index, $snmp_status{$condition}, $currpwr),
776 $status2nagios{$snmp_status{$condition}}, $part, $spare, $serial );
777 }
778 else {
779 my $msg = sprintf q{PSU %d is %s},
780 $index, $snmp_status{$condition};
781 $msg .= " ($psu_status{$status})" if $status >= 1;
782 $msg .= ", input line status: $inputline_status{$inputline}" if $inputline >= 1;
783
784 report( $msg, $status2nagios{$snmp_status{$condition}}, $part, $spare, $serial );
785 }
786 }
787
788 # Collect performance data
789 if (defined $opt{perfdata}) {
790 push @perfdata, "'total_watt'=${total_wattage}W;0;0";
791 }
792
793 return;
794 }
795
796
797 # Check the IO modules
798 sub check_iom {
799 my @output = ();
800
801 my $index = undef; # index
802 my $present = undef; # if device is present
803 my $part = undef; # part number
804 my $spare = undef; # spare part number
805 my $serial = undef; # serial number
806 my $model = undef; # The model name of the network connector
807 my $location = undef; # The location of the network connector within the enclosure
808 my $devtype = undef; # The type of interrconnect in the enclosure
809
810 # OIDs we are interested in
811 my %oid
812 = (
813 '1.3.6.1.4.1.232.22.2.6.1.1.1.3' => 'cpqRackNetConnectorIndex',
814 '1.3.6.1.4.1.232.22.2.6.1.1.1.6' => 'cpqRackNetConnectorModel',
815 '1.3.6.1.4.1.232.22.2.6.1.1.1.7' => 'cpqRackNetConnectorSerialNum',
816 '1.3.6.1.4.1.232.22.2.6.1.1.1.8' => 'cpqRackNetConnectorPartNumber',
817 '1.3.6.1.4.1.232.22.2.6.1.1.1.9' => 'cpqRackNetConnectorSparePartNumber',
818 '1.3.6.1.4.1.232.22.2.6.1.1.1.12' => 'cpqRackNetConnectorLocation',
819 '1.3.6.1.4.1.232.22.2.6.1.1.1.13' => 'cpqRackNetConnectorPresent',
820 '1.3.6.1.4.1.232.22.2.6.1.1.1.17' => 'cpqRackNetConnectorDeviceType',
821 );
822
823 my $result = $snmp_session->get_entries(-columns => [keys %oid]);
824
825 # Error if we don't get anything
826 if (!defined $result) {
827 printf "SNMP ERROR: [fan table] %s\n", $snmp_session->error;
828 exit $E_UNKNOWN;
829 }
830
831 @output = @{ get_snmp_output($result, \%oid) };
832
833 my %device_type
834 = (
835 1 => 'noconnect',
836 2 => 'network',
837 3 => 'fibrechannel',
838 4 => 'sas',
839 5 => 'inifiband',
840 6 => 'pciexpress',
841 );
842
843 IOM:
844 foreach my $out (@output) {
845 $index = $out->{cpqRackNetConnectorIndex};
846 $present = $out->{cpqRackNetConnectorPresent};
847 $part = $out->{cpqRackNetConnectorPartNumber};
848 $model = $out->{cpqRackNetConnectorModel};
849 $location = $out->{cpqRackNetConnectorLocation};
850 $devtype = $out->{cpqRackNetConnectorDeviceType};
851
852 next IOM if $present_map{$present} ne 'present';
853 ++$count_ioms;
854
855 # report IOM
856 report( (sprintf q{I/O module %d is type %s: %s},
857 $index, $device_type{$devtype}, $model),
858 $E_OK, $part, $spare, $serial );
859 }
860
861 return;
862 }
863
864
865 # Default plugin output
866 sub output_default {
867 my $c = 0; # counter to determine linebreaks
868
869 # Run through each message, sorted by severity level
870 ALERT:
871 foreach (sort {$a->[1] < $b->[1]} @reports) {
872 my ($msg, $level, $part, $spare, $serial) = @{ $_ };
873 next ALERT if $level == $E_OK;
874
875 # Prefix with service tag if specified with option '-i|--info'
876 if ($opt{info}) {
877 $msg = "[$sysinfo{serial}] " . $msg;
878 }
879
880 # Prefix with nagios level if specified with option '--state'
881 $msg = $reverse_exitcode{$level} . ": $msg" if $opt{state};
882
883 # Prefix with one-letter nagios level if specified with option '--short-state'
884 $msg = (substr $reverse_exitcode{$level}, 0, 1) . ": $msg" if $opt{shortstate};
885
886 if ($opt{verbose} and $msg !~ m/overall health condition/) {
887 $msg .= sprintf q{ [part: %s, spare: %s, sn: %s]},
888 $part eq q{} ? 'n/a' : $part,
889 $spare eq q{} ? 'n/a' : $spare,
890 $serial eq q{} ? 'n/a' : $serial;
891 }
892
893 ($c++ == 0) ? print $msg : print $linebreak, $msg;
894
895 $nagios_alert_count{$reverse_exitcode{$level}}++;
896 }
897
898 return;
899 }
900
901 # Debug plugin output
902 sub output_debug {
903 print " System: $sysinfo{model}\n";
904 print " ServiceTag: $sysinfo{serial}\n";
905 print " Firmware: $sysinfo{firmware}";
906 print q{ } x (25 - length "$sysinfo{firmware}"), "Plugin version: $VERSION\n";
907 if ($#reports >= 0) {
908 print "-----------------------------------------------------------------------------\n";
909 print " System Component Status \n";
910 print "=============================================================================\n";
911 print " STATE | PART NO. | MESSAGE TEXT \n";
912 print "---------+----------------+--------------------------------------------------\n";
913 foreach (@reports) {
914 my ($msg, $level, $part, $spare, $serial) = @{$_};
915 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | "
916 . q{ } x (14 - length $part) . "$part | $msg\n";
917 $nagios_alert_count{$reverse_exitcode{$level}}++;
918 }
919 }
920
921 # Print system power readings
922 print "-----------------------------------------------------------------------------\n";
923 print " System Power Readings \n";
924 print "=============================================================================\n";
925 print " Total power consumption: $total_wattage W\n";
926
927 return;
928 }
929
930 # Performance data output
931 sub output_perfdata {
932 my $lb = $opt{perfdata} eq 'multiline' ? "\n" : q{ }; # line break for perfdata
933 print q{|};
934 print join $lb, @perfdata;
935 return;
936 }
937
938
939 #=====================================================================
940 # Main program
941 #=====================================================================
942
943 # Probe the blade chassis via SNMP
944 get_enclosure_status();
945
946 # Only check managers if global health is not Ok, or debug
947 if ($global ne 'Ok' or $opt{debug}) {
948 check_managers();
949 }
950
951 # Always these
952 check_fans();
953 check_blades();
954 check_iom();
955 check_psu();
956
957 # Print output
958 if ($opt{debug}) {
959 output_debug();
960 }
961 else {
962 output_default();
963 }
964
965 # Determine our exit code
966 $exit_code = $E_OK;
967 if ($nagios_alert_count{UNKNOWN} > 0) { $exit_code = $E_UNKNOWN; }
968 if ($nagios_alert_count{WARNING} > 0) { $exit_code = $E_WARNING; }
969 if ($nagios_alert_count{CRITICAL} > 0) { $exit_code = $E_CRITICAL; }
970
971 # Print any perl warnings that have occured
972 if (@perl_warnings) {
973 foreach (@perl_warnings) {
974 chop @$_;
975 print "${linebreak}INTERNAL ERROR: @$_";
976 }
977 $exit_code = $E_UNKNOWN;
978 }
979
980 # Reset the WARN signal
981 $SIG{__WARN__} = $original_sigwarn;
982
983 # OK message
984 if ($exit_code == $E_OK && !$opt{debug}) {
985 printf q{OK - System: '%s', SN: '%s', Firmware: '%s', hardware working fine, %d blades, %d i/o modules},
986 $sysinfo{model}, $sysinfo{serial}, $sysinfo{firmware}, $count_blades, $count_ioms;
987 }
988
989 # Extended info output
990 if ($opt{extinfo} && !$opt{debug} && $exit_code != $E_OK) {
991 print $linebreak;
992 printf '------ SYSTEM: %s, SN: %s, FW: %s',
993 $sysinfo{model}, $sysinfo{serial}, $sysinfo{firmware};
994 }
995
996 # Print performance data
997 if (defined $opt{perfdata} && !$opt{debug} && @perfdata) {
998 output_perfdata();
999 }
1000
1001 print "\n" if !$opt{debug};
1002
1003 # Exit with proper exit code
1004 exit $exit_code;