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