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