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