]> git.uio.no Git - check_openmanage.git/blame - check_openmanage
* version 3.5.6-beta3
[check_openmanage.git] / check_openmanage
CommitLineData
669797e1 1#!/usr/bin/perl
2#
3# Nagios plugin
4#
5# Monitor Dell server hardware status using Dell OpenManage Server
6# Administrator, either locally via NRPE, or remotely via SNMP.
7#
8# $Id$
9#
f1728beb 10# Copyright (C) 2010 Trond H. Amundsen
669797e1 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
26require 5.006; # Perl v5.6.0 or newer is required
27use strict;
28use warnings;
29use POSIX qw(isatty ceil);
30use Getopt::Long qw(:config no_ignore_case);
31
32# Global (package) variables used throughout the code
33use vars qw( $NAME $VERSION $AUTHOR $CONTACT $E_OK $E_WARNING $E_CRITICAL
34 $E_UNKNOWN $FW_LOCK $USAGE $HELP $LICENSE
35 $snmp_session $snmp_error $omreport $globalstatus $global
36 $linebreak $omopt_chassis $omopt_system $blade
cbbc270f 37 $exit_code $snmp $original_sigwarn
669797e1 38 %check %opt %perfdata %reverse_exitcode %status2nagios
39 %snmp_status %snmp_probestatus %probestatus2nagios %sysinfo
40 %blacklist %nagios_alert_count %count
cbbc270f 41 @perl_warnings @controllers @enclosures
669797e1 42 @report_storage @report_chassis @report_other
43 );
44
45#---------------------------------------------------------------------
46# Initialization and global variables
47#---------------------------------------------------------------------
48
eab0860a 49# Small subroutine to collect any perl warnings during execution
cbbc270f 50sub collect_perl_warning {
51 push @perl_warnings, [@_];
669797e1 52}
53
cbbc270f 54# Set the WARN signal to use our collect subroutine above
55$original_sigwarn = $SIG{__WARN__};
56$SIG{__WARN__} = \&collect_perl_warning;
57
669797e1 58# Version and similar info
59$NAME = 'check_openmanage';
c8eb5019 60$VERSION = '3.5.6-beta3';
669797e1 61$AUTHOR = 'Trond H. Amundsen';
62$CONTACT = 't.h.amundsen@usit.uio.no';
63
64# Exit codes
65$E_OK = 0;
66$E_WARNING = 1;
67$E_CRITICAL = 2;
68$E_UNKNOWN = 3;
69
70# Firmware update lock file [FIXME: location on Windows?]
71$FW_LOCK = '/var/lock/.spsetup'; # default on Linux
72
73# Usage text
74$USAGE = <<"END_USAGE";
75Usage: $NAME [OPTION]...
76END_USAGE
77
78# Help text
79$HELP = <<'END_HELP';
80
81GENERAL OPTIONS:
82
83 -p, --perfdata Output performance data
84 -t, --timeout Plugin timeout in seconds
85 -c, --critical Customise temperature critical limits
86 -w, --warning Customise temperature warning limits
87 -d, --debug Debug output, reports everything
88 -h, --help Display this help text
89 -V, --version Display version info
90
91SNMP OPTIONS:
92
93 -H, --hostname Hostname or IP of the server (needed for SNMP)
94 -C, --community SNMP community string
95 -P, --protocol SNMP protocol version
96 --port SNMP port number
97
98OUTPUT OPTIONS:
99
100 -i, --info Prefix any alerts with the service tag
101 -e, --extinfo Append system info to alerts
102 -s, --state Prefix alerts with alert state
057193f5 103 -S, --short-state Prefix alerts with alert state (abbreviated)
669797e1 104 -o, --okinfo Verbosity when check result is OK
bee55928 105 -I, --htmlinfo HTML output with clickable links
669797e1 106
107CHECK CONTROL AND BLACKLISTING:
108
109 -a, --all Check everything, even log content
110 -b, --blacklist Blacklist missing and/or failed components
111 --only Only check a certain component or alert type
112 --check Fine-tune which components are checked
113
114For more information and advanced options, see the manual page or URL:
115 http://folk.uio.no/trondham/software/check_openmanage.html
116END_HELP
117
118# Version and license text
119$LICENSE = <<"END_LICENSE";
120$NAME $VERSION
f1728beb 121Copyright (C) 2010 $AUTHOR
669797e1 122License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
123This is free software: you are free to change and redistribute it.
124There is NO WARRANTY, to the extent permitted by law.
125
126Written by $AUTHOR <$CONTACT>
127END_LICENSE
128
129# Options with default values
130%opt = ( 'blacklist' => [],
131 'check' => [],
132 'critical' => [],
133 'warning' => [],
134 'timeout' => 30, # default timeout is 30 seconds
135 'debug' => 0,
136 'help' => 0,
137 'perfdata' => undef,
138 'info' => 0,
139 'extinfo' => 0,
140 'htmlinfo' => undef,
141 'postmsg' => undef,
142 'state' => 0,
143 'short-state' => 0,
144 'okinfo' => 0, # default "ok" output level
145 'linebreak' => undef,
146 'version' => 0,
147 'all' => 0,
148 'only' => undef,
9ed0700c 149 'omreport' => undef,
669797e1 150 'port' => 161, # default SNMP port
151 'hostname' => undef,
152 'community' => 'public', # SMNP v1 or v2c
153 'protocol' => 2,
154 'username' => undef, # SMNP v3
155 'authpassword' => undef, # SMNP v3
156 'authkey' => undef, # SMNP v3
157 'authprotocol' => undef, # SMNP v3
158 'privpassword' => undef, # SMNP v3
159 'privkey' => undef, # SMNP v3
160 'privprotocol' => undef, # SMNP v3
161 );
162
163# Get options
164GetOptions('b|blacklist=s' => \@{ $opt{blacklist} },
165 'check=s' => \@{ $opt{check} },
166 'c|critical=s' => \@{ $opt{critical} },
167 'w|warning=s' => \@{ $opt{warning} },
168 't|timeout=i' => \$opt{timeout},
169 'd|debug' => \$opt{debug},
170 'h|help' => \$opt{help},
171 'V|version' => \$opt{version},
172 'p|perfdata:s' => \$opt{perfdata},
173 'i|info' => \$opt{info},
174 'e|extinfo' => \$opt{extinfo},
bee55928 175 'I|htmlinfo:s' => \$opt{htmlinfo},
669797e1 176 'postmsg=s' => \$opt{postmsg},
177 's|state' => \$opt{state},
057193f5 178 'S|short-state' => \$opt{shortstate},
669797e1 179 'o|ok-info=i' => \$opt{okinfo},
180 'l|linebreak=s' => \$opt{linebreak},
181 'a|all' => \$opt{all},
182 'only=s' => \$opt{only},
9ed0700c 183 'omreport=s' => \$opt{omreport},
669797e1 184 'port=i' => \$opt{port},
185 'H|hostname=s' => \$opt{hostname},
186 'C|community=s' => \$opt{community},
187 'P|protocol=i' => \$opt{protocol},
188 'U|username=s' => \$opt{username},
189 'authpassword=s' => \$opt{authpassword},
190 'authkey=s' => \$opt{authkey},
191 'authprotocol=s' => \$opt{authprotocol},
192 'privpassword=s' => \$opt{privpassword},
193 'privkey=s' => \$opt{privkey},
194 'privprotocol=s' => \$opt{privprotocol},
195 ) or do { print $USAGE; exit $E_UNKNOWN };
196
197# If user requested help
198if ($opt{help}) {
199 print $USAGE, $HELP;
200 exit $E_OK;
201}
202
203# If user requested version info
204if ($opt{version}) {
205 print $LICENSE;
206 exit $E_OK;
207}
208
209# Setting timeout
210$SIG{ALRM} = sub {
211 print "PLUGIN TIMEOUT: $NAME timed out after $opt{timeout} seconds\n";
212 exit $E_UNKNOWN;
213};
214alarm $opt{timeout};
215
216# If we're using SNMP
217$snmp = defined $opt{hostname} ? 1 : 0;
218
219# SNMP session variables
220$snmp_session = undef;
221$snmp_error = undef;
222
223# The omreport command
224$omreport = undef;
225
226# Check flags, override available with the --check option
227%check = ( 'storage' => 1, # check storage subsystem
228 'memory' => 1, # check memory (dimms)
229 'fans' => 1, # check fan status
230 'power' => 1, # check power supplies
231 'temp' => 1, # check temperature
232 'cpu' => 1, # check processors
233 'voltage' => 1, # check voltage
234 'batteries' => 1, # check battery probes
235 'amperage' => 1, # check power consumption
236 'intrusion' => 1, # check intrusion detection
237 'alertlog' => 0, # check the alert log
238 'esmlog' => 0, # check the ESM log (hardware log)
239 'esmhealth' => 1, # check the ESM log overall health
240 );
241
242# Default line break
51e99613 243$linebreak = isatty(*STDOUT) ? "\n" : '<br/>';
669797e1 244
245# Line break from option
246if (defined $opt{linebreak}) {
247 if ($opt{linebreak} eq 'REG') {
248 $linebreak = "\n";
249 }
250 elsif ($opt{linebreak} eq 'HTML') {
251 $linebreak = '<br/>';
252 }
253 else {
254 $linebreak = $opt{linebreak};
255 }
256}
257
258# Exit with status=UNKNOWN if there is firmware upgrade in progress
259if (!$snmp && -f $FW_LOCK) {
260 print "MONITORING DISABLED - Firmware update in progress ($FW_LOCK exists)\n";
261 exit $E_UNKNOWN;
262}
263
264# List of controllers and enclosures
265@controllers = (); # controllers
266@enclosures = (); # enclosures
267
268# Messages
269@report_storage = (); # messages with associated nagios level (storage)
270@report_chassis = (); # messages with associated nagios level (chassis)
271@report_other = (); # messages with associated nagios level (other)
272
273# Counters for everything
274%count
275 = (
276 'pdisk' => 0, # number of physical disks
277 'vdisk' => 0, # number of logical drives (virtual disks)
278 'temp' => 0, # number of temperature probes
279 'volt' => 0, # number of voltage probes
280 'amp' => 0, # number of amperage probes
281 'intr' => 0, # number of intrusion probes
282 'dimm' => 0, # number of memory modules
283 'fan' => 0, # number of fan probes
284 'cpu' => 0, # number of CPUs
285 'bat' => 0, # number of batteries
286 'power' => 0, # number of power supplies
287 'esm' => {
288 'Critical' => 0, # critical entries in ESM log
289 'Non-Critical' => 0, # warning entries in ESM log
290 'Ok' => 0, # ok entries in ESM log
291 },
292 'alert' => {
293 'Critical' => 0, # critical entries in alert log
294 'Non-Critical' => 0, # warning entries in alert log
295 'Ok' => 0, # ok entries in alert log
296 },
297 );
298
299# Performance data
300%perfdata = ();
301
302# Global health status
303$global = 1; # default is to check global status
304$globalstatus = $E_OK; # default global health status is "OK"
305
306# Nagios error levels reversed
307%reverse_exitcode
308 = (
309 $E_OK => 'OK',
310 $E_WARNING => 'WARNING',
311 $E_CRITICAL => 'CRITICAL',
312 $E_UNKNOWN => 'UNKNOWN',
313 );
314
315# OpenManage (omreport) and SNMP error levels
316%status2nagios
317 = (
318 'Unknown' => $E_CRITICAL,
319 'Critical' => $E_CRITICAL,
320 'Non-Critical' => $E_WARNING,
321 'Ok' => $E_OK,
322 'Non-Recoverable' => $E_CRITICAL,
323 'Other' => $E_CRITICAL,
324 );
325
326# Status via SNMP
327%snmp_status
328 = (
329 1 => 'Other',
330 2 => 'Unknown',
331 3 => 'Ok',
332 4 => 'Non-Critical',
333 5 => 'Critical',
334 6 => 'Non-Recoverable',
335 );
336
337# Probe Status via SNMP
338%snmp_probestatus
339 = (
340 1 => 'Other', # probe status is not one of the following:
341 2 => 'Unknown', # probe status is unknown (not known or monitored)
342 3 => 'Ok', # probe is reporting a value within the thresholds
343 4 => 'nonCriticalUpper', # probe has crossed upper noncritical threshold
344 5 => 'criticalUpper', # probe has crossed upper critical threshold
345 6 => 'nonRecoverableUpper', # probe has crossed upper non-recoverable threshold
346 7 => 'nonCriticalLower', # probe has crossed lower noncritical threshold
347 8 => 'criticalLower', # probe has crossed lower critical threshold
348 9 => 'nonRecoverableLower', # probe has crossed lower non-recoverable threshold
349 10 => 'failed', # probe is not functional
350 );
351
352# Probe status translated to Nagios alarm levels
353%probestatus2nagios
354 = (
355 'Other' => $E_CRITICAL,
356 'Unknown' => $E_CRITICAL,
357 'Ok' => $E_OK,
358 'nonCriticalUpper' => $E_WARNING,
359 'criticalUpper' => $E_CRITICAL,
360 'nonRecoverableUpper' => $E_CRITICAL,
361 'nonCriticalLower' => $E_WARNING,
362 'criticalLower' => $E_CRITICAL,
363 'nonRecoverableLower' => $E_CRITICAL,
364 'failed' => $E_CRITICAL,
365 );
366
367# System information gathered
368%sysinfo
369 = (
370 'bios' => 'N/A', # BIOS version
371 'biosdate' => 'N/A', # BIOS release date
372 'serial' => 'N/A', # serial number (service tag)
373 'model' => 'N/A', # system model
374 'osname' => 'N/A', # OS name
375 'osver' => 'N/A', # OS version
376 'om' => 'N/A', # OMSA version
377 'bmc' => 0, # HAS baseboard management controller (BMC)
378 'rac' => 0, # HAS remote access controller (RAC)
379 'rac_name' => 'N/A', # remote access controller (RAC)
380 'bmc_fw' => 'N/A', # BMC firmware
381 'rac_fw' => 'N/A', # RAC firmware
382 );
383
384# Adjust which checks to perform
385adjust_checks() if defined $opt{check};
386
387# Blacklisted components
388%blacklist = defined $opt{blacklist} ? %{ get_blacklist() } : ();
389
390# If blacklisting is in effect, don't check global health status
391if (scalar keys %blacklist > 0) {
392 $global = 0;
393}
394
395# Take into account new hardware and blades
396$omopt_chassis = 'chassis'; # default "chassis" option to omreport
397$omopt_system = 'system'; # default "system" option to omreport
398$blade = 0; # if this is a blade system
399
400# Some initializations and checking before we begin
401if ($snmp) {
402 snmp_initialize(); # initialize SNMP
403 snmp_check(); # check that SNMP works
404 snmp_detect_blade(); # detect blade via SNMP
405}
406else {
407 # Find the omreport binary
408 find_omreport();
409 # Check help output from omreport, see which options are available.
410 # Also detecting blade via omreport.
411 check_omreport_options();
412}
413
414
415#---------------------------------------------------------------------
416# Helper functions
417#---------------------------------------------------------------------
418
419#
420# Store a message in one of the message arrays
421#
422sub report {
423 my ($type, $msg, $exval, $id) = @_;
424 defined $id or $id = q{};
425
426 my %type2array
427 = (
428 'storage' => \@report_storage,
429 'chassis' => \@report_chassis,
430 'other' => \@report_other,
431 );
432
433 return push @{ $type2array{$type} }, [ $msg, $exval, $id ];
434}
435
436
437#
438# Run command, put resulting output lines in an array and return a
439# pointer to that array
440#
441sub run_command {
442 my $command = shift;
443
444 open my $CMD, '-|', $command
445 or do { report('other', "Couldn't run command '$command': $!", $E_UNKNOWN)
446 and return [] };
447 my @lines = <$CMD>;
448 close $CMD
449 or do { report('other', "Couldn't close filehandle for command '$command': $!", $E_UNKNOWN)
450 and return \@lines };
451 return \@lines;
452}
453
454#
455# Run command, put resulting output in a string variable and return it
456#
457sub slurp_command {
458 my $command = shift;
459
460 open my $CMD, '-|', $command
461 or do { report('other', "Couldn't run command '$command': $!", $E_UNKNOWN) and return };
462 my $rawtext = do { local $/ = undef; <$CMD> }; # slurping
463 close $CMD;
464
465 # NOTE: We don't check the return value of close() since omreport
466 # does something weird sometimes.
467
468 return $rawtext;
469}
470
471#
472# Initialize SNMP
473#
474sub snmp_initialize {
475 # Legal SNMP v3 protocols
476 my $snmp_v3_privprotocol = qr{\A des|aes|aes128|3des|3desde \z}xms;
477 my $snmp_v3_authprotocol = qr{\A md5|sha \z}xms;
478
479 # Parameters to Net::SNMP->session()
480 my %param
481 = (
482 '-port' => $opt{port},
483 '-hostname' => $opt{hostname},
484 '-version' => $opt{protocol},
485 );
486
487 # Parameters for SNMP v3
488 if ($opt{protocol} == 3) {
489
490 # Username is mandatory
491 if (defined $opt{username}) {
492 $param{'-username'} = $opt{username};
493 }
494 else {
495 print "SNMP ERROR: With SNMPv3 the username must be specified\n";
496 exit $E_UNKNOWN;
497 }
498
499 # Authpassword is optional
500 if (defined $opt{authpassword}) {
501 $param{'-authpassword'} = $opt{authpassword};
502 }
503
504 # Authkey is optional
505 if (defined $opt{authkey}) {
506 $param{'-authkey'} = $opt{authkey};
507 }
508
509 # Privpassword is optional
510 if (defined $opt{privpassword}) {
511 $param{'-privpassword'} = $opt{privpassword};
512 }
513
514 # Privkey is optional
515 if (defined $opt{privkey}) {
516 $param{'-privkey'} = $opt{privkey};
517 }
518
519 # Privprotocol is optional
520 if (defined $opt{privprotocol}) {
521 if ($opt{privprotocol} =~ m/$snmp_v3_privprotocol/xms) {
522 $param{'-privprotocol'} = $opt{privprotocol};
523 }
524 else {
525 print "SNMP ERROR: Unknown privprotocol '$opt{privprotocol}', "
526 . "must be one of [des|aes|aes128|3des|3desde]\n";
527 exit $E_UNKNOWN;
528 }
529 }
530
531 # Authprotocol is optional
532 if (defined $opt{authprotocol}) {
533 if ($opt{authprotocol} =~ m/$snmp_v3_authprotocol/xms) {
534 $param{'-authprotocol'} = $opt{authprotocol};
535 }
536 else {
537 print "SNMP ERROR: Unknown authprotocol '$opt{authprotocol}', "
538 . "must be one of [md5|sha]\n";
539 exit $E_UNKNOWN;
540 }
541 }
542 }
543 # Parameters for SNMP v2c or v1
544 elsif ($opt{protocol} == 2 or $opt{protocol} == 1) {
545 $param{'-community'} = $opt{community};
546 }
547 else {
548 print "SNMP ERROR: Unknown SNMP version '$opt{protocol}'\n";
549 exit $E_UNKNOWN;
550 }
551
552 # Try to initialize the SNMP session
553 if ( eval { require Net::SNMP; 1 } ) {
554 ($snmp_session, $snmp_error) = Net::SNMP->session( %param );
555 if (!defined $snmp_session) {
556 printf "SNMP: %s\n", $snmp_error;
557 exit $E_UNKNOWN;
558 }
559 }
560 else {
561 print "You need perl module Net::SNMP to run $NAME in SNMP mode\n";
562 exit $E_UNKNOWN;
563 }
564 return;
565}
566
567#
568# Checking if SNMP works by probing for "chassisModelName", which all
569# servers should have
570#
571sub snmp_check {
572 my $chassisModelName = '1.3.6.1.4.1.674.10892.1.300.10.1.9.1';
573 my $result = $snmp_session->get_request(-varbindlist => [$chassisModelName]);
574
575 # Typically if remote host isn't responding
576 if (!defined $result) {
577 printf "SNMP CRITICAL: %s\n", $snmp_session->error;
578 exit $E_CRITICAL;
579 }
580
581 # If OpenManage isn't installed or is not working
582 if ($result->{$chassisModelName} =~ m{\A noSuch (Instance|Object) \z}xms) {
583 print "ERROR: (SNMP) OpenManage is not installed or is not working correctly\n";
584 exit $E_UNKNOWN;
585 }
586 return;
587}
588
589#
590# Detecting blade via SNMP
591#
592sub snmp_detect_blade {
593 my $DellBaseBoardType = '1.3.6.1.4.1.674.10892.1.300.80.1.7.1.1';
594 my $result = $snmp_session->get_request(-varbindlist => [$DellBaseBoardType]);
595
596 # Identify blade. Older models (4th and 5th gen models) and/or old
597 # OMSA (4.x) don't have this OID. If we get "noSuchInstance" or
598 # similar, we assume that this isn't a blade
5c370da3 599 if (exists $result->{$DellBaseBoardType} && $result->{$DellBaseBoardType} eq '3') {
669797e1 600 $blade = 1;
601 }
602 return;
603}
604
605#
606# Locate the omreport binary
607#
608sub find_omreport {
ac760e0d 609 # If user has specified path to omreport
610 if (defined $opt{omreport} and -x $opt{omreport}) {
60994ca4 611 $omreport = qq{"$opt{omreport}"};
ac760e0d 612 return;
613 }
614
669797e1 615 # Possible full paths for omreport
616 my @omreport_paths
617 = (
618 '/usr/bin/omreport', # default on Linux
6a050646 619 '/opt/dell/srvadmin/bin/omreport', # default on Linux with OMSA 6.2.0
669797e1 620 '/opt/dell/srvadmin/oma/bin/omreport.sh', # alternate on Linux
621 '/opt/dell/srvadmin/oma/bin/omreport', # alternate on Linux
9025e83f 622 'C:\Program Files (x86)\Dell\SysMgt\oma\bin\omreport.exe', # default on Windows x64
623 'C:\Program Files\Dell\SysMgt\oma\bin\omreport.exe', # default on Windows x32
421b6c77 624 'c:\progra~1\dell\sysmgt\oma\bin\omreport.exe', # 8bit legacy default on Windows x32
625 'c:\progra~2\dell\sysmgt\oma\bin\omreport.exe', # 8bit legacy default on Windows x64
669797e1 626 );
627
628 # Find the one to use
629 OMREPORT_PATH:
630 foreach my $bin (@omreport_paths) {
631 if (-x $bin) {
60347693 632 $omreport = qq{"$bin"};
669797e1 633 last OMREPORT_PATH;
634 }
635 }
636
637 # Exit with status=UNKNOWN if OM is not installed, or we don't
638 # have permission to execute the binary
639 if (!defined $omreport) {
640 print "ERROR: Dell OpenManage Server Administrator (OMSA) is not installed\n";
641 exit $E_UNKNOWN;
642 }
643 return;
644}
645
646#
647# Checks output from 'omreport -?' and searches for arguments to
648# omreport, to accommodate deprecated options "chassis" and "system"
649# (on newer hardware), as well as blade servers.
650#
651sub check_omreport_options {
652 foreach (@{ run_command("$omreport -? 2>&1") }) {
653 if (m/\A servermodule /xms) {
654 # If "servermodule" argument to omreport exists, use it
655 # instead of argument "system"
656 $omopt_system = 'servermodule';
657 }
658 elsif (m/\A mainsystem /xms) {
659 # If "mainsystem" argument to omreport exists, use it
660 # instead of argument "chassis"
661 $omopt_chassis = 'mainsystem';
662 }
663 elsif (m/\A modularenclosure /xms) {
664 # If "modularenclusure" argument to omreport exists, assume
665 # that this is a blade
666 $blade = 1;
667 }
668 }
669 return;
670}
671
672#
673# Read the blacklist option and return a hash containing the
674# blacklisted components
675#
676sub get_blacklist {
677 my @bl = ();
678 my %blacklist = ();
679
680 if (scalar @{ $opt{blacklist} } >= 0) {
681 foreach my $black (@{ $opt{blacklist} }) {
682 my $tmp = q{};
683 if (-f $black) {
684 open my $BL, '<', $black
685 or do { report('other', "Couldn't open blacklist file $black: $!", $E_UNKNOWN)
686 and return {} };
687 $tmp = <$BL>;
688 close $BL;
689 chomp $tmp;
690 }
691 else {
692 $tmp = $black;
693 }
694 push @bl, $tmp;
695 }
696 }
697
698 return {} if $#bl < 0;
699
700 # Parse blacklist string, put in hash
701 foreach my $black (@bl) {
702 my @comps = split m{/}xms, $black;
703 foreach my $c (@comps) {
704 next if $c !~ m/=/xms;
705 my ($key, $val) = split /=/xms, $c;
706 my @vals = split /,/xms, $val;
707 $blacklist{$key} = \@vals;
708 }
709 }
710
711 return \%blacklist;
712}
713
714#
715# Read the check option and adjust the hash %check, which is a rough
716# list of components to be checked
717#
718sub adjust_checks {
719 my @cl = ();
720
721 # Adjust checking based on the '--all' option
722 if ($opt{all}) {
723 # Check option usage
724 if (defined $opt{only} and $opt{only} !~ m{\A critical|warning \z}xms) {
725 print qq{ERROR: Wrong simultaneous usage of the "--all" and "--only" options\n};
726 exit $E_UNKNOWN;
727 }
728 if (scalar @{ $opt{check} } > 0) {
729 print qq{ERROR: Wrong simultaneous usage of the "--all" and "--check" options\n};
730 exit $E_UNKNOWN;
731 }
732
733 # set the check hash to check everything
734 map { $_ = 1 } values %check;
735
736 return;
737 }
738
739 # Adjust checking based on the '--only' option
740 if (defined $opt{only} and $opt{only} !~ m{\A critical|warning \z}xms) {
741 # Check option usage
742 if (scalar @{ $opt{check} } > 0) {
743 print qq{ERROR: Wrong simultaneous usage of the "--only" and "--check" options\n};
744 exit $E_UNKNOWN;
745 }
a2bbb2c1 746 if (! exists $check{$opt{only}} && $opt{only} ne 'chassis') {
669797e1 747 print qq{ERROR: "$opt{only}" is not a known keyword for the "--only" option\n};
748 exit $E_UNKNOWN;
749 }
750
751 # reset the check hash
752 map { $_ = 0 } values %check;
753
754 # adjust the check hash
755 if ($opt{only} eq 'chassis') {
756 map { $check{$_} = 1 } qw(memory fans power temp cpu voltage
757 batteries amperage intrusion esmhealth);
758 }
759 else {
760 $check{$opt{only}} = 1;
761 }
762
763 return;
764 }
765
766 # Adjust checking based on the '--check' option
767 if (scalar @{ $opt{check} } >= 0) {
768 foreach my $check (@{ $opt{check} }) {
769 my $tmp = q{};
770 if (-f $check) {
771 open my $CL, '<', $check
772 or do { report('other', "Couldn't open check file $check: $!", $E_UNKNOWN) and return };
773 $tmp = <$CL>;
774 close $CL;
775 }
776 else {
777 $tmp = $check;
778 }
779 push @cl, $tmp;
780 }
781 }
782
783 return if $#cl < 0;
784
785 # Parse checklist string, put in hash
786 foreach my $check (@cl) {
787 my @checks = split /,/xms, $check;
788 foreach my $c (@checks) {
789 next if $c !~ m/=/xms;
790 my ($key, $val) = split /=/xms, $c;
791 $check{$key} = $val;
792 }
793 }
794
795 # Check if we should check global health status
796 CHECK_KEY:
797 foreach (keys %check) {
798 next CHECK_KEY if $_ eq 'esmlog'; # not part of global status
799 next CHECK_KEY if $_ eq 'alertlog'; # not part of global status
800
801 if ($check{$_} == 0) { # found something with checking turned off
802 $global = 0;
803 last CHECK_KEY;
804 }
805 }
806
807 return;
808}
809
810#
811# Runs omreport and returns an array of anonymous hashes containing
812# the output.
813# Takes one argument: string containing parameters to omreport
814#
815sub run_omreport {
816 my $command = shift;
817 my @output = ();
818 my @keys = ();
819
820 # Errors that are OK. Some low-end poweredge (and blades) models
821 # don't have RAID controllers, intrusion detection sensor, or
822 # redundant/instrumented power supplies etc.
823 my $ok_errors
824 = qr{
825 Intrusion\sinformation\sis\snot\sfound\sfor\sthis\ssystem # No intrusion probe
826 | No\sinstrumented\spower\ssupplies\sfound\son\sthis\ssystem # No instrumented PS (blades/low-end)
827 | No\scontrollers\sfound # No RAID controller
828 | No\sbattery\sprobes\sfound\son\sthis\ssystem # No battery probes
829 | Invalid\scommand:\spwrmonitoring # Older OMSAs lack this command(?)
4a4baf82 830# | Current\sprobes\snot\sfound # No power monitoring capability
669797e1 831 }xms;
832
833 # Errors that are OK on blade servers
834 my $ok_blade_errors
835 = qr{
836 No\sfan\sprobes\sfound\son\sthis\ssystem # No fan probes
837 }xms;
838
839 # Run omreport and fetch output
840 my $rawtext = slurp_command("$omreport $command -fmt ssv 2>&1");
841 return [] if !defined $rawtext;
842
843 # Workaround for Openmanage BUG introduced in OMSA 5.5.0
4a4baf82 844 $rawtext =~ s{\n;}{;}gxms if $command eq 'storage controller';
845
846 # Openmanage sometimes puts a linebreak between "Error" and the
847 # actual error text
49a51b07 848 $rawtext =~ s{^Error\s*\n}{Error: }xms;
669797e1 849
850 # Parse output, store in array
4a4baf82 851 for ((split m{\n}xms, $rawtext)) {
852 if (m{\AError}xms) {
669797e1 853 next if m{$ok_errors}xms;
854 next if ($blade and m{$ok_blade_errors}xms);
855 report('other', "Problem running 'omreport $command': $_", $E_UNKNOWN);
856 }
857
858 next if !m/(.*?;){2}/xms; # ignore lines with less than 3 fields
859 my @vals = split /;/xms;
8ce893fd 860 if ($vals[0] =~ m/\A (Index|ID|Severity|Processor|Current\sSpeed) \z/xms) {
669797e1 861 @keys = @vals;
862 }
863 else {
864 my $i = 0;
865 push @output, { map { $_ => $vals[$i++] } @keys };
866 }
867
868 }
869
870 # Finally, return the collected information
871 return \@output;
872}
873
874
875#
876# Checks if a component is blacklisted. Returns 1 if the component is
877# blacklisted, 0 otherwise. Takes two arguments:
878# arg1: component name
879# arg2: component id or index
880#
881sub blacklisted {
882 my $name = shift; # component name
883 my $id = shift; # component id
884 my $ret = 0; # return value
885
886 if (defined $blacklist{$name}) {
887 foreach my $comp (@{ $blacklist{$name} }) {
d4c27ad8 888 if (defined $id and ($comp eq $id or uc($comp) eq 'ALL')) {
669797e1 889 $ret = 1;
890 }
891 }
892 }
893
894 return $ret;
895}
896
897# Converts the NexusID from SNMP to our version
898sub convert_nexus {
899 my $nexus = shift;
900 $nexus =~ s{\A \\}{}xms;
901 $nexus =~ s{\\}{:}gxms;
902 return $nexus;
903}
904
905# Sets custom temperature thresholds based on user supplied options
906sub custom_temperature_thresholds {
907 my $type = shift; # type of threshold, either w (warning) or c (critical)
908 my %thres = (); # will contain the thresholds
909 my @limits = (); # holds the input
910
911 my @opt = $type eq 'w' ? @{ $opt{warning} } : @{ $opt{critical} };
912
913 if (scalar @opt >= 0) {
914 foreach my $t (@opt) {
915 my $tmp = q{};
916 if (-f $t) {
917 open my $F, '<', $t
918 or do { report('other', "Couldn't open temperature threshold file $t: $!",
919 $E_UNKNOWN) and return {} };
920 $tmp = <$F>;
921 close $F;
922 }
923 else {
924 $tmp = $t;
925 }
926 push @limits, $tmp;
927 }
928 }
929
930 # Parse checklist string, put in hash
931 foreach my $th (@limits) {
932 my @tmp = split m{,}xms, $th;
933 foreach my $t (@tmp) {
934 next if $t !~ m{=}xms;
935 my ($key, $val) = split m{=}xms, $t;
936 if ($val =~ m{/}xms) {
937 my ($max, $min) = split m{/}xms, $val;
938 $thres{$key}{max} = $max;
939 $thres{$key}{min} = $min;
940 }
941 else {
942 $thres{$key}{max} = $val;
943 }
944 }
945 }
946
947 return \%thres;
948}
949
950
951# Gets the output from SNMP result according to the OIDs checked
952sub get_snmp_output {
953 my ($result,$oidref) = @_;
b0e15fc9 954 my @temp = ();
669797e1 955 my @output = ();
956
957 foreach my $oid (keys %{ $result }) {
b0e15fc9 958 my $short = $oid;
f47687c4 959 $short =~ s{\s}{}gxms; # remove whitespace
960 $short =~ s{\A (.+) \. (\d+) \z}{$1}xms; # remove last number
b0e15fc9 961 my $id = $2;
962 if (exists $oidref->{$short}) {
963 $temp[$id]{$oidref->{$short}} = $result->{$oid};
669797e1 964 }
965 }
b0e15fc9 966
967 # Remove any empty indexes
968 foreach my $out (@temp) {
969 if (defined $out) {
970 push @output, $out;
971 }
972 }
973
669797e1 974 return \@output;
975}
976
977
978# Map the controller or other item in-place
979sub map_item {
980 my ($key, $val, $list) = @_;
981
982 foreach my $lst (@{ $list }) {
983 if (!exists $lst->{$key}) {
984 $lst->{$key} = $val;
985 }
986 }
987 return;
988}
989
990# Return the URL for official Dell documentation for a specific
991# PowerEdge server
992sub documentation_url {
993 my $model = shift;
994
995 # create model short form, e.g. "r710"
996 $model =~ s{\A PowerEdge \s (.+?) \z}{lc($1)}exms;
997
998 # special case for blades (e.g. M600, M710), they have common
999 # documentation
1000 $model =~ s{\A m\d+ \z}{m}xms;
1001
1002 return 'http://support.dell.com/support/edocs/systems/pe' . $model . '/';
1003}
1004
1005# Return the URL for warranty information for a server with a given
1006# serial number (servicetag)
1007sub warranty_url {
1008 my $tag = shift;
1009
1010 # Dell support sites for different parts of the world
1011 my %supportsite
1012 = (
1013 'emea' => 'http://support.euro.dell.com/support/topics/topic.aspx/emea/shared/support/my_systems_info/',
1014 'ap' => 'http://supportapj.dell.com/support/topics/topic.aspx/ap/shared/support/my_systems_info/en/details?',
1015 'glob' => 'http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?',
1016 );
1017
1018 # warranty URLs for different country codes
1019 my %url
1020 = (
1021 # EMEA
1022 'at' => $supportsite{emea} . 'de/details?c=at&l=de&ServiceTag=', # Austria
1023 'be' => $supportsite{emea} . 'nl/details?c=be&l=nl&ServiceTag=', # Belgium
1024 'cz' => $supportsite{emea} . 'cs/details?c=cz&l=cs&ServiceTag=', # Czech Republic
1025 'de' => $supportsite{emea} . 'de/details?c=de&l=de&ServiceTag=', # Germany
1026 'dk' => $supportsite{emea} . 'da/details?c=dk&l=da&ServiceTag=', # Denmark
1027 'es' => $supportsite{emea} . 'es/details?c=es&l=es&ServiceTag=', # Spain
1028 'fi' => $supportsite{emea} . 'fi/details?c=fi&l=fi&ServiceTag=', # Finland
1029 'fr' => $supportsite{emea} . 'fr/details?c=fr&l=fr&ServiceTag=', # France
1030 'gr' => $supportsite{emea} . 'en/details?c=gr&l=el&ServiceTag=', # Greece
1031 'it' => $supportsite{emea} . 'it/details?c=it&l=it&ServiceTag=', # Italy
1032 'il' => $supportsite{emea} . 'en/details?c=il&l=en&ServiceTag=', # Israel
1033 'me' => $supportsite{emea} . 'en/details?c=me&l=en&ServiceTag=', # Middle East
1034 'no' => $supportsite{emea} . 'no/details?c=no&l=no&ServiceTag=', # Norway
1035 'nl' => $supportsite{emea} . 'nl/details?c=nl&l=nl&ServiceTag=', # The Netherlands
1036 'pl' => $supportsite{emea} . 'pl/details?c=pl&l=pl&ServiceTag=', # Poland
1037 'pt' => $supportsite{emea} . 'en/details?c=pt&l=pt&ServiceTag=', # Portugal
1038 'ru' => $supportsite{emea} . 'ru/details?c=ru&l=ru&ServiceTag=', # Russia
1039 'se' => $supportsite{emea} . 'sv/details?c=se&l=sv&ServiceTag=', # Sweden
1040 'uk' => $supportsite{emea} . 'en/details?c=uk&l=en&ServiceTag=', # United Kingdom
1041 'za' => $supportsite{emea} . 'en/details?c=za&l=en&ServiceTag=', # South Africa
1042 # America
1043 'br' => $supportsite{glob} . 'c=br&l=pt&ServiceTag=', # Brazil
1044 'ca' => $supportsite{glob} . 'c=ca&l=en&ServiceTag=', # Canada
1045 'mx' => $supportsite{glob} . 'c=mx&l=es&ServiceTag=', # Mexico
1046 'us' => $supportsite{glob} . 'c=us&l=en&ServiceTag=', # USA
1047 # Asia/Pacific
1048 'au' => $supportsite{ap} . 'c=au&l=en&ServiceTag=', # Australia
1049 'cn' => $supportsite{ap} . 'c=cn&l=zh&ServiceTag=', # China
1050 'in' => $supportsite{ap} . 'c=in&l=en&ServiceTag=', # India
1051 # default fallback
1052 'XX' => $supportsite{glob} . 'ServiceTag=', # default
1053 );
1054
1055 if (exists $url{$opt{htmlinfo}}) {
1056 return $url{$opt{htmlinfo}} . $tag;
1057 }
1058 else {
1059 return $url{XX} . $tag;
1060 }
1061}
1062
1063
1064
1065#---------------------------------------------------------------------
1066# Check functions
1067#---------------------------------------------------------------------
1068
1069#-----------------------------------------
1070# Check global health status
1071#-----------------------------------------
1072sub check_global {
1073 my $health = $E_OK;
1074
1075 if ($snmp) {
1076 #
1077 # Checks global status, i.e. both storage and chassis
1078 #
1079 my $systemStateGlobalSystemStatus = '1.3.6.1.4.1.674.10892.1.200.10.1.2.1';
1080 my $result = $snmp_session->get_request(-varbindlist => [$systemStateGlobalSystemStatus]);
1081 if (!defined $result) {
98b224a3 1082 printf "SNMP ERROR [global]: %s\n", $snmp_error;
669797e1 1083 exit $E_UNKNOWN;
1084 }
1085 $health = $status2nagios{$snmp_status{$result->{$systemStateGlobalSystemStatus}}};
1086 }
1087 else {
1088 #
1089 # NB! This does not check storage, only chassis...
1090 #
1091 foreach (@{ run_command("$omreport $omopt_system -fmt ssv") }) {
1092 next if !m/;/xms;
1093 next if m/\A SEVERITY;COMPONENT/xms;
1094 if (m/\A (.+?);Main\sSystem(\sChassis)? /xms) {
1095 $health = $status2nagios{$1};
1096 last;
1097 }
1098 }
1099 }
1100
1101 # Return the status
1102 return $health;
1103}
1104
1105
1106#-----------------------------------------
1107# STORAGE: Check controllers
1108#-----------------------------------------
1109sub check_controllers {
1110 my $id = undef;
1111 my $nexus = undef;
1112 my $name = undef;
1113 my $state = undef;
1114 my $status = undef;
1115 my $minfw = undef;
1116 my $mindr = undef;
1117 my $firmware = undef;
1118 my $driver = undef;
08c259f3 1119 my $minstdr = undef; # Minimum required Storport driver version (whats this?)
1120 my $stdr = undef; # Storport driver version (whats this?)
669797e1 1121 my @output = ();
1122
1123 if ($snmp) {
1124 my %ctrl_oid
1125 = (
1126 '1.3.6.1.4.1.674.10893.1.20.130.1.1.1' => 'controllerNumber',
1127 '1.3.6.1.4.1.674.10893.1.20.130.1.1.2' => 'controllerName',
1128 '1.3.6.1.4.1.674.10893.1.20.130.1.1.5' => 'controllerState',
1129 '1.3.6.1.4.1.674.10893.1.20.130.1.1.8' => 'controllerFWVersion',
1130 '1.3.6.1.4.1.674.10893.1.20.130.1.1.38' => 'controllerComponentStatus',
1131 '1.3.6.1.4.1.674.10893.1.20.130.1.1.39' => 'controllerNexusID',
1132 '1.3.6.1.4.1.674.10893.1.20.130.1.1.41' => 'controllerDriverVersion',
1133 '1.3.6.1.4.1.674.10893.1.20.130.1.1.44' => 'controllerMinFWVersion',
1134 '1.3.6.1.4.1.674.10893.1.20.130.1.1.45' => 'controllerMinDriverVersion',
08c259f3 1135 '1.3.6.1.4.1.674.10893.1.20.130.1.1.55' => 'FIXME_StorportDriverVersion',
1136 '1.3.6.1.4.1.674.10893.1.20.130.1.1.56' => 'FIXME_StorportMinDriverVersion',
669797e1 1137 );
ba199ee0 1138
1139 # We use get_table() here for the odd case where a server has
1140 # two or more controllers, and where some OIDs are missing on
1141 # one of the controllers.
1142 my $controllerTable = '1.3.6.1.4.1.674.10893.1.20.130.1';
1143 my $result = $snmp_session->get_table(-baseoid => $controllerTable);
669797e1 1144
1145 # No controllers is OK
1146 return if !defined $result;
1147
1148 @output = @{ get_snmp_output($result, \%ctrl_oid) };
1149 }
1150 else {
1151 @output = @{ run_omreport('storage controller') };
1152 }
1153
1154 my %ctrl_state
1155 = (
1156 0 => 'Unknown',
1157 1 => 'Ready',
1158 2 => 'Failed',
1159 3 => 'Online',
1160 4 => 'Offline',
1161 6 => 'Degraded',
1162 );
1163
1164 CTRL:
1165 foreach my $out (@output) {
1166 if ($snmp) {
08c259f3 1167 $id = $out->{controllerNumber} - 1;
1168 $name = $out->{controllerName};
1169 $state = $ctrl_state{$out->{controllerState}};
1170 $status = $snmp_status{$out->{controllerComponentStatus}};
1171 $minfw = exists $out->{controllerMinFWVersion}
1172 ? $out->{controllerMinFWVersion} : undef;
1173 $mindr = exists $out->{controllerMinDriverVersion}
1174 ? $out->{controllerMinDriverVersion} : undef;
669797e1 1175 $firmware = exists $out->{controllerFWVersion}
1176 ? $out->{controllerFWVersion} : 'N/A';
1177 $driver = exists $out->{controllerDriverVersion}
1178 ? $out->{controllerDriverVersion} : 'N/A';
08c259f3 1179 $minstdr = exists $out->{'FIXME_StorportMinDriverVersion'}
1180 ? $out->{FIXME_StorportMinDriverVersion} : undef;
1181 $stdr = exists $out->{FIXME_StorportDriverVersion}
956cf4d1 1182 ? $out->{FIXME_StorportDriverVersion} : undef;
669797e1 1183 $nexus = convert_nexus($out->{controllerNexusID});
1184 }
1185 else {
1186 $id = $out->{ID};
1187 $name = $out->{Name};
1188 $state = $out->{State};
1189 $status = $out->{Status};
1190 $minfw = $out->{'Minimum Required Firmware Version'} ne 'Not Applicable'
1191 ? $out->{'Minimum Required Firmware Version'} : undef;
1192 $mindr = $out->{'Minimum Required Driver Version'} ne 'Not Applicable'
1193 ? $out->{'Minimum Required Driver Version'} : undef;
1194 $firmware = $out->{'Firmware Version'} ne 'Not Applicable'
1195 ? $out->{'Firmware Version'} : 'N/A';
1196 $driver = $out->{'Driver Version'} ne 'Not Applicable'
1197 ? $out->{'Driver Version'} : 'N/A';
f86e57b8 1198 $minstdr = (exists $out->{'Minimum Required Storport Driver Version'}
1199 and $out->{'Minimum Required Storport Driver Version'} ne 'Not Applicable')
08c259f3 1200 ? $out->{'Minimum Required Storport Driver Version'} : undef;
f86e57b8 1201 $stdr = (exists $out->{'Storport Driver Version'}
1202 and $out->{'Storport Driver Version'} ne 'Not Applicable')
956cf4d1 1203 ? $out->{'Storport Driver Version'} : undef;
669797e1 1204 $nexus = $id;
1205 }
1206
1207 $name =~ s{\s+\z}{}xms; # remove trailing whitespace
1208 push @controllers, $id;
1209
1210 # Collecting some storage info
1211 $sysinfo{'controller'}{$id}{'id'} = $nexus;
1212 $sysinfo{'controller'}{$id}{'name'} = $name;
1213 $sysinfo{'controller'}{$id}{'driver'} = $driver;
1214 $sysinfo{'controller'}{$id}{'firmware'} = $firmware;
956cf4d1 1215 $sysinfo{'controller'}{$id}{'storport'} = $stdr;
669797e1 1216
1217 next CTRL if blacklisted('ctrl', $nexus);
1218
1219 # Special case: old firmware
1220 if (!blacklisted('ctrl_fw', $id) && defined $minfw) {
1221 chomp $firmware;
98b224a3 1222 my $msg = sprintf q{Controller %d [%s]: Firmware '%s' is out of date},
669797e1 1223 $id, $name, $firmware;
1224 report('storage', $msg, $E_WARNING, $nexus);
1225 }
1226 # Special case: old driver
1227 if (!blacklisted('ctrl_driver', $id) && defined $mindr) {
1228 chomp $driver;
98b224a3 1229 my $msg = sprintf q{Controller %d [%s]: Driver '%s' is out of date},
669797e1 1230 $id, $name, $driver;
1231 report('storage', $msg, $E_WARNING, $nexus);
1232 }
08c259f3 1233 # Special case: old storport driver
1234 if (!blacklisted('ctrl_stdr', $id) && defined $minstdr) {
1235 chomp $stdr;
1236 my $msg = sprintf q{Controller %d [%s]: Storport driver '%s' is out of date},
1237 $id, $name, $stdr;
1238 report('storage', $msg, $E_WARNING, $nexus);
1239 }
669797e1 1240 # Ok
1241 if ($status eq 'Ok' or ($status eq 'Non-Critical'
babe647a 1242 and (defined $minfw or defined $mindr or defined $minstdr))) {
98b224a3 1243 my $msg = sprintf 'Controller %d [%s] is %s',
669797e1 1244 $id, $name, $state;
1245 report('storage', $msg, $E_OK, $nexus);
1246 }
1247 # Default
1248 else {
98b224a3 1249 my $msg = sprintf 'Controller %d [%s] needs attention: %s',
669797e1 1250 $id, $name, $state;
1251 report('storage', $msg, $status2nagios{$status}, $nexus);
1252 }
1253 }
1254 return;
1255}
1256
1257
1258#-----------------------------------------
1259# STORAGE: Check physical drives
1260#-----------------------------------------
1261sub check_physical_disks {
1262 return if $#controllers == -1;
c8eb5019 1263 return if blacklisted('pdisk', 'all');
669797e1 1264
1265 my $id = undef;
1266 my $nexus = undef;
1267 my $name = undef;
1268 my $state = undef;
1269 my $status = undef;
1270 my $fpred = undef;
1271 my $progr = undef;
1272 my $ctrl = undef;
1273 my $vendor = undef; # disk vendor
1274 my $product = undef; # product ID
1275 my $capacity = undef; # disk length (size) in bytes
1276 my @output = ();
1277
1278 if ($snmp) {
1279 my %pdisk_oid
1280 = (
1281 '1.3.6.1.4.1.674.10893.1.20.130.4.1.1' => 'arrayDiskNumber',
1282 '1.3.6.1.4.1.674.10893.1.20.130.4.1.2' => 'arrayDiskName',
1283 '1.3.6.1.4.1.674.10893.1.20.130.4.1.3' => 'arrayDiskVendor',
1284 '1.3.6.1.4.1.674.10893.1.20.130.4.1.4' => 'arrayDiskState',
1285 '1.3.6.1.4.1.674.10893.1.20.130.4.1.6' => 'arrayDiskProductID',
1286 '1.3.6.1.4.1.674.10893.1.20.130.4.1.9' => 'arrayDiskEnclosureID',
1287 '1.3.6.1.4.1.674.10893.1.20.130.4.1.10' => 'arrayDiskChannel',
1288 '1.3.6.1.4.1.674.10893.1.20.130.4.1.11' => 'arrayDiskLengthInMB',
1289 '1.3.6.1.4.1.674.10893.1.20.130.4.1.15' => 'arrayDiskTargetID',
1290 '1.3.6.1.4.1.674.10893.1.20.130.4.1.16' => 'arrayDiskLunID',
1291 '1.3.6.1.4.1.674.10893.1.20.130.4.1.24' => 'arrayDiskComponentStatus',
1292 '1.3.6.1.4.1.674.10893.1.20.130.4.1.26' => 'arrayDiskNexusID',
1293 '1.3.6.1.4.1.674.10893.1.20.130.4.1.31' => 'arrayDiskSmartAlertIndication',
669797e1 1294 '1.3.6.1.4.1.674.10893.1.20.130.5.1.7' => 'arrayDiskEnclosureConnectionControllerNumber',
c11849d6 1295 '1.3.6.1.4.1.674.10893.1.20.130.6.1.7' => 'arrayDiskChannelConnectionControllerNumber',
669797e1 1296 );
1297 my $result = $snmp_session->get_entries(-columns => [keys %pdisk_oid]);
1298
1299 if (!defined $result) {
98b224a3 1300 printf "SNMP ERROR [storage / pdisk]: %s.\n", $snmp_session->error;
669797e1 1301 $snmp_session->close;
1302 exit $E_UNKNOWN;
1303 }
1304
1305 @output = @{ get_snmp_output($result, \%pdisk_oid) };
1306 }
1307 else {
1308 foreach my $c (@controllers) {
1309 push @output, @{ run_omreport("storage pdisk controller=$c") };
1310 map_item('ctrl', $c, \@output);
1311 }
1312 }
1313
1314 my %pdisk_state
1315 = (
1316 0 => 'Unknown',
1317 1 => 'Ready',
1318 2 => 'Failed',
1319 3 => 'Online',
1320 4 => 'Offline',
1321 6 => 'Degraded',
1322 7 => 'Recovering',
1323 11 => 'Removed',
1324 15 => 'Resynching',
1325 24 => 'Rebuilding',
1326 25 => 'No Media',
1327 26 => 'Formatting',
1328 28 => 'Diagnostics',
1329 34 => 'Predictive failure',
1330 35 => 'Initializing',
1331 39 => 'Foreign',
1332 40 => 'Clear',
1333 41 => 'Unsupported',
1334 53 => 'Incompatible',
1335 );
1336
1337 # Check physical disks on each of the controllers
1338 PDISK:
1339 foreach my $out (@output) {
1340 if ($snmp) {
1341 $name = $out->{arrayDiskName};
07d224b2 1342 if (exists $out->{arrayDiskEnclosureID}) {
669797e1 1343 $id = join q{:}, ($out->{arrayDiskChannel}, $out->{arrayDiskEnclosureID},
07d224b2 1344 $out->{arrayDiskTargetID});
669797e1 1345 }
1346 else {
1347 $id = join q{:}, ($out->{arrayDiskChannel}, $out->{arrayDiskTargetID});
1348 }
1349 $state = $pdisk_state{$out->{arrayDiskState}};
1350 $status = $snmp_status{$out->{arrayDiskComponentStatus}};
1351 $fpred = $out->{arrayDiskSmartAlertIndication} == 2 ? 1 : 0;
1352 $progr = q{};
669797e1 1353 $nexus = convert_nexus($out->{arrayDiskNexusID});
1354 $vendor = $out->{arrayDiskVendor};
1355 $product = $out->{arrayDiskProductID};
1356 $capacity = $out->{arrayDiskLengthInMB} * 1024**2;
c11849d6 1357 if (exists $out->{arrayDiskEnclosureConnectionControllerNumber}) {
1358 $ctrl = $out->{arrayDiskEnclosureConnectionControllerNumber} - 1;
1359 }
1360 elsif (exists $out->{arrayDiskChannelConnectionControllerNumber}) {
1361 $ctrl = $out->{arrayDiskChannelConnectionControllerNumber} - 1;
1362 }
1363 else {
1364 $ctrl = -1;
1365 }
669797e1 1366 }
1367 else {
1368 $id = $out->{'ID'};
1369 $name = $out->{'Name'};
1370 $state = $out->{'State'};
1371 $status = $out->{'Status'};
1372 $fpred = lc($out->{'Failure Predicted'}) eq 'yes' ? 1 : 0;
1373 $progr = ' [' . $out->{'Progress'} . ']';
1374 $ctrl = $out->{'ctrl'};
1375 $nexus = join q{:}, $out->{ctrl}, $id;
1376 $vendor = $out->{'Vendor ID'};
1377 $product = $out->{'Product ID'};
1378 $capacity = $out->{'Capacity'};
1379 $capacity =~ s{\A .*? \((\d+) \s bytes\) \z}{$1}xms;
1380 }
1381
1382 next PDISK if blacklisted('pdisk', $nexus);
1383 $count{pdisk}++;
1384
1385 $vendor =~ s{\s+\z}{}xms; # remove trailing whitespace
1386 $product =~ s{\s+\z}{}xms; # remove trailing whitespace
1387
1388 # Calculate human readable capacity
1389 $capacity = ceil($capacity / 1000**3) >= 1000
1390 ? sprintf '%.1fTB', ($capacity / 1000**4)
1391 : sprintf '%.0fGB', ($capacity / 1000**3);
1392 $capacity = '450GB' if $capacity eq '449GB'; # quick fix for 450GB disks
8ce893fd 1393 $capacity = '300GB' if $capacity eq '299GB'; # quick fix for 300GB disks
669797e1 1394 $capacity = '146GB' if $capacity eq '147GB'; # quick fix for 146GB disks
669797e1 1395
1396 # Capitalize only the first letter of the vendor name
1397 $vendor = (substr $vendor, 0, 1) . lc (substr $vendor, 1, length $vendor);
1398
1399 # Remove unnecessary trademark rubbish from vendor name
1400 $vendor =~ s{\(tm\)\z}{}xms;
1401
1402 # Special case: Failure predicted
1403 if ($status eq 'Non-Critical' and $fpred) {
c11849d6 1404 my $msg = sprintf '%s [%s %s, %s] on ctrl %d needs attention: Failure Predicted',
1405 $name, $vendor, $product, $capacity, $ctrl;
669797e1 1406 report('storage', $msg, $E_WARNING, $nexus);
1407 }
1408 # Special case: Rebuilding
1409 elsif ($state eq 'Rebuilding') {
c11849d6 1410 my $msg = sprintf '%s [%s] on ctrl %d is %s%s',
1411 $name, $capacity, $ctrl, $state, $progr;
669797e1 1412 report('storage', $msg, $E_WARNING, $nexus);
1413 }
1414 # Default
1415 elsif ($status ne 'Ok') {
c11849d6 1416 my $msg = sprintf '%s [%s %s, %s] on ctrl %d needs attention: %s',
1417 $name, $vendor, $product, $capacity, $ctrl, $state;
669797e1 1418 report('storage', $msg, $status2nagios{$status}, $nexus);
1419 }
1420 # Ok
1421 else {
c11849d6 1422 my $msg = sprintf '%s [%s] on ctrl %d is %s',
1423 $name, $capacity, $ctrl, $state;
669797e1 1424 report('storage', $msg, $E_OK, $nexus);
1425 }
1426 }
1427 return;
1428}
1429
1430
1431#-----------------------------------------
1432# STORAGE: Check logical drives
1433#-----------------------------------------
1434sub check_virtual_disks {
1435 return if $#controllers == -1;
1436
1437 my $id = undef;
25d04c34 1438 my $name = undef;
669797e1 1439 my $nexus = undef;
1440 my $dev = undef;
1441 my $state = undef;
1442 my $status = undef;
1443 my $layout = undef;
1444 my $size = undef;
1445 my $progr = undef;
25d04c34 1446 my $ctrl = undef;
669797e1 1447 my @output = ();
1448
1449 if ($snmp) {
1450 my %vdisk_oid
1451 = (
669797e1 1452 '1.3.6.1.4.1.674.10893.1.20.140.1.1.3' => 'virtualDiskDeviceName',
1453 '1.3.6.1.4.1.674.10893.1.20.140.1.1.4' => 'virtualDiskState',
1454 '1.3.6.1.4.1.674.10893.1.20.140.1.1.6' => 'virtualDiskLengthInMB',
1455 '1.3.6.1.4.1.674.10893.1.20.140.1.1.13' => 'virtualDiskLayout',
25d04c34 1456 '1.3.6.1.4.1.674.10893.1.20.140.1.1.17' => 'virtualDiskTargetID',
669797e1 1457 '1.3.6.1.4.1.674.10893.1.20.140.1.1.20' => 'virtualDiskComponentStatus',
1458 '1.3.6.1.4.1.674.10893.1.20.140.1.1.21' => 'virtualDiskNexusID',
1459 );
1460 my $result = $snmp_session->get_entries(-columns => [keys %vdisk_oid]);
1461
1462 # No logical drives is OK
1463 return if !defined $result;
1464
1465 @output = @{ get_snmp_output($result, \%vdisk_oid) };
1466 }
1467 else {
1468 foreach my $c (@controllers) {
1469 push @output, @{ run_omreport("storage vdisk controller=$c") };
1470 map_item('ctrl', $c, \@output);
1471 }
1472 }
1473
1474 my %vdisk_state
1475 = (
1476 0 => 'Unknown',
1477 1 => 'Ready',
1478 2 => 'Failed',
1479 3 => 'Online',
1480 4 => 'Offline',
1481 6 => 'Degraded',
1482 15 => 'Resynching',
1483 16 => 'Regenerating',
1484 24 => 'Rebuilding',
1485 26 => 'Formatting',
1486 32 => 'Reconstructing',
1487 35 => 'Initializing',
1488 36 => 'Background Initialization',
1489 38 => 'Resynching Paused',
1490 52 => 'Permanently Degraded',
1491 54 => 'Degraded Redundancy',
1492 );
1493
1494 my %vdisk_layout
1495 = (
1496 1 => 'Concatenated',
1497 2 => 'RAID-0',
1498 3 => 'RAID-1',
1499 7 => 'RAID-5',
1500 8 => 'RAID-6',
1501 10 => 'RAID-10',
1502 12 => 'RAID-50',
1503 19 => 'Concatenated RAID 1',
1504 24 => 'RAID-60',
1505 );
1506
1507 # Check virtual disks on each of the controllers
1508 VDISK:
1509 foreach my $out (@output) {
1510 if ($snmp) {
25d04c34 1511 $id = $out->{virtualDiskTargetID};
669797e1 1512 $dev = $out->{virtualDiskDeviceName};
1513 $state = $vdisk_state{$out->{virtualDiskState}};
1514 $status = $snmp_status{$out->{virtualDiskComponentStatus}};
1515 $layout = $vdisk_layout{$out->{virtualDiskLayout}};
1516 $size = sprintf '%.2f GB', $out->{virtualDiskLengthInMB} / 1024;
1517 $progr = q{}; # can't get this from SNMP(?)
1518 $nexus = convert_nexus($out->{virtualDiskNexusID});
25d04c34 1519 $ctrl = $nexus; # We use the nexus id to get the controller id
1520 $ctrl =~ s{\A (\d+):\d+ \z}{$1}xms;
669797e1 1521 }
1522 else {
1523 $id = $out->{ID};
1524 $dev = $out->{'Device Name'};
1525 $state = $out->{State};
1526 $status = $out->{Status};
1527 $layout = $out->{Layout};
1528 $size = $out->{Size};
1529 $progr = ' [' . $out->{Progress} . ']';
1530 $size =~ s{\A (.*GB).* \z}{$1}xms;
1531 $nexus = join q{:}, $out->{ctrl}, $id;
25d04c34 1532 $ctrl = $out->{ctrl};
669797e1 1533 }
1534
1535 next VDISK if blacklisted('vdisk', $nexus);
1536 $count{vdisk}++;
1537
04b0f13b 1538 # The device name is undefined sometimes
1539 $dev = q{} if !defined $dev;
1540
669797e1 1541 # Special case: Regenerating
1542 if ($state eq 'Regenerating') {
98b224a3 1543 my $msg = sprintf q{Logical drive %d '%s' [%s, %s] on ctrl %d is %s%s},
1544 $id, $dev, $layout, $size, $ctrl, $state, $progr;
669797e1 1545 report('storage', $msg, $E_WARNING, $nexus);
1546 }
1547 # Default
1548 elsif ($status ne 'Ok') {
98b224a3 1549 my $msg = sprintf q{Logical drive %d '%s' [%s, %s] on ctrl %d needs attention: %s},
1550 $id, $dev, $layout, $size, $ctrl, $state;
669797e1 1551 report('storage', $msg, $status2nagios{$status}, $nexus);
1552 }
1553 # Ok
1554 else {
98b224a3 1555 my $msg = sprintf q{Logical drive %d '%s' [%s, %s] on ctrl %d is %s},
1556 $id, $dev, $layout, $size, $ctrl, $state;
669797e1 1557 report('storage', $msg, $E_OK, $nexus);
1558 }
1559 }
1560 return;
1561}
1562
1563
1564#-----------------------------------------
1565# STORAGE: Check cache batteries
1566#-----------------------------------------
1567sub check_cache_battery {
1568 return if $#controllers == -1;
1569
1570 my $id = undef;
1571 my $nexus = undef;
1572 my $state = undef;
1573 my $status = undef;
1574 my $ctrl = undef;
1575 my $learn = undef; # learn state
1576 my $pred = undef; # battery's ability to be charged
1577 my @output = ();
1578
1579 if ($snmp) {
1580 my %bat_oid
1581 = (
669797e1 1582 '1.3.6.1.4.1.674.10893.1.20.130.15.1.4' => 'batteryState',
1583 '1.3.6.1.4.1.674.10893.1.20.130.15.1.6' => 'batteryComponentStatus',
1584 '1.3.6.1.4.1.674.10893.1.20.130.15.1.9' => 'batteryNexusID',
1585 '1.3.6.1.4.1.674.10893.1.20.130.15.1.10' => 'batteryPredictedCapacity',
1586 '1.3.6.1.4.1.674.10893.1.20.130.15.1.12' => 'batteryLearnState',
1587 '1.3.6.1.4.1.674.10893.1.20.130.16.1.5' => 'batteryConnectionControllerNumber',
1588 );
1589 my $result = $snmp_session->get_entries(-columns => [keys %bat_oid]);
1590
1591 # No cache battery is OK
1592 return if !defined $result;
1593
1594 @output = @{ get_snmp_output($result, \%bat_oid) };
1595 }
1596 else {
1597 foreach my $c (@controllers) {
1598 push @output, @{ run_omreport("storage battery controller=$c") };
1599 map_item('ctrl', $c, \@output);
1600 }
1601 }
1602
1603 my %bat_state
1604 = (
1605 0 => 'Unknown',
1606 1 => 'Ready',
1607 2 => 'Failed',
1608 6 => 'Degraded',
1609 7 => 'Reconditioning',
1610 9 => 'High',
1611 10 => 'Power Low',
1612 12 => 'Charging',
1613 21 => 'Missing',
1614 36 => 'Learning',
1615 );
1616
a49bcfe8 1617 # Specifies the learn state activity of the battery
669797e1 1618 my %bat_learn_state
1619 = (
1620 1 => 'Failed',
1621 2 => 'Active',
1622 4 => 'Timed out',
1623 8 => 'Requested',
1624 16 => 'Idle',
1625 );
1626
a49bcfe8 1627 # This property displays the battery's ability to be charged
669797e1 1628 my %bat_pred_cap
1629 = (
1630 1 => 'Failed', # The battery cannot be charged and needs to be replaced
1631 2 => 'Ready', # The battery can be charged to full capacity
1632 4 => 'Unknown', # The battery is completing a Learn cycle. The charge capacity of the
1633 # battery cannot be determined until the Learn cycle is complete
1634 );
1635
1636 # Check battery on each of the controllers
1637 BATTERY:
1638 foreach my $out (@output) {
1639 if ($snmp) {
669797e1 1640 $state = $bat_state{$out->{batteryState}};
1641 $status = $snmp_status{$out->{batteryComponentStatus}};
1642 $learn = exists $out->{batteryLearnState}
1643 ? $bat_learn_state{$out->{batteryLearnState}} : undef;
1644 $pred = exists $out->{batteryPredictedCapacity}
1645 ? $bat_pred_cap{$out->{batteryPredictedCapacity}} : undef;
1646 $ctrl = $out->{batteryConnectionControllerNumber} - 1;
1647 $nexus = convert_nexus($out->{batteryNexusID});
25d04c34 1648 $id = $nexus;
1649 $id =~ s{\A \d+:(\d+) \z}{$1}xms;
669797e1 1650 }
1651 else {
1652 $id = $out->{'ID'};
1653 $state = $out->{'State'};
1654 $status = $out->{'Status'};
1655 $learn = $out->{'Learn State'};
1656 $pred = $out->{'Predicted Capacity Status'};
1657 $ctrl = $out->{'ctrl'};
1658 $nexus = join q{:}, $out->{ctrl}, $id;
1659 }
1660
1661 next BATTERY if blacklisted('bat', $nexus);
1662
1663 # Special case: Charging
1664 if ($state eq 'Charging') {
50d6bc4a 1665 if ($pred eq 'Failed') {
1666 my $msg = sprintf 'Cache battery %d in controller %d is %s (%s) [replace battery]',
1667 $id, $ctrl, $state, $pred;
1668 report('storage', $msg, $E_CRITICAL, $nexus);
1669 }
1670 else {
1671 next BATTERY if blacklisted('bat_charge', $nexus);
1672 my $msg = sprintf 'Cache battery %d in controller %d is %s (%s) [probably harmless]',
1673 $id, $ctrl, $state, $pred;
1674 report('storage', $msg, $E_WARNING, $nexus);
1675 }
669797e1 1676 }
1677 # Special case: Learning (battery learns its capacity)
1678 elsif ($state eq 'Learning') {
50d6bc4a 1679 if ($learn eq 'Failed') {
1680 my $msg = sprintf 'Cache battery %d in controller %d is %s (%s)',
1681 $id, $ctrl, $state, $learn;
1682 report('storage', $msg, $E_CRITICAL, $nexus);
1683 }
1684 else {
1685 next BATTERY if blacklisted('bat_charge', $nexus);
1686 my $msg = sprintf 'Cache battery %d in controller %d is %s (%s) [probably harmless]',
1687 $id, $ctrl, $state, $learn;
1688 report('storage', $msg, $E_WARNING, $nexus);
1689 }
669797e1 1690 }
1691 # Special case: Power Low (first part of recharge cycle)
1692 elsif ($state eq 'Power Low') {
5a28cf7f 1693 next BATTERY if blacklisted('bat_charge', $nexus);
669797e1 1694 my $msg = sprintf 'Cache battery %d in controller %d is %s [probably harmless]',
1695 $id, $ctrl, $state;
1696 report('storage', $msg, $E_WARNING, $nexus);
1697 }
5a28cf7f 1698 # Special case: Degraded and Non-Critical (usually part of recharge cycle)
1699 elsif ($state eq 'Degraded' && $status eq 'Non-Critical') {
1700 next BATTERY if blacklisted('bat_charge', $nexus);
1701 my $msg = sprintf 'Cache battery %d in controller %d is %s (%s) [probably harmless]',
1702 $id, $ctrl, $state, $status;
1703 report('storage', $msg, $E_WARNING, $nexus);
1704 }
669797e1 1705 # Default
1706 elsif ($status ne 'Ok') {
1707 my $msg = sprintf 'Cache battery %d in controller %d needs attention: %s (%s)',
1708 $id, $ctrl, $state, $status;
1709 report('storage', $msg, $status2nagios{$status}, $nexus);
1710 }
1711 # Ok
1712 else {
1713 my $msg = sprintf 'Cache battery %d in controller %d is %s',
1714 $id, $ctrl, $state;
1715 report('storage', $msg, $E_OK, $nexus);
1716 }
1717 }
1718 return;
1719}
1720
1721
1722#-----------------------------------------
1723# STORAGE: Check connectors (channels)
1724#-----------------------------------------
1725sub check_connectors {
1726 return if $#controllers == -1;
1727
1728 my $id = undef;
1729 my $nexus = undef;
1730 my $name = undef;
1731 my $state = undef;
1732 my $status = undef;
1733 my $type = undef;
1734 my $ctrl = undef;
1735 my @output = ();
1736
1737 if ($snmp) {
1738 my %conn_oid
1739 = (
1740 '1.3.6.1.4.1.674.10893.1.20.130.2.1.1' => 'channelNumber',
1741 '1.3.6.1.4.1.674.10893.1.20.130.2.1.2' => 'channelName',
1742 '1.3.6.1.4.1.674.10893.1.20.130.2.1.3' => 'channelState',
1743 '1.3.6.1.4.1.674.10893.1.20.130.2.1.8' => 'channelComponentStatus',
1744 '1.3.6.1.4.1.674.10893.1.20.130.2.1.9' => 'channelNexusID',
1745 '1.3.6.1.4.1.674.10893.1.20.130.2.1.11' => 'channelBusType',
1746 );
1747 my $result = $snmp_session->get_entries(-columns => [keys %conn_oid]);
1748
1749 if (!defined $result) {
98b224a3 1750 printf "SNMP ERROR [storage / channel]: %s.\n", $snmp_session->error;
669797e1 1751 $snmp_session->close;
1752 exit $E_UNKNOWN;
1753 }
1754
1755 @output = @{ get_snmp_output($result, \%conn_oid) };
1756 }
1757 else {
1758 foreach my $c (@controllers) {
1759 push @output, @{ run_omreport("storage connector controller=$c") };
1760 map_item('ctrl', $c, \@output);
1761 }
1762 }
1763
1764 my %conn_state
1765 = (
1766 0 => 'Unknown',
1767 1 => 'Ready',
1768 2 => 'Failed',
1769 3 => 'Online',
1770 4 => 'Offline',
1771 6 => 'Degraded',
1772 );
1773
1774 my %conn_bustype
1775 = (
1776 1 => 'SCSI',
1777 2 => 'IDE',
1778 3 => 'Fibre Channel',
1779 4 => 'SSA',
1780 6 => 'USB',
1781 7 => 'SATA',
1782 8 => 'SAS',
1783 );
1784
1785 # Check connectors on each of the controllers
1786 CHANNEL:
1787 foreach my $out (@output) {
1788 if ($snmp) {
1789 $id = $out->{channelNumber} - 1;
1790 $name = $out->{channelName};
1791 $state = $conn_state{$out->{channelState}};
1792 $status = $snmp_status{$out->{channelComponentStatus}};
1793 $type = $conn_bustype{$out->{channelBusType}};
1794 $nexus = convert_nexus($out->{channelNexusID});
1795 $ctrl = $nexus;
1796 $ctrl =~ s{(\d+):\d+}{$1}xms;
1797 }
1798 else {
1799 $id = $out->{'ID'};
1800 $name = $out->{'Name'};
1801 $state = $out->{'State'};
1802 $status = $out->{'Status'};
1803 $type = $out->{'Connector Type'};
1804 $ctrl = $out->{ctrl};
1805 $nexus = join q{:}, $out->{ctrl}, $id;
1806 }
1807
1808 next CHANNEL if blacklisted('conn', $nexus);
1809
98b224a3 1810 my $msg = sprintf '%s [%s] on controller %d is %s',
669797e1 1811 $name, $type, $ctrl, $state;
1812 report('storage', $msg, $status2nagios{$status}, $nexus);
1813 }
1814 return;
1815}
1816
1817
1818#-----------------------------------------
1819# STORAGE: Check enclosures
1820#-----------------------------------------
1821sub check_enclosures {
1822 my $id = undef;
1823 my $nexus = undef;
1824 my $name = undef;
1825 my $state = undef;
1826 my $status = undef;
1827 my $firmware = undef;
25d04c34 1828 my $ctrl = undef;
669797e1 1829 my @output = ();
1830
1831 if ($snmp) {
1832 my %encl_oid
1833 = (
1834 '1.3.6.1.4.1.674.10893.1.20.130.3.1.1' => 'enclosureNumber',
1835 '1.3.6.1.4.1.674.10893.1.20.130.3.1.2' => 'enclosureName',
1836 '1.3.6.1.4.1.674.10893.1.20.130.3.1.4' => 'enclosureState',
1837 '1.3.6.1.4.1.674.10893.1.20.130.3.1.19' => 'enclosureChannelNumber',
1838 '1.3.6.1.4.1.674.10893.1.20.130.3.1.24' => 'enclosureComponentStatus',
1839 '1.3.6.1.4.1.674.10893.1.20.130.3.1.25' => 'enclosureNexusID',
1840 '1.3.6.1.4.1.674.10893.1.20.130.3.1.26' => 'enclosureFirmwareVersion',
1841 );
1842 my $result = $snmp_session->get_entries(-columns => [keys %encl_oid]);
1843
1844 # No enclosures is OK
1845 return if !defined $result;
1846
1847 @output = @{ get_snmp_output($result, \%encl_oid) };
1848 }
1849 else {
1850 foreach my $c (@controllers) {
1851 push @output, @{ run_omreport("storage enclosure controller=$c") };
1852 map_item('ctrl', $c, \@output);
1853 }
1854 }
1855
1856 my %encl_state
1857 = (
1858 0 => 'Unknown',
1859 1 => 'Ready',
1860 2 => 'Failed',
1861 3 => 'Online',
1862 4 => 'Offline',
1863 6 => 'Degraded',
1864 );
1865
1866 ENCLOSURE:
1867 foreach my $out (@output) {
1868 if ($snmp) {
1869 $id = $out->{'enclosureNumber'} - 1;
1870 $name = $out->{'enclosureName'};
1871 $state = $encl_state{$out->{'enclosureState'}};
1872 $status = $snmp_status{$out->{'enclosureComponentStatus'}};
1873 $firmware = exists $out->{enclosureFirmwareVersion}
1874 ? $out->{enclosureFirmwareVersion} : 'N/A';
1875 $nexus = convert_nexus($out->{enclosureNexusID});
25d04c34 1876 $ctrl = $nexus;
1877 $ctrl =~ s{\A (\d+):.* \z}{$1}xms;
669797e1 1878 }
1879 else {
1880 $id = $out->{ID};
1881 $name = $out->{Name};
1882 $state = $out->{State};
1883 $status = $out->{Status};
1884 $firmware = $out->{'Firmware Version'} ne 'Not Applicable'
1885 ? $out->{'Firmware Version'} : 'N/A';
1886 $nexus = join q{:}, $out->{ctrl}, $id;
25d04c34 1887 $ctrl = $out->{ctrl};
669797e1 1888 }
1889
1890 $name =~ s{\s+\z}{}xms; # remove trailing whitespace
1891 $firmware =~ s{\s+\z}{}xms; # remove trailing whitespace
1892
1893 # store enclosure data for future use
1894 push @enclosures, { 'id' => $id,
1895 'ctrl' => $out->{ctrl},
1896 'name' => $name };
1897
1898 # Collecting some storage info
1899 $sysinfo{'enclosure'}{$nexus}{'id'} = $nexus;
1900 $sysinfo{'enclosure'}{$nexus}{'name'} = $name;
1901 $sysinfo{'enclosure'}{$nexus}{'firmware'} = $firmware;
1902
1903 next ENCLOSURE if blacklisted('encl', $nexus);
1904
98b224a3 1905 my $msg = sprintf 'Enclosure %s [%s] on controller %d is %s',
25d04c34 1906 $nexus, $name, $ctrl, $state;
669797e1 1907 report('storage', $msg, $status2nagios{$status}, $nexus);
1908 }
1909 return;
1910}
1911
1912
1913#-----------------------------------------
1914# STORAGE: Check enclosure fans
1915#-----------------------------------------
1916sub check_enclosure_fans {
1917 return if $#controllers == -1;
1918
1919 my $id = undef;
1920 my $nexus = undef;
1921 my $name = undef;
1922 my $state = undef;
1923 my $status = undef;
1924 my $speed = undef;
1925 my $encl_id = undef;
1926 my $encl_name = undef;
1927 my @output = ();
1928
1929 if ($snmp) {
1930 my %fan_oid
1931 = (
1932 '1.3.6.1.4.1.674.10893.1.20.130.7.1.1' => 'fanNumber',
1933 '1.3.6.1.4.1.674.10893.1.20.130.7.1.2' => 'fanName',
1934 '1.3.6.1.4.1.674.10893.1.20.130.7.1.4' => 'fanState',
1935 '1.3.6.1.4.1.674.10893.1.20.130.7.1.11' => 'fanProbeCurrValue',
1936 '1.3.6.1.4.1.674.10893.1.20.130.7.1.15' => 'fanComponentStatus',
1937 '1.3.6.1.4.1.674.10893.1.20.130.7.1.16' => 'fanNexusID',
1938 '1.3.6.1.4.1.674.10893.1.20.130.8.1.4' => 'fanConnectionEnclosureName',
1939 '1.3.6.1.4.1.674.10893.1.20.130.8.1.5' => 'fanConnectionEnclosureNumber',
1940 );
1941
1942 my $result = $snmp_session->get_entries(-columns => [keys %fan_oid]);
1943
1944 # No enclosure fans is OK
1945 return if !defined $result;
1946
1947 @output = @{ get_snmp_output($result, \%fan_oid) };
1948 }
1949 else {
1950 foreach my $enc (@enclosures) {
1951 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=fans") };
1952 map_item('ctrl', $enc->{ctrl}, \@output);
1953 map_item('encl_id', $enc->{id}, \@output);
1954 map_item('encl_name', $enc->{name}, \@output);
1955 }
1956 }
1957
1958 my %fan_state
1959 = (
1960 0 => 'Unknown',
1961 1 => 'Ready',
1962 2 => 'Failed',
1963 3 => 'Online',
1964 4 => 'Offline',
1965 6 => 'Degraded',
1966 21 => 'Missing',
1967 );
1968
1969 # Check fans on each of the enclosures
1970 FAN:
1971 foreach my $out (@output) {
1972 if ($snmp) {
1973 $id = $out->{fanNumber} - 1;
1974 $name = $out->{fanName};
1975 $state = $fan_state{$out->{fanState}};
1976 $status = $snmp_status{$out->{fanComponentStatus}};
1977 $speed = $out->{fanProbeCurrValue};
1978 $encl_id = $out->{fanConnectionEnclosureNumber} - 1;
1979 $encl_name = $out->{fanConnectionEnclosureName};
1980 $nexus = convert_nexus($out->{fanNexusID});
1981 }
1982 else {
1983 $id = $out->{'ID'};
1984 $name = $out->{'Name'};
1985 $state = $out->{'State'};
1986 $status = $out->{'Status'};
1987 $speed = $out->{'Speed'};
1988 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
1989 $encl_name = $out->{encl_name};
1990 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, $id;
1991 }
1992
1993 next FAN if blacklisted('encl_fan', $nexus);
1994
1995 # Default
1996 if ($status ne 'Ok') {
98b224a3 1997 my $msg = sprintf '%s in enclosure %s [%s] needs attention: %s',
669797e1 1998 $name, $encl_id, $encl_name, $state;
1999 report('storage', $msg, $status2nagios{$status}, $nexus);
2000 }
2001 # Ok
2002 else {
98b224a3 2003 my $msg = sprintf '%s in enclosure %s [%s] is %s (speed=%s)',
669797e1 2004 $name, $encl_id, $encl_name, $state, $speed;
2005 report('storage', $msg, $E_OK, $nexus);
2006 }
2007 }
2008 return;
2009}
2010
2011
2012#-----------------------------------------
2013# STORAGE: Check enclosure power supplies
2014#-----------------------------------------
2015sub check_enclosure_pwr {
2016 return if $#controllers == -1;
2017
2018 my $id = undef;
2019 my $nexus = undef;
2020 my $name = undef;
2021 my $state = undef;
2022 my $status = undef;
2023 my $encl_id = undef;
2024 my $encl_name = undef;
2025 my @output = ();
2026
2027 if ($snmp) {
2028 my %ps_oid
2029 = (
2030 '1.3.6.1.4.1.674.10893.1.20.130.9.1.1' => 'powerSupplyNumber',
2031 '1.3.6.1.4.1.674.10893.1.20.130.9.1.2' => 'powerSupplyName',
2032 '1.3.6.1.4.1.674.10893.1.20.130.9.1.4' => 'powerSupplyState',
2033 '1.3.6.1.4.1.674.10893.1.20.130.9.1.9' => 'powerSupplyComponentStatus',
2034 '1.3.6.1.4.1.674.10893.1.20.130.9.1.10' => 'powerSupplyNexusID',
2035 '1.3.6.1.4.1.674.10893.1.20.130.10.1.4' => 'powerSupplyConnectionEnclosureName',
2036 '1.3.6.1.4.1.674.10893.1.20.130.10.1.5' => 'powerSupplyConnectionEnclosureNumber',
2037 );
2038 my $result = $snmp_session->get_entries(-columns => [keys %ps_oid]);
2039
2040 # No enclosure power supplies is OK
2041 return if !defined $result;
2042
2043 @output = @{ get_snmp_output($result, \%ps_oid) };
2044 }
2045 else {
2046 foreach my $enc (@enclosures) {
2047 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=pwrsupplies") };
2048 map_item('ctrl', $enc->{ctrl}, \@output);
2049 map_item('encl_id', $enc->{id}, \@output);
2050 map_item('encl_name', $enc->{name}, \@output);
2051 }
2052 }
2053
2054 my %ps_state
2055 = (
2056 0 => 'Unknown',
2057 1 => 'Ready',
2058 2 => 'Failed',
2059 5 => 'Not Installed',
2060 6 => 'Degraded',
2061 11 => 'Removed',
2062 21 => 'Missing',
2063 );
2064
2065 # Check power supplies on each of the enclosures
2066 PS:
2067 foreach my $out (@output) {
2068 if ($snmp) {
2069 $id = $out->{powerSupplyNumber};
2070 $name = $out->{powerSupplyName};
2071 $state = $ps_state{$out->{powerSupplyState}};
2072 $status = $snmp_status{$out->{powerSupplyComponentStatus}};
2073 $encl_id = $out->{powerSupplyConnectionEnclosureNumber} - 1;
2074 $encl_name = $out->{powerSupplyConnectionEnclosureName};
2075 $nexus = convert_nexus($out->{powerSupplyNexusID});
2076 }
2077 else {
2078 $id = $out->{'ID'};
2079 $name = $out->{'Name'};
2080 $state = $out->{'State'};
2081 $status = $out->{'Status'};
2082 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
2083 $encl_name = $out->{encl_name};
2084 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, $id;
2085 }
2086
2087 next PS if blacklisted('encl_ps', $nexus);
2088
2089 # Default
2090 if ($status ne 'Ok') {
98b224a3 2091 my $msg = sprintf '%s in enclosure %s [%s] needs attention: %s',
669797e1 2092 $name, $encl_id, $encl_name, $state;
2093 report('storage', $msg, $status2nagios{$status}, $nexus);
2094 }
2095 # Ok
2096 else {
98b224a3 2097 my $msg = sprintf '%s in enclosure %s [%s] is %s',
669797e1 2098 $name, $encl_id, $encl_name, $state;
2099 report('storage', $msg, $E_OK, $nexus);
2100 }
2101 }
2102 return;
2103}
2104
2105
2106#-----------------------------------------
2107# STORAGE: Check enclosure temperatures
2108#-----------------------------------------
2109sub check_enclosure_temp {
2110 return if $#controllers == -1;
2111
2112 my $id = undef;
2113 my $nexus = undef;
2114 my $name = undef;
2115 my $state = undef;
2116 my $status = undef;
2117 my $reading = undef;
2118 my $unit = undef;
2119 my $max_warn = undef;
2120 my $max_crit = undef;
2121 my $encl_id = undef;
2122 my $encl_name = undef;
2123 my @output = ();
2124
2125 if ($snmp) {
2126 my %temp_oid
2127 = (
2128 '1.3.6.1.4.1.674.10893.1.20.130.11.1.1' => 'temperatureProbeNumber',
2129 '1.3.6.1.4.1.674.10893.1.20.130.11.1.2' => 'temperatureProbeName',
2130 '1.3.6.1.4.1.674.10893.1.20.130.11.1.4' => 'temperatureProbeState',
2131 '1.3.6.1.4.1.674.10893.1.20.130.11.1.6' => 'temperatureProbeUnit',
2132 '1.3.6.1.4.1.674.10893.1.20.130.11.1.9' => 'temperatureProbeMaxWarning',
2133 '1.3.6.1.4.1.674.10893.1.20.130.11.1.10' => 'temperatureProbeMaxCritical',
2134 '1.3.6.1.4.1.674.10893.1.20.130.11.1.11' => 'temperatureProbeCurValue',
2135 '1.3.6.1.4.1.674.10893.1.20.130.11.1.13' => 'temperatureProbeComponentStatus',
2136 '1.3.6.1.4.1.674.10893.1.20.130.11.1.14' => 'temperatureProbeNexusID',
2137 '1.3.6.1.4.1.674.10893.1.20.130.12.1.4' => 'temperatureConnectionEnclosureName',
2138 '1.3.6.1.4.1.674.10893.1.20.130.12.1.5' => 'temperatureConnectionEnclosureNumber',
2139 );
2140 my $result = $snmp_session->get_entries(-columns => [keys %temp_oid]);
2141
2142 # No enclosure temperature probes is OK
2143 return if !defined $result;
2144
2145 @output = @{ get_snmp_output($result, \%temp_oid) };
2146 }
2147 else {
2148 foreach my $enc (@enclosures) {
2149 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=temps") };
2150 map_item('ctrl', $enc->{ctrl}, \@output);
2151 map_item('encl_id', $enc->{id}, \@output);
2152 map_item('encl_name', $enc->{name}, \@output);
2153 }
2154 }
2155
2156 my %temp_state
2157 = (
2158 0 => 'Unknown',
2159 1 => 'Ready',
2160 2 => 'Failed',
2161 4 => 'Offline',
2162 6 => 'Degraded',
2163 9 => 'Inactive',
2164 21 => 'Missing',
2165 );
2166
2167 # Check temperature probes on each of the enclosures
2168 TEMP:
2169 foreach my $out (@output) {
2170 if ($snmp) {
2171 $id = $out->{temperatureProbeNumber} - 1;
2172 $name = $out->{temperatureProbeName};
2173 $state = $temp_state{$out->{temperatureProbeState}};
2174 $status = $snmp_status{$out->{temperatureProbeComponentStatus}};
2175 $unit = $out->{temperatureProbeUnit};
2176 $reading = $out->{temperatureProbeCurValue};
2177 $max_warn = $out->{temperatureProbeMaxWarning};
2178 $max_crit = $out->{temperatureProbeMaxCritical};
2179 $encl_id = $out->{temperatureConnectionEnclosureNumber} - 1;
2180 $encl_name = $out->{temperatureConnectionEnclosureName};
2181 $nexus = convert_nexus($out->{temperatureProbeNexusID});
2182 }
2183 else {
2184 $id = $out->{'ID'};
2185 $name = $out->{'Name'};
2186 $state = $out->{'State'};
2187 $status = $out->{'Status'};
2188 $unit = 'FIXME';
2189 $reading = $out->{'Reading'}; $reading =~ s{\s*C}{}xms;
2190 $max_warn = $out->{'Maximum Warning Threshold'}; $max_warn =~ s{\s*C}{}xms;
2191 $max_crit = $out->{'Maximum Failure Threshold'}; $max_crit =~ s{\s*C}{}xms;
2192 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
2193 $encl_name = $out->{encl_name};
2194 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, $id;
2195 }
2196
2197 next TEMP if blacklisted('encl_temp', $nexus);
2198
2199 # Default
2200 if ($status ne 'Ok') {
8a565bfc 2201 my $msg = sprintf '%s in enclosure %s [%s] is %s C at %s (%s max)',
669797e1 2202 $name, $encl_id, $encl_name, $state, $reading, $max_crit;
2203 report('storage', $msg, $status2nagios{$status}, $nexus);
2204 }
2205 # Ok
2206 else {
8a565bfc 2207 my $msg = sprintf '%s in enclosure %s [%s]: %s C (%s max)',
669797e1 2208 $name, $encl_id, $encl_name, $reading, $max_crit;
2209 report('storage', $msg, $E_OK, $nexus);
2210 }
2211
2212 # Collect performance data
2213 if (defined $opt{perfdata}) {
2214 $name =~ s{\A Temperature\sProbe\s(\d+) \z}{temp_$1}gxms;
2215 my $pkey = "enclosure_${encl_id}_${name}";
2216 my $pval = join q{;}, "${reading}C", $max_warn, $max_crit;
2217 $perfdata{$pkey} = $pval;
2218 }
2219 }
2220 return;
2221}
2222
2223
2224#-----------------------------------------
2225# STORAGE: Check enclosure management modules (EMM)
2226#-----------------------------------------
2227sub check_enclosure_emms {
2228 return if $#controllers == -1;
2229
2230 my $id = undef;
2231 my $nexus = undef;
2232 my $name = undef;
2233 my $state = undef;
2234 my $status = undef;
2235 my $encl_id = undef;
2236 my $encl_name = undef;
2237 my @output = ();
2238
2239 if ($snmp) {
2240 my %emms_oid
2241 = (
2242 '1.3.6.1.4.1.674.10893.1.20.130.13.1.1' => 'enclosureManagementModuleNumber',
2243 '1.3.6.1.4.1.674.10893.1.20.130.13.1.2' => 'enclosureManagementModuleName',
2244 '1.3.6.1.4.1.674.10893.1.20.130.13.1.4' => 'enclosureManagementModuleState',
2245 '1.3.6.1.4.1.674.10893.1.20.130.13.1.11' => 'enclosureManagementModuleComponentStatus',
2246 '1.3.6.1.4.1.674.10893.1.20.130.13.1.12' => 'enclosureManagementModuleNexusID',
2247 '1.3.6.1.4.1.674.10893.1.20.130.14.1.4' => 'enclosureManagementModuleConnectionEnclosureName',
2248 '1.3.6.1.4.1.674.10893.1.20.130.14.1.5' => 'enclosureManagementModuleConnectionEnclosureNumber',
2249 );
2250 my $result = $snmp_session->get_entries(-columns => [keys %emms_oid]);
2251
2252 # No enclosure EMMs is OK
2253 return if !defined $result;
2254
2255 @output = @{ get_snmp_output($result, \%emms_oid) };
2256 }
2257 else {
2258 foreach my $enc (@enclosures) {
2259 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=emms") };
2260 map_item('ctrl', $enc->{ctrl}, \@output);
2261 map_item('encl_id', $enc->{id}, \@output);
2262 map_item('encl_name', $enc->{name}, \@output);
2263 }
2264 }
2265
2266 my %emms_state
2267 = (
2268 0 => 'Unknown',
2269 1 => 'Ready',
2270 2 => 'Failed',
2271 3 => 'Online',
2272 4 => 'Offline',
2273 5 => 'Not Installed',
2274 6 => 'Degraded',
2275 21 => 'Missing',
2276 );
2277
2278 # Check temperature probes on each of the enclosures
2279 EMM:
2280 foreach my $out (@output) {
2281 if ($snmp) {
2282 $id = $out->{enclosureManagementModuleNumber} - 1;
2283 $name = $out->{enclosureManagementModuleName};
2284 $state = $emms_state{$out->{enclosureManagementModuleState}};
2285 $status = $snmp_status{$out->{enclosureManagementModuleComponentStatus}};
2286 $encl_id = $out->{enclosureManagementModuleConnectionEnclosureNumber} - 1;
2287 $encl_name = $out->{enclosureManagementModuleConnectionEnclosureName};
2288 $nexus = convert_nexus($out->{enclosureManagementModuleNexusID});
2289 }
2290 else {
2291 $id = $out->{'ID'};
2292 $name = $out->{'Name'};
2293 $state = $out->{'State'};
2294 $status = $out->{'Status'};
2295 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
2296 $encl_name = $out->{encl_name};
2297 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, $id;
2298 }
2299
2300 next EMM if blacklisted('encl_emm', $nexus);
2301
2302 # Default
2303 if ($status ne 'Ok') {
98b224a3 2304 my $msg = sprintf '%s in enclosure %s [%s] needs attention: %s',
669797e1 2305 $name, $encl_id, $encl_name, $state;
2306 report('storage', $msg, $status2nagios{$status}, $nexus);
2307 }
2308 # Ok
2309 else {
98b224a3 2310 my $msg = sprintf '%s in enclosure %s [%s] is %s',
669797e1 2311 $name, $encl_id, $encl_name, $state;
2312 report('storage', $msg, $E_OK, $nexus);
2313 }
2314 }
2315 return;
2316}
2317
2318
2319#-----------------------------------------
2320# CHASSIS: Check memory modules
2321#-----------------------------------------
2322sub check_memory {
2323 my $index = undef;
2324 my $status = undef;
2325 my $location = undef;
2326 my $size = undef;
2327 my $modes = undef;
2328 my @failures = ();
2329 my @output = ();
2330
2331 if ($snmp) {
2332 my %dimm_oid
2333 = (
2334 '1.3.6.1.4.1.674.10892.1.1100.50.1.2.1' => 'memoryDeviceIndex',
2335 '1.3.6.1.4.1.674.10892.1.1100.50.1.5.1' => 'memoryDeviceStatus',
2336 '1.3.6.1.4.1.674.10892.1.1100.50.1.8.1' => 'memoryDeviceLocationName',
2337 '1.3.6.1.4.1.674.10892.1.1100.50.1.14.1' => 'memoryDeviceSize',
2338 '1.3.6.1.4.1.674.10892.1.1100.50.1.20.1' => 'memoryDeviceFailureModes',
2339 );
2340 my $result = $snmp_session->get_entries(-columns => [keys %dimm_oid]);
2341
2342 if (!defined $result) {
98b224a3 2343 printf "SNMP ERROR [memory]: %s.\n", $snmp_session->error;
669797e1 2344 $snmp_session->close;
2345 exit $E_UNKNOWN;
2346 }
2347
2348 @output = @{ get_snmp_output($result, \%dimm_oid) };
2349 }
2350 else {
2351 @output = @{ run_omreport("$omopt_chassis memory") };
2352 }
2353
2354 # Note: These values are bit masks, so combination values are
2355 # possible. If value is 0 (zero), memory device has no faults.
2356 my %failure_mode
2357 = (
2358 1 => 'ECC single bit correction warning rate exceeded',
2359 2 => 'ECC single bit correction failure rate exceeded',
2360 4 => 'ECC multibit fault encountered',
2361 8 => 'ECC single bit correction logging disabled',
2362 16 => 'device disabled because of spare activation',
2363 );
2364
2365 DIMM:
2366 foreach my $out (@output) {
2367 @failures = (); # Initialize
2368 if ($snmp) {
2369 $index = $out->{memoryDeviceIndex};
2370 $status = $snmp_status{$out->{memoryDeviceStatus}};
2371 $location = $out->{memoryDeviceLocationName};
2372 $size = sprintf '%d MB', $out->{memoryDeviceSize}/1024;
2373 $modes = $out->{memoryDeviceFailureModes};
2374 if ($modes > 0) {
2375 foreach my $mask (sort keys %failure_mode) {
2376 if (($modes & $mask) != 0) { push @failures, $failure_mode{$mask}; }
2377 }
2378 }
2379 }
2380 else {
2381 $index = $out->{'Type'} eq '[Not Occupied]' ? undef : $out->{'Index'};
2382 $status = $out->{'Status'};
2383 $location = $out->{'Connector Name'};
2384 $size = $out->{'Size'};
2385 if (defined $size) {
2386 $size =~ s{\s\s}{ }gxms;
2387 }
2388 # Run 'omreport chassis memory index=X' to get the failures
2389 if ($status ne 'Ok' && defined $index) {
2390 foreach (@{ run_command("$omreport $omopt_chassis memory index=$index -fmt ssv") }) {
2391 if (m/\A Failures; (.+?) \z/xms) {
2392 chop(my $fail = $1);
2393 push @failures, split m{\.}xms, $fail;
2394 }
2395 }
2396 }
2397 }
2398 $location =~ s{\A \s*(.*?)\s* \z}{$1}xms;
2399
2400 next DIMM if blacklisted('dimm', $index);
2401
2402 # Ignore empty memory slots
2403 next DIMM if !defined $index;
2404 $count{dimm}++;
2405
2406 if ($status ne 'Ok') {
2407 my $msg = undef;
2408 if (scalar @failures == 0) {
98b224a3 2409 $msg = sprintf 'Memory module %d [%s, %s] needs attention (%s)',
669797e1 2410 $index, $location, $size, $status;
2411 }
2412 else {
98b224a3 2413 $msg = sprintf 'Memory module %d [%s, %s] needs attention: %s',
669797e1 2414 $index, $location, $size, (join q{, }, @failures);
2415 }
2416
2417 report('chassis', $msg, $status2nagios{$status}, $index);
2418 }
2419 # Ok
2420 else {
98b224a3 2421 my $msg = sprintf 'Memory module %d [%s, %s] is %s',
669797e1 2422 $index, $location, $size, $status;
2423 report('chassis', $msg, $E_OK, $index);
2424 }
2425 }
2426 return;
2427}
2428
2429
2430#-----------------------------------------
2431# CHASSIS: Check fans
2432#-----------------------------------------
2433sub check_fans {
2434 my $index = undef;
2435 my $status = undef;
2436 my $reading = undef;
2437 my $location = undef;
2438 my $max_crit = undef;
2439 my $max_warn = undef;
2440 my @output = ();
2441
2442 if ($snmp) {
2443 my %cool_oid
2444 = (
2445 '1.3.6.1.4.1.674.10892.1.700.12.1.2.1' => 'coolingDeviceIndex',
2446 '1.3.6.1.4.1.674.10892.1.700.12.1.5.1' => 'coolingDeviceStatus',
2447 '1.3.6.1.4.1.674.10892.1.700.12.1.6.1' => 'coolingDeviceReading',
2448 '1.3.6.1.4.1.674.10892.1.700.12.1.8.1' => 'coolingDeviceLocationName',
2449 '1.3.6.1.4.1.674.10892.1.700.12.1.10.1' => 'coolingDeviceUpperCriticalThreshold',
2450 '1.3.6.1.4.1.674.10892.1.700.12.1.11.1' => 'coolingDeviceUpperNonCriticalThreshold',
2451 );
2452 my $result = $snmp_session->get_entries(-columns => [keys %cool_oid]);
2453
2454 if ($blade && !defined $result) {
2455 return 0;
2456 }
2457 elsif (!$blade && !defined $result) {
98b224a3 2458 printf "SNMP ERROR [cooling]: %s.\n", $snmp_session->error;
669797e1 2459 $snmp_session->close;
2460 exit $E_UNKNOWN;
2461 }
2462
2463 @output = @{ get_snmp_output($result, \%cool_oid) };
2464 }
2465 else {
2466 @output = @{ run_omreport("$omopt_chassis fans") };
2467 }
2468
2469 FAN:
2470 foreach my $out (@output) {
2471 if ($snmp) {
2472 $index = $out->{coolingDeviceIndex};
2473 $status = $snmp_probestatus{$out->{coolingDeviceStatus}};
2474 $reading = $out->{coolingDeviceReading};
2475 $location = $out->{coolingDeviceLocationName};
2476 $max_crit = exists $out->{coolingDeviceUpperCriticalThreshold}
2477 ? $out->{coolingDeviceUpperCriticalThreshold} : 0;
2478 $max_warn = exists $out->{coolingDeviceUpperNonCriticalThreshold}
2479 ? $out->{coolingDeviceUpperNonCriticalThreshold} : 0;
2480 }
2481 else {
2482 $index = $out->{'Index'};
2483 $status = $out->{'Status'};
2484 $reading = $out->{'Reading'};
2485 $location = $out->{'Probe Name'};
2486 $max_crit = $out->{'Maximum Failure Threshold'} ne '[N/A]'
2487 ? $out->{'Maximum Failure Threshold'} : 0;
2488 $max_warn = $out->{'Maximum Warning Threshold'} ne '[N/A]'
2489 ? $out->{'Maximum Warning Threshold'} : 0;
2490 $reading =~ s{\A (\d+).* \z}{$1}xms;
2491 $max_warn =~ s{\A (\d+).* \z}{$1}xms;
2492 $max_crit =~ s{\A (\d+).* \z}{$1}xms;
2493 }
2494
2495 next FAN if blacklisted('fan', $index);
2496 $count{fan}++;
2497
2498 if ($status ne 'Ok') {
98b224a3 2499 my $msg = sprintf 'Chassis fan %d [%s] needs attention: %s',
669797e1 2500 $index, $location, $status;
2501 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2502 report('chassis', $msg, $err, $index);
2503 }
2504 else {
98b224a3 2505 my $msg = sprintf 'Chassis fan %d [%s]: %s',
669797e1 2506 $index, $location, $reading;
2507 report('chassis', $msg, $E_OK, $index);
2508 }
2509
2510 # Collect performance data
2511 if (defined $opt{perfdata}) {
2512 my $pname = lc $location;
2513 $pname =~ s{\s}{_}gxms;
2514 $pname =~ s{proc_}{cpu#}xms;
2515 my $pkey = join q{_}, 'fan', $index, $pname;
2516 my $pval = join q{;}, "${reading}RPM", $max_warn, $max_crit;
2517 $perfdata{$pkey} = $pval;
2518 }
2519 }
2520 return;
2521}
2522
2523
2524#-----------------------------------------
2525# CHASSIS: Check power supplies
2526#-----------------------------------------
2527sub check_powersupplies {
2528 my $index = undef;
2529 my $status = undef;
2530 my $type = undef;
2531 my $err_type = undef;
2532 my $state = undef;
2533 my @states = ();
2534 my @output = ();
2535
2536 if ($snmp) {
2537 my %ps_oid
2538 = (
2539 '1.3.6.1.4.1.674.10892.1.600.12.1.2.1' => 'powerSupplyIndex',
2540 '1.3.6.1.4.1.674.10892.1.600.12.1.5.1' => 'powerSupplyStatus',
2541 '1.3.6.1.4.1.674.10892.1.600.12.1.7.1' => 'powerSupplyType',
2542 '1.3.6.1.4.1.674.10892.1.600.12.1.11.1' => 'powerSupplySensorState',
2543 '1.3.6.1.4.1.674.10892.1.600.12.1.12.1' => 'powerSupplyConfigurationErrorType',
2544 );
2545 my $result = $snmp_session->get_entries(-columns => [keys %ps_oid]);
2546
2547 # No instrumented PSU is OK (blades, low-end servers)
2548 return 0 if !defined $result;
2549
2550 @output = @{ get_snmp_output($result, \%ps_oid) };
2551 }
2552 else {
2553 @output = @{ run_omreport("$omopt_chassis pwrsupplies") };
2554 }
2555
2556 my %ps_type
2557 = (
2558 1 => 'Other',
2559 2 => 'Unknown',
2560 3 => 'Linear',
2561 4 => 'Switching',
2562 5 => 'Battery',
2563 6 => 'Uninterruptible Power Supply',
2564 7 => 'Converter',
2565 8 => 'Regulator',
2566 9 => 'AC',
2567 10 => 'DC',
2568 11 => 'VRM',
2569 );
2570
2571 my %ps_state
2572 = (
2573 1 => 'Presence detected',
2574 2 => 'Failure detected',
2575 4 => 'Predictive Failure',
2576 8 => 'AC lost',
2577 16 => 'AC lost or out-of-range',
2578 32 => 'AC out-of-range but present',
2579 64 => 'Configuration error',
2580 );
2581
2582 my %ps_config_error_type
2583 = (
2584 1 => 'Vendor mismatch',
2585 2 => 'Revision mismatch',
2586 3 => 'Processor missing',
2587 );
2588
2589 PS:
2590 foreach my $out (@output) {
2591 if ($snmp) {
2592 @states = (); # contains states for the PS
2593
2594 $index = $out->{powerSupplyIndex} - 1;
2595 $status = $snmp_status{$out->{powerSupplyStatus}};
2596 $type = $ps_type{$out->{powerSupplyType}};
2597 $err_type = defined $out->{powerSupplyConfigurationErrorType}
2598 ? $ps_config_error_type{$out->{powerSupplyConfigurationErrorType}} : undef;
2599
2600 # get the combined state from the StatusReading OID
2601 foreach my $mask (sort keys %ps_state) {
2602 if (($out->{powerSupplySensorState} & $mask) != 0) {
2603 push @states, $ps_state{$mask};
2604 }
2605 }
2606
2607 # If configuration error, also include the error type
2608 if (defined $err_type) {
2609 push @states, $err_type;
2610 }
2611
2612 # Finally, construct the state string
2613 $state = join q{, }, @states;
2614 }
2615 else {
2616 $index = $out->{'Index'};
2617 $status = $out->{'Status'};
2618 $type = $out->{'Type'};
2619 $state = $out->{'Online Status'};
2620 }
2621
2622 next PS if blacklisted('ps', $index);
2623 $count{power}++;
2624
2625 if ($status ne 'Ok') {
98b224a3 2626 my $msg = sprintf 'Power Supply %d [%s] needs attention: %s',
669797e1 2627 $index, $type, $state;
2628 report('chassis', $msg, $status2nagios{$status}, $index);
2629 }
2630 else {
98b224a3 2631 my $msg = sprintf 'Power Supply %d [%s]: %s',
669797e1 2632 $index, $type, $state;
2633 report('chassis', $msg, $E_OK, $index);
2634 }
2635 }
2636 return;
2637}
2638
2639
2640#-----------------------------------------
2641# CHASSIS: Check temperatures
2642#-----------------------------------------
2643sub check_temperatures {
2644 my $index = undef;
2645 my $status = undef;
2646 my $reading = undef;
2647 my $location = undef;
2648 my $max_crit = undef;
2649 my $max_warn = undef;
2650 my $min_warn = undef;
2651 my $min_crit = undef;
2652 my $type = undef;
2653 my $discrete = undef;
2654 my @output = ();
2655
2656 # Getting custom temperature thresholds (user option)
2657 my %warn_threshold = %{ custom_temperature_thresholds('w') };
2658 my %crit_threshold = %{ custom_temperature_thresholds('c') };
2659
2660 if ($snmp) {
2661 my %temp_oid
2662 = (
2663 '1.3.6.1.4.1.674.10892.1.700.20.1.2.1' => 'temperatureProbeIndex',
2664 '1.3.6.1.4.1.674.10892.1.700.20.1.5.1' => 'temperatureProbeStatus',
2665 '1.3.6.1.4.1.674.10892.1.700.20.1.6.1' => 'temperatureProbeReading',
2666 '1.3.6.1.4.1.674.10892.1.700.20.1.7.1' => 'temperatureProbeType',
2667 '1.3.6.1.4.1.674.10892.1.700.20.1.8.1' => 'temperatureProbeLocationName',
2668 '1.3.6.1.4.1.674.10892.1.700.20.1.10.1' => 'temperatureProbeUpperCriticalThreshold',
2669 '1.3.6.1.4.1.674.10892.1.700.20.1.11.1' => 'temperatureProbeUpperNonCriticalThreshold',
2670 '1.3.6.1.4.1.674.10892.1.700.20.1.12.1' => 'temperatureProbeLowerNonCriticalThreshold',
2671 '1.3.6.1.4.1.674.10892.1.700.20.1.13.1' => 'temperatureProbeLowerCriticalThreshold',
2672 '1.3.6.1.4.1.674.10892.1.700.20.1.16.1' => 'temperatureProbeDiscreteReading',
2673 );
ba199ee0 2674 # this didn't work well for some reason
2675 #my $result = $snmp_session->get_entries(-columns => [keys %temp_oid]);
2676
2677 # Getting values using the table
2678 my $temperatureProbeTable = '1.3.6.1.4.1.674.10892.1.700.20';
2679 my $result = $snmp_session->get_table(-baseoid => $temperatureProbeTable);
669797e1 2680
2681 if (!defined $result) {
98b224a3 2682 printf "SNMP ERROR [temperatures]: %s.\n", $snmp_session->error;
669797e1 2683 $snmp_session->close;
2684 exit $E_UNKNOWN;
2685 }
2686
2687 @output = @{ get_snmp_output($result, \%temp_oid) };
2688 }
2689 else {
2690 @output = @{ run_omreport("$omopt_chassis temps") };
2691 }
2692
2693 my %probe_type
2694 = (
2695 1 => 'Other', # type is other than following values
2696 2 => 'Unknown', # type is unknown
2697 3 => 'AmbientESM', # type is Ambient Embedded Systems Management temperature probe
2698 16 => 'Discrete', # type is temperature probe with discrete reading
2699 );
2700
2701 TEMP:
2702 foreach my $out (@output) {
2703 if ($snmp) {
2704 $index = $out->{temperatureProbeIndex} - 1;
2705 $status = $snmp_probestatus{$out->{temperatureProbeStatus}};
2706 $reading = $out->{temperatureProbeReading} / 10;
2707 $location = $out->{temperatureProbeLocationName};
2708 $max_crit = $out->{temperatureProbeUpperCriticalThreshold} / 10;
2709 $max_warn = $out->{temperatureProbeUpperNonCriticalThreshold} / 10;
2710 $min_crit = exists $out->{temperatureProbeLowerCriticalThreshold}
2711 ? $out->{temperatureProbeLowerCriticalThreshold} / 10 : '[N/A]';
2712 $min_warn = exists $out->{temperatureProbeLowerNonCriticalThreshold}
2713 ? $out->{temperatureProbeLowerNonCriticalThreshold} / 10 : '[N/A]';
2714 $type = $probe_type{$out->{temperatureProbeType}};
2715 $discrete = exists $out->{temperatureProbeDiscreteReading}
2716 ? $out->{temperatureProbeDiscreteReading} : undef;
2717 }
2718 else {
2719 $index = $out->{'Index'};
2720 $status = $out->{'Status'};
2721 $reading = $out->{'Reading'}; $reading =~ s{\.0\s+C}{}xms;
2722 $location = $out->{'Probe Name'};
2723 $max_crit = $out->{'Maximum Failure Threshold'}; $max_crit =~ s{\.0\s+C}{}xms;
2724 $max_warn = $out->{'Maximum Warning Threshold'}; $max_warn =~ s{\.0\s+C}{}xms;
2725 $min_crit = $out->{'Minimum Failure Threshold'}; $min_crit =~ s{\.0\s+C}{}xms;
2726 $min_warn = $out->{'Minimum Warning Threshold'}; $min_warn =~ s{\.0\s+C}{}xms;
2727 $type = $reading =~ m{\A\d+\z}xms ? 'AmbientESM' : 'Discrete';
2728 $discrete = $reading;
2729 }
2730
2731 next TEMP if blacklisted('temp', $index);
2732 $count{temp}++;
2733
2734 if ($type eq 'Discrete') {
2735 my $msg = sprintf 'Temperature probe %d (%s): is %s',
2736 $index, $location, $discrete;
2737 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2738 report('chassis', $msg, $err, $index);
2739 }
2740 else {
2741 # First check according to custom thresholds
2742 if (exists $crit_threshold{$index}{max} and $reading > $crit_threshold{$index}{max}) {
2743 # Custom critical MAX
98b224a3 2744 my $msg = sprintf 'Temperature Probe %d [%s] reads %d C (custom max=%d)',
669797e1 2745 $index, $location, $reading, $crit_threshold{$index}{max};
2746 report('chassis', $msg, $E_CRITICAL, $index);
2747 }
2748 elsif (exists $warn_threshold{$index}{max} and $reading > $warn_threshold{$index}{max}) {
2749 # Custom warning MAX
98b224a3 2750 my $msg = sprintf 'Temperature Probe %d [%s] reads %d C (custom max=%d)',
669797e1 2751 $index, $location, $reading, $warn_threshold{$index}{max};
2752 report('chassis', $msg, $E_WARNING, $index);
2753 }
2754 elsif (exists $crit_threshold{$index}{min} and $reading < $crit_threshold{$index}{min}) {
2755 # Custom critical MIN
98b224a3 2756 my $msg = sprintf 'Temperature Probe %d [%s] reads %d C (custom min=%d)',
669797e1 2757 $index, $location, $reading, $crit_threshold{$index}{min};
2758 report('chassis', $msg, $E_CRITICAL, $index);
2759 }
2760 elsif (exists $warn_threshold{$index}{min} and $reading < $warn_threshold{$index}{min}) {
2761 # Custom warning MIN
98b224a3 2762 my $msg = sprintf 'Temperature Probe %d [%s] reads %d C (custom min=%d)',
669797e1 2763 $index, $location, $reading, $warn_threshold{$index}{min};
2764 report('chassis', $msg, $E_WARNING, $index);
2765 }
2766 elsif ($status ne 'Ok' and $max_crit ne '[N/A]' and $reading > $max_crit) {
98b224a3 2767 my $msg = sprintf 'Temperature Probe %d [%s] is critically high at %d C',
669797e1 2768 $index, $location, $reading;
2769 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2770 report('chassis', $msg, $err, $index);
2771 }
2772 elsif ($status ne 'Ok' and $max_warn ne '[N/A]' and $reading > $max_warn) {
98b224a3 2773 my $msg = sprintf 'Temperature Probe %d [%s] is too high at %d C',
669797e1 2774 $index, $location, $reading;
2775 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2776 report('chassis', $msg, $err, $index);
2777 }
2778 elsif ($status ne 'Ok' and $min_crit ne '[N/A]' and $reading < $min_crit) {
98b224a3 2779 my $msg = sprintf 'Temperature Probe %d [%s] is critically low at %d C',
669797e1 2780 $index, $location, $reading;
2781 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2782 report('chassis', $msg, $err, $index);
2783 }
2784 elsif ($status ne 'Ok' and $min_warn ne '[N/A]' and $reading < $min_warn) {
98b224a3 2785 my $msg = sprintf 'Temperature Probe %d [%s] is too low at %d C',
669797e1 2786 $index, $location, $reading;
2787 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2788 report('chassis', $msg, $err, $index);
2789 }
2790 # Ok
2791 else {
304c4cba 2792 my $msg = sprintf 'Temperature Probe %d [%s] reads %d C',
2793 $index, $location, $reading;
2794 if ($min_warn eq '[N/A]' and $min_crit eq '[N/A]') {
2795 $msg .= sprintf ' (max=%s/%s)', $max_warn, $max_crit;
2796 }
2797 else {
2798 $msg .= sprintf ' (min=%s/%s, max=%s/%s)',
2799 $min_warn, $min_crit, $max_warn, $max_crit;
8ce893fd 2800 }
669797e1 2801 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2802 report('chassis', $msg, $err, $index);
2803 }
2804
2805 # Collect performance data
2806 if (defined $opt{perfdata}) {
2807 my $pname = lc $location;
2808 $pname =~ s{\s}{_}gxms;
2809 $pname =~ s{_temp\z}{}xms;
2810 $pname =~ s{proc_}{cpu#}xms;
2811 my $pkey = join q{_}, 'temp', $index, $pname;
2812 my $pval = join q{;}, "${reading}C", $max_warn, $max_crit;
2813 $perfdata{$pkey} = $pval;
2814 }
2815 }
2816 }
2817 return;
2818}
2819
2820
2821#-----------------------------------------
2822# CHASSIS: Check processors
2823#-----------------------------------------
2824sub check_processors {
2825 my $index = undef;
2826 my $status = undef;
2827 my $state = undef;
8ce893fd 2828 my $brand = undef;
2829 my $family = undef;
2830 my $man = undef;
2831 my $speed = undef;
8ce893fd 2832 my @output = ();
669797e1 2833
2834 if ($snmp) {
2835
2836 # NOTE: For some reason, older models don't have the
8ce893fd 2837 # "Processor Device Status" OIDs. We check both the newer
2838 # (preferred) OIDs and the old ones.
669797e1 2839
8ce893fd 2840 my %cpu_oid
669797e1 2841 = (
8ce893fd 2842 '1.3.6.1.4.1.674.10892.1.1100.30.1.2.1' => 'processorDeviceIndex',
2843 '1.3.6.1.4.1.674.10892.1.1100.30.1.5.1' => 'processorDeviceStatus',
2844 '1.3.6.1.4.1.674.10892.1.1100.30.1.8.1' => 'processorDeviceManufacturerName',
2845 '1.3.6.1.4.1.674.10892.1.1100.30.1.9.1' => 'processorDeviceStatusState',
2846 '1.3.6.1.4.1.674.10892.1.1100.30.1.10.1' => 'processorDeviceFamily',
2847 '1.3.6.1.4.1.674.10892.1.1100.30.1.12.1' => 'processorDeviceCurrentSpeed',
2848 '1.3.6.1.4.1.674.10892.1.1100.30.1.23.1' => 'processorDeviceBrandName',
2849 '1.3.6.1.4.1.674.10892.1.1100.32.1.2.1' => 'processorDeviceStatusIndex',
2850 '1.3.6.1.4.1.674.10892.1.1100.32.1.5.1' => 'processorDeviceStatusStatus',
2851 '1.3.6.1.4.1.674.10892.1.1100.32.1.6.1' => 'processorDeviceStatusReading',
669797e1 2852 );
2853
8ce893fd 2854 my $result = $snmp_session->get_entries(-columns => [keys %cpu_oid]);
669797e1 2855
2856 if (!defined $result) {
98b224a3 2857 printf "SNMP ERROR [processors]: %s.\n", $snmp_session->error;
669797e1 2858 $snmp_session->close;
2859 exit $E_UNKNOWN;
2860 }
2861
8ce893fd 2862 @output = @{ get_snmp_output($result, \%cpu_oid) };
669797e1 2863 }
2864 else {
2865 @output = @{ run_omreport("$omopt_chassis processors") };
2866 }
2867
2868 my %cpu_state
2869 = (
2870 1 => 'Other', # other than following values
2871 2 => 'Unknown', # unknown
2872 3 => 'Enabled', # enabled
2873 4 => 'User Disabled', # disabled by user via BIOS setup
2874 5 => 'BIOS Disabled', # disabled by BIOS (POST error)
2875 6 => 'Idle', # idle
2876 );
2877
2878 my %cpu_reading
2879 = (
2880 1 => 'Internal Error', # Internal Error
2881 2 => 'Thermal Trip', # Thermal Trip
2882 32 => 'Configuration Error', # Configuration Error
2883 128 => 'Present', # Processor Present
2884 256 => 'Disabled', # Processor Disabled
2885 512 => 'Terminator Present', # Terminator Present
2886 1024 => 'Throttled', # Processor Throttled
2887 );
2888
8ce893fd 2889 # Mapping between family numbers from SNMP and actual CPU family
2890 my %cpu_family
2891 = (
d10e7068 2892 1 => 'Other', 2 => 'Unknown', 3 => '8086',
2893 4 => '80286', 5 => '386', 6 => '486',
2894 7 => '8087', 8 => '80287', 9 => '80387',
2895 10 => '80487', 11 => 'Pentium', 12 => 'Pentium Pro',
2896 13 => 'Pentium II', 14 => 'Pentium with MMX', 15 => 'Celeron',
2897 16 => 'Pentium II Xeon', 17 => 'Pentium III', 18 => 'Pentium III Xeon',
2898 19 => 'Pentium III', 20 => 'Itanium', 21 => 'Xeon',
2899 22 => 'Pentium 4', 23 => 'Xeon MP', 24 => 'Itanium 2',
2900 25 => 'K5', 26 => 'K6', 27 => 'K6-2',
2901 28 => 'K6-3', 29 => 'Athlon', 30 => 'AMD2900',
2902 31 => 'K6-2+', 32 => 'Power PC', 33 => 'Power PC 601',
2903 34 => 'Power PC 603', 35 => 'Power PC 603+', 36 => 'Power PC 604',
2904 37 => 'Power PC 620', 38 => 'Power PC x704', 39 => 'Power PC 750',
2905 48 => 'Alpha', 49 => 'Alpha 21064', 50 => 'Alpha 21066',
2906 51 => 'Alpha 21164', 52 => 'Alpha 21164PC', 53 => 'Alpha 21164a',
2907 54 => 'Alpha 21264', 55 => 'Alpha 21364', 64 => 'MIPS',
2908 65 => 'MIPS R4000', 66 => 'MIPS R4200', 67 => 'MIPS R4400',
2909 68 => 'MIPS R4600', 69 => 'MIPS R10000', 80 => 'SPARC',
2910 81 => 'SuperSPARC', 82 => 'microSPARC II', 83 => 'microSPARC IIep',
2911 84 => 'UltraSPARC', 85 => 'UltraSPARC II', 86 => 'UltraSPARC IIi',
2912 87 => 'UltraSPARC III', 88 => 'UltraSPARC IIIi', 96 => '68040',
2913 97 => '68xxx', 98 => '68000', 99 => '68010',
2914 100 => '68020', 101 => '68030', 112 => 'Hobbit',
2915 120 => 'Crusoe TM5000', 121 => 'Crusoe TM3000', 122 => 'Efficeon TM8000',
2916 128 => 'Weitek', 131 => 'Athlon 64', 132 => 'Opteron',
2917 133 => 'Sempron', 134 => 'Turion 64 Mobile', 135 => 'Dual-Core Opteron',
2918 136 => 'Athlon 64 X2 DC', 137 => 'Turion 64 X2 M', 138 => 'Quad-Core Opteron',
2919 139 => '3rd gen Opteron', 144 => 'PA-RISC', 145 => 'PA-RISC 8500',
2920 146 => 'PA-RISC 8000', 147 => 'PA-RISC 7300LC', 148 => 'PA-RISC 7200',
2921 149 => 'PA-RISC 7100LC', 150 => 'PA-RISC 7100', 160 => 'V30',
2922 171 => 'Dual-Core Xeon 5200', 172 => 'Dual-Core Xeon 7200', 173 => 'Quad-Core Xeon 7300',
2923 174 => 'Quad-Core Xeon 7400', 175 => 'Multi-Core Xeon 7400', 176 => 'M1',
2924 177 => 'M2', 180 => 'AS400', 182 => 'Athlon XP',
2925 183 => 'Athlon MP', 184 => 'Duron', 185 => 'Pentium M',
2926 186 => 'Celeron D', 187 => 'Pentium D', 188 => 'Pentium Extreme',
2927 189 => 'Core Solo', 190 => 'Core2', 191 => 'Core2 Duo',
2928 198 => 'Core i7', 199 => 'Dual-Core Celeron', 200 => 'IBM390',
2929 201 => 'G4', 202 => 'G5', 203 => 'ESA/390 G6',
2930 204 => 'z/Architectur', 210 => 'C7-M', 211 => 'C7-D',
2931 212 => 'C7', 213 => 'Eden', 214 => 'Multi-Core Xeon',
2932 215 => 'Dual-Core Xeon 3xxx', 216 => 'Quad-Core Xeon 3xxx', 218 => 'Dual-Core Xeon 5xxx',
2933 219 => 'Quad-Core Xeon 5xxx', 221 => 'Dual-Core Xeon 7xxx', 222 => 'Quad-Core Xeon 7xxx',
24f706a6 2934 223 => 'Multi-Core Xeon 7xxx', 250 => 'i860', 251 => 'i960',
8ce893fd 2935 );
669797e1 2936
2937 CPU:
2938 foreach my $out (@output) {
2939 if ($snmp) {
8ce893fd 2940 $index = exists $out->{processorDeviceStatusIndex}
2941 ? $out->{processorDeviceStatusIndex} - 1
2942 : $out->{processorDeviceIndex} - 1;
2943 $status = exists $out->{processorDeviceStatusStatus}
2944 ? $snmp_status{$out->{processorDeviceStatusStatus}}
2945 : $snmp_status{$out->{processorDeviceStatus}};
2946 if (exists $out->{processorDeviceStatusReading}) {
669797e1 2947 my @states = (); # contains states for the CPU
669797e1 2948
2949 # get the combined state from the StatusReading OID
2950 foreach my $mask (sort keys %cpu_reading) {
2951 if (($out->{processorDeviceStatusReading} & $mask) != 0) {
2952 push @states, $cpu_reading{$mask};
2953 }
2954 }
2955
2956 # Finally, create the state string
2957 $state = join q{, }, @states;
2958 }
2959 else {
669797e1 2960 $state = $cpu_state{$out->{processorDeviceStatusState}};
2961 }
8ce893fd 2962 $man = $out->{processorDeviceManufacturerName};
87a0958c 2963 $family = (exists $out->{processorDeviceFamily}
04a878db 2964 and exists $cpu_family{$out->{processorDeviceFamily}})
2965 ? $cpu_family{$out->{processorDeviceFamily}} : undef;
8ce893fd 2966 $speed = $out->{processorDeviceCurrentSpeed};
2967 $brand = $out->{processorDeviceBrandName};
669797e1 2968 }
2969 else {
2970 $index = $out->{'Index'};
2971 $status = $out->{'Status'};
2972 $state = $out->{'State'};
8ce893fd 2973 $brand = exists $out->{'Processor Brand'} ? $out->{'Processor Brand'} : undef;
2974 $family = exists $out->{'Processor Family'} ? $out->{'Processor Family'} : undef;
2975 $man = exists $out->{'Processor Manufacturer'} ? $out->{'Processor Manufacturer'} : undef;
2976 $speed = exists $out->{'Current Speed'} ? $out->{'Current Speed'} : undef;
669797e1 2977 }
2978
2979 next CPU if blacklisted('cpu', $index);
2980
2981 # Ignore unoccupied CPU slots (omreport)
2982 next CPU if (defined $out->{'Processor Manufacturer'}
2983 and $out->{'Processor Manufacturer'} eq '[Not Occupied]')
2984 or (defined $out->{'Processor Brand'} and $out->{'Processor Brand'} eq '[Not Occupied]');
2985
2986 # Ignore unoccupied CPU slots (snmp)
2987 if ($snmp and exists $out->{processorDeviceStatusReading}
2988 and $out->{processorDeviceStatusReading} == 0) {
2989 next CPU;
2990 }
2991
2992 $count{cpu}++;
2993
8ce893fd 2994 if (defined $brand) {
2995 $brand =~ s{\s\s+}{ }gxms;
e7dc67d0 2996 $brand =~ s{\((R|tm)\)}{}gxms;
2997 $brand =~ s{\s(CPU|Processor)}{}xms;
8ce893fd 2998 $brand =~ s{\s\@}{}xms;
2999 }
3000 elsif (defined $family and defined $man and defined $speed) {
3001 $speed =~ s{\A (\d+) .*}{$1}xms;
3002 $brand = sprintf '%s %s %.2fGHz', $man, $family, $speed / 1000;
3003 }
3004 else {
3005 $brand = "unknown";
3006 }
3007
669797e1 3008 # Default
3009 if ($status ne 'Ok') {
0a0813de 3010 my $msg = sprintf 'Processor %d [%s] needs attention: %s',
8ce893fd 3011 $index, $brand, $state;
669797e1 3012 report('chassis', $msg, $status2nagios{$status}, $index);
3013 }
3014 # Ok
3015 else {
0a0813de 3016 my $msg = sprintf 'Processor %d [%s] is %s',
8ce893fd 3017 $index, $brand, $state;
669797e1 3018 report('chassis', $msg, $E_OK, $index);
3019 }
3020 }
3021 return;
3022}
3023
3024
3025#-----------------------------------------
3026# CHASSIS: Check voltage probes
3027#-----------------------------------------
3028sub check_volts {
3029 my $index = undef;
3030 my $status = undef;
3031 my $reading = undef;
3032 my $location = undef;
3033 my @output = ();
3034
3035 if ($snmp) {
3036 my %volt_oid
3037 = (
3038 '1.3.6.1.4.1.674.10892.1.600.20.1.2.1' => 'voltageProbeIndex',
3039 '1.3.6.1.4.1.674.10892.1.600.20.1.5.1' => 'voltageProbeStatus',
3040 '1.3.6.1.4.1.674.10892.1.600.20.1.6.1' => 'voltageProbeReading',
3041 '1.3.6.1.4.1.674.10892.1.600.20.1.8.1' => 'voltageProbeLocationName',
3042 '1.3.6.1.4.1.674.10892.1.600.20.1.16.1' => 'voltageProbeDiscreteReading',
3043 );
ba199ee0 3044
3045 my $voltageProbeTable = '1.3.6.1.4.1.674.10892.1.600.20.1';
3046 my $result = $snmp_session->get_table(-baseoid => $voltageProbeTable);
669797e1 3047
3048 if (!defined $result) {
98b224a3 3049 printf "SNMP ERROR [voltage]: %s.\n", $snmp_session->error;
669797e1 3050 $snmp_session->close;
3051 exit $E_UNKNOWN;
3052 }
3053
3054 @output = @{ get_snmp_output($result, \%volt_oid) };
3055 }
3056 else {
3057 @output = @{ run_omreport("$omopt_chassis volts") };
3058 }
3059
3060 my %volt_discrete_reading
3061 = (
3062 1 => 'Good',
3063 2 => 'Bad',
3064 );
3065
3066 VOLT:
3067 foreach my $out (@output) {
3068 if ($snmp) {
3069 $index = $out->{voltageProbeIndex} - 1;
ffa570fc 3070 $status = $snmp_probestatus{$out->{voltageProbeStatus}};
669797e1 3071 $reading = exists $out->{voltageProbeReading}
3072 ? sprintf('%.3f V', $out->{voltageProbeReading}/1000)
3073 : $volt_discrete_reading{$out->{voltageProbeDiscreteReading}};
3074 $location = $out->{voltageProbeLocationName};
3075 }
3076 else {
3077 $index = $out->{'Index'};
3078 $status = $out->{'Status'};
3079 $reading = $out->{'Reading'};
3080 $location = $out->{'Probe Name'};
3081 }
3082
3083 next VOLT if blacklisted('volt', $index);
3084 $count{volt}++;
3085
98b224a3 3086 my $msg = sprintf 'Voltage sensor %d [%s] is %s',
669797e1 3087 $index, $location, $reading;
3088 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3089 report('chassis', $msg, $err, $index);
3090 }
3091 return;
3092}
3093
3094
3095#-----------------------------------------
3096# CHASSIS: Check batteries
3097#-----------------------------------------
3098sub check_batteries {
3099 my $index = undef;
3100 my $status = undef;
3101 my $reading = undef;
3102 my $location = undef;
3103 my @output = ();
3104
3105 if ($snmp) {
3106 my %bat_oid
3107 = (
3108 '1.3.6.1.4.1.674.10892.1.600.50.1.2.1' => 'batteryIndex',
3109 '1.3.6.1.4.1.674.10892.1.600.50.1.5.1' => 'batteryStatus',
3110 '1.3.6.1.4.1.674.10892.1.600.50.1.6.1' => 'batteryReading',
3111 '1.3.6.1.4.1.674.10892.1.600.50.1.7.1' => 'batteryLocationName',
3112 );
3113 my $result = $snmp_session->get_entries(-columns => [keys %bat_oid]);
3114
3115 # No batteries is OK
3116 return 0 if !defined $result;
3117
3118 @output = @{ get_snmp_output($result, \%bat_oid) };
3119 }
3120 else {
3121 @output = @{ run_omreport("$omopt_chassis batteries") };
3122 }
3123
3124 my %bat_reading
3125 = (
3126 1 => 'Predictive Failure',
3127 2 => 'Failed',
3128 4 => 'Presence Detected',
3129 );
3130
3131 BATTERY:
3132 foreach my $out (@output) {
3133 if ($snmp) {
3134 $index = $out->{batteryIndex} - 1;
3135 $status = $snmp_status{$out->{batteryStatus}};
3136 $reading = $bat_reading{$out->{batteryReading}};
3137 $location = $out->{batteryLocationName};
3138 }
3139 else {
3140 $index = $out->{'Index'};
3141 $status = $out->{'Status'};
3142 $reading = $out->{'Reading'};
3143 $location = $out->{'Probe Name'};
3144 }
3145
3146 next BATTERY if blacklisted('bp', $index);
3147 $count{bat}++;
3148
98b224a3 3149 my $msg = sprintf 'Battery probe %d [%s] is %s',
669797e1 3150 $index, $location, $reading;
3151 report('chassis', $msg, $status2nagios{$status}, $index);
3152 }
3153 return;
3154}
3155
3156
3157#-----------------------------------------
3158# CHASSIS: Check amperage probes (power monitoring)
3159#-----------------------------------------
3160sub check_pwrmonitoring {
3161 my $index = undef;
3162 my $status = undef;
3163 my $reading = undef;
3164 my $location = undef;
3165 my $max_crit = undef;
3166 my $max_warn = undef;
3167 my $unit = undef;
3168 my @output = ();
3169
3170 if ($snmp) {
3171 my %amp_oid
3172 = (
3173 '1.3.6.1.4.1.674.10892.1.600.30.1.2.1' => 'amperageProbeIndex',
3174 '1.3.6.1.4.1.674.10892.1.600.30.1.5.1' => 'amperageProbeStatus',
3175 '1.3.6.1.4.1.674.10892.1.600.30.1.6.1' => 'amperageProbeReading',
3176 '1.3.6.1.4.1.674.10892.1.600.30.1.7.1' => 'amperageProbeType',
3177 '1.3.6.1.4.1.674.10892.1.600.30.1.8.1' => 'amperageProbeLocationName',
3178 '1.3.6.1.4.1.674.10892.1.600.30.1.10.1' => 'amperageProbeUpperCriticalThreshold',
3179 '1.3.6.1.4.1.674.10892.1.600.30.1.11.1' => 'amperageProbeUpperNonCriticalThreshold',
3180 '1.3.6.1.4.1.674.10892.1.600.30.1.16.1' => 'amperageProbeDiscreteReading',
3181 );
3182 my $result = $snmp_session->get_entries(-columns => [keys %amp_oid]);
3183
3184 # No pwrmonitoring is OK
3185 return 0 if !defined $result;
3186
3187 @output = @{ get_snmp_output($result, \%amp_oid) };
3188 }
3189 else {
3190 @output = @{ run_omreport("$omopt_chassis pwrmonitoring") };
3191 }
3192
3193 my %amp_type # Amperage probe types
3194 = (
3195 1 => 'amperageProbeTypeIsOther', # other than following values
3196 2 => 'amperageProbeTypeIsUnknown', # unknown
3197 3 => 'amperageProbeTypeIs1Point5Volt', # 1.5 amperage probe
3198 4 => 'amperageProbeTypeIs3Point3volt', # 3.3 amperage probe
3199 5 => 'amperageProbeTypeIs5Volt', # 5 amperage probe
3200 6 => 'amperageProbeTypeIsMinus5Volt', # -5 amperage probe
3201 7 => 'amperageProbeTypeIs12Volt', # 12 amperage probe
3202 8 => 'amperageProbeTypeIsMinus12Volt', # -12 amperage probe
3203 9 => 'amperageProbeTypeIsIO', # I/O probe
3204 10 => 'amperageProbeTypeIsCore', # Core probe
3205 11 => 'amperageProbeTypeIsFLEA', # FLEA (standby) probe
3206 12 => 'amperageProbeTypeIsBattery', # Battery probe
3207 13 => 'amperageProbeTypeIsTerminator', # SCSI Termination probe
3208 14 => 'amperageProbeTypeIs2Point5Volt', # 2.5 amperage probe
3209 15 => 'amperageProbeTypeIsGTL', # GTL (ground termination logic) probe
3210 16 => 'amperageProbeTypeIsDiscrete', # amperage probe with discrete reading
3211 23 => 'amperageProbeTypeIsPowerSupplyAmps', # Power Supply probe with reading in Amps
3212 24 => 'amperageProbeTypeIsPowerSupplyWatts', # Power Supply probe with reading in Watts
3213 25 => 'amperageProbeTypeIsSystemAmps', # System probe with reading in Amps
3214 26 => 'amperageProbeTypeIsSystemWatts', # System probe with reading in Watts
3215 );
3216
3217 my %amp_discrete
3218 = (
3219 1 => 'Good',
3220 2 => 'Bad',
3221 );
3222
3223 my %amp_unit
3224 = (
3225 'amperageProbeTypeIsPowerSupplyAmps' => 'hA', # tenths of Amps
3226 'amperageProbeTypeIsSystemAmps' => 'hA', # tenths of Amps
3227 'amperageProbeTypeIsPowerSupplyWatts' => 'W', # Watts
3228 'amperageProbeTypeIsSystemWatts' => 'W', # Watts
3229 'amperageProbeTypeIsDiscrete' => q{}, # discrete reading, no unit
3230 );
3231
3232 AMP:
3233 foreach my $out (@output) {
3234 if ($snmp) {
3235 $index = $out->{amperageProbeIndex} - 1;
3236 $status = $snmp_status{$out->{amperageProbeStatus}};
3237 $reading = $amp_type{$out->{amperageProbeType}} eq 'amperageProbeTypeIsDiscrete'
3238 ? $amp_discrete{$out->{amperageProbeDiscreteReading}}
3239 : $out->{amperageProbeReading};
3240 $location = $out->{amperageProbeLocationName};
3241 $max_crit = exists $out->{amperageProbeUpperCriticalThreshold}
3242 ? $out->{amperageProbeUpperCriticalThreshold} : 0;
3243 $max_warn = exists $out->{amperageProbeUpperNonCriticalThreshold}
3244 ? $out->{amperageProbeUpperNonCriticalThreshold} : 0;
3245 $unit = exists $amp_unit{$amp_type{$out->{amperageProbeType}}}
3246 ? $amp_unit{$amp_type{$out->{amperageProbeType}}} : 'mA';
3247 if ($unit eq 'hA') {
3248 $reading /= 10;
3249 $max_crit /= 10;
3250 $max_warn /= 10;
3251 $unit = 'A';
3252 }
3253 }
3254 else {
3255 $index = $out->{'Index'};
0be00f80 3256 next AMP if (!defined $index || $index !~ m/^\d+$/x);
669797e1 3257 $status = $out->{'Status'};
3258 $reading = $out->{'Reading'};
3259 $location = $out->{'Probe Name'};
3260 $max_crit = $out->{'Failure Threshold'} ne '[N/A]'
3261 ? $out->{'Failure Threshold'} : 0;
3262 $max_warn = $out->{'Warning Threshold'} ne '[N/A]'
3263 ? $out->{'Warning Threshold'} : 0;
3264 $reading =~ s{\A (\d+.*?)\s+([a-zA-Z]+) \s*\z}{$1}xms;
3265 $unit = $2;
3266 $max_warn =~ s{\A (\d+.*?)\s+[a-zA-Z]+ \s*\z}{$1}xms;
3267 $max_crit =~ s{\A (\d+.*?)\s+[a-zA-Z]+ \s*\z}{$1}xms;
3268 }
3269
78dbab97 3270 next AMP if blacklisted('amp', $index);
669797e1 3271 next AMP if $index !~ m{\A \d+ \z}xms;
3272 $count{amp}++;
3273
98b224a3 3274 my $msg = sprintf 'Amperage probe %d [%s] reads %s %s',
669797e1 3275 $index, $location, $reading, $unit, $status;
3276 report('chassis', $msg, $status2nagios{$status}, $index);
3277
3278 # Collect performance data
3279 if (defined $opt{perfdata}) {
3280 next AMP if $reading !~ m{\A \d+(\.\d+)? \z}xms; # discrete reading (not number)
3281 my $pname = lc $location;
3282 $pname =~ s{\s}{_}gxms;
3283 my $pkey = join q{_}, 'pwr_mon', $index, $pname;
3284 my $pval = join q{;}, "$reading$unit", $max_warn, $max_crit;
3285 $perfdata{$pkey} = $pval;
3286 }
3287 }
3288
3289 # Collect EXTRA performance data not found at first run. This is a
3290 # rather ugly hack
3291 if (defined $opt{perfdata} && !$snmp) {
3292 my $found = 0;
3293 my $index = 0;
3294 my %used = ();
3295
3296 # find used indexes
3297 foreach (keys %perfdata) {
3298 if (m/\A pwr_mon_(\d+)/xms) {
3299 $used{$1} = 1;
3300 }
3301 }
3302
3303 AMP2:
3304 foreach my $line (@{ run_command("$omreport $omopt_chassis pwrmonitoring -fmt ssv") }) {
3305 chop $line;
3306 if ($line eq 'Location;Reading') {
3307 $found = 1;
3308 next AMP2;
3309 }
3310 if ($line eq q{}) {
3311 $found = 0;
3312 next AMP2;
3313 }
3314 if ($found and $line =~ m/\A ([^;]+?) ; (\d*\.\d+) \s ([AW]) \z/xms) {
3315 my $aname = lc $1;
3316 my $aval = $2;
3317 my $aunit = $3;
3318 $aname =~ s{\s}{_}gxms;
3319
3320 # don't use an existing index
3321 while (exists $used{$index}) { ++$index; }
3322
3323 $perfdata{"pwr_mon_${index}_${aname}"} = "$aval$aunit;0;0";
3324 ++$index;
3325 }
3326 }
3327 }
3328
3329 return;
3330}
3331
3332
3333#-----------------------------------------
3334# CHASSIS: Check intrusion
3335#-----------------------------------------
3336sub check_intrusion {
3337 my $index = undef;
3338 my $status = undef;
3339 my $reading = undef;
3340 my @output = ();
3341
3342 if ($snmp) {
3343 my %int_oid
3344 = (
3345 '1.3.6.1.4.1.674.10892.1.300.70.1.2.1' => 'intrusionIndex',
3346 '1.3.6.1.4.1.674.10892.1.300.70.1.5.1' => 'intrusionStatus',
3347 '1.3.6.1.4.1.674.10892.1.300.70.1.6.1' => 'intrusionReading',
3348 );
3349 my $result = $snmp_session->get_entries(-columns => [keys %int_oid]);
3350
3351 # No intrusion is OK
3352 return 0 if !defined $result;
3353
3354 @output = @{ get_snmp_output($result, \%int_oid) };
3355 }
3356 else {
3357 @output = @{ run_omreport("$omopt_chassis intrusion") };
3358 }
3359
3360 my %int_reading
3361 = (
3362 1 => 'Not Breached', # chassis not breached and no uncleared breaches
3363 2 => 'Breached', # chassis currently breached
3364 3 => 'Breached Prior', # chassis breached prior to boot and has not been cleared
3365 4 => 'Breach Sensor Failure', # intrusion sensor has failed
3366 );
3367
3368 INTRUSION:
3369 foreach my $out (@output) {
3370 if ($snmp) {
3371 $index = $out->{intrusionIndex} - 1;
3372 $status = $snmp_status{$out->{intrusionStatus}};
3373 $reading = $int_reading{$out->{intrusionReading}};
3374 }
3375 else {
3376 $index = $out->{'Index'};
3377 $status = $out->{'Status'};
3378 $reading = $out->{'State'};
3379 }
3380
3381 next INTRUSION if blacklisted('intr', $index);
3382 $count{intr}++;
3383
3384 if ($status ne 'Ok') {
3385 my $msg = sprintf 'Chassis intrusion %d detected: %s',
3386 $index, $reading;
3387 report('chassis', $msg, $E_WARNING, $index);
3388 }
3389 # Ok
3390 else {
3391 my $msg = sprintf 'Chassis intrusion %d detection: %s (%s)',
3392 $index, $status, $reading;
3393 report('chassis', $msg, $E_OK, $index);
3394 }
3395 }
3396 return;
3397}
3398
3399
3400#-----------------------------------------
3401# CHASSIS: Check alert log
3402#-----------------------------------------
3403sub check_alertlog {
3404 return if $snmp; # Not supported with SNMP
3405
3406 my @output = @{ run_omreport("$omopt_system alertlog") };
3407 foreach my $out (@output) {
3408 ++$count{alert}{$out->{Severity}};
3409 }
3410
3411 # Create error messages and set exit value if appropriate
3412 my $err = 0;
3413 if ($count{alert}{'Critical'} > 0) { $err = $E_CRITICAL; }
3414 elsif ($count{alert}{'Non-Critical'} > 0) { $err = $E_WARNING; }
3415
3416 my $msg = sprintf 'Alert log content: %d critical, %d non-critical, %d ok',
3417 $count{alert}{'Critical'}, $count{alert}{'Non-Critical'}, $count{alert}{'Ok'};
3418 report('other', $msg, $err);
3419
3420 return;
3421}
3422
3423#-----------------------------------------
3424# CHASSIS: Check ESM log overall health
3425#-----------------------------------------
3426sub check_esmlog_health {
3427 my $health = 'Ok';
3428
3429 if ($snmp) {
3430 my $systemStateEventLogStatus = '1.3.6.1.4.1.674.10892.1.200.10.1.41.1';
3431 my $result = $snmp_session->get_request(-varbindlist => [$systemStateEventLogStatus]);
3432 if (!defined $result) {
98b224a3 3433 my $msg = sprintf 'SNMP ERROR [esmhealth]: %s',
669797e1 3434 $snmp_session->error;
3435 report('other', $msg, $E_UNKNOWN);
3436 }
3437 $health = $snmp_status{$result->{$systemStateEventLogStatus}};
3438 }
3439 else {
3440 foreach (@{ run_command("$omreport $omopt_system esmlog -fmt ssv") }) {
3441 if (m/\A Health;(.+) \z/xms) {
3442 $health = $1;
3443 chop $health;
3444 last;
3445 }
3446 }
3447 }
3448
3449 # If the overall health of the ESM log is other than "Ok", the
3450 # fill grade of the log is more than 80% and the log should be
3451 # cleared
3452 if ($health eq 'Ok') {
af7c7f76 3453 my $msg = sprintf 'ESM log health is Ok (less than 80%% full)';
669797e1 3454 report('other', $msg, $E_OK);
3455 }
3456 elsif ($health eq 'Critical') {
328d0a74 3457 my $msg = sprintf 'ESM log is 100%% full';
669797e1 3458 report('other', $msg, $status2nagios{$health});
3459 }
3460 else {
3461 my $msg = sprintf 'ESM log is more than 80%% full';
3462 report('other', $msg, $status2nagios{$health});
3463 }
3464
3465 return;
3466}
3467
3468#-----------------------------------------
3469# CHASSIS: Check ESM log
3470#-----------------------------------------
3471sub check_esmlog {
3472 my @output = ();
3473
3474 if ($snmp) {
3475 my %esm_oid
3476 = (
3477 '1.3.6.1.4.1.674.10892.1.300.40.1.7.1' => 'eventLogSeverityStatus',
3478 );
3479 my $result = $snmp_session->get_entries(-columns => [keys %esm_oid]);
3480
3481 # No entries is OK
3482 return if !defined $result;
3483
3484 @output = @{ get_snmp_output($result, \%esm_oid) };
3485 foreach my $out (@output) {
3486 ++$count{esm}{$snmp_status{$out->{eventLogSeverityStatus}}};
3487 }
3488 }
3489 else {
3490 @output = @{ run_omreport("$omopt_system esmlog") };
3491 foreach my $out (@output) {
3492 ++$count{esm}{$out->{Severity}};
3493 }
3494 }
3495
3496 # Create error messages and set exit value if appropriate
3497 my $err = 0;
3498 if ($count{esm}{'Critical'} > 0) { $err = $E_CRITICAL; }
3499 elsif ($count{esm}{'Non-Critical'} > 0) { $err = $E_WARNING; }
3500
3501 my $msg = sprintf 'ESM log content: %d critical, %d non-critical, %d ok',
3502 $count{esm}{'Critical'}, $count{esm}{'Non-Critical'}, $count{esm}{'Ok'};
3503 report('other', $msg, $err);
3504
3505 return;
3506}
3507
3508#
3509# Handy function for checking all storage components
3510#
3511sub check_storage {
3512 check_controllers();
3513 check_physical_disks();
3514 check_virtual_disks();
3515 check_cache_battery();
3516 check_connectors();
3517 check_enclosures();
3518 check_enclosure_fans();
3519 check_enclosure_pwr();
3520 check_enclosure_temp();
3521 check_enclosure_emms();
3522 return;
3523}
3524
3525
3526
3527#---------------------------------------------------------------------
3528# Info functions
3529#---------------------------------------------------------------------
3530
3531#
3532# Fetch output from 'omreport chassis info', put in sysinfo hash
3533#
3534sub get_omreport_chassis_info {
3535 if (open my $INFO, '-|', "$omreport $omopt_chassis info -fmt ssv") {
3536 my @lines = <$INFO>;
3537 close $INFO;
3538 foreach (@lines) {
3539 next if !m/\A (Chassis\sModel|Chassis\sService\sTag|Model|Service\sTag)/xms;
3540 my ($key, $val) = split /;/xms;
3541 $key =~ s{\s+\z}{}xms; # remove trailing whitespace
3542 $val =~ s{\s+\z}{}xms; # remove trailing whitespace
3543 if ($key eq 'Chassis Model' or $key eq 'Model') {
3544 $sysinfo{model} = $val;
3545 }
3546 if ($key eq 'Chassis Service Tag' or $key eq 'Service Tag') {
3547 $sysinfo{serial} = $val;
3548 }
3549 }
3550 }
3551 return;
3552}
3553
3554#
3555# Fetch output from 'omreport chassis bios', put in sysinfo hash
3556#
3557sub get_omreport_chassis_bios {
3558 if (open my $BIOS, '-|', "$omreport $omopt_chassis bios -fmt ssv") {
3559 my @lines = <$BIOS>;
3560 close $BIOS;
3561 foreach (@lines) {
3562 next if !m/;/xms;
3563 my ($key, $val) = split /;/xms;
3564 $key =~ s{\s+\z}{}xms; # remove trailing whitespace
3565 $val =~ s{\s+\z}{}xms; # remove trailing whitespace
3566 $sysinfo{bios} = $val if $key eq 'Version';
3567 $sysinfo{biosdate} = $val if $key eq 'Release Date';
3568 }
3569 }
3570 return;
3571}
3572
3573#
3574# Fetch output from 'omreport system operatingsystem', put in sysinfo hash
3575#
3576sub get_omreport_system_operatingsystem {
3577 if (open my $VER, '-|', "$omreport $omopt_system operatingsystem -fmt ssv") {
3578 my @lines = <$VER>;
3579 close $VER;
3580 foreach (@lines) {
3581 next if !m/;/xms;
3582 my ($key, $val) = split /;/xms;
3583 $key =~ s{\s+\z}{}xms; # remove trailing whitespace
3584 $val =~ s{\s+\z}{}xms; # remove trailing whitespace
3585 if ($key eq 'Operating System') {
3586 $sysinfo{osname} = $val;
3587 }
3588 elsif ($key eq 'Operating System Version') {
3589 $sysinfo{osver} = $val;
3590 }
3591 }
3592 }
3593 return;
3594}
3595
3596#
3597# Fetch output from 'omreport about', put in sysinfo hash
3598#
3599sub get_omreport_about {
3600 if (open my $OM, '-|', "$omreport about -fmt ssv") {
3601 my @lines = <$OM>;
3602 close $OM;
3603 foreach (@lines) {
3604 if (m/\A Version;(.+) \z/xms) {
3605 $sysinfo{om} = $1;
3606 chomp $sysinfo{om};
3607 }
3608 }
3609 }
3610 return;
3611}
3612
3613#
3614# Fetch chassis info via SNMP, put in sysinfo hash
3615#
3616sub get_snmp_chassis_info {
3617 my %chassis_oid
3618 = (
3619 '1.3.6.1.4.1.674.10892.1.300.10.1.9.1' => 'chassisModelName',
3620 '1.3.6.1.4.1.674.10892.1.300.10.1.11.1' => 'chassisServiceTagName',
3621 );
3622
3623 my $chassisInformationTable = '1.3.6.1.4.1.674.10892.1.300.10.1';
3624 my $result = $snmp_session->get_table(-baseoid => $chassisInformationTable);
3625
3626 if (defined $result) {
3627 foreach my $oid (keys %{ $result }) {
3628 if (exists $chassis_oid{$oid} and $chassis_oid{$oid} eq 'chassisModelName') {
3629 $sysinfo{model} = $result->{$oid};
3630 $sysinfo{model} =~ s{\s+\z}{}xms; # remove trailing whitespace
3631 }
3632 elsif (exists $chassis_oid{$oid} and $chassis_oid{$oid} eq 'chassisServiceTagName') {
3633 $sysinfo{serial} = $result->{$oid};
3634 }
3635 }
3636 }
3637 else {
3638 my $msg = sprintf 'SNMP ERROR getting chassis info: %s',
3639 $snmp_session->error;
3640 report('other', $msg, $E_UNKNOWN);
3641 }
3642 return;
3643}
3644
3645#
3646# Fetch BIOS info via SNMP, put in sysinfo hash
3647#
3648sub get_snmp_chassis_bios {
3649 my %bios_oid
3650 = (
3651 '1.3.6.1.4.1.674.10892.1.300.50.1.7.1.1' => 'systemBIOSReleaseDateName',
3652 '1.3.6.1.4.1.674.10892.1.300.50.1.8.1.1' => 'systemBIOSVersionName',
3653 );
3654
3655 my $systemBIOSTable = '1.3.6.1.4.1.674.10892.1.300.50.1';
3656 my $result = $snmp_session->get_table(-baseoid => $systemBIOSTable);
3657
3658 if (defined $result) {
3659 foreach my $oid (keys %{ $result }) {
3660 if (exists $bios_oid{$oid} and $bios_oid{$oid} eq 'systemBIOSReleaseDateName') {
3661 $sysinfo{biosdate} = $result->{$oid};
3662 $sysinfo{biosdate} =~ s{\A (\d{4})(\d{2})(\d{2}).*}{$2/$3/$1}xms;
3663 }
3664 elsif (exists $bios_oid{$oid} and $bios_oid{$oid} eq 'systemBIOSVersionName') {
3665 $sysinfo{bios} = $result->{$oid};
3666 }
3667 }
3668 }
3669 else {
3670 my $msg = sprintf 'SNMP ERROR getting BIOS info: %s',
3671 $snmp_session->error;
3672 report('other', $msg, $E_UNKNOWN);
3673 }
3674 return;
3675}
3676
3677#
3678# Fetch OS info via SNMP, put in sysinfo hash
3679#
3680sub get_snmp_system_operatingsystem {
3681 my %os_oid
3682 = (
3683 '1.3.6.1.4.1.674.10892.1.400.10.1.6.1' => 'operatingSystemOperatingSystemName',
3684 '1.3.6.1.4.1.674.10892.1.400.10.1.7.1' => 'operatingSystemOperatingSystemVersionName',
3685 );
3686
3687 my $operatingSystemTable = '1.3.6.1.4.1.674.10892.1.400.10.1';
3688 my $result = $snmp_session->get_table(-baseoid => $operatingSystemTable);
3689
3690 if (defined $result) {
3691 foreach my $oid (keys %{ $result }) {
3692 if (exists $os_oid{$oid} and $os_oid{$oid} eq 'operatingSystemOperatingSystemName') {
3693 $sysinfo{osname} = ($result->{$oid});
3694 }
3695 elsif (exists $os_oid{$oid} and $os_oid{$oid} eq 'operatingSystemOperatingSystemVersionName') {
3696 $sysinfo{osver} = $result->{$oid};
3697 }
3698 }
3699 }
3700 else {
3701 my $msg = sprintf 'SNMP ERROR getting OS info: %s',
3702 $snmp_session->error;
3703 report('other', $msg, $E_UNKNOWN);
3704 }
3705 return;
3706}
3707
3708#
3709# Fetch OMSA version via SNMP, put in sysinfo hash
3710#
3711sub get_snmp_about {
3712 my %omsa_oid
3713 = (
3714 '1.3.6.1.4.1.674.10892.1.100.10.0' => 'systemManagementSoftwareGlobalVersionName',
3715 );
3716 my $systemManagementSoftwareGroup = '1.3.6.1.4.1.674.10892.1.100';
3717 my $result = $snmp_session->get_table(-baseoid => $systemManagementSoftwareGroup);
3718 if (defined $result) {
3719 foreach my $oid (keys %{ $result }) {
3720 if (exists $omsa_oid{$oid} and $omsa_oid{$oid} eq 'systemManagementSoftwareGlobalVersionName') {
3721 $sysinfo{om} = ($result->{$oid});
3722 }
3723 }
3724 }
3725 else {
3726 my $msg = sprintf 'SNMP ERROR getting OMSA info: %s',
3727 $snmp_session->error;
3728 report('other', $msg, $E_UNKNOWN);
3729 }
3730 return;
3731}
3732
3733#
3734# Collects some information about the system
3735#
3736sub get_sysinfo
3737{
3738 # Get system model and serial number
3739 $snmp ? get_snmp_chassis_info() : get_omreport_chassis_info();
3740
3741 # Get BIOS information. Only if needed
3742 if ( $opt{okinfo} >= 1
3743 or $opt{debug}
3744 or (defined $opt{postmsg} and $opt{postmsg} =~ m/[%][bd]/xms) ) {
3745 $snmp ? get_snmp_chassis_bios() : get_omreport_chassis_bios();
3746 }
3747
f711f8c7 3748 # Get OMSA information. Only if needed
3749 if ($opt{okinfo} >= 3 or $opt{debug}) {
3750 $snmp ? get_snmp_about() : get_omreport_about();
3751 }
3752
669797e1 3753 # Return now if debug
3754 return if $opt{debug};
3755
3756 # Get OS information. Only if needed
3757 if (defined $opt{postmsg} and $opt{postmsg} =~ m/[%][or]/xms) {
3758 $snmp ? get_snmp_system_operatingsystem() : get_omreport_system_operatingsystem();
3759 }
3760
669797e1 3761 return;
3762}
3763
3764
3765# Helper function for running omreport when the results are strictly
3766# name=value pairs.
3767sub run_omreport_info {
3768 my $command = shift;
3769 my %output = ();
3770 my @keys = ();
3771
3772 # Run omreport and fetch output
3773 my $rawtext = slurp_command("$omreport $command -fmt ssv 2>&1");
3774
3775 # Parse output, store in array
3776 for ((split /\n/xms, $rawtext)) {
3777 if (m/\A Error/xms) {
3778 my $msg = "Problem running 'omreport $command': $_";
3779 report('other', $msg, $E_UNKNOWN);
3780 }
3781 next if !m/;/xms; # ignore lines with less than two fields
3782 my @vals = split m/;/xms;
3783 $output{$vals[0]} = $vals[1];
3784 }
3785
3786 # Finally, return the collected information
3787 return \%output;
3788}
3789
3790# Get various firmware information (BMC, RAC)
3791sub get_firmware_info {
3792 my @snmp_output = ();
3793 my %nrpe_output = ();
3794
3795 if ($snmp) {
3796 my %fw_oid
3797 = (
3798 '1.3.6.1.4.1.674.10892.1.300.60.1.7.1' => 'firmwareType',
3799 '1.3.6.1.4.1.674.10892.1.300.60.1.8.1' => 'firmwareTypeName',
3800 '1.3.6.1.4.1.674.10892.1.300.60.1.11.1' => 'firmwareVersionName',
3801 );
3802
3803 my $firmwareTable = '1.3.6.1.4.1.674.10892.1.300.60.1';
3804 my $result = $snmp_session->get_table(-baseoid => $firmwareTable);
3805
3806 # Some don't have this OID, this is ok
3807 if (!defined $result) {
3808 return;
3809 }
3810
3811 @snmp_output = @{ get_snmp_output($result, \%fw_oid) };
3812 }
3813 else {
3814 %nrpe_output = %{ run_omreport_info("$omopt_chassis info") };
3815 }
3816
3817 my %fw_type # Firmware types
3818 = (
3819 1 => 'other', # other than following values
3820 2 => 'unknown', # unknown
3821 3 => 'systemBIOS', # System BIOS
3822 4 => 'embeddedSystemManagementController', # Embedded System Management Controller
3823 5 => 'powerSupplyParallelingBoard', # Power Supply Paralleling Board
3824 6 => 'systemBackPlane', # System (Primary) Backplane
3825 7 => 'powerVault2XXSKernel', # PowerVault 2XXS Kernel
3826 8 => 'powerVault2XXSApplication', # PowerVault 2XXS Application
3827 9 => 'frontPanel', # Front Panel Controller
3828 10 => 'baseboardManagementController', # Baseboard Management Controller
3829 11 => 'hotPlugPCI', # Hot Plug PCI Controller
3830 12 => 'sensorData', # Sensor Data Records
3831 13 => 'peripheralBay', # Peripheral Bay Backplane
3832 14 => 'secondaryBackPlane', # Secondary Backplane for ESM 2 systems
3833 15 => 'secondaryBackPlaneESM3And4', # Secondary Backplane for ESM 3 and 4 systems
3834 16 => 'rac', # Remote Access Controller
3835 17 => 'imc' # Integrated Management Controller
3836 );
3837
3838
3839 if ($snmp) {
3840 foreach my $out (@snmp_output) {
3841 if ($fw_type{$out->{firmwareType}} eq 'baseboardManagementController') {
3842 $sysinfo{'bmc'} = 1;
3843 $sysinfo{'bmc_fw'} = $out->{firmwareVersionName};
3844 }
3845 elsif ($fw_type{$out->{firmwareType}} =~ m{\A rac|imc \z}xms) {
3846 my $name = $out->{firmwareTypeName}; $name =~ s/\s//gxms;
3847 $sysinfo{'rac'} = 1;
3848 $sysinfo{'rac_name'} = $name;
3849 $sysinfo{'rac_fw'} = $out->{firmwareVersionName};
3850 }
3851 }
3852 }
3853 else {
3854 foreach my $key (keys %nrpe_output) {
3855 next if !defined $nrpe_output{$key};
3856 if ($key eq 'BMC Version' or $key eq 'Baseboard Management Controller Version') {
3857 $sysinfo{'bmc'} = 1;
3858 $sysinfo{'bmc_fw'} = $nrpe_output{$key};
3859 }
3860 elsif ($key =~ m{\A (i?DRAC)\s*(\d?)\s+Version}xms) {
3861 my $name = "$1$2";
3862 $sysinfo{'rac'} = 1;
3863 $sysinfo{'rac_fw'} = $nrpe_output{$key};
3864 $sysinfo{'rac_name'} = $name;
3865 }
3866 }
3867 }
3868
3869 return;
3870}
3871
3872
3873
3874#=====================================================================
3875# Main program
3876#=====================================================================
3877
3878# Here we do the actual checking of components
3879# Check global status if applicable
3880if ($global) {
3881 $globalstatus = check_global();
3882}
3883
3884# Do multiple selected checks
3885if ($check{storage}) { check_storage(); }
3886if ($check{memory}) { check_memory(); }
3887if ($check{fans}) { check_fans(); }
3888if ($check{power}) { check_powersupplies(); }
3889if ($check{temp}) { check_temperatures(); }
3890if ($check{cpu}) { check_processors(); }
3891if ($check{voltage}) { check_volts(); }
3892if ($check{batteries}) { check_batteries(); }
3893if ($check{amperage}) { check_pwrmonitoring(); }
3894if ($check{intrusion}) { check_intrusion(); }
3895if ($check{alertlog}) { check_alertlog(); }
3896if ($check{esmlog}) { check_esmlog(); }
3897if ($check{esmhealth}) { check_esmlog_health(); }
3898
3899
3900#---------------------------------------------------------------------
3901# Finish up
3902#---------------------------------------------------------------------
3903
3904# Counter variable
3905%nagios_alert_count
3906 = (
3907 'OK' => 0,
3908 'WARNING' => 0,
3909 'CRITICAL' => 0,
3910 'UNKNOWN' => 0,
3911 );
3912
3913# Get system information
3914get_sysinfo();
3915
3916# Get firmware info if requested via option
3917if ($opt{okinfo} >= 1) {
3918 get_firmware_info();
3919}
3920
3921# Close SNMP session
3922if ($snmp) {
3923 $snmp_session->close;
3924}
3925
3926# Print messages
3927if ($opt{debug}) {
3928 print " System: $sysinfo{model}\n";
f711f8c7 3929 print " ServiceTag: $sysinfo{serial}";
3930 print q{ } x (25 - length $sysinfo{serial}), "OMSA version: $sysinfo{om}\n";
3931 print " BIOS/date: $sysinfo{bios} $sysinfo{biosdate}";
3932 print q{ } x (25 - length "$sysinfo{bios} $sysinfo{biosdate}"), "Plugin version: $VERSION\n";
669797e1 3933 if ($#report_storage >= 0) {
3934 print "-----------------------------------------------------------------------------\n";
3935 print " Storage Components \n";
3936 print "=============================================================================\n";
3937 print " STATE | ID | MESSAGE TEXT \n";
3938 print "---------+----------+--------------------------------------------------------\n";
3939 foreach (@report_storage) {
3940 my ($msg, $level, $nexus) = @{$_};
3941 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | "
3942 . q{ } x (8 - length $nexus) . "$nexus | $msg\n";
3943 $nagios_alert_count{$reverse_exitcode{$level}}++;
3944 }
3945 }
3946 if ($#report_chassis >= 0) {
3947 print "-----------------------------------------------------------------------------\n";
3948 print " Chassis Components \n";
3949 print "=============================================================================\n";
1d003803 3950 print " STATE | ID | MESSAGE TEXT \n";
669797e1 3951 print "---------+------+------------------------------------------------------------\n";
3952 foreach (@report_chassis) {
3953 my ($msg, $level, $nexus) = @{$_};
3954 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | "
3955 . q{ } x (4 - length $nexus) . "$nexus | $msg\n";
3956 $nagios_alert_count{$reverse_exitcode{$level}}++;
3957 }
3958 }
3959 if ($#report_other >= 0) {
3960 print "-----------------------------------------------------------------------------\n";
3961 print " Other messages \n";
3962 print "=============================================================================\n";
3963 print " STATE | MESSAGE TEXT \n";
3964 print "---------+-------------------------------------------------------------------\n";
3965 foreach (@report_other) {
3966 my ($msg, $level, $nexus) = @{$_};
3967 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | $msg\n";
3968 $nagios_alert_count{$reverse_exitcode{$level}}++;
3969 }
3970 }
3971}
3972else {
3973 my $c = 0; # counter to determine linebreaks
3974
3975 # Run through each message, sorted by severity level
3976 ALERT:
3977 foreach (sort {$a->[1] < $b->[1]} (@report_storage, @report_chassis, @report_other)) {
3978 my ($msg, $level, $nexus) = @{ $_ };
3979 next ALERT if $level == $E_OK;
3980
3981 if (defined $opt{only}) {
3982 # If user wants only critical alerts
3983 next ALERT if ($opt{only} eq 'critical' and $level == $E_WARNING);
3984
3985 # If user wants only warning alerts
3986 next ALERT if ($opt{only} eq 'warning' and $level == $E_CRITICAL);
3987 }
3988
3989 # Prefix with service tag if specified with option '-i|--info'
3990 if ($opt{info}) {
3991 if (defined $opt{htmlinfo}) {
3992 $msg = '[<a href="' . warranty_url($sysinfo{serial})
3993 . "\">$sysinfo{serial}</a>] " . $msg;
3994 }
3995 else {
3996 $msg = "[$sysinfo{serial}] " . $msg;
3997 }
3998 }
3999
4000 # Prefix with nagios level if specified with option '--state'
4001 $msg = $reverse_exitcode{$level} . ": $msg" if $opt{state};
4002
4003 # Prefix with one-letter nagios level if specified with option '--short-state'
4004 $msg = (substr $reverse_exitcode{$level}, 0, 1) . ": $msg" if $opt{shortstate};
4005
4006 ($c++ == 0) ? print $msg : print $linebreak, $msg;
4007
4008 $nagios_alert_count{$reverse_exitcode{$level}}++;
4009 }
4010}
4011
4012# Determine our exit code
4013$exit_code = $E_OK;
4014$exit_code = $E_UNKNOWN if $nagios_alert_count{'UNKNOWN'} > 0;
4015$exit_code = $E_WARNING if $nagios_alert_count{'WARNING'} > 0;
4016$exit_code = $E_CRITICAL if $nagios_alert_count{'CRITICAL'} > 0;
4017
4018# Global status via SNMP.. extra safety check
4019if ($globalstatus != $E_OK && $exit_code == $E_OK && !defined $opt{only}) {
4020 print "OOPS! Something is wrong with this server, but I don't know what. ";
4021 print "The global system health status is $reverse_exitcode{$globalstatus}, ";
4022 print "but every component check is OK. This may be a bug in the Nagios plugin, ";
4023 print "please file a bug report.\n";
4024 exit $E_UNKNOWN;
4025}
4026
4027# Print OK message
4028if ($exit_code == $E_OK && defined $opt{only} && $opt{only} !~ m{\A critical|warning|chassis \z}xms && !$opt{debug}) {
4029 my %okmsg
4030 = ( 'storage' => "STORAGE OK - $count{pdisk} physical drives, $count{vdisk} logical drives",
4031 'fans' => $count{fan} == 0 && $blade ? 'OK - blade system with no fan probes' : "FANS OK - $count{fan} fan probes checked",
4032 'temp' => "TEMPERATURES OK - $count{temp} temperature probes checked",
4033 'memory' => "MEMORY OK - $count{dimm} memory modules checked",
4034 'power' => $count{power} == 0 ? 'OK - no instrumented power supplies found' : "POWER OK - $count{power} power supplies checked",
4035 'cpu' => "PROCESSORS OK - $count{cpu} processors checked",
4036 'voltage' => "VOLTAGE OK - $count{volt} voltage probes checked",
4037 'batteries' => $count{bat} == 0 ? 'OK - no batteries found' : "BATTERIES OK - $count{bat} batteries checked",
4038 'amperage' => $count{amp} == 0 ? 'OK - no power monitoring probes found' : "AMPERAGE OK - $count{amp} amperage (power monitoring) probes checked",
4039 'intrusion' => $count{intr} == 0 ? 'OK - no intrusion detection probes found' : "INTRUSION OK - $count{intr} intrusion detection probes checked",
4040 'alertlog' => $snmp ? 'OK - not supported via snmp' : "OK - Alert Log content: $count{alert}{Ok} ok, $count{alert}{'Non-Critical'} warning and $count{alert}{Critical} critical",
4041 'esmlog' => "OK - ESM Log content: $count{esm}{Ok} ok, $count{esm}{'Non-Critical'} warning and $count{esm}{Critical} critical",
4042 'esmhealth' => "ESM LOG OK - less than 80% used",
4043 );
4044
4045 print $okmsg{$opt{only}};
4046}
4047elsif ($exit_code == $E_OK && !$opt{debug}) {
4048 if (defined $opt{htmlinfo}) {
4049 printf q{OK - System: '<a href="%s">%s</a>', SN: '<a href="%s">%s</a>', hardware working fine},
4050 documentation_url($sysinfo{model}), $sysinfo{model},
4051 warranty_url($sysinfo{serial}), $sysinfo{serial};
4052 }
4053 else {
4054 printf q{OK - System: '%s', SN: '%s', hardware working fine},
4055 $sysinfo{model}, $sysinfo{serial};
4056 }
4057
4058 if ($check{storage}) {
4059 printf ', %d logical drives, %d physical drives',
4060 $count{vdisk}, $count{pdisk};
4061 }
4062 else {
4063 print ', not checking storage';
4064 }
4065
4066 if ($opt{okinfo} >= 1) {
4067 print $linebreak;
4068 printf q{----- BIOS='%s %s'}, $sysinfo{bios}, $sysinfo{biosdate};
4069
4070 if ($sysinfo{rac}) {
4071 printf q{, %s='%s'}, $sysinfo{rac_name}, $sysinfo{rac_fw};
4072 }
4073 if ($sysinfo{bmc}) {
4074 printf q{, BMC='%s'}, $sysinfo{bmc_fw};
4075 }
4076 }
4077
4078 if ($opt{okinfo} >= 2) {
4079 if ($check{storage}) {
4080 my @storageprint = ();
4081 foreach my $id (sort keys %{ $sysinfo{controller} }) {
4082 chomp $sysinfo{controller}{$id}{driver};
956cf4d1 4083 my $msg = sprintf q{----- Ctrl %s [%s]: Fw='%s', Dr='%s'},
669797e1 4084 $sysinfo{controller}{$id}{id}, $sysinfo{controller}{$id}{name},
4085 $sysinfo{controller}{$id}{firmware}, $sysinfo{controller}{$id}{driver};
956cf4d1 4086 if (defined $sysinfo{controller}{$id}{storport}) {
4087 $msg .= sprintf q{, Storport: '%s'}, $sysinfo{controller}{$id}{storport};
4088 }
4089 push @storageprint, $msg;
669797e1 4090 }
4091 foreach my $id (sort keys %{ $sysinfo{enclosure} }) {
956cf4d1 4092 push @storageprint, sprintf q{----- Encl %s [%s]: Fw='%s'},
669797e1 4093 $sysinfo{enclosure}{$id}->{id}, $sysinfo{enclosure}{$id}->{name},
4094 $sysinfo{enclosure}{$id}->{firmware};
4095 }
4096
4097 # print stuff
4098 foreach my $line (@storageprint) {
4099 print $linebreak, $line;
4100 }
4101 }
4102 }
4103
4104 if ($opt{okinfo} >= 3) {
4105 print "$linebreak----- OpenManage Server Administrator (OMSA) version: '$sysinfo{om}'";
4106 }
4107
4108}
4109else {
4110 if ($opt{extinfo}) {
4111 print $linebreak;
4112 if (defined $opt{htmlinfo}) {
4113 printf '------ SYSTEM: <a href="%s">%s</a>, SN: <a href="%s">%s</a>',
4114 documentation_url($sysinfo{model}), $sysinfo{model},
4115 warranty_url($sysinfo{serial}), $sysinfo{serial};
4116 }
4117 else {
4118 printf '------ SYSTEM: %s, SN: %s',
4119 $sysinfo{model}, $sysinfo{serial};
4120 }
4121 }
4122 if (defined $opt{postmsg}) {
4123 my $post = undef;
4124 if (-f $opt{postmsg}) {
4125 open my $POST, '<', $opt{postmsg}
4126 or ( print $linebreak
4127 and print "ERROR: Couldn't open post message file $opt{postmsg}: $!\n"
4128 and exit $E_UNKNOWN );
4129 $post = <$POST>;
4130 close $POST;
4131 chomp $post;
4132 }
4133 else {
4134 $post = $opt{postmsg};
4135 }
4136 if (defined $post) {
4137 print $linebreak;
4138 $post =~ s{[%]s}{$sysinfo{serial}}gxms;
4139 $post =~ s{[%]m}{$sysinfo{model}}gxms;
4140 $post =~ s{[%]b}{$sysinfo{bios}}gxms;
4141 $post =~ s{[%]d}{$sysinfo{biosdate}}gxms;
4142 $post =~ s{[%]o}{$sysinfo{osname}}gxms;
4143 $post =~ s{[%]r}{$sysinfo{osver}}gxms;
4144 $post =~ s{[%]p}{$count{pdisk}}gxms;
4145 $post =~ s{[%]l}{$count{vdisk}}gxms;
4146 $post =~ s{[%]n}{$linebreak}gxms;
4147 $post =~ s{[%]{2}}{%}gxms;
4148 print $post;
4149 }
4150 }
4151}
4152
cbbc270f 4153# Print any perl warnings that have occured
4154if (@perl_warnings) {
4155 foreach (@perl_warnings) {
4156 chop @$_;
4157 print "${linebreak}INTERNAL ERROR: @$_";
4158 }
4159 $exit_code = $E_UNKNOWN;
4160}
4161
4162# Reset the WARN signal
4163$SIG{__WARN__} = $original_sigwarn;
4164
669797e1 4165# Print performance data
4166if (defined $opt{perfdata} && !$opt{debug} && %perfdata) {
4167 my $lb = $opt{perfdata} eq 'multiline' ? "\n" : q{ }; # line break for perfdata
4168 print q{|};
4169
4170 sub perfdata {
4171 my %order
4172 = (
4173 fan => 0,
4174 pwr => 1,
4175 temp => 2,
4176 enclosure => 3,
4177 );
4178 return ($order{(split /_/, $a, 2)[0]} cmp $order{(split /_/, $b, 2)[0]}) || $a cmp $b;
4179 }
4180
4181 print join $lb, map { "'$_'=$perfdata{$_}" } sort perfdata keys %perfdata;
4182}
e133d101 4183
4184# Print a linebreak at the end
669797e1 4185print "\n" if !$opt{debug};
4186
4187# Exit with proper exit code
4188exit $exit_code;