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