[Nagiosplug-checkins] CVS: nagiosplug/plugins-scripts check_ifoperstatus.pl,1.1,1.2

Subhendu Ghosh sghosh at users.sourceforge.net
Mon Oct 14 23:24:06 CEST 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins-scripts
In directory usw-pr-cvs1:/tmp/cvs-serv20454

Modified Files:
	check_ifoperstatus.pl 
Log Message:
new exit states, more conditional checking

Index: check_ifoperstatus.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/check_ifoperstatus.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** check_ifoperstatus.pl	9 May 2002 19:03:51 -0000	1.1
--- check_ifoperstatus.pl	15 Oct 2002 06:23:46 -0000	1.2
***************
*** 3,7 ****
  # check_ifoperstatus.pl - nagios plugin 
  #
! # Copyright (C) 2000 Christoph Kron
  # Modified 5/2002 to conform to updated Nagios Plugin Guidelines
  # Added support for named interfaces per Valdimir Ivaschenko (S. Ghosh)
--- 3,7 ----
  # check_ifoperstatus.pl - nagios plugin 
  #
! # Copyright (C) 2000 Christoph Kron,
  # Modified 5/2002 to conform to updated Nagios Plugin Guidelines
  # Added support for named interfaces per Valdimir Ivaschenko (S. Ghosh)
***************
*** 22,29 ****
  #
  #
! # Report bugs to: ck at zet.net, nagiosplug-help at lists.sf.net
  #
  # 11.01.2000 Version 1.0
  # $Id$
  
  use POSIX;
--- 22,35 ----
  #
  #
! # Report bugs to:  nagiosplug-help at lists.sourceforge.net
  #
  # 11.01.2000 Version 1.0
  # $Id$
+ #
+ # Patches from Guy Van Den Bergh to warn on ifadminstatus down interfaces
+ # instead of critical.
+ #
+ # Primary MIB reference - RFC 2863
+ 
  
  use POSIX;
***************
*** 43,47 ****
  			 '4','unknown',
  			 '5','dormant',
! 			 '6','notPresent');
  
  my $state = "UNKNOWN";
--- 49,54 ----
  			 '4','unknown',
  			 '5','dormant',
! 			 '6','notPresent',
! 			 '7','lowerLayerDown');  # down due to the state of lower layer interface(s)
  
  my $state = "UNKNOWN";
***************
*** 51,60 ****
  my $port = 161;
  my @snmpoids;
! my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2';
  my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
! my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1';
! my $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18';
! my $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28';
  my $hostname;
  my $session;
  my $error;
--- 58,71 ----
  my $port = 161;
  my @snmpoids;
! my $sysUptime        = '1.3.6.1.2.1.1.3.0';
! my $snmpIfDescr      = '1.3.6.1.2.1.2.2.1.2';
! my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7';
  my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
! my $snmpIfName       = '1.3.6.1.2.1.31.1.1.1.1';
! my $snmpIfLastChange = '1.3.6.1.2.1.2.2.1.9';
! my $snmpIfAlias      = '1.3.6.1.2.1.31.1.1.1.18';
! my $snmpLocIfDescr   = '1.3.6.1.4.1.9.2.2.1.1.28';
  my $hostname;
+ my $ifName;
  my $session;
  my $error;
***************
*** 66,69 ****
--- 77,83 ----
  my $ifdescr;
  my $key;
+ my $lastc;
+ my $dormantWarn;
+ my $name;
  
  
***************
*** 77,80 ****
--- 91,96 ----
  
  
+ ### Validate Arguments
+ 
  $status = GetOptions(
  			"V"   => \$opt_V, "version"    => \$opt_V,
***************
*** 84,90 ****
  			"k=i" =>\$snmpkey, "key=i",\$snmpkey,
  			"d=s" =>\$ifdescr, "descr=s" => \$ifdescr,
  			"p=i" =>\$port,  "port=i",\$port,
  			"H=s" => \$hostname, "hostname=s" => \$hostname,
! 			"I"	  => \$ifXTable, "ifmib" => \$ifXTable);
  
  
--- 100,109 ----
  			"k=i" =>\$snmpkey, "key=i",\$snmpkey,
  			"d=s" =>\$ifdescr, "descr=s" => \$ifdescr,
+ 			"l=s" => \$lastc,  "lastchange=s" => \$lastc,
  			"p=i" =>\$port,  "port=i",\$port,
  			"H=s" => \$hostname, "hostname=s" => \$hostname,
