/[nagios-plugins-perl]/trunk/plugins/check_dell_openmanager.pl
ViewVC logotype

Contents of /trunk/plugins/check_dell_openmanager.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations) (download)
Thu Nov 12 13:29:04 2009 UTC (11 years ago) by racvision
File MIME type: text/plain
File size: 18101 byte(s)
convert source structure from autotools to rpm-build.sh
1 #!/usr/bin/perl -w
2 #
3 # ============================== SUMMARY =====================================
4 #
5 # Program : check_dell_openmanager.pl
6 # Version : 1.0
7 # Date : Jan 6 2009
8 # Author : Jason Ellison - infotek@gmail.com
9 # Summary : This is a nagios plugin that checks the status of objects
10 # monitored by Dell OpenManage on Dell PowerEdge servers via SNMP
11 #
12 # Licence : GPL - summary below, full text at http://www.fsf.org/licenses/gpl.txt
13 #
14 # =========================== PROGRAM LICENSE =================================
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #
30 # ===================== INFORMATION ABOUT THIS PLUGIN =========================
31 #
32 # This plugin checks the status of objects monitored by OpenManage via SNMP
33 # and returns OK, WARNING, CRITICAL or UNKNOWN. If a failure occurs it will
34 # describe the subsystem that failed and the failure code.
35 #
36 # This program is written and maintained by:
37 # Jason Ellison - infotek(at)gmail.com
38 #
39 # It is based on check_snmp_temperature.pl plugin by:
40 # William Leibzon - william(at)leibzon.org
41 #
42 # Using information from
43 # Dell OpenManage Server Administrator Version 5.4 SNMP Reference Guide
44 # http://support.dell.com/support/edocs/software/svradmin/
45 #
46 # System Types
47 #
48 # "dellom" monitors the following OID's:
49 # systemStateChassisStatus .1.3.6.1.4.1.674.10892.1.200.10.1.4.1
50 # systemStatePowerSupplyStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.9.1
51 # systemStateVoltageStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.12.1
52 # systemStateCoolingDeviceStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.21.1
53 # systemStateTemperatureStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.24.1
54 # systemStateMemoryDeviceStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.27.1
55 # systemStateChassisIntrusionStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.30.1
56 # systemStateEventLogStatus .1.3.6.1.4.1.674.10892.1.200.10.1.41.1
57 #
58 # "dellom_storage" test all of the OID's "dellom" tests plus the storage OID
59 # systemStateChassisStatus .1.3.6.1.4.1.674.10892.1.200.10.1.4.1
60 # systemStatePowerSupplyStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.9.1
61 # systemStateVoltageStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.12.1
62 # systemStateCoolingDeviceStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.21.1
63 # systemStateTemperatureStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.24.1
64 # systemStateMemoryDeviceStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.27.1
65 # systemStateChassisIntrusionStatusCombined .1.3.6.1.4.1.674.10892.1.200.10.1.30.1
66 # systemStateEventLogStatus .1.3.6.1.4.1.674.10892.1.200.10.1.41.1
67 # StorageManagement-MIB::agentGlobalSystemStatus .1.3.6.1.4.1.674.10893.1.20.110.13.0
68 #
69 # "global" monitors
70 # GlobalSystemStatus .1.3.6.1.4.1.674.10892.1.200.10.1.2.1
71 #
72 # "chassis" monitors
73 # ChassisStatus .1.3.6.1.4.1.674.10892.1.200.10.1.4.1
74 #
75 # "custom" is meant to be customised by advanced users
76 #
77 # ============================= SETUP NOTES ====================================
78 #
79 # Copy this file to your Nagios installation folder in "libexec/". Rename
80 # to "check_dell_openmanager.pl".
81 #
82 # You must have Dell OpenManage installed on the server that you want to
83 # monitor. You must have enabled SNMP on the server and allow SNMP queries.
84 # On the server that will be running the plugin you must have the perl
85 # "Net::SNMP" module installed.
86 #
87 # perl -MCPAN -e shell
88 # cpan> install Net::SNMP
89 #
90 # For SNMPv3 support make sure you have the following modules installed:
91 # .Crypt::DES., .Digest::SHA1., .Digest::HMAC.
92 #
93 # Check Dell OpenManage on the local host for alert thresholds like min/max
94 # fan speeds and temperatures...
95 #
96 # To test using SNMPv1 use the following syntax:
97 #
98 # ./check_dell_openmanager.pl -v -H <host> -C <snmp_community> -T <type>
99 #
100 # Where <type> is "dellom", "dellom_storage", "global", "chassis" or "custom"
101 #
102 # ========================= SETUP EXAMPLES ==================================
103 #
104 # define command{
105 # command_name check_dell_open_manager
106 # command_line $USER1$/check_dell_openmanager.pl -H $HOSTADDRESS$ -C $ARG1$ -T $ARG2$
107 # }
108 #
109 # define service{
110 # use generic-host
111 # host_name DELL-SERVER-00
112 # service_description Dell OpenManage Status
113 # check_command check_dell_open_manager!public!dellom
114 # normal_check_interval 3
115 # retry_check_interval 1
116 # }
117 #
118 # define service{
119 # use generic-host
120 # host_name DELL-SERVER-01
121 # service_description Dell OpenManage Status plus Storage
122 # check_command check_dell_open_manager!public!dellom_storage
123 # normal_check_interval 3
124 # retry_check_interval 1
125 # }
126 #
127 # =================================== TODO ===================================
128 #
129 # Fix bugs and make more user friendly.
130 #
131 # ================================ REVISION ==================================
132 #
133 # ver 1.0
134 #
135 # while in verbose mode report which OID failed in a more readable manner.
136 # add "global", "chassis", and "custom" type.
137 #
138 # ver 0.9
139 # change added type dellom_storage as this is more accurate. This plugin works
140 # with all PowerEdge servers it has been tested with. left pe2950 in for compat
141 # remove min max int options from help text as they are no longer relevant
142 #
143 # ver 0.8
144 #
145 # removed ucdavis definition. Added note about SNMPv3 dependencies
146 # check that perl environment has "Net::SNMP" if not found complain.
147 # missing "Net::SNMP" is the most common issue users report.
148 #
149 # ver 0.7
150 #
151 # removed ucdavis definition. Added note about SNMPv3 dependencies
152 #
153 # ver 0.6
154 #
155 # + Added StorageManagement GlobalSystemStatus
156 # StorageManagement-MIB::agentGlobalSystemStatus
157 # .1.3.6.1.4.1.674.10893.1.20.110.13.0
158 #
159 # ver 0.5
160 #
161 # + Cleaned up verbose output for debugging
162 #
163 # ver 0.4
164 #
165 # + Fixed major flaw in logic that cause errors to not be reported.
166 #
167 # + Added to the system_types error warning and unkown variables like seen on
168 # http://www.mail-archive.com/intermapper-talk@list.dartware.com/msg02687.html
169 # below section: "This section performs value to text conversions"
170 #
171 # ========================== START OF PROGRAM CODE ============================
172
173 use strict;
174
175 use Getopt::Long;
176 my $TIMEOUT = 20;
177 my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
178 my %system_types = (
179 "dellom" => [ ['GlobalSystemStatus', 'ChassisStatus', 'PowerSupplyStatusCombined', 'VoltageStatusCombined', 'CoolingDeviceStatusCombined', 'TemperatureStatusCombined', 'MemoryDeviceStatusCombined', 'IntrusionStatusCombined', 'EventLogStatus'], ['.1.3.6.1.4.1.674.10892.1.200.10.1.2.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.4.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.9.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.12.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.21.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.24.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.27.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.30.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.41.1'] ],
180 "dellom_storage" => [ ['Chassis Status', 'Power Supply Status', 'Voltage Status', 'Cooling Device Status', 'Temperature Status', 'Memory Device Status', 'Intrusion Status', 'Event Log Status', 'Storage Management Status'], ['.1.3.6.1.4.1.674.10892.1.200.10.1.4.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.9.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.12.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.21.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.24.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.27.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.30.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.41.1', '.1.3.6.1.4.1.674.10893.1.20.110.13.0'] ],
181 "global" => [ ['Global Health'], ['.1.3.6.1.4.1.674.10892.1.200.10.1.2.1'] ],
182 "chassis" => [ ['Chassis Health'], ['.1.3.6.1.4.1.674.10892.1.200.10.1.4.1'] ],
183 "custom" => [ ['Chassis Status', 'Power Supply Status', 'Voltage Status', 'Cooling Device Status', 'Temperature Status', 'Memory Device Status', 'Intrusion Status', 'Event Log Status', 'Storage Management Status'], ['.1.3.6.1.4.1.674.10892.1.200.10.1.4.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.9.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.12.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.21.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.24.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.27.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.30.1', '.1.3.6.1.4.1.674.10892.1.200.10.1.41.1', '.1.3.6.1.4.1.674.10893.1.20.110.0'] ],
184 );
185 my $Version='0.9';
186 my $o_host= undef; # hostname
187 my $o_community= undef; # community
188 my $o_port= 161; # SNMP port
189 my $o_help= undef; # help option
190 my $o_verb= undef; # verbose mode
191 my $o_version= undef; # version info option
192 my $o_warn= undef; # warning level option
193 my @o_warnL= (); # array for above list
194 my $o_crit= undef; # Critical level option
195 my @o_critL= (); # array for above list
196 my $o_timeout= 5; # Default 5s Timeout
197 my $o_version2= undef; # use snmp v2c
198 # SNMPv3 specific
199 my $o_login= undef; # Login for snmpv3
200 my $o_passwd= undef; # Pass for snmpv3
201 my $o_attr= undef; # What attribute(s) to check (specify more then one separated by '.')
202 my @o_attrL= (); # array for above list
203 my $oid_names= undef; # OID for base of sensor attribute names
204 my $oid_data= undef; # OID for base of actual data for those attributes found when walking name base
205 my $oid_resp= undef; # The expected response from the OID get
206 my $o_unkdef= undef; # Default value to report for unknown attributes
207 my $o_type= undef; # Type of system to check (predefined values for $oid_names, $oid_data, $oid_resp)
208
209 sub print_version { print "$0: $Version\n" };
210
211 sub print_usage {
212 print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-P <port>] -T dellom|dellom_storage|global|chassis|custom [-f] [-t <timeout>] [-V] [-u <unknown_default>]\n";
213 }
214
215 # Return true if arg is a number
216 sub isnum {
217 my $num = shift;
218 if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 1 ;}
219 return 0;
220 }
221
222 sub help {
223 print "\nSNMP Dell OpenManage Monitor for Nagios version ",$Version,"\n";
224 print " by Jason Ellison - infotek(at)gmail.com\n\n";
225 print_usage();
226 print <<EOD;
227 -v, --verbose
228 print extra debugging information
229 -h, --help
230 print this help message
231 -H, --hostname=HOST
232 name or IP address of host to check
233 -C, --community=COMMUNITY NAME
234 community name for the host's SNMP agent (implies v 1 protocol)
235 -2, --v2c
236 use SNMP v2 (instead of SNMP v1)
237 -P, --port=PORT
238 SNMPd port (Default 161)
239 -t, --timeout=INTEGER
240 timeout for SNMP in seconds (Default: 5)
241 -V, --version
242 prints version number
243 -u, --unknown_default=INT
244 If attribute is not found then report the output as this number (i.e. -u 0)
245 -T, --type=dellom|dellom_storage|global|chassis|custom
246 This allows to use pre-defined system type
247 Currently support systems types are:
248 dellom (Dell OpenManage general detailed)
249 dellom_storage (Dell OpenManage plus Storage Management detailed)
250 global (only check the global health status)
251 chassis (only check the system chassis health status)
252 custom (intended for customization)
253
254 EOD
255 }
256
257 # For verbose output - don't use it right now
258 sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
259 # Get the alarm signal (just in case snmp timout screws up)
260 $SIG{'ALRM'} = sub {
261 print ("ERROR: Alarm signal (Nagios time-out)\n");
262 exit $ERRORS{"UNKNOWN"};
263 };
264 sub check_options {
265 Getopt::Long::Configure ("bundling");
266 GetOptions(
267 'v' => \$o_verb, 'verbose' => \$o_verb,
268 'h' => \$o_help, 'help' => \$o_help,
269 'H:s' => \$o_host, 'hostname:s' => \$o_host,
270 'P:i' => \$o_port, 'port:i' => \$o_port,
271 'C:s' => \$o_community, 'community:s' => \$o_community,
272 'l:s' => \$o_login, 'login:s' => \$o_login,
273 'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
274 't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
275 'V' => \$o_version, 'version' => \$o_version,
276 '2' => \$o_version2, 'v2c' => \$o_version2,
277 'u:i' => \$o_unkdef, 'unknown_default:i' => \$o_unkdef,
278 'T:s' => \$o_type, 'type:s' => \$o_type
279 );
280 if (defined($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}; }
281 if (defined($o_version)) { print_version(); exit $ERRORS{"UNKNOWN"}; }
282 if (! defined($o_host) ) # check host and filter
283 { print "No host defined!\n";print_usage(); exit $ERRORS{"UNKNOWN"}; }
284 # check snmp information
285 if (!defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
286 { print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
287 if (!defined($o_type)) { print "Must define system type!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
288 if (defined ($o_type)) {
289 if (defined($system_types{$o_type})) {
290 $oid_names = $system_types{$o_type}[0];
291 $oid_data = $system_types{$o_type}[1];
292 }
293 else { print "Unknown system type $o_type !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}; }
294 }
295 }
296 ########## MAIN #######
297 check_options();
298 # Check global timeout if something goes wrong
299 if (defined($TIMEOUT)) {
300 verb("Alarm at $TIMEOUT");
301 alarm($TIMEOUT);
302 } else {
303 verb("no timeout defined : $o_timeout + 10");
304 alarm ($o_timeout+10);
305 }
306
307 eval "use Net::SNMP";
308 if ($@) {
309 verb("ERROR: You do NOT have the Net:".":SNMP library \n"
310 . " Install it by running: \n"
311 . " perl -MCPAN -e shell \n"
312 . " cpan[1]> install Net::SNMP \n");
313 } else {
314 verb("The Net:".":SNMP library is available on your server \n");
315 }
316
317 # SNMP Connection to the host
318 my ($session,$error);
319 if (defined($o_login) && defined($o_passwd)) {
320 # SNMPv3 login
321 verb("SNMPv3 login");
322 ($session, $error) = Net::SNMP->session(
323 -hostname => $o_host,
324 -version => '3',
325 -username => $o_login,
326 -authpassword => $o_passwd,
327 -authprotocol => 'md5',
328 -privpassword => $o_passwd,
329 -timeout => $o_timeout
330 );
331 } else {
332 if (defined ($o_version2)) {
333 # SNMPv2 Login
334 ($session, $error) = Net::SNMP->session(
335 -hostname => $o_host,
336 -version => 2,
337 -community => $o_community,
338 -port => $o_port,
339 -timeout => $o_timeout
340 );
341 } else {
342 # SNMPV1 login
343 ($session, $error) = Net::SNMP->session(
344 -hostname => $o_host,
345 -community => $o_community,
346 -port => $o_port,
347 -timeout => $o_timeout
348 );
349 }
350 }
351 # next part of the code builds list of attributes to be retrieved
352 my $i;
353 my $oid;
354 my $line;
355 my $resp;
356 my $attr;
357 my @varlist = ();
358 my %dataresults;
359 for ($i=0;$i<scalar(@{$oid_names});$i++) {
360 $dataresults{$oid_names->[$i]} = [ $oid_data->[$i], undef ];
361 #verb("dataresults stuffed with oid_name $oid_names->[$i] oid_data $oid_data->[$i]");
362 push(@varlist, $oid_data->[$i]);
363 }
364
365 verb("Getting SNMP data for oids: " . join(" ",@varlist) . "\n");
366
367 my $result;
368
369 $result = $session->get_request(
370 -Varbindlist => \@varlist
371 );
372 if (!defined($result)) {
373 printf("ERROR: Attempted to retrieve the following OID(s):\n %s \n %s.\n", join(" ",@varlist), $session->error);
374 #verb("ERROR: $system_types{$o_type}[0][8] \n");
375 $session->close();
376 exit $ERRORS{"UNKNOWN"};
377 }
378 else {
379 foreach $attr (keys %dataresults) {
380 if (defined($$result{$dataresults{$attr}[0]})) {
381 $dataresults{$attr}[1]=$$result{$dataresults{$attr}[0]};
382 verb("attr = $attr \n snmp_oid = $dataresults{$attr}[0] \n snmp_response = $dataresults{$attr}[1] \n");
383 }
384 else {
385 if (defined($o_unkdef)) {
386 $dataresults{$attr}[1]=$o_unkdef;
387 verb("could not find snmp data for $attr, setting to to default value $o_unkdef");
388 }
389 else {
390 verb("could not find snmp data for $attr");
391 }
392 }
393 }
394 }
395
396 # loop to check if warning & critical attributes are ok
397 verb("Loop through SNMP responses...");
398
399 my $statuscode = "OK";
400 my $statusinfo = "";
401 my $statusdata = "";
402
403 my $statuscritical = "0";
404 my $statuswarning = "0";
405 my $statusunknown = "0";
406
407 foreach $attr (keys %dataresults) {
408 if ($dataresults{$attr}[1] eq "6") {
409 $statuscritical = "1";
410 $statuscode="CRITICAL";
411 $statusinfo .= ", " if ($statusinfo);
412 $statusinfo .= "$attr=Non-Recoverable";
413 }
414 elsif ($dataresults{$attr}[1] eq "5") {
415 $statuscritical="1";
416 $statuscode="CRITICAL";
417 $statusinfo .= ", " if ($statusinfo);
418 $statusinfo .= "$attr=Critical";
419 }
420 elsif ($dataresults{$attr}[1] eq "4") {
421 $statuswarning = "1";
422 $statuscode="WARNING";
423 $statusinfo .= ", " if ($statusinfo);
424 $statusinfo .= "$attr=Non-Critical";
425 }
426 elsif ($dataresults{$attr}[1] eq "2") {
427 $statusunknown = "1";
428 $statuscode="UNKNOWN";
429 $statusinfo .= ", " if ($statusinfo);
430 $statusinfo .= "$attr=UKNOWN";
431 }
432 elsif ($dataresults{$attr}[1] eq "1") {
433 $statusunknown = "1";
434 $statuscode="UNKNOWN";
435 $statusinfo .= ", " if ($statusinfo);
436 $statusinfo .= "$attr=Other";
437 }
438 elsif ($dataresults{$attr}[1] eq "3") {
439 $statuscode="OK";
440 }
441 else {
442 $statusunknown = "1";
443 $statuscode="UNKNOWN";
444 $statusinfo .= ", " if ($statusinfo);
445 $statusinfo .= "$attr=UKNOWN";
446 }
447 verb("$attr: statuscode = $statuscode");
448 }
449 $session->close;
450
451 $statuscode="OK";
452
453 if ($statuscritical eq '1'){
454 $statuscode="CRITICAL";
455 }
456 elsif ($statuswarning eq '1'){
457 $statuscode="WARNING";
458 }
459 elsif ($statusunknown eq '1'){
460 $statuscode="UNKNOWN";
461 }
462
463 #printf("$statuscode:");
464 if ($statuscode ne 'OK'){
465 printf("$statuscode:$statusinfo");
466 }
467 else {
468 printf("$statuscode");
469 }
470 print "\n";
471
472 exit $ERRORS{$statuscode};

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8