6,26c6
< # Originally written by SATOH Fumiyasu <fumiya@samba.gr.jp>.
< # Modified Oct 2001 by Dan Urist <durist@world.std.com>
< #   Changes: added usage, SNMP v.3 support, -T threshold option and
< #            unique-ified errors
< #
< # Usage:
< #       [-h]                # Usage
< #       [-t Timeout]        # Timeout in ms (default: 1000000)
< #       [-r Retries]        # Retries before failure (default: 5)
< #       [-v SNMPversion]    # 1,2,2c or 3 (default: 1)
< #       [-c Community]      # For SNMP v.1,2,2c (default: public)
< #       [-u snmpuser]       # For SNMP v.3 (default: initial)
< #       [-l seclevel]       # For SNMP v.3 (default: noAuthNoPriv)
< #       [-A authpassphrase] # For SNMP v.3 
< #       [-T threshold]      # If a disk threshold is given, the script
< #                           # will exit with the value of the highest
< #                           # disk percentage found that is over the
< #                           # threshold; if no disks are over the threshold
< #                           # it will exit with value 0, and it will exit
< #                           # with value 2 for SNMP error
< #       host [host ...]
---
> # Arguments are:
27a8
> # [-c community] host [host ...]
37,43c18,22
< # If the -T threshold option is used, the script will exit with the
< # highest disk percentage found that is over the threshold. The intent
< # is to allow use with mon's "alert exit=value" parameter to allow for
< # finer-grained alerts based on disk usage.  If no disks are over the
< # threshold, the script will exit with value 0; if an SNMP error
< # occurs (and there are no other errors), the script will exit with
< # value 2.
---
> # There probably should be a better way to specify a given filesystem to
> # watch instead of everything-ucd-snmp-is-watching.
> #
> # $Id$
> #
61,62c40
< 
< use SNMP; 
---
> use SNMP;
67,88c45,46
< getopts("ht:r:v:c:u:l:A:T:");
< my $VERSION = "0.1";
< if( $opt_h || (scalar @ARGV == 0) ){
<   print <<"USAGE";
< $0 Version $VERSION; original version by SATOH Fumiyasu <fumiya@samba.gr.jp>,
< SNMP v.3 support by Daniel J. Urist <durist\@world.std.com>.
< 
< Usage:
<       [-h]                # Usage
<       [-t Timeout]        # Timeout in ms (default: 1000000)
<       [-r Retries]        # Retries before failure (default: 5)
<       [-v SNMPversion]    # 1,2,2c or 3 (default: 1)
<       [-c Community]      # For SNMP v.1,2,2c (default: public)
<       [-u snmpuser]       # For SNMP v.3 (default: initial)
<       [-l seclevel]       # For SNMP v.3 (default: noAuthNoPriv)
<       [-A authpassphrase] # For SNMP v.3 
<       [-T threshold]      # If a disk threshold is given, the script will exit
<                           # with the value of the highest disk percentage found
<                           # that is over the threshold; if no disks are over the
<                           # the threshold it will exit with value 0, and it will
<                           # exit with value 2 for SNMP error
<       host [host ...]
---
> getopts("c:");
> $community = $opt_c || 'public';
90,121c48
< USAGE
<   exit;
< }
< 
< # FIXME we should probably offer all the v3 options that the SNMP module does
< my $Timeout = $opt_t || 1000000;
< my $Retries = $opt_r || 5;
< my $SNMPVersion = $opt_v || 1;
< my $Community = $opt_c || 'public';
< my $SecName = $opt_u || 'initial'; 
< my $SecLevel = $opt_l || 'noAuthNoPriv';
< my $Authpass = $opt_A || '';
< my $Threshold = $opt_T if defined($opt_T);
< 
< my %SNMPARGS = (
< 		Timeout => $Timeout,
< 		Version => $SNMPVersion,
< 	       );
< 
< if ($SNMPVersion eq "3"){
<   $SNMPARGS{SecName} = $SecName;
<   $SNMPARGS{SecLevel} = $SecLevel;
<   $SNMPARGS{AuthPass} = $Authpass;
< }
< else{
<   $SNMPARGS{Community} = $Community;
< }
< 
< my $RETVAL = 0;
< my %Failures;
< my %Longerr;
< my $Session;
---
> $RETVAL = 0;
124,160c51,57
<   $Session = new SNMP::Session(
< 			       DestHost => $host,
< 			       %SNMPARGS,
< 			      );
<   unless( defined($Session) ) {
<     $RETVAL = 2 if $RETVAL == 0; # Other errors take precedence over SNMP error
<     $Failures{"$host session error"} = "";
<     $Longerr{"$host could not get SNMP session"} = "";
<     next;
<   }
< 
<   my $v = new SNMP::Varbind (["dskIndex"]);
<   $Session->getnext ($v);
< 
<   while (!$Session->{"ErrorStr"} && $v->tag eq "dskIndex") {
<     my @q = $Session->get ([
< 			    ["dskPath", $v->iid],	# 0
< 			    ["dskDevice", $v->iid],	# 1
< 			    ["dskMinimum", $v->iid],	# 2
< 			    ["dskMinPercent", $v->iid],	# 3
< 			    ["dskTotal", $v->iid],	# 4
< 			    ["dskAvail", $v->iid],	# 5
< 			    ["dskUsed", $v->iid],	# 6
< 			    ["dskPercent", $v->iid],	# 7
< 			    ["dskPercentNode", $v->iid],# 8
< 			    ["dskErrorFlag", $v->iid],	# 9
< 			    ["dskErrorMsg", $v->iid],	# 10
< 			   ]);
<     last if ($Session->{"ErrorStr"});
< 
<     if( defined $Threshold ){
<       if($q[7] > $Threshold){
< 	$RETVAL = $q[7] if $q[7] > $RETVAL;
< 	my ($t, $u, $a) = map { int($_/1024) } @q[4, 6, 5];
< 	$Failures{$host} = "";
< 	$Longerr{"$host:$q[0]($q[1]) total=$t used=$u($q[7]%) free=$a threshold=$Threshold%"} = "";
<       }
---
>     $session = new SNMP::Session(DestHost => $host,
>                                  Community => $community);
>     if (!defined ($session)) {
>     	$RETVAL = ($RETVAL == 1) ? 1 : 2;
> 	push @failures, "$host session error";
> 	push @longerr, "$host could not get SNMP session";
> 	next;
162,166c59,87
<     elsif ($q[9] > 0) {
<       $RETVAL = 1;	    
<       my ($t, $u, $a) = map { int($_/1024) } @q[4, 6, 5];
<       $Failures{$host} = "";
<       $Longerr{"$host:$q[0]($q[1]) total=$t used=$u($q[7]%) free=$a err=$q[10]"} = "";
---
> 
>     my $v = new SNMP::Varbind (["dskIndex"]);
>     $session->getnext ($v);
> 
>     while (!$session->{"ErrorStr"} && $v->tag eq "dskIndex") {
> 	my @q = $session->get ([
> 	    ["dskPath", $v->iid],	# 0
> 	    ["dskDevice", $v->iid],	# 1
> 	    ["dskMinimum", $v->iid],	# 2
> 	    ["dskMinPercent", $v->iid],	# 3
> 	    ["dskTotal", $v->iid],	# 4
> 	    ["dskAvail", $v->iid],	# 5
> 	    ["dskUsed", $v->iid],	# 6
> 	    ["dskPercent", $v->iid],	# 7
> 	    ["dskPercentNode", $v->iid],# 8
> 	    ["dskErrorFlag", $v->iid],	# 9
> 	    ["dskErrorMsg", $v->iid],	# 10
> 	]);
> 
> 	last if ($session->{"ErrorStr"});
> 
>         if ($q[9] > 0) {
> 	    $RETVAL = 1;	    
> 	    my ($t, $u, $a) = map { int($_/1024) } @q[4, 6, 5];
>     	    push (@failures, $host);
>             push (@longerr, "$host:$q[0]($q[1]) total=$t used=$u($q[7]%) free=$a err=$q[10]");
>         }
> 
> 	$session->getnext ($v);
169,176c90,93
<     $Session->getnext ($v);
<   }
<   
<   if ($Session->{"ErrorStr"}) {
<     $RETVAL = 2 if $RETVAL == 0; # Other errors take precedence over SNMP error
<     $Failures{$host} = "";
<     $Longerr{"$host returned an SNMP error: " . $Session->{"ErrorStr"}} = "";
<   }
---
>     if ($session->{"ErrorStr"}) {
>     	push (@failures, $host);
> 	push (@longerr, "$host returned an SNMP error: " . $session->{"ErrorStr"});
>     }
179,181c96,98
< if (scalar keys %Failures) {
<     print join (", ", sort keys %Failures), "\n", "\n";
<     print join ("\n", sort keys %Longerr), "\n";
---
> if (@failures) {
>     print join (", ", @failures), "\n", "\n";
>     print join ("\n", @longerr), "\n";
185d101
< 