! 			"I"	  => \$ifXTable, "ifmib" => \$ifXTable,
! 			"n=s" => \$ifName, "name=s" => \$ifName,
! 			"w=s" => \$dormantWarn, "warn=s" => \$dormantWarn );
  
  
***************
*** 112,115 ****
--- 131,145 ----
  
  
+ unless ($snmpkey > 0 || defined $ifdescr){
+ 	printf "Either a valid snmpkey key (-k) or a ifDescr (-d) must be provided)\n";
+ 	usage();
+ 	exit $ERRORS{"UNKNOWN"};
+ }
+ 
+ 
+ if (defined $name) {
+ 	$ifXTable=1;
+ }
+ 
  if ( $snmp_version =~ /[12]/ ) {
     ($session, $error) = Net::SNMP->session(
***************
*** 136,139 ****
--- 166,175 ----
  }
  
+ ## End validation
+ 
+ 
+ 
+ ## map ifdescr to ifindex - should look at being able to cache this value
+ 
  if (defined $ifdescr) {
  	# escape "/" in ifdescr - very common in the Cisco world
***************
*** 144,165 ****
  	if ($status==0) {
  		$state = "UNKNOWN";
! 		printf "$state: could not retrive ifIndex - $status-$snmpkey\n";
  		$session->close;
  		exit $ERRORS{$state};
  	}
  }
- if ( $snmpkey == 0 ) {
- 	printf "ifIndex key cannot be 0\n";
- 	usage();
- 	exit $ERRORS{'UNKNOWN'};
- }
  
-    $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8' . "." . $snmpkey;
-    $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2' . "." . $snmpkey;
-    $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18' . "." . $snmpkey ; 
  
  
  push(@snmpoids,$snmpIfOperStatus);
  push(@snmpoids,$snmpIfDescr);
  push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
  
--- 180,202 ----
  	if ($status==0) {
  		$state = "UNKNOWN";
! 		printf "$state: could not retrive snmpkey - $status-$snmpkey\n";
  		$session->close;
  		exit $ERRORS{$state};
  	}
  }
  
  
+ ## Main function
  
+ $snmpIfAdminStatus = $snmpIfAdminStatus . "." . $snmpkey;
+ $snmpIfOperStatus = $snmpIfOperStatus . "." . $snmpkey;
+ $snmpIfDescr = $snmpIfDescr . "." . $snmpkey;
+ $snmpIfName	= $snmpIfName . "." . $snmpkey ;
+ $snmpIfAlias = $snmpIfAlias . "." . $snmpkey ; 
+ 
+ push(@snmpoids,$snmpIfAdminStatus);
  push(@snmpoids,$snmpIfOperStatus);
  push(@snmpoids,$snmpIfDescr);
+ push(@snmpoids,$snmpIfName) if (defined $ifXTable) ;
  push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
  
***************
*** 167,172 ****
        $answer=$session->error;
        $session->close;
!       $state = 'CRITICAL';
!       print ("$state: $answer for ifIndex $snmpkey\n");
        exit $ERRORS{$state};
     }
--- 204,209 ----
        $answer=$session->error;
        $session->close;
!       $state = 'WARNING';
!       print ("$state: SNMP error: $answer\n");
        exit $ERRORS{$state};
     }
***************
*** 179,195 ****
     );
  
-    $session->close;
  
!    if ( $response->{$snmpIfOperStatus} == 1 ) {
!       $state = 'OK';
     }
