]> git.uio.no Git - check_openmanage.git/blame - check_openmanage
fix regression on systems with ePN
[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';
28b46baa 52$VERSION = '3.7.11-beta';
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
885e1c14
THA
2011 if (($state eq 'Online' or $state eq 'Ready')
2012 and $status eq 'Non-Critical' and blacklisted('pdisk_cert', $nexus)) {
784dfd76
THA
2013 --$stack;
2014 }
2015 else {
2016 push @states, 'Not Certified';
2017 }
8e56a211
THA
2018 }
2019 # Special case: Foreign disk
2020 if ($state eq 'Foreign' and blacklisted('pdisk_foreign', $nexus)) {
2021 --$stack;
2022 }
2023
2024 # Create combined status and state
2025 my $combo_state = join ', ', @states;
2026 my $combo_status = undef;
8097ee52
THA
2027 if ($stack >= 2) { $combo_status = $E_CRITICAL; }
2028 elsif ($stack == 1) { $combo_status = $E_WARNING; }
2029 elsif ($stack <= 0) { $combo_status = $E_OK; }
8e56a211 2030
c5c69973 2031 # Special case: Rebuilding / Replacing
8e56a211 2032 if ($state =~ m{\A Rebuilding|Replacing \z}xms) {
ddeae63c 2033 my $msg = sprintf '%s [%s %s, %s] on ctrl %d is %s%s',
2034 $name, $vendor, $product, $capacity, $ctrl, $state, $progr;
669797e1 2035 report('storage', $msg, $E_WARNING, $nexus);
2036 }
2037 # Default
8e56a211 2038 elsif ($combo_status != $E_OK) {
8097ee52 2039 my $msg = sprintf '%s [%s %s, %s] on ctrl %d is %s',
8e56a211
THA
2040 $name, $vendor, $product, $capacity, $ctrl, $combo_state;
2041 report('storage', $msg, $combo_status, $nexus);
669797e1 2042 }
2043 # Ok
2044 else {
ac93da95 2045 my $msg = sprintf '%s [%s%s] on ctrl %d is %s',
8e56a211 2046 $name, $busmedia, $capacity, $ctrl, $combo_state;
e26aa120 2047 if (defined $spare) { $msg .= " ($spare)"; }
669797e1 2048 report('storage', $msg, $E_OK, $nexus);
2049 }
2050 }
2051 return;
2052}
2053
2054
2055#-----------------------------------------
2056# STORAGE: Check logical drives
2057#-----------------------------------------
2058sub check_virtual_disks {
2059 return if $#controllers == -1;
2060
25d04c34 2061 my $name = undef;
669797e1 2062 my $nexus = undef;
2063 my $dev = undef;
2064 my $state = undef;
2065 my $status = undef;
2066 my $layout = undef;
2067 my $size = undef;
2068 my $progr = undef;
25d04c34 2069 my $ctrl = undef;
669797e1 2070 my @output = ();
2071
2072 if ($snmp) {
2073 my %vdisk_oid
2074 = (
669797e1 2075 '1.3.6.1.4.1.674.10893.1.20.140.1.1.3' => 'virtualDiskDeviceName',
2076 '1.3.6.1.4.1.674.10893.1.20.140.1.1.4' => 'virtualDiskState',
2077 '1.3.6.1.4.1.674.10893.1.20.140.1.1.6' => 'virtualDiskLengthInMB',
2078 '1.3.6.1.4.1.674.10893.1.20.140.1.1.13' => 'virtualDiskLayout',
2079 '1.3.6.1.4.1.674.10893.1.20.140.1.1.20' => 'virtualDiskComponentStatus',
2080 '1.3.6.1.4.1.674.10893.1.20.140.1.1.21' => 'virtualDiskNexusID',
2081 );
4cabd748 2082 my $result = undef;
2083 if ($opt{use_get_table}) {
2084 my $virtualDiskTable = '1.3.6.1.4.1.674.10893.1.20.140.1';
2085 $result = $snmp_session->get_table(-baseoid => $virtualDiskTable);
2086 }
2087 else {
2088 $result = $snmp_session->get_entries(-columns => [keys %vdisk_oid]);
2089 }
669797e1 2090
2091 # No logical drives is OK
2092 return if !defined $result;
2093
2094 @output = @{ get_snmp_output($result, \%vdisk_oid) };
2095 }
2096 else {
2097 foreach my $c (@controllers) {
2098 push @output, @{ run_omreport("storage vdisk controller=$c") };
2099 map_item('ctrl', $c, \@output);
2100 }
2101 }
2102
2103 my %vdisk_state
2104 = (
2105 0 => 'Unknown',
2106 1 => 'Ready',
2107 2 => 'Failed',
2108 3 => 'Online',
2109 4 => 'Offline',
2110 6 => 'Degraded',
2111 15 => 'Resynching',
2112 16 => 'Regenerating',
2113 24 => 'Rebuilding',
2114 26 => 'Formatting',
2115 32 => 'Reconstructing',
2116 35 => 'Initializing',
2117 36 => 'Background Initialization',
2118 38 => 'Resynching Paused',
2119 52 => 'Permanently Degraded',
2120 54 => 'Degraded Redundancy',
2121 );
2122
2123 my %vdisk_layout
2124 = (
2125 1 => 'Concatenated',
2126 2 => 'RAID-0',
2127 3 => 'RAID-1',
28dd8010 2128 4 => 'UNSUPPORTED:raid-2',
2129 5 => 'UNSUPPORTED:raid-3',
2130 6 => 'UNSUPPORTED:raid-4',
669797e1 2131 7 => 'RAID-5',
2132 8 => 'RAID-6',
28dd8010 2133 9 => 'UNSUPPORTED:raid-7',
669797e1 2134 10 => 'RAID-10',
28dd8010 2135 11 => 'UNSUPPORTED:raid-30',
669797e1 2136 12 => 'RAID-50',
28dd8010 2137 13 => 'UNSUPPORTED:addSpares',
2138 14 => 'UNSUPPORTED:deleteLogical',
2139 15 => 'UNSUPPORTED:transformLogical',
2140 18 => 'UNSUPPORTED:raid-0-plus-1',
9113fb39 2141 19 => 'Concatenated RAID-1',
28dd8010 2142 20 => 'UNSUPPORTED:concatRaid-5',
2143 21 => 'UNSUPPORTED:noRaid',
2144 22 => 'UNSUPPORTED:volume',
2145 23 => 'UNSUPPORTED:raidMorph',
669797e1 2146 24 => 'RAID-60',
75ce30f5 2147 25 => 'CacheCade',
669797e1 2148 );
2149
2150 # Check virtual disks on each of the controllers
2151 VDISK:
2152 foreach my $out (@output) {
2153 if ($snmp) {
fcbd60e6 2154 $dev = $out->{virtualDiskDeviceName} || 'Unknown device';
4a7c67f1 2155 $state = get_hashval($out->{virtualDiskState}, \%vdisk_state) || 'Unknown state';
2156 $layout = get_hashval($out->{virtualDiskLayout}, \%vdisk_layout) || 'Unknown layout';
b460a3d6 2157 $status = get_snmp_status($out->{virtualDiskComponentStatus});
fcbd60e6 2158 $size = sprintf '%.2f GB', ($out->{virtualDiskLengthInMB} || 0) / 1024;
2159 $progr = q{}; # not available via SNMP
2160 $nexus = convert_nexus(($out->{virtualDiskNexusID} || 9999));
669797e1 2161 }
2162 else {
fcbd60e6 2163 $dev = get_nonempty_string('Device Name', $out, 'Unknown device');
2164 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2165 $status = get_nonempty_string('Status', $out, 'Unknown');
fcbd60e6 2166 $layout = get_nonempty_string('Layout', $out, 'Unknown layout');
2167 $size = get_nonempty_string('Size', $out, 'Unavailable');
669797e1 2168 $size =~ s{\A (.*GB).* \z}{$1}xms;
fcbd60e6 2169 $progr = ' [' . get_nonempty_string('Progress', $out, q{}) . ']';
25d04c34 2170 $ctrl = $out->{ctrl};
fcbd60e6 2171 $nexus = join q{:}, $ctrl, get_nonempty_string('ID', $out, '9999');
669797e1 2172 }
2173
669797e1 2174 $count{vdisk}++;
35a7e76e 2175 next VDISK if blacklisted('vdisk', $nexus);
669797e1 2176
04b0f13b 2177 # The device name is undefined sometimes
2178 $dev = q{} if !defined $dev;
2179
669797e1 2180 # Special case: Regenerating
2181 if ($state eq 'Regenerating') {
cad6434b 2182 my $msg = sprintf q{Logical Drive '%s' [%s, %s] is %s%s},
44b3048a 2183 $dev, $layout, $size, $state, $progr;
6300568f
THA
2184 my $lvl = $opt{vdisk_critical} ? $E_CRITICAL : $E_WARNING;
2185 report('storage', $msg, $lvl, $nexus);
669797e1 2186 }
2187 # Default
669797e1 2188 else {
cad6434b 2189 my $msg = sprintf q{Logical Drive '%s' [%s, %s] is %s},
44b3048a 2190 $dev, $layout, $size, $state;
6300568f
THA
2191 my $lvl = $status2nagios{$status};
2192 if ($opt{vdisk_critical} && $lvl != $E_OK) {
2193 $lvl = $E_CRITICAL;
2194 }
2195 report('storage', $msg, $lvl, $nexus);
669797e1 2196 }
2197 }
2198 return;
2199}
2200
2201
2202#-----------------------------------------
2203# STORAGE: Check cache batteries
2204#-----------------------------------------
2205sub check_cache_battery {
2206 return if $#controllers == -1;
2207
2208 my $id = undef;
2209 my $nexus = undef;
2210 my $state = undef;
2211 my $status = undef;
2212 my $ctrl = undef;
2213 my $learn = undef; # learn state
2214 my $pred = undef; # battery's ability to be charged
2215 my @output = ();
2216
2217 if ($snmp) {
2218 my %bat_oid
2219 = (
669797e1 2220 '1.3.6.1.4.1.674.10893.1.20.130.15.1.4' => 'batteryState',
2221 '1.3.6.1.4.1.674.10893.1.20.130.15.1.6' => 'batteryComponentStatus',
2222 '1.3.6.1.4.1.674.10893.1.20.130.15.1.9' => 'batteryNexusID',
2223 '1.3.6.1.4.1.674.10893.1.20.130.15.1.10' => 'batteryPredictedCapacity',
2224 '1.3.6.1.4.1.674.10893.1.20.130.15.1.12' => 'batteryLearnState',
2225 '1.3.6.1.4.1.674.10893.1.20.130.16.1.5' => 'batteryConnectionControllerNumber',
2226 );
4cabd748 2227 my $result = undef;
2228 if ($opt{use_get_table}) {
2229 my $batteryTable = '1.3.6.1.4.1.674.10893.1.20.130.15';
c849fd4c 2230 my $batteryConnectionTable = '1.3.6.1.4.1.674.10893.1.20.130.16';
2231
4cabd748 2232 $result = $snmp_session->get_table(-baseoid => $batteryTable);
c849fd4c 2233 my $ext = $snmp_session->get_table(-baseoid => $batteryConnectionTable);
2234
2235 if (defined $result) {
2236 defined $ext && map { $$result{$_} = $$ext{$_} } keys %{ $ext };
2237 }
4cabd748 2238 }
2239 else {
2240 $result = $snmp_session->get_entries(-columns => [keys %bat_oid]);
2241 }
669797e1 2242
2243 # No cache battery is OK
2244 return if !defined $result;
2245
2246 @output = @{ get_snmp_output($result, \%bat_oid) };
2247 }
2248 else {
2249 foreach my $c (@controllers) {
2250 push @output, @{ run_omreport("storage battery controller=$c") };
2251 map_item('ctrl', $c, \@output);
2252 }
2253 }
2254
2255 my %bat_state
2256 = (
2257 0 => 'Unknown',
2258 1 => 'Ready',
2259 2 => 'Failed',
2260 6 => 'Degraded',
2261 7 => 'Reconditioning',
2262 9 => 'High',
2263 10 => 'Power Low',
2264 12 => 'Charging',
2265 21 => 'Missing',
2266 36 => 'Learning',
2267 );
2268
a49bcfe8 2269 # Specifies the learn state activity of the battery
669797e1 2270 my %bat_learn_state
2271 = (
2272 1 => 'Failed',
2273 2 => 'Active',
2274 4 => 'Timed out',
2275 8 => 'Requested',
2276 16 => 'Idle',
08013509 2277 32 => 'Due',
669797e1 2278 );
2279
a49bcfe8 2280 # This property displays the battery's ability to be charged
669797e1 2281 my %bat_pred_cap
2282 = (
2283 1 => 'Failed', # The battery cannot be charged and needs to be replaced
2284 2 => 'Ready', # The battery can be charged to full capacity
2285 4 => 'Unknown', # The battery is completing a Learn cycle. The charge capacity of the
2286 # battery cannot be determined until the Learn cycle is complete
2287 );
2288
2289 # Check battery on each of the controllers
2290 BATTERY:
2291 foreach my $out (@output) {
2292 if ($snmp) {
b460a3d6 2293 $status = get_snmp_status($out->{batteryComponentStatus});
4a7c67f1 2294 $state = get_hashval($out->{batteryState}, \%bat_state) || 'Unknown state';
2295 $learn = get_hashval($out->{batteryLearnState}, \%bat_learn_state) || 'Unknown learn state';
2296 $pred = get_hashval($out->{batteryPredictedCapacity}, \%bat_pred_cap) || 'Unknown predicted capacity status';
393d8348 2297 $ctrl = $snmp_controller{$out->{batteryConnectionControllerNumber}};
fcbd60e6 2298 $nexus = convert_nexus(($out->{batteryNexusID} || 9999));
25d04c34 2299 $id = $nexus;
2300 $id =~ s{\A \d+:(\d+) \z}{$1}xms;
669797e1 2301 }
2302 else {
fcbd60e6 2303 $id = get_nonempty_string('ID', $out, 9999);
2304 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2305 $status = get_nonempty_string('Status', $out, 'Unknown');
fcbd60e6 2306 $learn = get_nonempty_string('Learn State', $out, 'Unknown learn state');
2307 $pred = get_nonempty_string('Predicted Capacity Status', $out, 'Unknown predicted capacity status');
669797e1 2308 $ctrl = $out->{'ctrl'};
2309 $nexus = join q{:}, $out->{ctrl}, $id;
2310 }
2311
2312 next BATTERY if blacklisted('bat', $nexus);
2313
2314 # Special case: Charging
2315 if ($state eq 'Charging') {
50d6bc4a 2316 if ($pred eq 'Failed') {
cad6434b 2317 my $msg = sprintf 'Cache Battery %d in controller %d is %s (%s) [replace battery]',
50d6bc4a 2318 $id, $ctrl, $state, $pred;
2319 report('storage', $msg, $E_CRITICAL, $nexus);
2320 }
2321 else {
2322 next BATTERY if blacklisted('bat_charge', $nexus);
cad6434b 2323 my $msg = sprintf 'Cache Battery %d in controller %d is %s (%s) [probably harmless]',
50d6bc4a 2324 $id, $ctrl, $state, $pred;
2325 report('storage', $msg, $E_WARNING, $nexus);
2326 }
669797e1 2327 }
2328 # Special case: Learning (battery learns its capacity)
2329 elsif ($state eq 'Learning') {
50d6bc4a 2330 if ($learn eq 'Failed') {
cad6434b 2331 my $msg = sprintf 'Cache Battery %d in controller %d is %s (%s)',
50d6bc4a 2332 $id, $ctrl, $state, $learn;
2333 report('storage', $msg, $E_CRITICAL, $nexus);
2334 }
2335 else {
2336 next BATTERY if blacklisted('bat_charge', $nexus);
cad6434b 2337 my $msg = sprintf 'Cache Battery %d in controller %d is %s (%s) [probably harmless]',
50d6bc4a 2338 $id, $ctrl, $state, $learn;
2339 report('storage', $msg, $E_WARNING, $nexus);
2340 }
669797e1 2341 }
2342 # Special case: Power Low (first part of recharge cycle)
2343 elsif ($state eq 'Power Low') {
5a28cf7f 2344 next BATTERY if blacklisted('bat_charge', $nexus);
cad6434b 2345 my $msg = sprintf 'Cache Battery %d in controller %d is %s [probably harmless]',
669797e1 2346 $id, $ctrl, $state;
2347 report('storage', $msg, $E_WARNING, $nexus);
2348 }
5a28cf7f 2349 # Special case: Degraded and Non-Critical (usually part of recharge cycle)
2350 elsif ($state eq 'Degraded' && $status eq 'Non-Critical') {
2351 next BATTERY if blacklisted('bat_charge', $nexus);
cad6434b 2352 my $msg = sprintf 'Cache Battery %d in controller %d is %s (%s) [probably harmless]',
5a28cf7f 2353 $id, $ctrl, $state, $status;
2354 report('storage', $msg, $E_WARNING, $nexus);
2355 }
1ed27946
THA
2356 # Special case: Ready and Non-Critical and "Unknown" predicted status
2357 elsif ($state eq 'Ready' && $status eq 'Non-Critical' && $pred eq 'Unknown') {
2358 next BATTERY if blacklisted('bat_charge', $nexus);
2359 my $msg = sprintf 'Cache Battery %d in controller %d predicted capacity is %s [probably harmless]',
2360 $id, $ctrl, $pred;
2361 report('storage', $msg, $E_WARNING, $nexus);
2362 }
a65bb046 2363 # Default
669797e1 2364 else {
cad6434b 2365 my $msg = sprintf 'Cache Battery %d in controller %d is %s',
669797e1 2366 $id, $ctrl, $state;
a65bb046 2367 report('storage', $msg, $status2nagios{$status}, $nexus);
669797e1 2368 }
2369 }
2370 return;
2371}
2372
2373
2374#-----------------------------------------
2375# STORAGE: Check connectors (channels)
2376#-----------------------------------------
2377sub check_connectors {
2378 return if $#controllers == -1;
2379
669797e1 2380 my $nexus = undef;
2381 my $name = undef;
2382 my $state = undef;
2383 my $status = undef;
2384 my $type = undef;
2385 my $ctrl = undef;
2386 my @output = ();
2387
2388 if ($snmp) {
2389 my %conn_oid
2390 = (
669797e1 2391 '1.3.6.1.4.1.674.10893.1.20.130.2.1.2' => 'channelName',
2392 '1.3.6.1.4.1.674.10893.1.20.130.2.1.3' => 'channelState',
2393 '1.3.6.1.4.1.674.10893.1.20.130.2.1.8' => 'channelComponentStatus',
2394 '1.3.6.1.4.1.674.10893.1.20.130.2.1.9' => 'channelNexusID',
2395 '1.3.6.1.4.1.674.10893.1.20.130.2.1.11' => 'channelBusType',
2396 );
4cabd748 2397 my $result = undef;
2398 if ($opt{use_get_table}) {
2399 my $channelTable = '1.3.6.1.4.1.674.10893.1.20.130.2';
2400 $result = $snmp_session->get_table(-baseoid => $channelTable);
2401 }
2402 else {
2403 $result = $snmp_session->get_entries(-columns => [keys %conn_oid]);
2404 }
669797e1 2405
2406 if (!defined $result) {
98b224a3 2407 printf "SNMP ERROR [storage / channel]: %s.\n", $snmp_session->error;
669797e1 2408 $snmp_session->close;
2409 exit $E_UNKNOWN;
2410 }
2411
2412 @output = @{ get_snmp_output($result, \%conn_oid) };
2413 }
2414 else {
2415 foreach my $c (@controllers) {
2416 push @output, @{ run_omreport("storage connector controller=$c") };
2417 map_item('ctrl', $c, \@output);
2418 }
2419 }
2420
2421 my %conn_state
2422 = (
2423 0 => 'Unknown',
2424 1 => 'Ready',
2425 2 => 'Failed',
2426 3 => 'Online',
2427 4 => 'Offline',
2428 6 => 'Degraded',
2429 );
2430
2431 my %conn_bustype
2432 = (
2433 1 => 'SCSI',
2434 2 => 'IDE',
2435 3 => 'Fibre Channel',
2436 4 => 'SSA',
2437 6 => 'USB',
2438 7 => 'SATA',
2439 8 => 'SAS',
2440 );
2441
2442 # Check connectors on each of the controllers
2443 CHANNEL:
2444 foreach my $out (@output) {
2445 if ($snmp) {
fcbd60e6 2446 $name = $out->{channelName} || 'Unknown channel';
b460a3d6 2447 $status = get_snmp_status($out->{channelComponentStatus});
4a7c67f1 2448 $state = get_hashval($out->{channelState}, \%conn_state) || 'Unknown state';
2449 $type = get_hashval($out->{channelBusType}, \%conn_bustype) || 'Unknown type';
fcbd60e6 2450 $nexus = convert_nexus(($out->{channelNexusID} || 9999));
669797e1 2451 $ctrl = $nexus;
2452 $ctrl =~ s{(\d+):\d+}{$1}xms;
2453 }
2454 else {
fcbd60e6 2455 $name = get_nonempty_string('Name', $out, 'Unknown channel');
2456 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2457 $status = get_nonempty_string('Status', $out, 'Unknown');
fcbd60e6 2458 $type = get_nonempty_string('Connector Type', $out, 'Unknown type');
669797e1 2459 $ctrl = $out->{ctrl};
7b81efb0 2460 $nexus = join q{:}, $out->{ctrl}, $out->{'ID'};
669797e1 2461 }
2462
2463 next CHANNEL if blacklisted('conn', $nexus);
2464
98b224a3 2465 my $msg = sprintf '%s [%s] on controller %d is %s',
669797e1 2466 $name, $type, $ctrl, $state;
2467 report('storage', $msg, $status2nagios{$status}, $nexus);
2468 }
2469 return;
2470}
2471
2472
2473#-----------------------------------------
2474# STORAGE: Check enclosures
2475#-----------------------------------------
2476sub check_enclosures {
2477 my $id = undef;
2478 my $nexus = undef;
2479 my $name = undef;
2480 my $state = undef;
2481 my $status = undef;
2482 my $firmware = undef;
25d04c34 2483 my $ctrl = undef;
3fc06a4b 2484 my $occupied_slots = undef; # number of occupied slots
2485 my $total_slots = undef; # number of total slots
669797e1 2486 my @output = ();
2487
2488 if ($snmp) {
2489 my %encl_oid
2490 = (
2491 '1.3.6.1.4.1.674.10893.1.20.130.3.1.1' => 'enclosureNumber',
2492 '1.3.6.1.4.1.674.10893.1.20.130.3.1.2' => 'enclosureName',
2493 '1.3.6.1.4.1.674.10893.1.20.130.3.1.4' => 'enclosureState',
2494 '1.3.6.1.4.1.674.10893.1.20.130.3.1.19' => 'enclosureChannelNumber',
2495 '1.3.6.1.4.1.674.10893.1.20.130.3.1.24' => 'enclosureComponentStatus',
2496 '1.3.6.1.4.1.674.10893.1.20.130.3.1.25' => 'enclosureNexusID',
2497 '1.3.6.1.4.1.674.10893.1.20.130.3.1.26' => 'enclosureFirmwareVersion',
3fc06a4b 2498 '1.3.6.1.4.1.674.10893.1.20.130.3.1.31' => 'enclosureOccupiedSlotCount', # new in OMSA 6.3.0
2499 '1.3.6.1.4.1.674.10893.1.20.130.3.1.32' => 'enclosureTotalSlots', # new in OMSA 6.3.0
669797e1 2500 );
4cabd748 2501 my $result = undef;
2502 if ($opt{use_get_table}) {
2503 my $enclosureTable = '1.3.6.1.4.1.674.10893.1.20.130.3';
2504 $result = $snmp_session->get_table(-baseoid => $enclosureTable);
2505 }
2506 else {
2507 $result = $snmp_session->get_entries(-columns => [keys %encl_oid]);
2508 }
669797e1 2509
2510 # No enclosures is OK
2511 return if !defined $result;
2512
2513 @output = @{ get_snmp_output($result, \%encl_oid) };
2514 }
2515 else {
2516 foreach my $c (@controllers) {
2517 push @output, @{ run_omreport("storage enclosure controller=$c") };
2518 map_item('ctrl', $c, \@output);
2519 }
2520 }
2521
2522 my %encl_state
2523 = (
2524 0 => 'Unknown',
2525 1 => 'Ready',
2526 2 => 'Failed',
2527 3 => 'Online',
2528 4 => 'Offline',
2529 6 => 'Degraded',
2530 );
2531
2532 ENCLOSURE:
2533 foreach my $out (@output) {
2534 if ($snmp) {
fcbd60e6 2535 $id = ($out->{enclosureNumber} || 10000) - 1;
2536 $name = $out->{enclosureName} || 'Unknown enclosure';
4a7c67f1 2537 $state = get_hashval($out->{enclosureState}, \%encl_state) || 'Unknown state';
b460a3d6 2538 $status = get_snmp_status($out->{enclosureComponentStatus});
fcbd60e6 2539 $firmware = $out->{enclosureFirmwareVersion} || 'N/A';
2540 $nexus = convert_nexus(($out->{enclosureNexusID} || 9999));
25d04c34 2541 $ctrl = $nexus;
2542 $ctrl =~ s{\A (\d+):.* \z}{$1}xms;
3fc06a4b 2543 # for the next two, a value of 9999 means feature not available
fcbd60e6 2544 $occupied_slots = defined $out->{enclosureOccupiedSlotCount}
3fc06a4b 2545 && $out->{enclosureOccupiedSlotCount} != 9999
2546 ? $out->{enclosureOccupiedSlotCount} : undef;
fcbd60e6 2547 $total_slots = defined $out->{enclosureTotalSlots}
3fc06a4b 2548 && $out->{enclosureTotalSlots} != 9999
2549 ? $out->{enclosureTotalSlots} : undef;
669797e1 2550 }
2551 else {
fcbd60e6 2552 $id = get_nonempty_string('ID', $out, 9999);
2553 $name = get_nonempty_string('Name', $out, 'Unknown enclosure');
2554 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2555 $status = get_nonempty_string('Status', $out, 'Unknown');
fcbd60e6 2556 $firmware = get_nonempty_string('Firmware Version', $out, 'N/A');
2557 $firmware =~ s{Not\sApplicable}{N/A}xms;
669797e1 2558 $nexus = join q{:}, $out->{ctrl}, $id;
25d04c34 2559 $ctrl = $out->{ctrl};
669797e1 2560 }
2561
2562 $name =~ s{\s+\z}{}xms; # remove trailing whitespace
2563 $firmware =~ s{\s+\z}{}xms; # remove trailing whitespace
2564
2565 # store enclosure data for future use
b1f48712 2566 if ($snmp) {
2567 $snmp_enclosure{$out->{enclosureNumber}}{id} = $id;
2568 $snmp_enclosure{$out->{enclosureNumber}}{name} = $name;
2569 $snmp_enclosure{$out->{enclosureNumber}}{nexus} = $nexus;
2570 }
661c2c5e 2571 else {
2572 push @enclosures, { 'id' => $id,
2573 'ctrl' => $out->{ctrl},
2574 'name' => $name };
2575 }
669797e1 2576
2577 # Collecting some storage info
2578 $sysinfo{'enclosure'}{$nexus}{'id'} = $nexus;
2579 $sysinfo{'enclosure'}{$nexus}{'name'} = $name;
2580 $sysinfo{'enclosure'}{$nexus}{'firmware'} = $firmware;
2581
2582 next ENCLOSURE if blacklisted('encl', $nexus);
2583
3fc06a4b 2584 my $msg = q{};
2585 if (defined $occupied_slots && defined $total_slots) {
cad6434b 2586 $msg = sprintf 'Enclosure %s [%s, %d/%d slots occupied] on ctrl %d is %s',
3fc06a4b 2587 $nexus, $name, $occupied_slots, $total_slots, $ctrl, $state;
2588 }
2589 else {
2590 $msg = sprintf 'Enclosure %s [%s] on controller %d is %s',
2591 $nexus, $name, $ctrl, $state;
2592 }
669797e1 2593 report('storage', $msg, $status2nagios{$status}, $nexus);
2594 }
2595 return;
2596}
2597
2598
2599#-----------------------------------------
2600# STORAGE: Check enclosure fans
2601#-----------------------------------------
2602sub check_enclosure_fans {
2603 return if $#controllers == -1;
2604
669797e1 2605 my $nexus = undef;
2606 my $name = undef;
2607 my $state = undef;
2608 my $status = undef;
2609 my $speed = undef;
2610 my $encl_id = undef;
2611 my $encl_name = undef;
2612 my @output = ();
2613
2614 if ($snmp) {
2615 my %fan_oid
2616 = (
669797e1 2617 '1.3.6.1.4.1.674.10893.1.20.130.7.1.2' => 'fanName',
2618 '1.3.6.1.4.1.674.10893.1.20.130.7.1.4' => 'fanState',
2619 '1.3.6.1.4.1.674.10893.1.20.130.7.1.11' => 'fanProbeCurrValue',
2620 '1.3.6.1.4.1.674.10893.1.20.130.7.1.15' => 'fanComponentStatus',
2621 '1.3.6.1.4.1.674.10893.1.20.130.7.1.16' => 'fanNexusID',
2622 '1.3.6.1.4.1.674.10893.1.20.130.8.1.4' => 'fanConnectionEnclosureName',
2623 '1.3.6.1.4.1.674.10893.1.20.130.8.1.5' => 'fanConnectionEnclosureNumber',
2624 );
4cabd748 2625 my $result = undef;
2626 if ($opt{use_get_table}) {
2627 my $fanTable = '1.3.6.1.4.1.674.10893.1.20.130.7';
c849fd4c 2628 my $fanConnectionTable = '1.3.6.1.4.1.674.10893.1.20.130.8';
2629
4cabd748 2630 $result = $snmp_session->get_table(-baseoid => $fanTable);
c849fd4c 2631 my $ext = $snmp_session->get_table(-baseoid => $fanConnectionTable);
2632
2633 if (defined $result) {
2634 defined $ext && map { $$result{$_} = $$ext{$_} } keys %{ $ext };
2635 }
4cabd748 2636 }
2637 else {
2638 $result = $snmp_session->get_entries(-columns => [keys %fan_oid]);
2639 }
669797e1 2640
2641 # No enclosure fans is OK
2642 return if !defined $result;
2643
2644 @output = @{ get_snmp_output($result, \%fan_oid) };
2645 }
2646 else {
2647 foreach my $enc (@enclosures) {
2648 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=fans") };
2649 map_item('ctrl', $enc->{ctrl}, \@output);
2650 map_item('encl_id', $enc->{id}, \@output);
2651 map_item('encl_name', $enc->{name}, \@output);
2652 }
2653 }
2654
2655 my %fan_state
2656 = (
2657 0 => 'Unknown',
2658 1 => 'Ready',
2659 2 => 'Failed',
2660 3 => 'Online',
2661 4 => 'Offline',
2662 6 => 'Degraded',
2663 21 => 'Missing',
2664 );
2665
2666 # Check fans on each of the enclosures
2667 FAN:
2668 foreach my $out (@output) {
2669 if ($snmp) {
fcbd60e6 2670 $name = $out->{fanName} || 'Unknown fan';
4a7c67f1 2671 $state = get_hashval($out->{fanState}, \%fan_state) || 'Unknown state';
b460a3d6 2672 $status = get_snmp_status($out->{fanComponentStatus});
fcbd60e6 2673 $speed = $out->{fanProbeCurrValue} || 'N/A';
2674 $encl_name = $out->{fanConnectionEnclosureName} || 'Unknown enclosure';
b1f48712 2675 $encl_id = $snmp_enclosure{$out->{fanConnectionEnclosureNumber}}{nexus};
fcbd60e6 2676 $nexus = convert_nexus(($out->{fanNexusID} || 9999));
669797e1 2677 }
2678 else {
fcbd60e6 2679 $name = get_nonempty_string('Name', $out, 'Unknown fan');
2680 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2681 $status = get_nonempty_string('Status', $out, 'Unknown');
fcbd60e6 2682 $speed = get_nonempty_string('Speed', $out, 'N/A');
669797e1 2683 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
2684 $encl_name = $out->{encl_name};
fcbd60e6 2685 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, get_nonempty_string('ID', $out, '9999');
669797e1 2686 }
2687
2688 next FAN if blacklisted('encl_fan', $nexus);
2689
2690 # Default
2691 if ($status ne 'Ok') {
ef3b5f84 2692 my $msg = sprintf '%s in enclosure %s [%s] is %s',
669797e1 2693 $name, $encl_id, $encl_name, $state;
2694 report('storage', $msg, $status2nagios{$status}, $nexus);
2695 }
2696 # Ok
2697 else {
98b224a3 2698 my $msg = sprintf '%s in enclosure %s [%s] is %s (speed=%s)',
669797e1 2699 $name, $encl_id, $encl_name, $state, $speed;
2700 report('storage', $msg, $E_OK, $nexus);
2701 }
2702 }
2703 return;
2704}
2705
2706
2707#-----------------------------------------
2708# STORAGE: Check enclosure power supplies
2709#-----------------------------------------
2710sub check_enclosure_pwr {
2711 return if $#controllers == -1;
2712
669797e1 2713 my $nexus = undef;
2714 my $name = undef;
2715 my $state = undef;
2716 my $status = undef;
2717 my $encl_id = undef;
2718 my $encl_name = undef;
2719 my @output = ();
2720
2721 if ($snmp) {
2722 my %ps_oid
2723 = (
669797e1 2724 '1.3.6.1.4.1.674.10893.1.20.130.9.1.2' => 'powerSupplyName',
2725 '1.3.6.1.4.1.674.10893.1.20.130.9.1.4' => 'powerSupplyState',
2726 '1.3.6.1.4.1.674.10893.1.20.130.9.1.9' => 'powerSupplyComponentStatus',
2727 '1.3.6.1.4.1.674.10893.1.20.130.9.1.10' => 'powerSupplyNexusID',
2728 '1.3.6.1.4.1.674.10893.1.20.130.10.1.4' => 'powerSupplyConnectionEnclosureName',
2729 '1.3.6.1.4.1.674.10893.1.20.130.10.1.5' => 'powerSupplyConnectionEnclosureNumber',
2730 );
4cabd748 2731 my $result = undef;
2732 if ($opt{use_get_table}) {
2733 my $powerSupplyTable = '1.3.6.1.4.1.674.10893.1.20.130.9';
c849fd4c 2734 my $powerSupplyConnectionTable = '1.3.6.1.4.1.674.10893.1.20.130.10';
2735
4cabd748 2736 $result = $snmp_session->get_table(-baseoid => $powerSupplyTable);
c849fd4c 2737 my $ext = $snmp_session->get_table(-baseoid => $powerSupplyConnectionTable);
2738
2739 if (defined $result) {
2740 defined $ext && map { $$result{$_} = $$ext{$_} } keys %{ $ext };
2741 }
4cabd748 2742 }
2743 else {
2744 $result = $snmp_session->get_entries(-columns => [keys %ps_oid]);
2745 }
669797e1 2746
2747 # No enclosure power supplies is OK
2748 return if !defined $result;
2749
2750 @output = @{ get_snmp_output($result, \%ps_oid) };
2751 }
2752 else {
2753 foreach my $enc (@enclosures) {
2754 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=pwrsupplies") };
2755 map_item('ctrl', $enc->{ctrl}, \@output);
2756 map_item('encl_id', $enc->{id}, \@output);
2757 map_item('encl_name', $enc->{name}, \@output);
2758 }
2759 }
2760
2761 my %ps_state
2762 = (
2763 0 => 'Unknown',
2764 1 => 'Ready',
2765 2 => 'Failed',
2766 5 => 'Not Installed',
2767 6 => 'Degraded',
2768 11 => 'Removed',
2769 21 => 'Missing',
2770 );
2771
2772 # Check power supplies on each of the enclosures
2773 PS:
2774 foreach my $out (@output) {
2775 if ($snmp) {
fcbd60e6 2776 $name = $out->{powerSupplyName} || 'Unknown PSU';
4a7c67f1 2777 $state = get_hashval($out->{powerSupplyState}, \%ps_state) || 'Unknown state';
b460a3d6 2778 $status = get_snmp_status($out->{powerSupplyComponentStatus});
b1f48712 2779 $encl_id = $snmp_enclosure{$out->{powerSupplyConnectionEnclosureNumber}}{nexus};
fcbd60e6 2780 $encl_name = $out->{powerSupplyConnectionEnclosureName} || 'Unknown enclosure';
2781 $nexus = convert_nexus(($out->{powerSupplyNexusID} || 9999));
669797e1 2782 }
2783 else {
fcbd60e6 2784 $name = get_nonempty_string('Name', $out, 'Unknown PSU');
2785 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2786 $status = get_nonempty_string('Status', $out, 'Unknown');
669797e1 2787 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
2788 $encl_name = $out->{encl_name};
fcbd60e6 2789 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, get_nonempty_string('ID', $out, '9999');
669797e1 2790 }
2791
2792 next PS if blacklisted('encl_ps', $nexus);
2793
2794 # Default
ef3b5f84
THA
2795 my $msg = sprintf '%s in enclosure %s [%s] is %s',
2796 $name, $encl_id, $encl_name, $state;
2797 report('storage', $msg, $status2nagios{$status}, $nexus);
669797e1 2798 }
2799 return;
2800}
2801
2802
2803#-----------------------------------------
2804# STORAGE: Check enclosure temperatures
2805#-----------------------------------------
2806sub check_enclosure_temp {
2807 return if $#controllers == -1;
2808
669797e1 2809 my $nexus = undef;
2810 my $name = undef;
2811 my $state = undef;
2812 my $status = undef;
2813 my $reading = undef;
2814 my $unit = undef;
2815 my $max_warn = undef;
2816 my $max_crit = undef;
a0c9fa40 2817 my $min_warn = undef;
2818 my $min_crit = undef;
669797e1 2819 my $encl_id = undef;
2820 my $encl_name = undef;
2821 my @output = ();
2822
2823 if ($snmp) {
2824 my %temp_oid
2825 = (
669797e1 2826 '1.3.6.1.4.1.674.10893.1.20.130.11.1.2' => 'temperatureProbeName',
2827 '1.3.6.1.4.1.674.10893.1.20.130.11.1.4' => 'temperatureProbeState',
2828 '1.3.6.1.4.1.674.10893.1.20.130.11.1.6' => 'temperatureProbeUnit',
a0c9fa40 2829 '1.3.6.1.4.1.674.10893.1.20.130.11.1.7' => 'temperatureProbeMinWarning',
2830 '1.3.6.1.4.1.674.10893.1.20.130.11.1.8' => 'temperatureProbeMinCritical',
669797e1 2831 '1.3.6.1.4.1.674.10893.1.20.130.11.1.9' => 'temperatureProbeMaxWarning',
2832 '1.3.6.1.4.1.674.10893.1.20.130.11.1.10' => 'temperatureProbeMaxCritical',
2833 '1.3.6.1.4.1.674.10893.1.20.130.11.1.11' => 'temperatureProbeCurValue',
2834 '1.3.6.1.4.1.674.10893.1.20.130.11.1.13' => 'temperatureProbeComponentStatus',
2835 '1.3.6.1.4.1.674.10893.1.20.130.11.1.14' => 'temperatureProbeNexusID',
2836 '1.3.6.1.4.1.674.10893.1.20.130.12.1.4' => 'temperatureConnectionEnclosureName',
2837 '1.3.6.1.4.1.674.10893.1.20.130.12.1.5' => 'temperatureConnectionEnclosureNumber',
2838 );
4cabd748 2839 my $result = undef;
2840 if ($opt{use_get_table}) {
2841 my $temperatureProbeTable = '1.3.6.1.4.1.674.10893.1.20.130.11';
c849fd4c 2842 my $temperatureConnectionTable = '1.3.6.1.4.1.674.10893.1.20.130.12';
2843
4cabd748 2844 $result = $snmp_session->get_table(-baseoid => $temperatureProbeTable);
c849fd4c 2845 my $ext = $snmp_session->get_table(-baseoid => $temperatureConnectionTable);
2846
2847 if (defined $result) {
2848 defined $ext && map { $$result{$_} = $$ext{$_} } keys %{ $ext };
2849 }
4cabd748 2850 }
2851 else {
2852 $result = $snmp_session->get_entries(-columns => [keys %temp_oid]);
2853 }
669797e1 2854
2855 # No enclosure temperature probes is OK
2856 return if !defined $result;
2857
2858 @output = @{ get_snmp_output($result, \%temp_oid) };
2859 }
2860 else {
2861 foreach my $enc (@enclosures) {
2862 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=temps") };
2863 map_item('ctrl', $enc->{ctrl}, \@output);
2864 map_item('encl_id', $enc->{id}, \@output);
2865 map_item('encl_name', $enc->{name}, \@output);
2866 }
2867 }
2868
2869 my %temp_state
2870 = (
2871 0 => 'Unknown',
2872 1 => 'Ready',
2873 2 => 'Failed',
2874 4 => 'Offline',
2875 6 => 'Degraded',
2876 9 => 'Inactive',
2877 21 => 'Missing',
2878 );
2879
2880 # Check temperature probes on each of the enclosures
2881 TEMP:
2882 foreach my $out (@output) {
2883 if ($snmp) {
fcbd60e6 2884 $name = $out->{temperatureProbeName} || 'Unknown temp probe';
4a7c67f1 2885 $state = get_hashval($out->{temperatureProbeState}, \%temp_state) || 'Unknown state';
e7fd8bc9 2886 $status = get_snmp_probestatus($out->{temperatureProbeComponentStatus});
fcbd60e6 2887 $unit = $out->{temperatureProbeUnit} || 'Unknown unit';
2888 $reading = $out->{temperatureProbeCurValue} || '[N/A]';
2889 $max_warn = $out->{temperatureProbeMaxWarning} || '[N/A]';
2890 $max_crit = $out->{temperatureProbeMaxCritical} || '[N/A]';
2891 $min_warn = $out->{temperatureProbeMinWarning} || '[N/A]';
2892 $min_crit = $out->{temperatureProbeMinCritical} || '[N/A]';
b1f48712 2893 $encl_id = $snmp_enclosure{$out->{temperatureConnectionEnclosureNumber}}{nexus};
fcbd60e6 2894 $encl_name = $out->{temperatureConnectionEnclosureName} || 'Unknown enclosure';
2895 $nexus = convert_nexus(($out->{temperatureProbeNexusID} || 9999));
669797e1 2896 }
2897 else {
fcbd60e6 2898 $name = get_nonempty_string('Name', $out, 'Unknown temp probe');
2899 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 2900 $status = get_nonempty_string('Status', $out, 'Unknown');
669797e1 2901 $unit = 'FIXME';
fcbd60e6 2902 $reading = get_nonempty_string('Reading', $out, '[N/A]');
2903 $max_warn = get_nonempty_string('Maximum Warning Threshold', $out, '[N/A]');
2904 $max_crit = get_nonempty_string('Maximum Failure Threshold', $out, '[N/A]');
2905 $min_warn = get_nonempty_string('Minimum Warning Threshold', $out, '[N/A]');
2906 $min_crit = get_nonempty_string('Minimum Failure Threshold', $out, '[N/A]');
669797e1 2907 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
2908 $encl_name = $out->{encl_name};
fcbd60e6 2909 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, get_nonempty_string('ID', $out, '9999');
669797e1 2910 }
2911
2912 next TEMP if blacklisted('encl_temp', $nexus);
2913
a0c9fa40 2914 # Make sure these values are integers
2915 $reading =~ s{\A \s* (-?\d+) \s* C? \s* \z}{$1}xms or $reading = '[N/A]';
2916 $max_warn =~ s{\A \s* (-?\d+) \s* C? \s* \z}{$1}xms or $max_warn = '[N/A]';
2917 $max_crit =~ s{\A \s* (-?\d+) \s* C? \s* \z}{$1}xms or $max_crit = '[N/A]';
2918 $min_warn =~ s{\A \s* (-?\d+) \s* C? \s* \z}{$1}xms or $min_warn = '[N/A]';
2919 $min_crit =~ s{\A \s* (-?\d+) \s* C? \s* \z}{$1}xms or $min_crit = '[N/A]';
2920
2715ae8c 2921 # Convert temp units
2922 if ($opt{tempunit} ne 'C') {
0804d814
THA
2923 $reading = temp_from_celsius($reading, $opt{tempunit}) if $reading ne '[N/A]';
2924 $max_warn = temp_from_celsius($max_warn, $opt{tempunit}) if $max_warn ne '[N/A]';
2925 $max_crit = temp_from_celsius($max_crit, $opt{tempunit}) if $max_crit ne '[N/A]';
2926 $min_warn = temp_from_celsius($min_warn, $opt{tempunit}) if $min_warn ne '[N/A]';
2927 $min_crit = temp_from_celsius($min_crit, $opt{tempunit}) if $min_crit ne '[N/A]';
2715ae8c 2928 }
2929
2c1daec8 2930 # Inactive temp probes
2931 if ($status eq 'Unknown' and $state eq 'Inactive') {
2932 my $msg = sprintf '%s in enclosure %s [%s] is %s',
2933 $name, $encl_id, $encl_name, $state;
2934 report('storage', $msg, $E_OK, $nexus);
2935 }
022ccb0f 2936 elsif ($status ne 'Ok' and $reading ne '[N/A]' and $max_crit ne '[N/A]' and $reading > $max_crit) {
44232d73 2937 my $msg = sprintf '%s in enclosure %s [%s] is critically high at %s %s',
2715ae8c 2938 $name, $encl_id, $encl_name, $reading, $opt{tempunit};
a0c9fa40 2939 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2940 report('chassis', $msg, $err, $nexus);
2941 }
022ccb0f 2942 elsif ($status ne 'Ok' and $reading ne '[N/A]' and $max_warn ne '[N/A]' and $reading > $max_warn) {
44232d73 2943 my $msg = sprintf '%s in enclosure %s [%s] is too high at %s %s',
2715ae8c 2944 $name, $encl_id, $encl_name, $reading, $opt{tempunit};
a0c9fa40 2945 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2946 report('chassis', $msg, $err, $nexus);
2947 }
022ccb0f 2948 elsif ($status ne 'Ok' and $reading ne '[N/A]' and $min_crit ne '[N/A]' and $reading < $min_crit) {
44232d73 2949 my $msg = sprintf '%s in enclosure %s [%s] is critically low at %s %s',
2715ae8c 2950 $name, $encl_id, $encl_name, $reading, $opt{tempunit};
a0c9fa40 2951 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2952 report('chassis', $msg, $err, $nexus);
2953 }
022ccb0f 2954 elsif ($status ne 'Ok' and $reading ne '[N/A]' and $min_warn ne '[N/A]' and $reading < $min_warn) {
44232d73 2955 my $msg = sprintf '%s in enclosure %s [%s] is too low at %s %s',
2715ae8c 2956 $name, $encl_id, $encl_name, $reading, $opt{tempunit};
a0c9fa40 2957 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2958 report('chassis', $msg, $err, $nexus);
2959 }
669797e1 2960 # Default
2c1daec8 2961 elsif ($status ne 'Ok') {
2962 my $msg = sprintf '%s in enclosure %s [%s] is %s',
2963 $name, $encl_id, $encl_name, $state;
a38cf844 2964 if (defined $reading && $reading =~ m{\A -?\d+ \z}xms) {
2c1daec8 2965 # take into account that with certain states the
2966 # reading doesn't exist or is not an integer
2715ae8c 2967 $msg .= sprintf ' at %s %s', $reading, $opt{tempunit};
a0c9fa40 2968 if ($min_warn eq '[N/A]' or $min_crit eq '[N/A]') {
2969 $msg .= sprintf ' (max=%s/%s)', $max_warn, $max_crit;
2970 }
2971 else {
2972 $msg .= sprintf ' (min=%s/%s, max=%s/%s)',
2973 $min_warn, $min_crit, $max_warn, $max_crit;
2974 }
2c1daec8 2975 }
a0c9fa40 2976 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
2977 report('storage', $msg, $err, $nexus);
669797e1 2978 }
2979 # Ok
2980 else {
a0c9fa40 2981 my $msg = sprintf '%s in enclosure %s [%s]',
2982 $name, $encl_id, $encl_name;
2983 if (defined $reading && $reading ne '[N/A]') {
2984 # take into account that with certain states the
2985 # reading doesn't exist or is not an integer
44232d73 2986 $msg .= sprintf ' reads %s %s', $reading, $opt{tempunit};
a0c9fa40 2987 if ($min_warn eq '[N/A]' or $min_crit eq '[N/A]') {
2988 $msg .= sprintf ' (max=%s/%s)', $max_warn, $max_crit;
2989 }
2990 else {
2991 $msg .= sprintf ' (min=%s/%s, max=%s/%s)',
2992 $min_warn, $min_crit, $max_warn, $max_crit;
2993 }
2994 }
2995 else {
2996 $msg .= sprintf ' is %s', $state;
2997 }
669797e1 2998 report('storage', $msg, $E_OK, $nexus);
2999 }
3000
3001 # Collect performance data
a0c9fa40 3002 if (defined $opt{perfdata} && $reading ne '[N/A]') {
fce23cf9 3003 my $index = $name;
3004 $index =~ s{\A Temperature\sProbe\s(\d+) \z}{$1}gxms;
4572cb76 3005 my $legacy_name = $name;
3006 $legacy_name =~ s{\A Temperature\sProbe\s(\d+) \z}{temp_$1}gxms;
3007 my $legacy_label = lc "enclosure_${encl_id}_${legacy_name}";
3008 my $legacy_mini = $legacy_label;
3009 $legacy_mini =~ s{enclosure_(.+?)_temp_(.+?)}{e$1t$2}xms;
48aeec0b 3010 push @perfdata, {
4572cb76 3011 type => 'E',
3012 id => $opt{perfdata} eq 'minimal' ? "${encl_id}_t${index}" : "${encl_id}_temp_${index}",
3013 unit => $opt{tempunit},
3014 label => q{},
3015 legacy => $legacy_label,
3016 mini => $legacy_mini,
3017 value => $reading,
3018 warn => $max_warn,
3019 crit => $max_crit,
48aeec0b 3020 };
669797e1 3021 }
3022 }
3023 return;
3024}
3025
3026
3027#-----------------------------------------
3028# STORAGE: Check enclosure management modules (EMM)
3029#-----------------------------------------
3030sub check_enclosure_emms {
3031 return if $#controllers == -1;
3032
669797e1 3033 my $nexus = undef;
3034 my $name = undef;
3035 my $state = undef;
3036 my $status = undef;
3037 my $encl_id = undef;
3038 my $encl_name = undef;
3039 my @output = ();
3040
3041 if ($snmp) {
3042 my %emms_oid
3043 = (
669797e1 3044 '1.3.6.1.4.1.674.10893.1.20.130.13.1.2' => 'enclosureManagementModuleName',
3045 '1.3.6.1.4.1.674.10893.1.20.130.13.1.4' => 'enclosureManagementModuleState',
3046 '1.3.6.1.4.1.674.10893.1.20.130.13.1.11' => 'enclosureManagementModuleComponentStatus',
3047 '1.3.6.1.4.1.674.10893.1.20.130.13.1.12' => 'enclosureManagementModuleNexusID',
3048 '1.3.6.1.4.1.674.10893.1.20.130.14.1.4' => 'enclosureManagementModuleConnectionEnclosureName',
3049 '1.3.6.1.4.1.674.10893.1.20.130.14.1.5' => 'enclosureManagementModuleConnectionEnclosureNumber',
3050 );
4cabd748 3051 my $result = undef;
3052 if ($opt{use_get_table}) {
3053 my $enclosureManagementModuleTable = '1.3.6.1.4.1.674.10893.1.20.130.13';
c849fd4c 3054 my $enclosureManagementModuleConnectionTable = '1.3.6.1.4.1.674.10893.1.20.130.14';
3055
4cabd748 3056 $result = $snmp_session->get_table(-baseoid => $enclosureManagementModuleTable);
c849fd4c 3057 my $ext = $snmp_session->get_table(-baseoid => $enclosureManagementModuleConnectionTable);
3058
3059 if (defined $result) {
3060 defined $ext && map { $$result{$_} = $$ext{$_} } keys %{ $ext };
3061 }
4cabd748 3062 }
3063 else {
3064 $result = $snmp_session->get_entries(-columns => [keys %emms_oid]);
3065 }
669797e1 3066
3067 # No enclosure EMMs is OK
3068 return if !defined $result;
3069
3070 @output = @{ get_snmp_output($result, \%emms_oid) };
3071 }
3072 else {
3073 foreach my $enc (@enclosures) {
3074 push @output, @{ run_omreport("storage enclosure controller=$enc->{ctrl} enclosure=$enc->{id} info=emms") };
3075 map_item('ctrl', $enc->{ctrl}, \@output);
3076 map_item('encl_id', $enc->{id}, \@output);
3077 map_item('encl_name', $enc->{name}, \@output);
3078 }
3079 }
3080
3081 my %emms_state
3082 = (
3083 0 => 'Unknown',
3084 1 => 'Ready',
3085 2 => 'Failed',
3086 3 => 'Online',
3087 4 => 'Offline',
3088 5 => 'Not Installed',
3089 6 => 'Degraded',
3090 21 => 'Missing',
3091 );
3092
a0c9fa40 3093 # Check EMMs on each of the enclosures
669797e1 3094 EMM:
3095 foreach my $out (@output) {
3096 if ($snmp) {
fcbd60e6 3097 $name = $out->{enclosureManagementModuleName} || 'Unknown EMM';
4a7c67f1 3098 $state = get_hashval($out->{enclosureManagementModuleState}, \%emms_state) || 'Unknown state';
b460a3d6 3099 $status = get_snmp_status($out->{enclosureManagementModuleComponentStatus});
b1f48712 3100 $encl_id = $snmp_enclosure{$out->{enclosureManagementModuleConnectionEnclosureNumber}}{nexus};
fcbd60e6 3101 $encl_name = $out->{enclosureManagementModuleConnectionEnclosureName} || 'Unknown enclosure';
3102 $nexus = convert_nexus(($out->{enclosureManagementModuleNexusID} || 9999));
669797e1 3103 }
3104 else {
fcbd60e6 3105 $name = get_nonempty_string('Name', $out, 'Unknown EMM');
3106 $state = get_nonempty_string('State', $out, 'Unknown state');
0eed03e9 3107 $status = get_nonempty_string('Status', $out, 'Unknown');
669797e1 3108 $encl_id = join q{:}, $out->{ctrl}, $out->{'encl_id'};
3109 $encl_name = $out->{encl_name};
fcbd60e6 3110 $nexus = join q{:}, $out->{ctrl}, $out->{'encl_id'}, get_nonempty_string('ID', $out, '9999');
669797e1 3111 }
3112
3113 next EMM if blacklisted('encl_emm', $nexus);
3114
2c1daec8 3115 # Not installed
a0c9fa40 3116 if ($status =~ m{\A Other|Unknown \z}xms and $state eq 'Not Installed') {
2c1daec8 3117 my $msg = sprintf '%s in enclosure %s [%s] is %s',
3118 $name, $encl_id, $encl_name, $state;
3119 report('storage', $msg, $E_OK, $nexus);
3120 }
669797e1 3121 # Default
669797e1 3122 else {
98b224a3 3123 my $msg = sprintf '%s in enclosure %s [%s] is %s',
669797e1 3124 $name, $encl_id, $encl_name, $state;
ef3b5f84 3125 report('storage', $msg, $status2nagios{$status}, $nexus);
669797e1 3126 }
3127 }
3128 return;
3129}
3130
3131
3132#-----------------------------------------
3133# CHASSIS: Check memory modules
3134#-----------------------------------------
3135sub check_memory {
3136 my $index = undef;
3137 my $status = undef;
3138 my $location = undef;
3139 my $size = undef;
3140 my $modes = undef;
3141 my @failures = ();
3142 my @output = ();
3143
3144 if ($snmp) {
3145 my %dimm_oid
3146 = (
3147 '1.3.6.1.4.1.674.10892.1.1100.50.1.2.1' => 'memoryDeviceIndex',
3148 '1.3.6.1.4.1.674.10892.1.1100.50.1.5.1' => 'memoryDeviceStatus',
3149 '1.3.6.1.4.1.674.10892.1.1100.50.1.8.1' => 'memoryDeviceLocationName',
3150 '1.3.6.1.4.1.674.10892.1.1100.50.1.14.1' => 'memoryDeviceSize',
3151 '1.3.6.1.4.1.674.10892.1.1100.50.1.20.1' => 'memoryDeviceFailureModes',
3152 );
4cabd748 3153 my $result = undef;
3154 if ($opt{use_get_table}) {
3155 my $memoryDeviceTable = '1.3.6.1.4.1.674.10892.1.1100.50.1';
3156 $result = $snmp_session->get_table(-baseoid => $memoryDeviceTable);
3157 }
3158 else {
3159 $result = $snmp_session->get_entries(-columns => [keys %dimm_oid]);
3160 }
669797e1 3161
3162 if (!defined $result) {
98b224a3 3163 printf "SNMP ERROR [memory]: %s.\n", $snmp_session->error;
669797e1 3164 $snmp_session->close;
3165 exit $E_UNKNOWN;
3166 }
3167
3168 @output = @{ get_snmp_output($result, \%dimm_oid) };
3169 }
3170 else {
3171 @output = @{ run_omreport("$omopt_chassis memory") };
3172 }
3173
3174 # Note: These values are bit masks, so combination values are
3175 # possible. If value is 0 (zero), memory device has no faults.
3176 my %failure_mode
3177 = (
3178 1 => 'ECC single bit correction warning rate exceeded',
3179 2 => 'ECC single bit correction failure rate exceeded',
3180 4 => 'ECC multibit fault encountered',
3181 8 => 'ECC single bit correction logging disabled',
3182 16 => 'device disabled because of spare activation',
3183 );
3184
3185 DIMM:
3186 foreach my $out (@output) {
3187 @failures = (); # Initialize
3188 if ($snmp) {
205488c0 3189 $index = ($out->{memoryDeviceIndex} || 10000) - 1;
b460a3d6 3190 $status = get_snmp_status($out->{memoryDeviceStatus});
205488c0 3191 $location = $out->{memoryDeviceLocationName} || 'Unknown location';
3192 $size = sprintf '%d MB', ($out->{memoryDeviceSize} || 0)/1024;
3193 $modes = $out->{memoryDeviceFailureModes} || -9999;
669797e1 3194 if ($modes > 0) {
3195 foreach my $mask (sort keys %failure_mode) {
3196 if (($modes & $mask) != 0) { push @failures, $failure_mode{$mask}; }
3197 }
3198 }
205488c0 3199 elsif ($modes == -9999) {
3200 push @failures, q{ERROR: Failure modes not available via SNMP};
3201 }
669797e1 3202 }
3203 else {
205488c0 3204 my $type = get_nonempty_string('Type', $out, q{});
3205 $index = $type eq '[Not Occupied]' ? undef : get_nonempty_string('Index', $out, 9999);
0eed03e9 3206 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 3207 $location = get_nonempty_string('Connector Name', $out, 'Unknown location');
3208 $size = get_nonempty_string('Size', $out, 0);
669797e1 3209 if (defined $size) {
3210 $size =~ s{\s\s}{ }gxms;
3211 }
3212 # Run 'omreport chassis memory index=X' to get the failures
3213 if ($status ne 'Ok' && defined $index) {
3214 foreach (@{ run_command("$omreport $omopt_chassis memory index=$index -fmt ssv") }) {
3215 if (m/\A Failures; (.+?) \z/xms) {
3216 chop(my $fail = $1);
3217 push @failures, split m{\.}xms, $fail;
3218 }
3219 }
3220 }
3221 }
3222 $location =~ s{\A \s*(.*?)\s* \z}{$1}xms;
3223
14e95f92 3224 # calculate total memory
717be848 3225 my $msize = defined $size ? $size : 0;
14e95f92 3226 $msize =~ s{\A (\d+) \s MB}{$1}xms;
3227 $count{mem} += $msize;
3228
669797e1 3229 # Ignore empty memory slots
3230 next DIMM if !defined $index;
35a7e76e 3231
669797e1 3232 $count{dimm}++;
35a7e76e 3233 next DIMM if blacklisted('dimm', $index);
669797e1 3234
3235 if ($status ne 'Ok') {
3236 my $msg = undef;
3237 if (scalar @failures == 0) {
98b224a3 3238 $msg = sprintf 'Memory module %d [%s, %s] needs attention (%s)',
669797e1 3239 $index, $location, $size, $status;
3240 }
3241 else {
ef3b5f84 3242 $msg = sprintf 'Memory module %d [%s, %s]: %s',
669797e1 3243 $index, $location, $size, (join q{, }, @failures);
3244 }
3245
3246 report('chassis', $msg, $status2nagios{$status}, $index);
3247 }
3248 # Ok
3249 else {
98b224a3 3250 my $msg = sprintf 'Memory module %d [%s, %s] is %s',
669797e1 3251 $index, $location, $size, $status;
3252 report('chassis', $msg, $E_OK, $index);
3253 }
3254 }
7b5c99ff 3255 return;
669797e1 3256}
3257
3258
3259#-----------------------------------------
3260# CHASSIS: Check fans
3261#-----------------------------------------
3262sub check_fans {
3263 my $index = undef;
3264 my $status = undef;
3265 my $reading = undef;
3266 my $location = undef;
3267 my $max_crit = undef;
3268 my $max_warn = undef;
3269 my @output = ();
3270
3271 if ($snmp) {
3272 my %cool_oid
3273 = (
3274 '1.3.6.1.4.1.674.10892.1.700.12.1.2.1' => 'coolingDeviceIndex',
3275 '1.3.6.1.4.1.674.10892.1.700.12.1.5.1' => 'coolingDeviceStatus',
3276 '1.3.6.1.4.1.674.10892.1.700.12.1.6.1' => 'coolingDeviceReading',
3277 '1.3.6.1.4.1.674.10892.1.700.12.1.8.1' => 'coolingDeviceLocationName',
3278 '1.3.6.1.4.1.674.10892.1.700.12.1.10.1' => 'coolingDeviceUpperCriticalThreshold',
3279 '1.3.6.1.4.1.674.10892.1.700.12.1.11.1' => 'coolingDeviceUpperNonCriticalThreshold',
3280 );
4cabd748 3281 my $result = undef;
3282 if ($opt{use_get_table}) {
3283 my $coolingDeviceTable = '1.3.6.1.4.1.674.10892.1.700.12.1';
3284 $result = $snmp_session->get_table(-baseoid => $coolingDeviceTable);
3285 }
3286 else {
3287 $result = $snmp_session->get_entries(-columns => [keys %cool_oid]);
3288 }
669797e1 3289
3290 if ($blade && !defined $result) {
3291 return 0;
3292 }
3293 elsif (!$blade && !defined $result) {
98b224a3 3294 printf "SNMP ERROR [cooling]: %s.\n", $snmp_session->error;
669797e1 3295 $snmp_session->close;
3296 exit $E_UNKNOWN;
3297 }
3298
3299 @output = @{ get_snmp_output($result, \%cool_oid) };
3300 }
3301 else {
3302 @output = @{ run_omreport("$omopt_chassis fans") };
3303 }
3304
3305 FAN:
3306 foreach my $out (@output) {
3307 if ($snmp) {
205488c0 3308 $index = ($out->{coolingDeviceIndex} || 10000) - 1;
e7fd8bc9 3309 $status = get_snmp_probestatus($out->{coolingDeviceStatus});
205488c0 3310 $reading = $out->{coolingDeviceReading} || 0;
3311 $location = $out->{coolingDeviceLocationName} || 'Unknown location';
3312 $max_crit = $out->{coolingDeviceUpperCriticalThreshold} || 0;
3313 $max_warn = $out->{coolingDeviceUpperNonCriticalThreshold} || 0;
669797e1 3314 }
3315 else {
205488c0 3316 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 3317 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 3318 $reading = get_nonempty_string('Reading', $out, 0);
3319 $location = get_nonempty_string('Probe Name', $out, 'Unknown location');
3320 $max_crit = get_nonempty_string('Maximum Failure Threshold', $out, 0);
3321 $max_warn = get_nonempty_string('Maximum Warning Threshold', $out, 0);
3322 if ($max_crit eq '[N/A]') { $max_crit = 0; }
3323 if ($max_warn eq '[N/A]') { $max_warn = 0; }
669797e1 3324 $reading =~ s{\A (\d+).* \z}{$1}xms;
3325 $max_warn =~ s{\A (\d+).* \z}{$1}xms;
3326 $max_crit =~ s{\A (\d+).* \z}{$1}xms;
3327 }
3328
669797e1 3329 $count{fan}++;
35a7e76e 3330 next FAN if blacklisted('fan', $index);
669797e1 3331
87d555e7 3332 # Default
3afde253 3333 my $msg = sprintf 'Chassis fan %d [%s] reading: %s RPM',
87d555e7 3334 $index, $location, $reading;
eb43b6d4 3335 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3336 report('chassis', $msg, $err, $index);
669797e1 3337
3338 # Collect performance data
3339 if (defined $opt{perfdata}) {
434167a1 3340 my $pname = $location;
669797e1 3341 $pname =~ s{\s}{_}gxms;
3342 $pname =~ s{proc_}{cpu#}xms;
4572cb76 3343 my $legacy_pname = $pname;
434167a1 3344 $pname =~ s{_rpm\z}{}ixms;
48aeec0b 3345 push @perfdata, {
4572cb76 3346 type => 'F',
3347 id => $index,
3348 unit => 'rpm',
3349 label => $pname,
3350 legacy => lc "fan_${index}_${legacy_pname}",
3351 mini => "f$index",
3352 value => $reading,
3353 warn => $max_warn,
3354 crit => $max_crit,
48aeec0b 3355 };
669797e1 3356 }
3357 }
3358 return;
3359}
3360
3361
3362#-----------------------------------------
3363# CHASSIS: Check power supplies
3364#-----------------------------------------
3365sub check_powersupplies {
3366 my $index = undef;
3367 my $status = undef;
3368 my $type = undef;
3369 my $err_type = undef;
3370 my $state = undef;
3371 my @states = ();
3372 my @output = ();
3373
3374 if ($snmp) {
3375 my %ps_oid
3376 = (
3377 '1.3.6.1.4.1.674.10892.1.600.12.1.2.1' => 'powerSupplyIndex',
3378 '1.3.6.1.4.1.674.10892.1.600.12.1.5.1' => 'powerSupplyStatus',
3379 '1.3.6.1.4.1.674.10892.1.600.12.1.7.1' => 'powerSupplyType',
3380 '1.3.6.1.4.1.674.10892.1.600.12.1.11.1' => 'powerSupplySensorState',
3381 '1.3.6.1.4.1.674.10892.1.600.12.1.12.1' => 'powerSupplyConfigurationErrorType',
3382 );
4cabd748 3383 my $result = undef;
3384 if ($opt{use_get_table}) {
3385 my $powerDeviceTable = '1.3.6.1.4.1.674.10892.1.600.12.1';
3386 $result = $snmp_session->get_table(-baseoid => $powerDeviceTable);
3387 }
3388 else {
3389 $result = $snmp_session->get_entries(-columns => [keys %ps_oid]);
3390 }
669797e1 3391
3392 # No instrumented PSU is OK (blades, low-end servers)
3393 return 0 if !defined $result;
3394
3395 @output = @{ get_snmp_output($result, \%ps_oid) };
3396 }
3397 else {
3398 @output = @{ run_omreport("$omopt_chassis pwrsupplies") };
3399 }
3400
3401 my %ps_type
3402 = (
3403 1 => 'Other',
3404 2 => 'Unknown',
3405 3 => 'Linear',
3406 4 => 'Switching',
3407 5 => 'Battery',
3408 6 => 'Uninterruptible Power Supply',
3409 7 => 'Converter',
3410 8 => 'Regulator',
3411 9 => 'AC',
3412 10 => 'DC',
3413 11 => 'VRM',
3414 );
3415
3416 my %ps_state
3417 = (
3418 1 => 'Presence detected',
3419 2 => 'Failure detected',
3420 4 => 'Predictive Failure',
3421 8 => 'AC lost',
3422 16 => 'AC lost or out-of-range',
3423 32 => 'AC out-of-range but present',
3424 64 => 'Configuration error',
3425 );
3426
3427 my %ps_config_error_type
3428 = (
3429 1 => 'Vendor mismatch',
3430 2 => 'Revision mismatch',
3431 3 => 'Processor missing',
3432 );
3433
3434 PS:
3435 foreach my $out (@output) {
3436 if ($snmp) {
3437 @states = (); # contains states for the PS
3438
205488c0 3439 $index = ($out->{powerSupplyIndex} || 10000) - 1;
b460a3d6 3440 $status = get_snmp_status($out->{powerSupplyStatus});
4a7c67f1 3441 $type = get_hashval($out->{powerSupplyType}, \%ps_type) || 'Unknown type';
3442 $err_type = get_hashval($out->{powerSupplyConfigurationErrorType}, \%ps_config_error_type);
669797e1 3443
3444 # get the combined state from the StatusReading OID
205488c0 3445 my $raw_state = $out->{powerSupplySensorState} || 0;
669797e1 3446 foreach my $mask (sort keys %ps_state) {
205488c0 3447 if (($raw_state & $mask) != 0) {
669797e1 3448 push @states, $ps_state{$mask};
3449 }
3450 }
3451
3452 # If configuration error, also include the error type
3453 if (defined $err_type) {
3454 push @states, $err_type;
3455 }
3456
3457 # Finally, construct the state string
3458 $state = join q{, }, @states;
3459 }
3460 else {
205488c0 3461 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 3462 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 3463 $type = get_nonempty_string('Type', $out, 'Unknown type');
3464 $state = get_nonempty_string('Online Status', $out, 'Unknown state');
669797e1 3465 }
3466
669797e1 3467 $count{power}++;
35a7e76e 3468 next PS if blacklisted('ps', $index);
669797e1 3469
ef3b5f84
THA
3470 my $msg = sprintf 'Power Supply %d [%s]: %s',
3471 $index, $type, $state;
3472 report('chassis', $msg, $status2nagios{$status}, $index);
669797e1 3473 }
3474 return;
3475}
3476
3477
3478#-----------------------------------------
3479# CHASSIS: Check temperatures
3480#-----------------------------------------
3481sub check_temperatures {
3482 my $index = undef;
3483 my $status = undef;
3484 my $reading = undef;
3485 my $location = undef;
3486 my $max_crit = undef;
3487 my $max_warn = undef;
3488 my $min_warn = undef;
3489 my $min_crit = undef;
3490 my $type = undef;
3491 my $discrete = undef;
3492 my @output = ();
3493
3494 # Getting custom temperature thresholds (user option)
3495 my %warn_threshold = %{ custom_temperature_thresholds('w') };
3496 my %crit_threshold = %{ custom_temperature_thresholds('c') };
3497
3498 if ($snmp) {
3499 my %temp_oid
3500 = (
3501 '1.3.6.1.4.1.674.10892.1.700.20.1.2.1' => 'temperatureProbeIndex',
3502 '1.3.6.1.4.1.674.10892.1.700.20.1.5.1' => 'temperatureProbeStatus',
3503 '1.3.6.1.4.1.674.10892.1.700.20.1.6.1' => 'temperatureProbeReading',
3504 '1.3.6.1.4.1.674.10892.1.700.20.1.7.1' => 'temperatureProbeType',
3505 '1.3.6.1.4.1.674.10892.1.700.20.1.8.1' => 'temperatureProbeLocationName',
3506 '1.3.6.1.4.1.674.10892.1.700.20.1.10.1' => 'temperatureProbeUpperCriticalThreshold',
3507 '1.3.6.1.4.1.674.10892.1.700.20.1.11.1' => 'temperatureProbeUpperNonCriticalThreshold',
3508 '1.3.6.1.4.1.674.10892.1.700.20.1.12.1' => 'temperatureProbeLowerNonCriticalThreshold',
3509 '1.3.6.1.4.1.674.10892.1.700.20.1.13.1' => 'temperatureProbeLowerCriticalThreshold',
3510 '1.3.6.1.4.1.674.10892.1.700.20.1.16.1' => 'temperatureProbeDiscreteReading',
3511 );
ba199ee0 3512 # this didn't work well for some reason
3513 #my $result = $snmp_session->get_entries(-columns => [keys %temp_oid]);
3514
3515 # Getting values using the table
3516 my $temperatureProbeTable = '1.3.6.1.4.1.674.10892.1.700.20';
3517 my $result = $snmp_session->get_table(-baseoid => $temperatureProbeTable);
669797e1 3518
3519 if (!defined $result) {
98b224a3 3520 printf "SNMP ERROR [temperatures]: %s.\n", $snmp_session->error;
669797e1 3521 $snmp_session->close;
3522 exit $E_UNKNOWN;
3523 }
3524
3525 @output = @{ get_snmp_output($result, \%temp_oid) };
3526 }
3527 else {
3528 @output = @{ run_omreport("$omopt_chassis temps") };
3529 }
3530
3531 my %probe_type
3532 = (
3533 1 => 'Other', # type is other than following values
3534 2 => 'Unknown', # type is unknown
3535 3 => 'AmbientESM', # type is Ambient Embedded Systems Management temperature probe
3536 16 => 'Discrete', # type is temperature probe with discrete reading
3537 );
3538
3539 TEMP:
3540 foreach my $out (@output) {
3541 if ($snmp) {
205488c0 3542 $index = ($out->{temperatureProbeIndex} || 10000) - 1;
e7fd8bc9 3543 $status = get_snmp_probestatus($out->{temperatureProbeStatus});
205488c0 3544 $location = $out->{temperatureProbeLocationName} || 'Unknown location';
912d8679 3545 $type = get_hashval($out->{temperatureProbeType}, \%probe_type);
205488c0 3546 $reading = $out->{temperatureProbeReading} || '[N/A]';
3547 $max_crit = $out->{temperatureProbeUpperCriticalThreshold} || '[N/A]';
3548 $max_warn = $out->{temperatureProbeUpperNonCriticalThreshold} || '[N/A]';
3549 $min_crit = $out->{temperatureProbeLowerCriticalThreshold} || '[N/A]';
3550 $min_warn = $out->{temperatureProbeLowerNonCriticalThreshold} || '[N/A]';
3551 $discrete = $out->{temperatureProbeDiscreteReading} || '[N/A]';
3552
3553 # If numeric values, i.e. not discrete
0fdb79f2
THA
3554 $reading /= 10 if $reading =~ m{\A -?\d+ \z}xms;
3555 $max_crit /= 10 if $max_crit =~ m{\A -?\d+ \z}xms;
3556 $max_warn /= 10 if $max_warn =~ m{\A -?\d+ \z}xms;
3557 $min_crit /= 10 if $min_crit =~ m{\A -?\d+ \z}xms;
3558 $min_warn /= 10 if $min_warn =~ m{\A -?\d+ \z}xms;
205488c0 3559
7328e97b 3560 # workaround for bad temp probes
3561 if ($type eq 'AmbientESM' and $reading !~ m{\A \d+(\.\d+)? \z}xms) {
3562 $type = 'Discrete';
3563 }
669797e1 3564 }
3565 else {
205488c0 3566 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 3567 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 3568 $location = get_nonempty_string('Probe Name', $out, 'Unknown location');
3569 $reading = get_nonempty_string('Reading', $out, '[N/A]');
3570 $max_crit = get_nonempty_string('Maximum Failure Threshold', $out, '[N/A]');
3571 $max_warn = get_nonempty_string('Maximum Warning Threshold', $out, '[N/A]');
3572 $min_crit = get_nonempty_string('Minimum Failure Threshold', $out, '[N/A]');
3573 $min_warn = get_nonempty_string('Minimum Warning Threshold', $out, '[N/A]');
3574
3575 # Cleaning the temp readings
3576 $reading =~ s{\.0\s+C}{}xms;
3577 $max_crit =~ s{\.0\s+C}{}xms;
3578 $max_warn =~ s{\.0\s+C}{}xms;
3579 $min_crit =~ s{\.0\s+C}{}xms;
3580 $min_warn =~ s{\.0\s+C}{}xms;
3581
0fdb79f2 3582 $type = $reading =~ m{\A-?\d+\z}xms ? 'AmbientESM' : 'Discrete';
669797e1 3583 $discrete = $reading;
3584 }
3585
669797e1 3586 $count{temp}++;
35a7e76e 3587 next TEMP if blacklisted('temp', $index);
669797e1 3588
2715ae8c 3589 # Convert temp units
3590 if ($opt{tempunit} ne 'C') {
0804d814
THA
3591 $reading = temp_from_celsius($reading, $opt{tempunit}) if $reading ne '[N/A]';
3592 $max_warn = temp_from_celsius($max_warn, $opt{tempunit}) if $max_warn ne '[N/A]';
3593 $max_crit = temp_from_celsius($max_crit, $opt{tempunit}) if $max_crit ne '[N/A]';
3594 $min_warn = temp_from_celsius($min_warn, $opt{tempunit}) if $min_warn ne '[N/A]';
3595 $min_crit = temp_from_celsius($min_crit, $opt{tempunit}) if $min_crit ne '[N/A]';
2715ae8c 3596 }
3597
669797e1 3598 if ($type eq 'Discrete') {
7328e97b 3599 my $msg = sprintf 'Temperature probe %d [%s] is %s',
669797e1 3600 $index, $location, $discrete;
3601 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3602 report('chassis', $msg, $err, $index);
3603 }
3604 else {
3605 # First check according to custom thresholds
3606 if (exists $crit_threshold{$index}{max} and $reading > $crit_threshold{$index}{max}) {
3607 # Custom critical MAX
44232d73 3608 my $msg = sprintf 'Temperature Probe %d [%s] reads %s %s (custom max=%s)',
2715ae8c 3609 $index, $location, $reading, $opt{tempunit}, $crit_threshold{$index}{max};
669797e1 3610 report('chassis', $msg, $E_CRITICAL, $index);
3611 }
3612 elsif (exists $warn_threshold{$index}{max} and $reading > $warn_threshold{$index}{max}) {
3613 # Custom warning MAX
44232d73 3614 my $msg = sprintf 'Temperature Probe %d [%s] reads %s %s (custom max=%s)',
2715ae8c 3615 $index, $location, $reading, $opt{tempunit}, $warn_threshold{$index}{max};
669797e1 3616 report('chassis', $msg, $E_WARNING, $index);
3617 }
3618 elsif (exists $crit_threshold{$index}{min} and $reading < $crit_threshold{$index}{min}) {
3619 # Custom critical MIN
44232d73 3620 my $msg = sprintf 'Temperature Probe %d [%s] reads %s %s (custom min=%s)',
2715ae8c 3621 $index, $location, $reading, $opt{tempunit}, $crit_threshold{$index}{min};
669797e1 3622 report('chassis', $msg, $E_CRITICAL, $index);
3623 }
3624 elsif (exists $warn_threshold{$index}{min} and $reading < $warn_threshold{$index}{min}) {
3625 # Custom warning MIN
44232d73 3626 my $msg = sprintf 'Temperature Probe %d [%s] reads %s %s (custom min=%s)',
2715ae8c 3627 $index, $location, $reading, $opt{tempunit}, $warn_threshold{$index}{min};
669797e1 3628 report('chassis', $msg, $E_WARNING, $index);
3629 }
3630 elsif ($status ne 'Ok' and $max_crit ne '[N/A]' and $reading > $max_crit) {
44232d73 3631 my $msg = sprintf 'Temperature Probe %d [%s] is critically high at %s %s',
2715ae8c 3632 $index, $location, $reading, $opt{tempunit};
669797e1 3633 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3634 report('chassis', $msg, $err, $index);
3635 }
3636 elsif ($status ne 'Ok' and $max_warn ne '[N/A]' and $reading > $max_warn) {
44232d73 3637 my $msg = sprintf 'Temperature Probe %d [%s] is too high at %s %s',
2715ae8c 3638 $index, $location, $reading, $opt{tempunit};
669797e1 3639 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3640 report('chassis', $msg, $err, $index);
3641 }
3642 elsif ($status ne 'Ok' and $min_crit ne '[N/A]' and $reading < $min_crit) {
44232d73 3643 my $msg = sprintf 'Temperature Probe %d [%s] is critically low at %s %s',
2715ae8c 3644 $index, $location, $reading, $opt{tempunit};
669797e1 3645 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3646 report('chassis', $msg, $err, $index);
3647 }
3648 elsif ($status ne 'Ok' and $min_warn ne '[N/A]' and $reading < $min_warn) {
44232d73 3649 my $msg = sprintf 'Temperature Probe %d [%s] is too low at %s %s',
2715ae8c 3650 $index, $location, $reading, $opt{tempunit};
669797e1 3651 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3652 report('chassis', $msg, $err, $index);
3653 }
3654 # Ok
3655 else {
44232d73 3656 my $msg = sprintf 'Temperature Probe %d [%s] reads %s %s',
2715ae8c 3657 $index, $location, $reading, $opt{tempunit};
304c4cba 3658 if ($min_warn eq '[N/A]' and $min_crit eq '[N/A]') {
3659 $msg .= sprintf ' (max=%s/%s)', $max_warn, $max_crit;
3660 }
3661 else {
3662 $msg .= sprintf ' (min=%s/%s, max=%s/%s)',
3663 $min_warn, $min_crit, $max_warn, $max_crit;
8ce893fd 3664 }
669797e1 3665 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
3666 report('chassis', $msg, $err, $index);
3667 }
3668
3669 # Collect performance data
3670 if (defined $opt{perfdata}) {
434167a1 3671 my $pname = $location;
669797e1 3672 $pname =~ s{\s}{_}gxms;
4572cb76 3673 $pname =~ s{_temp\z}{}ixms;
669797e1 3674 $pname =~ s{proc_}{cpu#}xms;
48aeec0b 3675 push @perfdata, {
4572cb76 3676 type => 'T',
3677 id => $index,
3678 unit => $opt{tempunit},
3679 label => $pname,
3680 legacy => lc "temp_${index}_${pname}",
3681 mini => "t$index",
3682 value => $reading,
3683 warn => $max_warn,
3684 crit => $max_crit,
48aeec0b 3685 };
669797e1 3686 }
3687 }
3688 }
3689 return;
3690}
3691
3692
3693#-----------------------------------------
3694# CHASSIS: Check processors
3695#-----------------------------------------
3696sub check_processors {
3697 my $index = undef;
3698 my $status = undef;
3699 my $state = undef;
8ce893fd 3700 my $brand = undef;
3701 my $family = undef;
3702 my $man = undef;
3703 my $speed = undef;
8ce893fd 3704 my @output = ();
669797e1 3705
3706 if ($snmp) {
3707
3708 # NOTE: For some reason, older models don't have the
8ce893fd 3709 # "Processor Device Status" OIDs. We check both the newer
3710 # (preferred) OIDs and the old ones.
669797e1 3711
8ce893fd 3712 my %cpu_oid
669797e1 3713 = (
8ce893fd 3714 '1.3.6.1.4.1.674.10892.1.1100.30.1.2.1' => 'processorDeviceIndex',
3715 '1.3.6.1.4.1.674.10892.1.1100.30.1.5.1' => 'processorDeviceStatus',
3716 '1.3.6.1.4.1.674.10892.1.1100.30.1.8.1' => 'processorDeviceManufacturerName',
3717 '1.3.6.1.4.1.674.10892.1.1100.30.1.9.1' => 'processorDeviceStatusState',
3718 '1.3.6.1.4.1.674.10892.1.1100.30.1.10.1' => 'processorDeviceFamily',
3719 '1.3.6.1.4.1.674.10892.1.1100.30.1.12.1' => 'processorDeviceCurrentSpeed',
3720 '1.3.6.1.4.1.674.10892.1.1100.30.1.23.1' => 'processorDeviceBrandName',
3721 '1.3.6.1.4.1.674.10892.1.1100.32.1.2.1' => 'processorDeviceStatusIndex',
3722 '1.3.6.1.4.1.674.10892.1.1100.32.1.5.1' => 'processorDeviceStatusStatus',
3723 '1.3.6.1.4.1.674.10892.1.1100.32.1.6.1' => 'processorDeviceStatusReading',
669797e1 3724 );
4cabd748 3725 my $result = undef;
3726 if ($opt{use_get_table}) {
3727 my $processorDeviceTable = '1.3.6.1.4.1.674.10892.1.1100.30.1';
3728 my $processorDeviceStatusTable = '1.3.6.1.4.1.674.10892.1.1100.32.1';
669797e1 3729
c849fd4c 3730 $result = $snmp_session->get_table(-baseoid => $processorDeviceTable);
3731 my $ext = $snmp_session->get_table(-baseoid => $processorDeviceStatusTable);
4cabd748 3732
c849fd4c 3733 defined $ext && map { $$result{$_} = $$ext{$_} } keys %{ $ext };
4cabd748 3734 }
3735 else {
3736 $result = $snmp_session->get_entries(-columns => [keys %cpu_oid]);
3737 }
669797e1 3738
3739 if (!defined $result) {
98b224a3 3740 printf "SNMP ERROR [processors]: %s.\n", $snmp_session->error;
669797e1 3741 $snmp_session->close;
3742 exit $E_UNKNOWN;
3743 }
3744
8ce893fd 3745 @output = @{ get_snmp_output($result, \%cpu_oid) };
669797e1 3746 }
3747 else {
3748 @output = @{ run_omreport("$omopt_chassis processors") };
3749 }
3750
3751 my %cpu_state
3752 = (
3753 1 => 'Other', # other than following values
3754 2 => 'Unknown', # unknown
3755 3 => 'Enabled', # enabled
3756 4 => 'User Disabled', # disabled by user via BIOS setup
3757 5 => 'BIOS Disabled', # disabled by BIOS (POST error)
3758 6 => 'Idle', # idle
3759 );
3760
3761 my %cpu_reading
3762 = (
3763 1 => 'Internal Error', # Internal Error
3764 2 => 'Thermal Trip', # Thermal Trip
3765 32 => 'Configuration Error', # Configuration Error
3766 128 => 'Present', # Processor Present
3767 256 => 'Disabled', # Processor Disabled
3768 512 => 'Terminator Present', # Terminator Present
3769 1024 => 'Throttled', # Processor Throttled
3770 );
3771
8ce893fd 3772 # Mapping between family numbers from SNMP and actual CPU family
3773 my %cpu_family
3774 = (
b221393e 3775 1 => 'Other', 2 => 'Unknown',
3776 3 => '8086', 4 => '80286',
3777 5 => '386', 6 => '486',
3778 7 => '8087', 8 => '80287',
3779 9 => '80387', 10 => '80487',
3780 11 => 'Pentium', 12 => 'Pentium Pro',
3781 13 => 'Pentium II', 14 => 'Pentium with MMX',
3782 15 => 'Celeron', 16 => 'Pentium II Xeon',
3783 17 => 'Pentium III', 18 => 'Pentium III Xeon',
3784 19 => 'Pentium III', 20 => 'Itanium',
3785 21 => 'Xeon', 22 => 'Pentium 4',
3786 23 => 'Xeon MP', 24 => 'Itanium 2',
3787 25 => 'K5', 26 => 'K6',
3788 27 => 'K6-2', 28 => 'K6-3',
3789 29 => 'Athlon', 30 => 'AMD2900',
3790 31 => 'K6-2+', 32 => 'Power PC',
3791 33 => 'Power PC 601', 34 => 'Power PC 603',
3792 35 => 'Power PC 603+', 36 => 'Power PC 604',
3793 37 => 'Power PC 620', 38 => 'Power PC x704',
3794 39 => 'Power PC 750', 40 => 'Core Duo',
3795 41 => 'Core Duo mobile', 42 => 'Core Solo mobile',
3796 43 => 'Intel Atom', 44 => undef,
3797 45 => undef, 46 => undef,
3798 47 => undef, 48 => 'Alpha',
3799 49 => 'Alpha 21064', 50 => 'Alpha 21066',
3800 51 => 'Alpha 21164', 52 => 'Alpha 21164PC',
3801 53 => 'Alpha 21164a', 54 => 'Alpha 21264',
3802 55 => 'Alpha 21364', 56 => 'Turion II Ultra Dual-Core Mobile M',
3803 57 => 'Turion II Dual-Core Mobile M', 58 => 'Athlon II Dual-Core Mobile M ',
9cc9fcac 3804 59 => 'Opteron 6100', 60 => 'Opteron 4100',
b221393e 3805 61 => undef, 62 => undef,
3806 63 => undef, 64 => 'MIPS',
3807 65 => 'MIPS R4000', 66 => 'MIPS R4200',
3808 67 => 'MIPS R4400', 68 => 'MIPS R4600',
3809 69 => 'MIPS R10000', 70 => undef,
3810 71 => undef, 72 => undef,
3811 73 => undef, 74 => undef,
3812 75 => undef, 76 => undef,
3813 77 => undef, 78 => undef,
3814 79 => undef, 80 => 'SPARC',
3815 81 => 'SuperSPARC', 82 => 'microSPARC II',
3816 83 => 'microSPARC IIep', 84 => 'UltraSPARC',
3817 85 => 'UltraSPARC II', 86 => 'UltraSPARC IIi',
3818 87 => 'UltraSPARC III', 88 => 'UltraSPARC IIIi',
3819 89 => undef, 90 => undef,
3820 91 => undef, 92 => undef,
3821 93 => undef, 94 => undef,
3822 95 => undef, 96 => '68040',
3823 97 => '68xxx', 98 => '68000',
3824 99 => '68010', 100 => '68020',
3825 101 => '68030', 102 => undef,
3826 103 => undef, 104 => undef,
3827 105 => undef, 106 => undef,
3828 107 => undef, 108 => undef,
3829 109 => undef, 110 => undef,
3830 111 => undef, 112 => 'Hobbit',
3831 113 => undef, 114 => undef,
3832 115 => undef, 116 => undef,
3833 117 => undef, 118 => undef,
3834 119 => undef, 120 => 'Crusoe TM5000',
3835 121 => 'Crusoe TM3000', 122 => 'Efficeon TM8000',
3836 123 => undef, 124 => undef,
3837 125 => undef, 126 => undef,
3838 127 => undef, 128 => 'Weitek',
3839 129 => undef, 130 => 'Celeron M',
3840 131 => 'Athlon 64', 132 => 'Opteron',
3841 133 => 'Sempron', 134 => 'Turion 64 Mobile',
3842 135 => 'Dual-Core Opteron', 136 => 'Athlon 64 X2 DC',
3843 137 => 'Turion 64 X2 M', 138 => 'Quad-Core Opteron',
3844 139 => '3rd gen Opteron', 140 => 'AMD Phenom FX Quad-Core',
3845 141 => 'AMD Phenom X4 Quad-Core', 142 => 'AMD Phenom X2 Dual-Core',
3846 143 => 'AMD Athlon X2 Dual-Core', 144 => 'PA-RISC',
3847 145 => 'PA-RISC 8500', 146 => 'PA-RISC 8000',
3848 147 => 'PA-RISC 7300LC', 148 => 'PA-RISC 7200',
3849 149 => 'PA-RISC 7100LC', 150 => 'PA-RISC 7100',
3850 151 => undef, 152 => undef,
3851 153 => undef, 154 => undef,
3852 155 => undef, 156 => undef,
3853 157 => undef, 158 => undef,
3854 159 => undef, 160 => 'V30',
3855 161 => 'Quad-Core Xeon 3200', 162 => 'Dual-Core Xeon 3000',
3856 163 => 'Quad-Core Xeon 5300', 164 => 'Dual-Core Xeon 5100',
3857 165 => 'Dual-Core Xeon 5000', 166 => 'Dual-Core Xeon LV',
3858 167 => 'Dual-Core Xeon ULV', 168 => 'Dual-Core Xeon 7100',
3859 169 => 'Quad-Core Xeon 5400', 170 => 'Quad-Core Xeon',
3860 171 => 'Dual-Core Xeon 5200', 172 => 'Dual-Core Xeon 7200',
3861 173 => 'Quad-Core Xeon 7300', 174 => 'Quad-Core Xeon 7400',
3862 175 => 'Multi-Core Xeon 7400', 176 => 'M1',
3863 177 => 'M2', 178 => undef,
3864 179 => 'Pentium 4 HT', 180 => 'AS400',
3865 181 => undef, 182 => 'Athlon XP',
3866 183 => 'Athlon MP', 184 => 'Duron',
3867 185 => 'Pentium M', 186 => 'Celeron D',
3868 187 => 'Pentium D', 188 => 'Pentium Extreme',
3869 189 => 'Core Solo', 190 => 'Core2',
3870 191 => 'Core2 Duo', 192 => 'Core2 Solo',
3871 193 => 'Core2 Extreme', 194 => 'Core2 Quad',
3872 195 => 'Core2 Extreme mobile', 196 => 'Core2 Duo mobile',
3873 197 => 'Core2 Solo mobile', 198 => 'Core i7',
3874 199 => 'Dual-Core Celeron', 200 => 'IBM390',
3875 201 => 'G4', 202 => 'G5',
3876 203 => 'ESA/390 G6', 204 => 'z/Architectur',
9cc9fcac 3877 205 => 'Core i5', 206 => 'Core i3',
b221393e 3878 207 => undef, 208 => undef,
3879 209 => undef, 210 => 'C7-M',
3880 211 => 'C7-D', 212 => 'C7',
3881 213 => 'Eden', 214 => 'Multi-Core Xeon',
3882 215 => 'Dual-Core Xeon 3xxx', 216 => 'Quad-Core Xeon 3xxx',
9cc9fcac 3883 217 => 'VIA Nano', 218 => 'Dual-Core Xeon 5xxx',
b221393e 3884 219 => 'Quad-Core Xeon 5xxx', 220 => undef,
3885 221 => 'Dual-Core Xeon 7xxx', 222 => 'Quad-Core Xeon 7xxx',
9cc9fcac 3886 223 => 'Multi-Core Xeon 7xxx', 224 => 'Multi-Core Xeon 3400',
b221393e 3887 225 => undef, 226 => undef,
3888 227 => undef, 228 => undef,
3889 229 => undef, 230 => 'Embedded AMD Opteron Quad-Core',
3890 231 => 'AMD Phenom Triple-Core', 232 => 'AMD Turion Ultra Dual-Core Mobile',
3891 233 => 'AMD Turion Dual-Core Mobile', 234 => 'AMD Athlon Dual-Core',
3892 235 => 'AMD Sempron SI', 236 => 'AMD Phenom II',
3893 237 => 'AMD Athlon II', 238 => 'Six-Core AMD Opteron',
3894 239 => 'AMD Sempron M', 240 => undef,
3895 241 => undef, 242 => undef,
3896 243 => undef, 244 => undef,
3897 245 => undef, 246 => undef,
3898 247 => undef, 248 => undef,
3899 249 => undef, 250 => 'i860',
3900 251 => 'i960',
8ce893fd 3901 );
669797e1 3902
3903 CPU:
3904 foreach my $out (@output) {
3905 if ($snmp) {
8ce893fd 3906 $index = exists $out->{processorDeviceStatusIndex}
205488c0 3907 ? ($out->{processorDeviceStatusIndex} || 10000) - 1
3908 : ($out->{processorDeviceIndex} || 10000) - 1;
8ce893fd 3909 $status = exists $out->{processorDeviceStatusStatus}
b460a3d6 3910 ? get_snmp_status($out->{processorDeviceStatusStatus})
3911 : get_snmp_status($out->{processorDeviceStatus});
205488c0 3912 if (defined $out->{processorDeviceStatusReading}) {
669797e1 3913 my @states = (); # contains states for the CPU
669797e1 3914
3915 # get the combined state from the StatusReading OID
3916 foreach my $mask (sort keys %cpu_reading) {
3917 if (($out->{processorDeviceStatusReading} & $mask) != 0) {
3918 push @states, $cpu_reading{$mask};
3919 }
3920 }
3921
3922 # Finally, create the state string
3923 $state = join q{, }, @states;
3924 }
3925 else {
4a7c67f1 3926 $state = get_hashval($out->{processorDeviceStatusState}, \%cpu_state) || 'Unknown state';
669797e1 3927 }
205488c0 3928 $man = $out->{processorDeviceManufacturerName} || undef;
3929 $family = (defined $out->{processorDeviceFamily}
3930 and defined $cpu_family{$out->{processorDeviceFamily}})
04a878db 3931 ? $cpu_family{$out->{processorDeviceFamily}} : undef;
205488c0 3932 $speed = $out->{processorDeviceCurrentSpeed} || undef;
3933 $brand = $out->{processorDeviceBrandName} || undef;
669797e1 3934 }
3935 else {
205488c0 3936 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 3937 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 3938 $state = get_nonempty_string('State', $out, 'Unknown state');
3939 $brand = get_nonempty_string('Processor Brand', $out, undef);
3940 $family = get_nonempty_string('Processor Family', $out, undef);
3941 $man = get_nonempty_string('Processor Manufacturer', $out, undef);
3942 $speed = get_nonempty_string('Current Speed', $out, undef);
669797e1 3943 }
3944
669797e1 3945 # Ignore unoccupied CPU slots (omreport)
3946 next CPU if (defined $out->{'Processor Manufacturer'}
3947 and $out->{'Processor Manufacturer'} eq '[Not Occupied]')
3948 or (defined $out->{'Processor Brand'} and $out->{'Processor Brand'} eq '[Not Occupied]');
3949
3950 # Ignore unoccupied CPU slots (snmp)
205488c0 3951 if ($snmp and defined $out->{processorDeviceStatusReading}
669797e1 3952 and $out->{processorDeviceStatusReading} == 0) {
3953 next CPU;
3954 }
3955
3956 $count{cpu}++;
35a7e76e 3957 next CPU if blacklisted('cpu', $index);
669797e1 3958
8ce893fd 3959 if (defined $brand) {
3960 $brand =~ s{\s\s+}{ }gxms;
e7dc67d0 3961 $brand =~ s{\((R|tm)\)}{}gxms;
3962 $brand =~ s{\s(CPU|Processor)}{}xms;
8ce893fd 3963 $brand =~ s{\s\@}{}xms;
3964 }
3965 elsif (defined $family and defined $man and defined $speed) {
3966 $speed =~ s{\A (\d+) .*}{$1}xms;
49bf41a5 3967 $brand = sprintf '%s %s %.2fGHz', $man, $family, $speed / 1000;
8ce893fd 3968 }
3969 else {
3970 $brand = "unknown";
3971 }
3972
669797e1 3973 # Default
ef3b5f84
THA
3974 my $msg = sprintf 'Processor %d [%s] is %s',
3975 $index, $brand, $state;
3976 report('chassis', $msg, $status2nagios{$status}, $index);
669797e1 3977 }
3978 return;
3979}
3980
3981
3982#-----------------------------------------
3983# CHASSIS: Check voltage probes
3984#-----------------------------------------
3985sub check_volts {
3986 my $index = undef;
3987 my $status = undef;
3988 my $reading = undef;
3989 my $location = undef;
434167a1 3990 my $max_crit = undef;
3991 my $max_warn = undef;
669797e1 3992 my @output = ();
3993
3994 if ($snmp) {
3995 my %volt_oid
3996 = (
3997 '1.3.6.1.4.1.674.10892.1.600.20.1.2.1' => 'voltageProbeIndex',
3998 '1.3.6.1.4.1.674.10892.1.600.20.1.5.1' => 'voltageProbeStatus',
3999 '1.3.6.1.4.1.674.10892.1.600.20.1.6.1' => 'voltageProbeReading',
4000 '1.3.6.1.4.1.674.10892.1.600.20.1.8.1' => 'voltageProbeLocationName',
4001 '1.3.6.1.4.1.674.10892.1.600.20.1.16.1' => 'voltageProbeDiscreteReading',
4002 );
ba199ee0 4003
4004 my $voltageProbeTable = '1.3.6.1.4.1.674.10892.1.600.20.1';
4005 my $result = $snmp_session->get_table(-baseoid => $voltageProbeTable);
669797e1 4006
4007 if (!defined $result) {
98b224a3 4008 printf "SNMP ERROR [voltage]: %s.\n", $snmp_session->error;
669797e1 4009 $snmp_session->close;
4010 exit $E_UNKNOWN;
4011 }
4012
4013 @output = @{ get_snmp_output($result, \%volt_oid) };
4014 }
4015 else {
4016 @output = @{ run_omreport("$omopt_chassis volts") };
4017 }
4018
4019 my %volt_discrete_reading
4020 = (
4021 1 => 'Good',
4022 2 => 'Bad',
4023 );
4024
4025 VOLT:
4026 foreach my $out (@output) {
4027 if ($snmp) {
205488c0 4028 $index = ($out->{voltageProbeIndex} || 10000) - 1;
e7fd8bc9 4029 $status = get_snmp_probestatus($out->{voltageProbeStatus});
205488c0 4030 $reading = defined $out->{voltageProbeReading}
669797e1 4031 ? sprintf('%.3f V', $out->{voltageProbeReading}/1000)
bd3ec1c2 4032 : (get_hashval($out->{voltageProbeDiscreteReading}, \%volt_discrete_reading) || 'Unknown reading');
205488c0 4033 $location = $out->{voltageProbeLocationName} || 'Unknown location';
434167a1 4034 $max_crit = $out->{voltageProbeUpperCriticalThreshold} || 0;
4035 $max_warn = $out->{voltageProbeUpperNonCriticalThreshold} || 0;
669797e1 4036 }
4037 else {
205488c0 4038 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 4039 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 4040 $reading = get_nonempty_string('Reading', $out, 'Unknown reading');
4041 $location = get_nonempty_string('Probe Name', $out, 'Unknown location');
434167a1 4042 $max_crit = get_nonempty_string('Maximum Failure Threshold', $out, 0);
4043 $max_warn = get_nonempty_string('Maximum Warning Threshold', $out, 0);
4044
4045 $max_crit = 0 if $max_crit eq '[N/A]';
4046 $max_warn = 0 if $max_warn eq '[N/A]';
669797e1 4047 }
4048
669797e1 4049 $count{volt}++;
35a7e76e 4050 next VOLT if blacklisted('volt', $index);
669797e1 4051
95e121fe
THA
4052 # remove trailing zeroes (if reading is an integer)
4053 $reading =~ s{\A (\d+)\.000\sV \z}{$1 V}xms;
4054
4055 my $msg = undef;
4056 if ($reading =~ m{\A \d+(:?\.\d+)?\sV \z}xms) {
4057 # number reading
4058 $msg = sprintf 'Voltage sensor %d [%s] reads %s',
4059 $index, $location, $reading;
4060 }
4061 else {
4062 # discrete reading
4063 $msg = sprintf 'Voltage sensor %d [%s] is %s',
4064 $index, $location, $reading;
4065 }
669797e1 4066 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
4067 report('chassis', $msg, $err, $index);
434167a1 4068
4069 # Collect performance data
4572cb76 4070 if (defined $opt{perfdata} and !$opt{legacy_perfdata}) {
434167a1 4071 $reading =~ s{\s+V\z}{}xms; # remove unit
4072 $reading =~ s{\.000\z}{}xms; # if integer
4073 next VOLT if $reading !~ m{\A \d+(\.\d+)? \z}xms; # discrete reading (not number)
4074 my $label = join q{_}, $location;
4075 $label =~ s{\s}{_}gxms;
4076 push @perfdata, {
4572cb76 4077 type => 'V',
4078 id => $index,
4079 unit => 'V',
4080 label => $label,
4081 value => $reading,
4082 warn => 0,
4083 crit => 0,
434167a1 4084 };
4085 }
669797e1 4086 }
4087 return;
4088}
4089
4090
4091#-----------------------------------------
4092# CHASSIS: Check batteries
4093#-----------------------------------------
4094sub check_batteries {
4095 my $index = undef;
4096 my $status = undef;
4097 my $reading = undef;
4098 my $location = undef;
4099 my @output = ();
4100
4101 if ($snmp) {
4102 my %bat_oid
4103 = (
4104 '1.3.6.1.4.1.674.10892.1.600.50.1.2.1' => 'batteryIndex',
4105 '1.3.6.1.4.1.674.10892.1.600.50.1.5.1' => 'batteryStatus',
4106 '1.3.6.1.4.1.674.10892.1.600.50.1.6.1' => 'batteryReading',
4107 '1.3.6.1.4.1.674.10892.1.600.50.1.7.1' => 'batteryLocationName',
4108 );
4cabd748 4109 my $result = undef;
4110 if ($opt{use_get_table}) {
4111 my $batteryTable = '1.3.6.1.4.1.674.10892.1.600.50.1';
4112 $result = $snmp_session->get_table(-baseoid => $batteryTable);
4113 }
4114 else {
4115 $result = $snmp_session->get_entries(-columns => [keys %bat_oid]);
4116 }
669797e1 4117
4118 # No batteries is OK
4119 return 0 if !defined $result;
4120
4121 @output = @{ get_snmp_output($result, \%bat_oid) };
4122 }
4123 else {
4124 @output = @{ run_omreport("$omopt_chassis batteries") };
4125 }
4126
4127 my %bat_reading
4128 = (
4129 1 => 'Predictive Failure',
4130 2 => 'Failed',
4131 4 => 'Presence Detected',
4132 );
4133
4134 BATTERY:
4135 foreach my $out (@output) {
4136 if ($snmp) {
205488c0 4137 $index = ($out->{batteryIndex} || 10000) - 1;
b460a3d6 4138 $status = get_snmp_status($out->{batteryStatus});
4a7c67f1 4139 $reading = get_hashval($out->{batteryReading}, \%bat_reading) || 'Unknown reading';
205488c0 4140 $location = $out->{batteryLocationName} || 'Unknown location';
669797e1 4141 }
4142 else {
205488c0 4143 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 4144 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 4145 $reading = get_nonempty_string('Reading', $out, 'Unknown reading');
4146 $location = get_nonempty_string('Probe Name', $out, 'Unknown location');
669797e1 4147 }
4148
669797e1 4149 $count{bat}++;
35a7e76e 4150 next BATTERY if blacklisted('bp', $index);
669797e1 4151
98b224a3 4152 my $msg = sprintf 'Battery probe %d [%s] is %s',
669797e1 4153 $index, $location, $reading;
4154 report('chassis', $msg, $status2nagios{$status}, $index);
4155 }
4156 return;
4157}
4158
4159
4160#-----------------------------------------
4161# CHASSIS: Check amperage probes (power monitoring)
4162#-----------------------------------------
4163sub check_pwrmonitoring {
4164 my $index = undef;
4165 my $status = undef;
4166 my $reading = undef;
4167 my $location = undef;
4168 my $max_crit = undef;
4169 my $max_warn = undef;
4170 my $unit = undef;
3af78850 4171 my $type = undef;
669797e1 4172 my @output = ();
4173
4174 if ($snmp) {
4175 my %amp_oid
4176 = (
4177 '1.3.6.1.4.1.674.10892.1.600.30.1.2.1' => 'amperageProbeIndex',
4178 '1.3.6.1.4.1.674.10892.1.600.30.1.5.1' => 'amperageProbeStatus',
4179 '1.3.6.1.4.1.674.10892.1.600.30.1.6.1' => 'amperageProbeReading',
4180 '1.3.6.1.4.1.674.10892.1.600.30.1.7.1' => 'amperageProbeType',
4181 '1.3.6.1.4.1.674.10892.1.600.30.1.8.1' => 'amperageProbeLocationName',
4182 '1.3.6.1.4.1.674.10892.1.600.30.1.10.1' => 'amperageProbeUpperCriticalThreshold',
4183 '1.3.6.1.4.1.674.10892.1.600.30.1.11.1' => 'amperageProbeUpperNonCriticalThreshold',
4184 '1.3.6.1.4.1.674.10892.1.600.30.1.16.1' => 'amperageProbeDiscreteReading',
4185 );
4cabd748 4186 my $result = undef;
4187 if ($opt{use_get_table}) {
4188 my $amperageProbeTable = '1.3.6.1.4.1.674.10892.1.600.30.1';
4189 $result = $snmp_session->get_table(-baseoid => $amperageProbeTable);
4190 }
4191 else {
4192 $result = $snmp_session->get_entries(-columns => [keys %amp_oid]);
4193 }
669797e1 4194
4195 # No pwrmonitoring is OK
4196 return 0 if !defined $result;
4197
4198 @output = @{ get_snmp_output($result, \%amp_oid) };
4199 }
4200 else {
4201 @output = @{ run_omreport("$omopt_chassis pwrmonitoring") };
4202 }
4203
4204 my %amp_type # Amperage probe types
4205 = (
4206 1 => 'amperageProbeTypeIsOther', # other than following values
4207 2 => 'amperageProbeTypeIsUnknown', # unknown
4208 3 => 'amperageProbeTypeIs1Point5Volt', # 1.5 amperage probe
4209 4 => 'amperageProbeTypeIs3Point3volt', # 3.3 amperage probe
4210 5 => 'amperageProbeTypeIs5Volt', # 5 amperage probe
4211 6 => 'amperageProbeTypeIsMinus5Volt', # -5 amperage probe
4212 7 => 'amperageProbeTypeIs12Volt', # 12 amperage probe
4213 8 => 'amperageProbeTypeIsMinus12Volt', # -12 amperage probe
4214 9 => 'amperageProbeTypeIsIO', # I/O probe
4215 10 => 'amperageProbeTypeIsCore', # Core probe
4216 11 => 'amperageProbeTypeIsFLEA', # FLEA (standby) probe
4217 12 => 'amperageProbeTypeIsBattery', # Battery probe
4218 13 => 'amperageProbeTypeIsTerminator', # SCSI Termination probe
4219 14 => 'amperageProbeTypeIs2Point5Volt', # 2.5 amperage probe
4220 15 => 'amperageProbeTypeIsGTL', # GTL (ground termination logic) probe
4221 16 => 'amperageProbeTypeIsDiscrete', # amperage probe with discrete reading
4222 23 => 'amperageProbeTypeIsPowerSupplyAmps', # Power Supply probe with reading in Amps
4223 24 => 'amperageProbeTypeIsPowerSupplyWatts', # Power Supply probe with reading in Watts
4224 25 => 'amperageProbeTypeIsSystemAmps', # System probe with reading in Amps
4225 26 => 'amperageProbeTypeIsSystemWatts', # System probe with reading in Watts
4226 );
4227
4228 my %amp_discrete
4229 = (
4230 1 => 'Good',
4231 2 => 'Bad',
4232 );
4233
4234 my %amp_unit
4235 = (
4236 'amperageProbeTypeIsPowerSupplyAmps' => 'hA', # tenths of Amps
4237 'amperageProbeTypeIsSystemAmps' => 'hA', # tenths of Amps
4238 'amperageProbeTypeIsPowerSupplyWatts' => 'W', # Watts
4239 'amperageProbeTypeIsSystemWatts' => 'W', # Watts
4240 'amperageProbeTypeIsDiscrete' => q{}, # discrete reading, no unit
4241 );
4242
4243 AMP:
4244 foreach my $out (@output) {
4245 if ($snmp) {
205488c0 4246 $index = ($out->{amperageProbeIndex} || 10000) - 1;
e7fd8bc9 4247 $status = get_snmp_probestatus($out->{amperageProbeStatus});
3af78850 4248 $type = get_hashval($out->{amperageProbeType}, \%amp_type);
4249 $reading = $type eq 'amperageProbeTypeIsDiscrete'
912d8679 4250 ? get_hashval($out->{amperageProbeDiscreteReading}, \%amp_discrete)
205488c0 4251 : ($out->{amperageProbeReading} || 0);
4252 $location = $out->{amperageProbeLocationName} || 'Unknown location';
4253 $max_crit = $out->{amperageProbeUpperCriticalThreshold} || 0;
4254 $max_warn = $out->{amperageProbeUpperNonCriticalThreshold} || 0;
669797e1 4255 $unit = exists $amp_unit{$amp_type{$out->{amperageProbeType}}}
4256 ? $amp_unit{$amp_type{$out->{amperageProbeType}}} : 'mA';
3af78850 4257
3af78850 4258 # calculate proper values and set unit for ampere probes
4259 if ($unit eq 'hA' and $type ne 'amperageProbeTypeIsDiscrete') {
669797e1 4260 $reading /= 10;
4261 $max_crit /= 10;
4262 $max_warn /= 10;
4263 $unit = 'A';
4264 }
2b3b3776 4265 if ($unit eq 'mA' and $type ne 'amperageProbeTypeIsDiscrete') {
4266 $reading /= 1000;
4267 $max_crit /= 1000;
4268 $max_warn /= 1000;
4269 $unit = 'A';
4270 }
669797e1 4271 }
4272 else {
205488c0 4273 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 4274 $status = get_nonempty_string('Status', $out, 'Unknown');
205488c0 4275 $reading = get_nonempty_string('Reading', $out, 'Unknown reading');
4276 $location = get_nonempty_string('Probe Name', $out, 'Unknown location');
4277 $max_crit = get_nonempty_string('Failure Threshold', $out, 0);
4278 $max_warn = get_nonempty_string('Warning Threshold', $out, 0);
4279
4280 $max_crit = 0 if $max_crit eq '[N/A]';
4281 $max_warn = 0 if $max_warn eq '[N/A]';
4282
669797e1 4283 $reading =~ s{\A (\d+.*?)\s+([a-zA-Z]+) \s*\z}{$1}xms;
205488c0 4284 $unit = $2 || 'unknown';
669797e1 4285 $max_warn =~ s{\A (\d+.*?)\s+[a-zA-Z]+ \s*\z}{$1}xms;
4286 $max_crit =~ s{\A (\d+.*?)\s+[a-zA-Z]+ \s*\z}{$1}xms;
4287 }
4288
669797e1 4289 next AMP if $index !~ m{\A \d+ \z}xms;
027ee49c 4290
4291 # Special case: Probe is present but unknown. This happens via
4292 # SNMP on some systems where power monitoring capability is
4293 # disabled due to non-redundant and/or non-instrumented power
4294 # supplies.
4295 # E.g. R410 with newer BMC firmware and 1 power supply
aa309c5e 4296 if ($snmp && $status eq 'Unknown' && $reading == 0) {
027ee49c 4297 next AMP;
4298 }
4299
669797e1 4300 $count{amp}++;
35a7e76e 4301 next AMP if blacklisted('amp', $index);
669797e1 4302
027ee49c 4303 # Special case: Discrete reading
6a9a6fd1 4304 if (defined $type and $type eq 'amperageProbeTypeIsDiscrete') {
e8413daf 4305 my $msg = sprintf 'Amperage probe %d [%s] is %s',
4306 $index, $location, $reading;
66033e76 4307 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
4308 report('chassis', $msg, $err, $index);
e8413daf 4309 }
027ee49c 4310 # Default
e8413daf 4311 else {
4312 my $msg = sprintf 'Amperage probe %d [%s] reads %s %s',
4313 $index, $location, $reading, $unit;
66033e76 4314 my $err = $snmp ? $probestatus2nagios{$status} : $status2nagios{$status};
4315 report('chassis', $msg, $err, $index);
e8413daf 4316 }
669797e1 4317
4318 # Collect performance data
4319 if (defined $opt{perfdata}) {
4320 next AMP if $reading !~ m{\A \d+(\.\d+)? \z}xms; # discrete reading (not number)
434167a1 4321 my $label = join q{_}, $location;
48aeec0b 4322 $label =~ s{\s}{_}gxms;
4323 push @perfdata, {
4572cb76 4324 type => $unit,
4325 id => $index,
4326 unit => $unit,
4327 label => $label,
4328 legacy => (join q{_}, 'pwr_mon', $index, lc $label),
4329 mini => "p${index}" . lc $unit,
4330 value => $reading,
4331 warn => $max_warn,
4332 crit => $max_crit,
48aeec0b 4333 };
669797e1 4334 }
4335 }
4336
4337 # Collect EXTRA performance data not found at first run. This is a
4338 # rather ugly hack
4339 if (defined $opt{perfdata} && !$snmp) {
4340 my $found = 0;
4341 my $index = 0;
4342 my %used = ();
4343
4344 # find used indexes
48aeec0b 4345 foreach (@perfdata) {
434167a1 4346 if ($_->{label} =~ m/\A [WA](\d+)/xms) {
669797e1 4347 $used{$1} = 1;
4348 }
4349 }
4350
4351 AMP2:
4352 foreach my $line (@{ run_command("$omreport $omopt_chassis pwrmonitoring -fmt ssv") }) {
4353 chop $line;
130fd877 4354 if ($line eq 'Location;Reading' or $line eq 'Amperage') {
669797e1 4355 $found = 1;
4356 next AMP2;
4357 }
4358 if ($line eq q{}) {
4359 $found = 0;
4360 next AMP2;
4361 }
6f79fb81 4362 if ($found and $line =~ m/\A ([^;]+?) ; (\d*\.\d+) \s ([AW]) \z/xms) {
2919d5f8 4363 my $aname = $1;
6f79fb81 4364 my $aval = $2;
4365 my $aunit = $3;
669797e1 4366 $aname =~ s{\s}{_}gxms;
4367
4368 # don't use an existing index
4369 while (exists $used{$index}) { ++$index; }
4370
48aeec0b 4371 push @perfdata, {
4572cb76 4372 type => $aunit,
4373 id => $index,
4374 unit => $aunit,
4375 label => $aname,
4376 legacy => "pwr_mon_${index}_${aname}",
4377 mini => "p${index}a",
4378 value => $aval,
4379 warn => 0,
4380 crit => 0,
48aeec0b 4381 };
669797e1 4382 ++$index;
4383 }
4384 }
4385 }
4386
4387 return;
4388}
4389
4390
4391#-----------------------------------------
4392# CHASSIS: Check intrusion
4393#-----------------------------------------
4394sub check_intrusion {
4395 my $index = undef;
4396 my $status = undef;
4397 my $reading = undef;
4398 my @output = ();
4399
4400 if ($snmp) {
4401 my %int_oid
4402 = (
4403 '1.3.6.1.4.1.674.10892.1.300.70.1.2.1' => 'intrusionIndex',
4404 '1.3.6.1.4.1.674.10892.1.300.70.1.5.1' => 'intrusionStatus',
4405 '1.3.6.1.4.1.674.10892.1.300.70.1.6.1' => 'intrusionReading',
4406 );
4cabd748 4407 my $result = undef;
4408 if ($opt{use_get_table}) {
4409 my $intrusionTable = '1.3.6.1.4.1.674.10892.1.300.70.1';
4410 $result = $snmp_session->get_table(-baseoid => $intrusionTable);
4411 }
4412 else {
4413 $result = $snmp_session->get_entries(-columns => [keys %int_oid]);
4414 }
669797e1 4415
4416 # No intrusion is OK
4417 return 0 if !defined $result;
4418
4419 @output = @{ get_snmp_output($result, \%int_oid) };
4420 }
4421 else {
4422 @output = @{ run_omreport("$omopt_chassis intrusion") };
4423 }
4424
4425 my %int_reading
4426 = (
4427 1 => 'Not Breached', # chassis not breached and no uncleared breaches
4428 2 => 'Breached', # chassis currently breached
4429 3 => 'Breached Prior', # chassis breached prior to boot and has not been cleared
4430 4 => 'Breach Sensor Failure', # intrusion sensor has failed
4431 );
4432
4433 INTRUSION:
4434 foreach my $out (@output) {
4435 if ($snmp) {
205488c0 4436 $index = ($out->{intrusionIndex} || 10000) - 1;
b460a3d6 4437 $status = get_snmp_status($out->{intrusionStatus});
4a7c67f1 4438 $reading = get_hashval($out->{intrusionReading}, \%int_reading) || 'Unknown reading';
669797e1 4439 }
4440 else {
205488c0 4441 $index = get_nonempty_string('Index', $out, 9999);
0eed03e9 4442 $status = get_nonempty_string('Status', $out, 'Unknown');
4a7c67f1 4443 $reading = get_nonempty_string('State', $out, 'Unknown reading');
669797e1 4444 }
4445
669797e1 4446 $count{intr}++;
35a7e76e 4447 next INTRUSION if blacklisted('intr', $index);
669797e1 4448
4449 if ($status ne 'Ok') {
4450 my $msg = sprintf 'Chassis intrusion %d detected: %s',
4451 $index, $reading;
4452 report('chassis', $msg, $E_WARNING, $index);
4453 }
4454 # Ok
4455 else {
4456 my $msg = sprintf 'Chassis intrusion %d detection: %s (%s)',
4457 $index, $status, $reading;
4458 report('chassis', $msg, $E_OK, $index);
4459 }
4460 }
4461 return;
4462}
4463
4464
40619bb3 4465#-----------------------------------------
4466# CHASSIS: Check SD Card Device
4467#-----------------------------------------
4468sub check_sdcard {
40619bb3 4469 my $index = undef;
4470 my $status = undef;
4471 my $state = undef;
4472 my $location = undef;
4473 my $capacity = undef;
4474 my $setting = undef;
4475 my @output = ();
4476
4477 if ($snmp) {
4478 my %sd_oid
4479 = (
4480 '1.3.6.1.4.1.674.10892.1.1100.112.1.2.1' => 'sdCardDeviceIndex',
4481 '1.3.6.1.4.1.674.10892.1.1100.112.1.3.1' => 'sdCardDeviceStatus',
4482 '1.3.6.1.4.1.674.10892.1.1100.112.1.4.1' => 'sdCardDeviceType',
4483 '1.3.6.1.4.1.674.10892.1.1100.112.1.7.1' => 'sdCardDeviceLocationName',
4484 '1.3.6.1.4.1.674.10892.1.1100.112.1.8.1' => 'sdCardDeviceCardPresent',
4485 '1.3.6.1.4.1.674.10892.1.1100.112.1.9.1' => 'sdCardDeviceCardState',
4486 '1.3.6.1.4.1.674.10892.1.1100.112.1.10.1' => 'sdCardDeviceCardStorageSize',
4487 );
4488 my $result = undef;
4489 if ($opt{use_get_table}) {
4490 my $sdCardDeviceTable = '1.3.6.1.4.1.674.10892.1.1100.112.1';
4491 $result = $snmp_session->get_table(-baseoid => $sdCardDeviceTable);
4492 }
4493 else {
4494 $result = $snmp_session->get_entries(-columns => [keys %sd_oid]);
4495 }
4496
4497 # No SD cards is OK
4498 return 0 if !defined $result;
4499
4500 @output = @{ get_snmp_output($result, \%sd_oid) };
4501 }
4502 else {
4503 @output = @{ run_omreport("$omopt_chassis removableflashmedia") };
4504 }
4505
4506 # Note: These values are bit fields, so combination values are possible.
4507 my %sd_state
4508 = (
4509 0 => 'None', # state is none of the following:
4510 1 => 'Present', # device is present
4511 2 => 'IPMI-ready', # device is IPMI ready
4512 4 => 'Full-ready', # device is full ready
4513 8 => 'Offline', # device is offline
4514 16 => 'Failed', # device is failed
4515 32 => 'Active', # device is active
4516 64 => 'Bootable', # device is bootable
4517 128 => 'Write-protected', # device is write-protected
4518 256 => 'Standby', # device is in standby mode
4519 );
4520
4521 my $c = 0;
4522 SDCARD:
4523 foreach my $out (@output) {
4524 if ($snmp) {
205488c0 4525 $index = ($out->{sdCardDeviceIndex} || 10000) - 1;
b460a3d6 4526 $status = get_snmp_status($out->{sdCardDeviceStatus});
40619bb3 4527
205488c0 4528 if (defined $out->{sdCardDeviceCardState}) {
40619bb3 4529 my @states = (); # contains states SD card
4530
4531 # get the combined state from the Device Status OID
4532 foreach my $mask (sort keys %sd_state) {
4533 if (($out->{sdCardDeviceCardState} & $mask) != 0) {
4534 push @states, $sd_state{$mask};
4535 }
4536 }
4537
4538 # Finally, create the state string
4539 $state = join q{, }, @states;
4540
4541 # special case: absent
4542 if ($out->{sdCardDeviceCardState} % 2 == 0) {
4543 $state = 'Absent';
4544 }
4545 }
4546
205488c0 4547 $location = $out->{sdCardDeviceLocationName} || 'Unknown location';
4548 $capacity = sprintf '%s MB', ($out->{sdCardDeviceCardStorageSize} || 'Unknown size');
40619bb3 4549 }
4550 else {
4551 $index = $c++;
0eed03e9 4552 $status = get_nonempty_string('Status', $out, 'Ok');
205488c0 4553 $state = get_nonempty_string('State', $out, 'Unknown state');
4554 $location = get_nonempty_string('Connector Name', $out, 'Unknown location');
4555 $capacity = get_nonempty_string('Storage Size', $out, 'Unknown size');
4556
4557 $capacity =~ s{\[Not Available\]}{Unknown Size};
40619bb3 4558 }
4559
e62ffb8b 4560 $count{sd}++ if $state ne 'Absent';
35a7e76e 4561 next SDCARD if blacklisted('sd', $index);
40619bb3 4562
4563 if ($status ne 'Ok') {
ef3b5f84 4564 my $msg = sprintf 'SD Card %d is %s',
40619bb3 4565 $index, $state;
4566 report('chassis', $msg, $E_WARNING, $index);
4567 }
4568 # Special case: Not Present
4569 elsif ($status eq 'Ok' and $state eq 'Absent') {
4570 my $msg = sprintf 'SD Card %d [%s] is %s',
4571 $index, $location, $state;
4572 report('chassis', $msg, $E_OK, $index);
4573 }
4574 # Ok
4575 else {
4576 my $msg = sprintf 'SD Card %d [%s, %s] is %s',
4577 $index, $location, $capacity, $state;
4578 report('chassis', $msg, $E_OK, $index);
4579 }
4580 }
4581 return;
4582}
4583
4584
669797e1 4585#-----------------------------------------
4586# CHASSIS: Check alert log
4587#-----------------------------------------
4588sub check_alertlog {
4589 return if $snmp; # Not supported with SNMP
4590
4591 my @output = @{ run_omreport("$omopt_system alertlog") };
4592 foreach my $out (@output) {
4593 ++$count{alert}{$out->{Severity}};
4594 }
4595
4596 # Create error messages and set exit value if appropriate
4597 my $err = 0;
4598 if ($count{alert}{'Critical'} > 0) { $err = $E_CRITICAL; }
4599 elsif ($count{alert}{'Non-Critical'} > 0) { $err = $E_WARNING; }
4600
4601 my $msg = sprintf 'Alert log content: %d critical, %d non-critical, %d ok',
4602 $count{alert}{'Critical'}, $count{alert}{'Non-Critical'}, $count{alert}{'Ok'};
4603 report('other', $msg, $err);
4604
4605 return;
4606}
4607
4608#-----------------------------------------
4609# CHASSIS: Check ESM log overall health
4610#-----------------------------------------
4611sub check_esmlog_health {
4612 my $health = 'Ok';
4613
4614 if ($snmp) {
4615 my $systemStateEventLogStatus = '1.3.6.1.4.1.674.10892.1.200.10.1.41.1';
4616 my $result = $snmp_session->get_request(-varbindlist => [$systemStateEventLogStatus]);
4617 if (!defined $result) {
98b224a3 4618 my $msg = sprintf 'SNMP ERROR [esmhealth]: %s',
669797e1 4619 $snmp_session->error;
4620 report('other', $msg, $E_UNKNOWN);
4621 }
b460a3d6 4622 $health = get_snmp_status($result->{$systemStateEventLogStatus});
669797e1 4623 }
4624 else {
4625 foreach (@{ run_command("$omreport $omopt_system esmlog -fmt ssv") }) {
4626 if (m/\A Health;(.+) \z/xms) {
4627 $health = $1;
4628 chop $health;
4629 last;
4630 }
4631 }
4632 }
4633
4634 # If the overall health of the ESM log is other than "Ok", the
4635 # fill grade of the log is more than 80% and the log should be
4636 # cleared
4637 if ($health eq 'Ok') {
af7c7f76 4638 my $msg = sprintf 'ESM log health is Ok (less than 80%% full)';
669797e1 4639 report('other', $msg, $E_OK);
4640 }
4641 elsif ($health eq 'Critical') {
328d0a74 4642 my $msg = sprintf 'ESM log is 100%% full';
669797e1 4643 report('other', $msg, $status2nagios{$health});
4644 }
4645 else {
4646 my $msg = sprintf 'ESM log is more than 80%% full';
4647 report('other', $msg, $status2nagios{$health});
4648 }
4649
4650 return;
4651}
4652
4653#-----------------------------------------
4654# CHASSIS: Check ESM log
4655#-----------------------------------------
4656sub check_esmlog {
4657 my @output = ();
4658
4659 if ($snmp) {
4660 my %esm_oid
4661 = (
4662 '1.3.6.1.4.1.674.10892.1.300.40.1.7.1' => 'eventLogSeverityStatus',
4663 );
4664 my $result = $snmp_session->get_entries(-columns => [keys %esm_oid]);
4665
4666 # No entries is OK
4667 return if !defined $result;
4668
4669 @output = @{ get_snmp_output($result, \%esm_oid) };
4670 foreach my $out (@output) {
4671 ++$count{esm}{$snmp_status{$out->{eventLogSeverityStatus}}};
4672 }
4673 }
4674 else {
4675 @output = @{ run_omreport("$omopt_system esmlog") };
4676 foreach my $out (@output) {
4677 ++$count{esm}{$out->{Severity}};
4678 }
4679 }
4680
4681 # Create error messages and set exit value if appropriate
4682 my $err = 0;
4683 if ($count{esm}{'Critical'} > 0) { $err = $E_CRITICAL; }
4684 elsif ($count{esm}{'Non-Critical'} > 0) { $err = $E_WARNING; }
4685
4686 my $msg = sprintf 'ESM log content: %d critical, %d non-critical, %d ok',
4687 $count{esm}{'Critical'}, $count{esm}{'Non-Critical'}, $count{esm}{'Ok'};
4688 report('other', $msg, $err);
4689
4690 return;
4691}
4692
7dd03e89 4693#-----------------------------------------
4694# CHASSIS: Check service tag
4695#-----------------------------------------
4696sub check_servicetag {
4697 if ($sysinfo{serial} !~ m{\A [0-9A-Z]{7} \z}xms) {
0408244c 4698 my $msg = $sysinfo{serial} =~ m{\A \s* \z}xms
66b80295 4699 ? q{Chassis Service Tag is empty}
4700 : sprintf q{Chassis Service Tag is bogus: '%s'}, $sysinfo{serial};
7dd03e89 4701 report('other', $msg, $E_WARNING);
4702 }
4703 else {
4704 my $msg = sprintf 'Chassis Service Tag is sane';
4705 report('other', $msg, $E_OK);
4706 }
4707 return;
4708}
4709
4710
669797e1 4711#
4712# Handy function for checking all storage components
4713#
4714sub check_storage {
4715 check_controllers();
4716 check_physical_disks();
4717 check_virtual_disks();
4718 check_cache_battery();
4719 check_connectors();
4720 check_enclosures();
4721 check_enclosure_fans();
4722 check_enclosure_pwr();
4723 check_enclosure_temp();
4724 check_enclosure_emms();
4725 return;
4726}
4727
4728
4729
4730#---------------------------------------------------------------------
4731# Info functions
4732#---------------------------------------------------------------------
4733
4734#
4735# Fetch output from 'omreport chassis info', put in sysinfo hash
4736#
4737sub get_omreport_chassis_info {
4738 if (open my $INFO, '-|', "$omreport $omopt_chassis info -fmt ssv") {
4739 my @lines = <$INFO>;
4740 close $INFO;
4741 foreach (@lines) {
14ec7014 4742 next if !m/\A (Chassis\sModel|Chassis\sService\sTag|Model|Service\sTag|System\sRevision)/xms;
669797e1 4743 my ($key, $val) = split /;/xms;
4744 $key =~ s{\s+\z}{}xms; # remove trailing whitespace
4745 $val =~ s{\s+\z}{}xms; # remove trailing whitespace
4746 if ($key eq 'Chassis Model' or $key eq 'Model') {
4747 $sysinfo{model} = $val;
4748 }
4749 if ($key eq 'Chassis Service Tag' or $key eq 'Service Tag') {
28738b53 4750 $sysinfo{serial} = $opt{hide_servicetag} ? 'XXXXXXX' : $val;
669797e1 4751 }
62cd5524 4752 if ($key eq 'System Revision') {
51449135 4753 $sysinfo{rev} = q{ } . $val;
62cd5524 4754 }
669797e1 4755 }
4756 }
4757 return;
4758}
4759
4760#
4761# Fetch output from 'omreport chassis bios', put in sysinfo hash
4762#
4763sub get_omreport_chassis_bios {
4764 if (open my $BIOS, '-|', "$omreport $omopt_chassis bios -fmt ssv") {
4765 my @lines = <$BIOS>;
4766 close $BIOS;
4767 foreach (@lines) {
4768 next if !m/;/xms;
4769 my ($key, $val) = split /;/xms;
4770 $key =~ s{\s+\z}{}xms; # remove trailing whitespace
4771 $val =~ s{\s+\z}{}xms; # remove trailing whitespace
4772 $sysinfo{bios} = $val if $key eq 'Version';
4773 $sysinfo{biosdate} = $val if $key eq 'Release Date';
4774 }
4775 }
4776 return;
4777}
4778
4779#
4780# Fetch output from 'omreport system operatingsystem', put in sysinfo hash
4781#
4782sub get_omreport_system_operatingsystem {
4783 if (open my $VER, '-|', "$omreport $omopt_system operatingsystem -fmt ssv") {
4784 my @lines = <$VER>;
4785 close $VER;
4786 foreach (@lines) {
4787 next if !m/;/xms;
4788 my ($key, $val) = split /;/xms;
4789 $key =~ s{\s+\z}{}xms; # remove trailing whitespace
4790 $val =~ s{\s+\z}{}xms; # remove trailing whitespace
4791 if ($key eq 'Operating System') {
4792 $sysinfo{osname} = $val;
4793 }
4794 elsif ($key eq 'Operating System Version') {
4795 $sysinfo{osver} = $val;
4796 }
4797 }
4798 }
4799 return;
4800}
4801
4802#
4803# Fetch output from 'omreport about', put in sysinfo hash
4804#
4805sub get_omreport_about {
4806 if (open my $OM, '-|', "$omreport about -fmt ssv") {
4807 my @lines = <$OM>;
4808 close $OM;
4809 foreach (@lines) {
4810 if (m/\A Version;(.+) \z/xms) {
4811 $sysinfo{om} = $1;
4812 chomp $sysinfo{om};
4813 }
4814 }
4815 }
4816 return;
4817}
4818
4819#
4820# Fetch chassis info via SNMP, put in sysinfo hash
4821#
4822sub get_snmp_chassis_info {
4823 my %chassis_oid
4824 = (
4825 '1.3.6.1.4.1.674.10892.1.300.10.1.9.1' => 'chassisModelName',
4826 '1.3.6.1.4.1.674.10892.1.300.10.1.11.1' => 'chassisServiceTagName',
62cd5524 4827 '1.3.6.1.4.1.674.10892.1.300.10.1.48.1' => 'chassisSystemRevisionName',
669797e1 4828 );
4829
4830 my $chassisInformationTable = '1.3.6.1.4.1.674.10892.1.300.10.1';
4831 my $result = $snmp_session->get_table(-baseoid => $chassisInformationTable);
4832
4833 if (defined $result) {
4834 foreach my $oid (keys %{ $result }) {
4835 if (exists $chassis_oid{$oid} and $chassis_oid{$oid} eq 'chassisModelName') {
4836 $sysinfo{model} = $result->{$oid};
4837 $sysinfo{model} =~ s{\s+\z}{}xms; # remove trailing whitespace
4838 }
4839 elsif (exists $chassis_oid{$oid} and $chassis_oid{$oid} eq 'chassisServiceTagName') {
28738b53 4840 $sysinfo{serial} = $opt{hide_servicetag} ? 'XXXXXXX' : $result->{$oid};
669797e1 4841 }
62cd5524 4842 elsif (exists $chassis_oid{$oid} and $chassis_oid{$oid} eq 'chassisSystemRevisionName') {
51449135 4843 $sysinfo{rev} = q{ } . $result->{$oid};
62cd5524 4844 }
669797e1 4845 }
4846 }
4847 else {
4848 my $msg = sprintf 'SNMP ERROR getting chassis info: %s',
4849 $snmp_session->error;
4850 report('other', $msg, $E_UNKNOWN);
4851 }
4852 return;
4853}
4854
4855#
4856# Fetch BIOS info via SNMP, put in sysinfo hash
4857#
4858sub get_snmp_chassis_bios {
4859 my %bios_oid
4860 = (
4861 '1.3.6.1.4.1.674.10892.1.300.50.1.7.1.1' => 'systemBIOSReleaseDateName',
4862 '1.3.6.1.4.1.674.10892.1.300.50.1.8.1.1' => 'systemBIOSVersionName',
4863 );
4864
4865 my $systemBIOSTable = '1.3.6.1.4.1.674.10892.1.300.50.1';
4866 my $result = $snmp_session->get_table(-baseoid => $systemBIOSTable);
4867
4868 if (defined $result) {
4869 foreach my $oid (keys %{ $result }) {
4870 if (exists $bios_oid{$oid} and $bios_oid{$oid} eq 'systemBIOSReleaseDateName') {
4871 $sysinfo{biosdate} = $result->{$oid};
4872 $sysinfo{biosdate} =~ s{\A (\d{4})(\d{2})(\d{2}).*}{$2/$3/$1}xms;
4873 }
4874 elsif (exists $bios_oid{$oid} and $bios_oid{$oid} eq 'systemBIOSVersionName') {
4875 $sysinfo{bios} = $result->{$oid};
4876 }
4877 }
4878 }
4879 else {
4880 my $msg = sprintf 'SNMP ERROR getting BIOS info: %s',
4881 $snmp_session->error;
4882 report('other', $msg, $E_UNKNOWN);
4883 }
4884 return;
4885}
4886
4887#
4888# Fetch OS info via SNMP, put in sysinfo hash
4889#
4890sub get_snmp_system_operatingsystem {
4891 my %os_oid
4892 = (
4893 '1.3.6.1.4.1.674.10892.1.400.10.1.6.1' => 'operatingSystemOperatingSystemName',
4894 '1.3.6.1.4.1.674.10892.1.400.10.1.7.1' => 'operatingSystemOperatingSystemVersionName',
4895 );
4896
4897 my $operatingSystemTable = '1.3.6.1.4.1.674.10892.1.400.10.1';
4898 my $result = $snmp_session->get_table(-baseoid => $operatingSystemTable);
4899
4900 if (defined $result) {
4901 foreach my $oid (keys %{ $result }) {
4902 if (exists $os_oid{$oid} and $os_oid{$oid} eq 'operatingSystemOperatingSystemName') {
4903 $sysinfo{osname} = ($result->{$oid});
4904 }
4905 elsif (exists $os_oid{$oid} and $os_oid{$oid} eq 'operatingSystemOperatingSystemVersionName') {
4906 $sysinfo{osver} = $result->{$oid};
4907 }
4908 }
4909 }
4910 else {
4911 my $msg = sprintf 'SNMP ERROR getting OS info: %s',
4912 $snmp_session->error;
4913 report('other', $msg, $E_UNKNOWN);
4914 }
4915 return;
4916}
4917
4918#
4919# Fetch OMSA version via SNMP, put in sysinfo hash
4920#
4921sub get_snmp_about {
00d4098a 4922 # systemManagementSoftwareGlobalVersionName
4923 my $oid = '1.3.6.1.4.1.674.10892.1.100.10.0';
4924 my $result = $snmp_session->get_request(-varbindlist => [$oid]);
4925
df0b121b 4926 if (defined $result) {
4927 $sysinfo{om} = exists $result->{$oid} && $result->{$oid} ne q{}
4928 ? $result->{$oid} : 'unknown';
669797e1 4929 }
4930 else {
df0b121b 4931 my $msg = sprintf 'SNMP ERROR: Getting OMSA version failed: %s', $snmp_session->error;
4932 report('other', $msg, $E_UNKNOWN);
669797e1 4933 }
4934 return;
4935}
4936
4937#
4938# Collects some information about the system
4939#
4940sub get_sysinfo
4941{
4942 # Get system model and serial number
4943 $snmp ? get_snmp_chassis_info() : get_omreport_chassis_info();
4944
4945 # Get BIOS information. Only if needed
4946 if ( $opt{okinfo} >= 1
4947 or $opt{debug}
4948 or (defined $opt{postmsg} and $opt{postmsg} =~ m/[%][bd]/xms) ) {
4949 $snmp ? get_snmp_chassis_bios() : get_omreport_chassis_bios();
4950 }
4951
22b7a9af
THA
4952 # Get OMSA version information
4953 if ($snmp) {
4954 # always for SNMP because of OMSA 7.1.0 bug
4955 get_snmp_about();
4956 }
4957 elsif ($opt{okinfo} >= 3 or $opt{debug}) {
4958 # only if needed
4959 get_omreport_about();
f711f8c7 4960 }
4961
669797e1 4962 # Return now if debug
4963 return if $opt{debug};
4964
4965 # Get OS information. Only if needed
4966 if (defined $opt{postmsg} and $opt{postmsg} =~ m/[%][or]/xms) {
4967 $snmp ? get_snmp_system_operatingsystem() : get_omreport_system_operatingsystem();
4968 }
4969
669797e1 4970 return;
4971}
4972
4973
4974# Helper function for running omreport when the results are strictly
4975# name=value pairs.
4976sub run_omreport_info {
4977 my $command = shift;
4978 my %output = ();
4979 my @keys = ();
4980
4981 # Run omreport and fetch output
4982 my $rawtext = slurp_command("$omreport $command -fmt ssv 2>&1");
4983
4984 # Parse output, store in array
4985 for ((split /\n/xms, $rawtext)) {
4986 if (m/\A Error/xms) {
4987 my $msg = "Problem running 'omreport $command': $_";
4988 report('other', $msg, $E_UNKNOWN);
4989 }
4990 next if !m/;/xms; # ignore lines with less than two fields
4991 my @vals = split m/;/xms;
4992 $output{$vals[0]} = $vals[1];
4993 }
4994
4995 # Finally, return the collected information
4996 return \%output;
4997}
4998
4999# Get various firmware information (BMC, RAC)
5000sub get_firmware_info {
5001 my @snmp_output = ();
5002 my %nrpe_output = ();
5003
5004 if ($snmp) {
5005 my %fw_oid
5006 = (
5007 '1.3.6.1.4.1.674.10892.1.300.60.1.7.1' => 'firmwareType',
5008 '1.3.6.1.4.1.674.10892.1.300.60.1.8.1' => 'firmwareTypeName',
5009 '1.3.6.1.4.1.674.10892.1.300.60.1.11.1' => 'firmwareVersionName',
5010 );
5011
5012 my $firmwareTable = '1.3.6.1.4.1.674.10892.1.300.60.1';
5013 my $result = $snmp_session->get_table(-baseoid => $firmwareTable);
5014
5015 # Some don't have this OID, this is ok
5016 if (!defined $result) {
5017 return;
5018 }
5019
5020 @snmp_output = @{ get_snmp_output($result, \%fw_oid) };
5021 }
5022 else {
5023 %nrpe_output = %{ run_omreport_info("$omopt_chassis info") };
5024 }
5025
5026 my %fw_type # Firmware types
5027 = (
5028 1 => 'other', # other than following values
5029 2 => 'unknown', # unknown
5030 3 => 'systemBIOS', # System BIOS
5031 4 => 'embeddedSystemManagementController', # Embedded System Management Controller
5032 5 => 'powerSupplyParallelingBoard', # Power Supply Paralleling Board
5033 6 => 'systemBackPlane', # System (Primary) Backplane
5034 7 => 'powerVault2XXSKernel', # PowerVault 2XXS Kernel
5035 8 => 'powerVault2XXSApplication', # PowerVault 2XXS Application
5036 9 => 'frontPanel', # Front Panel Controller
5037 10 => 'baseboardManagementController', # Baseboard Management Controller
5038 11 => 'hotPlugPCI', # Hot Plug PCI Controller
5039 12 => 'sensorData', # Sensor Data Records
5040 13 => 'peripheralBay', # Peripheral Bay Backplane
5041 14 => 'secondaryBackPlane', # Secondary Backplane for ESM 2 systems
5042 15 => 'secondaryBackPlaneESM3And4', # Secondary Backplane for ESM 3 and 4 systems
5043 16 => 'rac', # Remote Access Controller
75ce30f5 5044 17 => 'iDRAC', # Integrated Dell Remote Access Controller
d2acbd6c 5045 18 => 'iDRAC6', # iDRAC6 (not defined in 7.0.0 MIB!)
75ce30f5 5046 19 => 'unifiedServerConfigurator', # Unified Server Configurator
5047 20 => 'lifecycleController', # Lifecycle Controller
e051ef49 5048 21 => 'iDRAC7', # iDRAC7 (not defined in 7.0.0 MIB!)
669797e1 5049 );
5050
5051
5052 if ($snmp) {
5053 foreach my $out (@snmp_output) {
5054 if ($fw_type{$out->{firmwareType}} eq 'baseboardManagementController') {
5055 $sysinfo{'bmc'} = 1;
5056 $sysinfo{'bmc_fw'} = $out->{firmwareVersionName};
5057 }
e051ef49 5058 elsif ($fw_type{$out->{firmwareType}} =~ m{\A rac|iDRAC. \z}xms) {
669797e1 5059 my $name = $out->{firmwareTypeName}; $name =~ s/\s//gxms;
5060 $sysinfo{'rac'} = 1;
5061 $sysinfo{'rac_name'} = $name;
5062 $sysinfo{'rac_fw'} = $out->{firmwareVersionName};
5063 }
5064 }
5065 }
5066 else {
5067 foreach my $key (keys %nrpe_output) {
5068 next if !defined $nrpe_output{$key};
5069 if ($key eq 'BMC Version' or $key eq 'Baseboard Management Controller Version') {
5070 $sysinfo{'bmc'} = 1;
5071 $sysinfo{'bmc_fw'} = $nrpe_output{$key};
5072 }
5073 elsif ($key =~ m{\A (i?DRAC)\s*(\d?)\s+Version}xms) {
5074 my $name = "$1$2";
5075 $sysinfo{'rac'} = 1;
5076 $sysinfo{'rac_fw'} = $nrpe_output{$key};
5077 $sysinfo{'rac_name'} = $name;
5078 }
5079 }
5080 }
5081
5082 return;
5083}
5084
5085
5086
5087#=====================================================================
5088# Main program
5089#=====================================================================
5090
7dd03e89 5091# Get system information
5092get_sysinfo();
5093
5094# Get firmware info if requested via option
5095if ($opt{okinfo} >= 1) {
5096 get_firmware_info();
5097}
5098
669797e1 5099# Here we do the actual checking of components
5100# Check global status if applicable
5101if ($global) {
5102 $globalstatus = check_global();
5103}
5104
5105# Do multiple selected checks
5106if ($check{storage}) { check_storage(); }
5107if ($check{memory}) { check_memory(); }
5108if ($check{fans}) { check_fans(); }
5109if ($check{power}) { check_powersupplies(); }
5110if ($check{temp}) { check_temperatures(); }
5111if ($check{cpu}) { check_processors(); }
5112if ($check{voltage}) { check_volts(); }
5113if ($check{batteries}) { check_batteries(); }
5114if ($check{amperage}) { check_pwrmonitoring(); }
5115if ($check{intrusion}) { check_intrusion(); }
40619bb3 5116if ($check{sdcard}) { check_sdcard(); }
669797e1 5117if ($check{alertlog}) { check_alertlog(); }
5118if ($check{esmlog}) { check_esmlog(); }
5119if ($check{esmhealth}) { check_esmlog_health(); }
7dd03e89 5120if ($check{servicetag}) { check_servicetag(); }
669797e1 5121
5122#---------------------------------------------------------------------
5123# Finish up
5124#---------------------------------------------------------------------
5125
7dd03e89 5126# Close SNMP session
5127if ($snmp) {
5128 $snmp_session->close;
5129}
5130
669797e1 5131# Counter variable
5132%nagios_alert_count
5133 = (
5134 'OK' => 0,
5135 'WARNING' => 0,
5136 'CRITICAL' => 0,
5137 'UNKNOWN' => 0,
5138 );
5139
669797e1 5140# Print messages
5141if ($opt{debug}) {
28faa168 5142 # finding the mode of operation
5143 my $mode = 'local';
5144 if ($snmp) {
5145 # Setting the domain (IP version and transport protocol)
5146 my $transport = $opt{tcp} ? 'TCP' : 'UDP';
5147 my $ipversion = $opt{ipv6} ? 'IPv6' : 'IPv4';
5148 $mode = "SNMPv$opt{protocol} $transport/$ipversion";
5149 }
5150
8e4b7bdf 5151 print " System: $sysinfo{model}$sysinfo{rev}";
5152 print q{ } x (25 - length "$sysinfo{model}$sysinfo{rev}"), "OMSA version: $sysinfo{om}\n";
f711f8c7 5153 print " ServiceTag: $sysinfo{serial}";
8e4b7bdf 5154 print q{ } x (25 - length $sysinfo{serial}), "Plugin version: $VERSION\n";
f711f8c7 5155 print " BIOS/date: $sysinfo{bios} $sysinfo{biosdate}";
c49a3011 5156 print q{ } x (25 - length "$sysinfo{bios} $sysinfo{biosdate}"), "Checking mode: $mode\n";
669797e1 5157 if ($#report_storage >= 0) {
5158 print "-----------------------------------------------------------------------------\n";
5159 print " Storage Components \n";
5160 print "=============================================================================\n";
5161 print " STATE | ID | MESSAGE TEXT \n";
5162 print "---------+----------+--------------------------------------------------------\n";
5163 foreach (@report_storage) {
5164 my ($msg, $level, $nexus) = @{$_};
5165 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | "
5166 . q{ } x (8 - length $nexus) . "$nexus | $msg\n";
5167 $nagios_alert_count{$reverse_exitcode{$level}}++;
5168 }
5169 }
5170 if ($#report_chassis >= 0) {
5171 print "-----------------------------------------------------------------------------\n";
5172 print " Chassis Components \n";
5173 print "=============================================================================\n";
1d003803 5174 print " STATE | ID | MESSAGE TEXT \n";
669797e1 5175 print "---------+------+------------------------------------------------------------\n";
5176 foreach (@report_chassis) {
5177 my ($msg, $level, $nexus) = @{$_};
5178 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | "
5179 . q{ } x (4 - length $nexus) . "$nexus | $msg\n";
5180 $nagios_alert_count{$reverse_exitcode{$level}}++;
5181 }
5182 }
5183 if ($#report_other >= 0) {
5184 print "-----------------------------------------------------------------------------\n";
5185 print " Other messages \n";
5186 print "=============================================================================\n";
5187 print " STATE | MESSAGE TEXT \n";
5188 print "---------+-------------------------------------------------------------------\n";
5189 foreach (@report_other) {
5190 my ($msg, $level, $nexus) = @{$_};
5191 print q{ } x (8 - length $reverse_exitcode{$level}) . "$reverse_exitcode{$level} | $msg\n";
5192 $nagios_alert_count{$reverse_exitcode{$level}}++;
5193 }
5194 }
5195}
5196else {
5197 my $c = 0; # counter to determine linebreaks
5198
5199 # Run through each message, sorted by severity level
5200 ALERT:
5201 foreach (sort {$a->[1] < $b->[1]} (@report_storage, @report_chassis, @report_other)) {
5202 my ($msg, $level, $nexus) = @{ $_ };
5203 next ALERT if $level == $E_OK;
5204
5205 if (defined $opt{only}) {
5206 # If user wants only critical alerts
5207 next ALERT if ($opt{only} eq 'critical' and $level == $E_WARNING);
5208
5209 # If user wants only warning alerts
5210 next ALERT if ($opt{only} eq 'warning' and $level == $E_CRITICAL);
5211 }
5212
5213 # Prefix with service tag if specified with option '-i|--info'
5214 if ($opt{info}) {
28738b53 5215 if (defined $opt{htmlinfo} and !$opt{hide_servicetag}) {
e90ad241 5216 $msg = '[<a target="_blank" href="' . warranty_url($sysinfo{serial})
669797e1 5217 . "\">$sysinfo{serial}</a>] " . $msg;
5218 }
5219 else {
5220 $msg = "[$sysinfo{serial}] " . $msg;
5221 }
5222 }
5223
5224 # Prefix with nagios level if specified with option '--state'
5225 $msg = $reverse_exitcode{$level} . ": $msg" if $opt{state};
5226
5227 # Prefix with one-letter nagios level if specified with option '--short-state'
5228 $msg = (substr $reverse_exitcode{$level}, 0, 1) . ": $msg" if $opt{shortstate};
5229
5230 ($c++ == 0) ? print $msg : print $linebreak, $msg;
5231
5232 $nagios_alert_count{$reverse_exitcode{$level}}++;
5233 }
5234}
5235
5236# Determine our exit code
5237$exit_code = $E_OK;
5238$exit_code = $E_UNKNOWN if $nagios_alert_count{'UNKNOWN'} > 0;
5239$exit_code = $E_WARNING if $nagios_alert_count{'WARNING'} > 0;
5240$exit_code = $E_CRITICAL if $nagios_alert_count{'CRITICAL'} > 0;
5241
5242# Global status via SNMP.. extra safety check
5243if ($globalstatus != $E_OK && $exit_code == $E_OK && !defined $opt{only}) {
5244 print "OOPS! Something is wrong with this server, but I don't know what. ";
5245 print "The global system health status is $reverse_exitcode{$globalstatus}, ";
5246 print "but every component check is OK. This may be a bug in the Nagios plugin, ";
5247 print "please file a bug report.\n";
5248 exit $E_UNKNOWN;
5249}
5250
5251# Print OK message
5252if ($exit_code == $E_OK && defined $opt{only} && $opt{only} !~ m{\A critical|warning|chassis \z}xms && !$opt{debug}) {
5253 my %okmsg
5254 = ( 'storage' => "STORAGE OK - $count{pdisk} physical drives, $count{vdisk} logical drives",
5255 'fans' => $count{fan} == 0 && $blade ? 'OK - blade system with no fan probes' : "FANS OK - $count{fan} fan probes checked",
5256 'temp' => "TEMPERATURES OK - $count{temp} temperature probes checked",
14e95f92 5257 'memory' => "MEMORY OK - $count{dimm} memory modules, $count{mem} MB total memory",
669797e1 5258 'power' => $count{power} == 0 ? 'OK - no instrumented power supplies found' : "POWER OK - $count{power} power supplies checked",
5259 'cpu' => "PROCESSORS OK - $count{cpu} processors checked",
5260 'voltage' => "VOLTAGE OK - $count{volt} voltage probes checked",
5261 'batteries' => $count{bat} == 0 ? 'OK - no batteries found' : "BATTERIES OK - $count{bat} batteries checked",
5262 'amperage' => $count{amp} == 0 ? 'OK - no power monitoring probes found' : "AMPERAGE OK - $count{amp} amperage (power monitoring) probes checked",
5263 'intrusion' => $count{intr} == 0 ? 'OK - no intrusion detection probes found' : "INTRUSION OK - $count{intr} intrusion detection probes checked",
5264 '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",
5265 'esmlog' => "OK - ESM Log content: $count{esm}{Ok} ok, $count{esm}{'Non-Critical'} warning and $count{esm}{Critical} critical",
5266 'esmhealth' => "ESM LOG OK - less than 80% used",
e62ffb8b 5267 'sdcard' => "SD CARDS OK - $count{sd} SD cards installed",
9b921db3 5268 'servicetag' => sprintf 'ServiceTag OK: %s', $opt{hide_servicetag} ? 'XXXXXXX' : $sysinfo{serial},
669797e1 5269 );
5270
5271 print $okmsg{$opt{only}};
35a7e76e 5272
5273 # show blacklisted components
5274 if ($opt{show_blacklist} and %blacklist) {
5275 my @blstr = ();
5276 foreach (keys %blacklist) {
5277 push @blstr, "$_=" . join ',', @{ $blacklist{$_} };
5278 }
5279 print $linebreak;
5280 print "----- BLACKLISTED: " . join '/', @blstr;
5281 }
669797e1 5282}
5283elsif ($exit_code == $E_OK && !$opt{debug}) {
28738b53 5284 if (defined $opt{htmlinfo} and !$opt{hide_servicetag}) {
e90ad241 5285 printf q{OK - System: '<a target="_blank" href="%s">%s%s</a>', SN: '<a target="_blank" href="%s">%s</a>'},
77afd26c 5286 documentation_url($sysinfo{model},$sysinfo{rev}), $sysinfo{model}, $sysinfo{rev},
51449135 5287 warranty_url($sysinfo{serial}), $sysinfo{serial};
669797e1 5288 }
c7fab830 5289 elsif (defined $opt{htmlinfo} and $opt{hide_servicetag}) {
28738b53 5290 printf q{OK - System: '<a target="_blank" href="%s">%s%s</a>', SN: '%s'},
77afd26c 5291 documentation_url($sysinfo{model},$sysinfo{rev}), $sysinfo{model}, $sysinfo{rev},
28738b53 5292 $sysinfo{serial};
5293 }
669797e1 5294 else {
62cd5524 5295 printf q{OK - System: '%s%s', SN: '%s'},
51449135 5296 $sysinfo{model}, $sysinfo{rev}, $sysinfo{serial};
669797e1 5297 }
5298
14e95f92 5299 if ($check{memory}) {
5300 my $unit = 'MB';
5301 if ($count{mem} >= 1024) {
5302 $count{mem} /= 1024;
5303 $unit = 'GB';
5304 }
5305 printf ', %d %s ram (%d dimms)', $count{mem}, $unit, $count{dimm};
5306 }
5307 else {
5308 print ', not checking memory';
5309 }
5310
669797e1 5311 if ($check{storage}) {
5312 printf ', %d logical drives, %d physical drives',
5313 $count{vdisk}, $count{pdisk};
5314 }
5315 else {
5316 print ', not checking storage';
5317 }
5318
04440248 5319 # show blacklisted components
5320 if ($opt{show_blacklist} and %blacklist) {
5321 my @blstr = ();
5322 foreach (keys %blacklist) {
5323 push @blstr, "$_=" . join ',', @{ $blacklist{$_} };
5324 }
5325 print $linebreak;
5326 print "----- BLACKLISTED: " . join '/', @blstr;
5327 }
5328
669797e1 5329 if ($opt{okinfo} >= 1) {
5330 print $linebreak;
5331 printf q{----- BIOS='%s %s'}, $sysinfo{bios}, $sysinfo{biosdate};
5332
5333 if ($sysinfo{rac}) {
5334 printf q{, %s='%s'}, $sysinfo{rac_name}, $sysinfo{rac_fw};
5335 }
5336 if ($sysinfo{bmc}) {
5337 printf q{, BMC='%s'}, $sysinfo{bmc_fw};
5338 }
5339 }
5340
5341 if ($opt{okinfo} >= 2) {
5342 if ($check{storage}) {
5343 my @storageprint = ();
5344 foreach my $id (sort keys %{ $sysinfo{controller} }) {
5345 chomp $sysinfo{controller}{$id}{driver};
956cf4d1 5346 my $msg = sprintf q{----- Ctrl %s [%s]: Fw='%s', Dr='%s'},
669797e1 5347 $sysinfo{controller}{$id}{id}, $sysinfo{controller}{$id}{name},
5348 $sysinfo{controller}{$id}{firmware}, $sysinfo{controller}{$id}{driver};
956cf4d1 5349 if (defined $sysinfo{controller}{$id}{storport}) {
5350 $msg .= sprintf q{, Storport: '%s'}, $sysinfo{controller}{$id}{storport};
5351 }
5352 push @storageprint, $msg;
669797e1 5353 }
5354 foreach my $id (sort keys %{ $sysinfo{enclosure} }) {
956cf4d1 5355 push @storageprint, sprintf q{----- Encl %s [%s]: Fw='%s'},
669797e1 5356 $sysinfo{enclosure}{$id}->{id}, $sysinfo{enclosure}{$id}->{name},
5357 $sysinfo{enclosure}{$id}->{firmware};
5358 }
5359
5360 # print stuff
5361 foreach my $line (@storageprint) {
5362 print $linebreak, $line;
5363 }
5364 }
5365 }
5366
5367 if ($opt{okinfo} >= 3) {
5368 print "$linebreak----- OpenManage Server Administrator (OMSA) version: '$sysinfo{om}'";
5369 }
5370
5371}
5372else {
5373 if ($opt{extinfo}) {
5374 print $linebreak;
28738b53 5375 if (defined $opt{htmlinfo} && !$opt{hide_servicetag}) {
e90ad241 5376 printf '------ SYSTEM: <a target="_blank" href="%s">%s%s</a>, SN: <a target="_blank" href="%s">%s</a>',
51449135 5377 documentation_url($sysinfo{model}), $sysinfo{model}, $sysinfo{rev},
5378 warranty_url($sysinfo{serial}), $sysinfo{serial};
669797e1 5379 }
28738b53 5380 elsif (defined $opt{htmlinfo} && $opt{hide_servicetag}) {
5381 printf '------ SYSTEM: <a target="_blank" href="%s">%s%s</a>, SN: %s',
5382 documentation_url($sysinfo{model}), $sysinfo{model}, $sysinfo{rev},
5383 $sysinfo{serial};
5384 }
669797e1 5385 else {
62cd5524 5386 printf '------ SYSTEM: %s%s, SN: %s',
51449135 5387 $sysinfo{model}, $sysinfo{rev}, $sysinfo{serial};
669797e1 5388 }
5389 }
5390 if (defined $opt{postmsg}) {
5391 my $post = undef;
5392 if (-f $opt{postmsg}) {
5393 open my $POST, '<', $opt{postmsg}
5394 or ( print $linebreak
5395 and print "ERROR: Couldn't open post message file $opt{postmsg}: $!\n"
5396 and exit $E_UNKNOWN );
5397 $post = <$POST>;
5398 close $POST;
5399 chomp $post;
5400 }
5401 else {
5402 $post = $opt{postmsg};
5403 }
5404 if (defined $post) {
5405 print $linebreak;
5406 $post =~ s{[%]s}{$sysinfo{serial}}gxms;
51449135 5407 $post =~ s{[%]m}{$sysinfo{model}$sysinfo{rev}}gxms;
669797e1 5408 $post =~ s{[%]b}{$sysinfo{bios}}gxms;
5409 $post =~ s{[%]d}{$sysinfo{biosdate}}gxms;
5410 $post =~ s{[%]o}{$sysinfo{osname}}gxms;
5411 $post =~ s{[%]r}{$sysinfo{osver}}gxms;
5412 $post =~ s{[%]p}{$count{pdisk}}gxms;
5413 $post =~ s{[%]l}{$count{vdisk}}gxms;
5414 $post =~ s{[%]n}{$linebreak}gxms;
5415 $post =~ s{[%]{2}}{%}gxms;
5416 print $post;
5417 }
5418 }
5419}
5420
7c03958b 5421# Reset the WARN signal
5422$SIG{__WARN__} = 'DEFAULT';
5423
cbbc270f 5424# Print any perl warnings that have occured
5425if (@perl_warnings) {
5426 foreach (@perl_warnings) {
5427 chop @$_;
5428 print "${linebreak}INTERNAL ERROR: @$_";
5429 }
5430 $exit_code = $E_UNKNOWN;
5431}
5432
669797e1 5433# Print performance data
48aeec0b 5434if (defined $opt{perfdata} && !$opt{debug} && @perfdata) {
669797e1 5435 my $lb = $opt{perfdata} eq 'multiline' ? "\n" : q{ }; # line break for perfdata
5436 print q{|};
5437
48aeec0b 5438 # Sort routine for performance data
5439 sub perfsort {
434167a1 5440 my %order = ( 'T' => 0, 'W' => 1, 'A' => 2, 'V' => 3, 'F' => 4, 'E' => 5, );
5441
5442 # sort in this order:
5443 # 1. the type according to the hash "order" above
5444 # 2. the id (index) numerically
5445 # 3. the id (index) alphabetically
5446 # 4. the label
5447 return $order{$a->{type}} cmp $order{$b->{type}} ||
5448 ($a->{id} =~ m{\A\d+\z}xms and $a->{id} <=> $b->{id}) ||
5449 ($a->{id} !~ m{\A\d+\z}xms and $a->{id} cmp $b->{id}) ||
5450 $a->{label} cmp $b->{label};
669797e1 5451 }
5452
4572cb76 5453 # LEGACY sort routine for performance data
5454 sub perfsort_legacy {
5455 my %order = ( fan => 0, pwr => 1, tem => 2, enc => 3, );
5456 return ($order{(substr $a->{legacy}, 0, 3)} cmp $order{(substr $b->{legacy}, 0, 3)}) ||
5457 $a->{legacy} cmp $b->{legacy};
5458 }
5459
48aeec0b 5460 # Print performance data sorted
4572cb76 5461 if ($opt{legacy_perfdata}) {
5462 my $type = $opt{perfdata} eq 'minimal' ? 'mini' : 'legacy';
5463 print join $lb, map { "$_->{$type}=$_->{value};$_->{warn};$_->{crit}" } sort perfsort_legacy @perfdata;
6b6fd602 5464 }
5465 else {
4572cb76 5466 if ($opt{perfdata} eq 'minimal') {
5467 print join $lb, map { "$_->{type}$_->{id}=$_->{value}$_->{unit};$_->{warn};$_->{crit}" } sort perfsort @perfdata;
5468 }
5469 else {
5470 print join $lb, map { "$_->{type}$_->{id}_$_->{label}=$_->{value}$_->{unit};$_->{warn};$_->{crit}" } sort perfsort @perfdata;
5471 }
6b6fd602 5472 }
669797e1 5473}
e133d101 5474
68bd19fb 5475# Wrapping up and finishing
a660c358 5476if ($opt{debug}) {
5477 # Exit with value 3 (unknown) if debug
5478 exit $E_UNKNOWN;
5479}
5480else {
5481 # Print a linebreak at the end if we have a TTY
5482 isatty(*STDOUT) && print "\n";
5483
5484 # Exit with proper exit code
5485 exit $exit_code;
5486}