#!/usr/bin/perl ############################## check_snmp_storage ############## # Version : 1.1 # Date : Feb 16 2005 # Author : Patrick Proy ( patrick at proy.org) # Help : http://www.manubulon.com/nagios/ # Licence : GPL - http://www.fsf.org/licenses/gpl.txt # TODO : better options in snmpv3 ################################################################# # # help : ./check_snmp_storage -h use strict; use Net::SNMP; use Getopt::Long; # Nagios specific use lib "/usr/local/nagios/libexec"; use utils qw(%ERRORS $TIMEOUT); #my $TIMEOUT = 15; #my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); # SNMP Datas my $storage_table= '1.3.6.1.2.1.25.2.3.1'; my $index_table = '1.3.6.1.2.1.25.2.3.1.1'; my $descr_table = '1.3.6.1.2.1.25.2.3.1.3'; my $size_table = '1.3.6.1.2.1.25.2.3.1.5.'; my $used_table = '1.3.6.1.2.1.25.2.3.1.6.'; my $alloc_units = '1.3.6.1.2.1.25.2.3.1.4.'; # Globals my $Name='check_snmp_storage'; my $Version='1.1'; my $o_host = undef; # hostname my $o_community = undef; # community my $o_port = 161; # port my $o_descr = undef; # description filter my $o_warn = undef; # warning limit my $o_crit= undef; # critical limit my $o_help= undef; # wan't some help ? my $o_type= undef; # pl, pu, mbl, mbu my @o_typeok= ("pu","pl","bu","bl"); # valid values for o_type my $o_verb= undef; # verbose mode my $o_version= undef; # print version my $o_noreg= undef; # Do not use Regexp for name my $o_sum= undef; # add all storage before testing my $o_index= undef; # Parse index instead of description my $o_negate= undef; # Negate the regexp if set my $o_timeout= 5; # Default 5s Timeout my $o_perf= undef; # Output performance data # SNMP V3 specific my $o_login= undef; # snmp v3 login my $o_passwd= undef; # snmp v3 passwd # functions sub p_version { print "$Name version : $Version\n"; } sub print_usage { print "Usage: $Name [-v] -H -C | (-l login -x passwd) [-p ] -m -w -c [-t ] [-T pl|pu|bl|bu ] [-r] [-s] [-i] [-e]\n"; } sub round ($$) { sprintf "%.$_[1]f", $_[0]; } # Get the alarm signal (just in case snmp timout screws up) $SIG{'ALRM'} = sub { print ("ERROR: General time-out (Alarm signal)\n"); exit $ERRORS{"UNKNOWN"}; }; sub help { print "\nSNMP Disk Monitor for Nagios version ",$Version,"\n"; print "(c)2004 to my cat Ratoune - Author : Patrick Proy\n\n"; print_usage(); print < warn and critical if %used > crit -v, --verbose print extra debugging information (and lists all storages) -h, --help print this help message -H, --hostname=HOST name or IP address of host to check -C, --community=COMMUNITY NAME community name for the host's SNMP agent (implies SNMP v1) -l, --login=LOGIN Login for snmpv3 authentication (implies v3 protocol with MD5) -x, --passwd=PASSWD Password for snmpv3 authentication -p, --port=PORT SNMP port (Default 161) -m, --name=NAME Name in description OID (can be mounpoints '/home' or 'Swap Space'...) This is treated as a regexp : -m /var will match /var , /var/log, /opt/var ... Test it before, because there are known bugs (ex : trailling /) No trailing slash for mountpoints ! -r, --noregexp Do not use regexp to match NAME in description OID -s, --sum Add all storages that match NAME (used space and total space) THEN make the tests. -i, --index Parse index table instead of description table to select storage -e, --exclude Select all storages except the one(s) selected by -m -T, --type=TYPE pl : calculate percent left pu : calculate percent used (Default) bl : calculate MegaBytes left bu : calculate MegaBytes used -w, --warn=INTEGER percent / MB of disk used to generate WARNING state you can add the % sign -c, --critical=INTEGER percent / MB of disk used to generate CRITICAL state you can add the % sign -f, --perfparse Perfparse compatible output -t, --timeout=INTEGER timeout for SNMP in seconds (Default: 5) -V, --version prints version number Note : with T=pu or T=bu : OK < warn < crit with T=pl ot T=bl : crit < warn < OK If multiple storage are selected, the worse condition will be returned i.e if one disk is critical, the return is critical example : Browse storage list :