!    else {
! 	$state = 'CRITICAL';
     }
  
  print ("$state: $answer");
  exit $ERRORS{$state};
  
  
  sub fetch_ifdescr {
  	if (!defined ($response = $session->get_table($snmpIfDescr))) {
--- 216,288 ----
     );
  
  
!    ## Check to see if ifName match is requested and it matches - exit if no match
!    ## not the interface we want to monitor
!    if ( defined $name && not ($response->{$snmpIfName} eq $name) ) {
!       $state = 'UNKNOWN';
!       $answer = "Interface name ($name) doesn't match snmp value ($response->{$snmpIfName}) (index $snmpkey)";
!       print ("$state: $answer");
!       exit $ERRORS{$state};
!    } 
! 
!    ## define the interface name
!    if (defined $ifXTable) {
!      $name = $response->{$snmpIfName} ." - " .$response->{$snmpIfAlias} ; 
!    }else{
!      $name = $response->{$snmpIfDescr} ;
     }
!    
!    ## if AdminStatus is down - some one made a consious effort to change config
!    ##
!    if ( not ($response->{$snmpIfAdminStatus} == 1) ) {
!       $state = 'WARNING';
!       $answer = "Interface $name (index $snmpkey) is administratively down.";
! 
!    } 
!    ## Check operational status
!    elsif ( $response->{$snmpIfOperStatus} == 2 ) {
!       $state = 'CRITICAL';
!       $answer = "Interface $name (index $snmpkey) is down.";
!    } elsif ( $response->{$snmpIfOperStatus} == 5 ) {
!       if (defined $dormantWarn ) {
! 	    if ($dormantWarn eq "w") {
! 	  	  $state = 'WARNNG';
! 		  $answer = "Interface $name (index $snmpkey) is dormant.";
! 	    }elsif($dormantWarn eq "c") {
! 	  	  $state = 'CRITICAL';
! 		  $answer = "Interface $name (index $snmpkey) is dormant.";
!         }elsif($dormantWarn eq "i") {
! 	  	  $state = 'OK';
! 		  $answer = "Interface $name (index $snmpkey) is dormant.";
!         }
! 	 }else{
! 	    # dormant interface  - but warning/critical/ignore not requested
!  	   $state = 'CRITICAL';
! 	   $answer = "Interface $name (index $snmpkey) is dormant.";
! 	}
!    } elsif ( $response->{$snmpIfOperStatus} == 6 ) {
! 	   $state = 'CRITICAL';
! 	   $answer = "Interface $name (index $snmpkey) notPresent - possible hotswap in progress.";
!    } elsif ( $response->{$snmpIfOperStatus} == 7 ) {
! 	   $state = 'CRITICAL';
! 	   $answer = "Interface $name (index $snmpkey) down due to lower layer being down.";
! 
!    } elsif ( $response->{$snmpIfOperStatus} == 3 || $response->{$snmpIfOperStatus} == 4  ) {
! 	   $state = 'CRITICAL';
! 	   $answer = "Interface $name (index $snmpkey) down (testing/unknown).";
! 
!    } else {
!       $state = 'OK';
!       $answer = "Interface $name (index $snmpkey) is up.";
     }
  
+ 
+ 
  print ("$state: $answer");
  exit $ERRORS{$state};
  
  
+ ### subroutines
+ 
  sub fetch_ifdescr {
  	if (!defined ($response = $session->get_table($snmpIfDescr))) {
***************
*** 197,201 ****
  		$session->close;
  		$state = 'CRITICAL';
! 		printf ("$state: $answer for $snmpIfDescr  with snmp version $snmp_version\n");
  		$session->close;
  		exit $ERRORS{$state};
--- 290,294 ----
  		$session->close;
  		$state = 'CRITICAL';
! 		printf ("$state: SNMP error with snmp version $snmp_version ($answer)\n");
  		$session->close;
  		exit $ERRORS{$state};
***************
*** 203,207 ****
  	
  	foreach $key ( keys %{$response}) {
! 		if ($response->{$key} =~ /$ifdescr/) {
  			$key =~ /.*\.(\d+)$/;
  			$snmpkey = $1;
--- 296,300 ----
  	
  	foreach $key ( keys %{$response}) {
! 		if ($response->{$key} =~ /^$ifdescr$/) {
  			$key =~ /.*\.(\d+)$/;
  			$snmpkey = $1;
***************
*** 243,254 ****
  	printf "                        SNMP v2c will use get_bulk for less overhead\n";
  	printf "                        if monitoring with -d\n";
! 	printf "   -k (--key)        SNMP ifIndex value\n";
  	printf "   -d (--descr)      SNMP ifDescr value\n";
  	printf "   -p (--port)       SNMP port (default 161)\n";
  	printf "   -I (--ifmib)      Agent supports IFMIB ifXTable.  Do not use if\n";
! 	printf "                     you don't know what this is.\n";
  	printf "   -V (--version)    Plugin version\n";
  	printf "   -h (--help)       usage help \n\n";
  	printf " -k or -d must be specified\n\n";
  	print_revision($PROGNAME, '$Revision$');
  	
--- 336,354 ----
  	printf "                        SNMP v2c will use get_bulk for less overhead\n";
  	printf "                        if monitoring with -d\n";
! 	printf "   -k (--key)        SNMP IfIndex value\n";
  	printf "   -d (--descr)      SNMP ifDescr value\n";
  	printf "   -p (--port)       SNMP port (default 161)\n";
  	printf "   -I (--ifmib)      Agent supports IFMIB ifXTable.  Do not use if\n";
! 	printf "                     you don't know what this is. \n";
! 	printf "   -n (--name)       the value should match the returned ifName\n";
! 	printf "                     (Implies the use of -I)\n";
! 	printf "   -w (--warn =i|w|c) ignore|warn|crit if the interface is dormant (default critical)\n";
  	printf "   -V (--version)    Plugin version\n";
  	printf "   -h (--help)       usage help \n\n";
  	printf " -k or -d must be specified\n\n";
+ 	printf "Note: either -k or -d must be specified and -d is much more network \n";
+ 	printf "intensive.  Use it sparingly or not at all.  -n is used to match against\n";
+ 	printf "a much more descriptive ifName value in the IfXTable to verify that the\n";
+ 	printf "snmpkey has not changed to some other network interface after a reboot.\n\n";
  	print_revision($PROGNAME, '$Revision$');
  	





More information about the Commits mailing list