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