[Nagiosplug-checkins] CVS: nagiosplug/plugins-scripts check_ifstatus.pl,1.3,1.4

Subhendu Ghosh sghosh at users.sourceforge.net
Fri Apr 11 15:10:11 CEST 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins-scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv26942/plugins-scripts

Modified Files:
	check_ifstatus.pl 
Log Message:
bug 691412, added feature -x (list of excluded ifTypes)

Index: check_ifstatus.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/check_ifstatus.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** check_ifstatus.pl	3 Feb 2003 05:29:54 -0000	1.3
--- check_ifstatus.pl	11 Apr 2003 22:09:48 -0000	1.4
***************
*** 71,74 ****
--- 71,75 ----
  my $ifdown =0;
  my $ifdormant = 0;
+ my $ifexclude =0 ;
  my $ifmessage = "";
  my $snmp_version = 1;
***************
*** 76,79 ****
--- 77,82 ----
  my $opt_h ;
  my $opt_V ;
+ my $opt_x ;
+ my %excluded ;
  
  
***************
*** 98,102 ****
  		"p=i" =>\$port, "port=i" => \$port,
  		"H=s" => \$hostname, "hostname=s" => \$hostname,
! 		"I"	  => \$ifXTable, "ifmib" => \$ifXTable );
  		
  if ($status == 0)
--- 101,106 ----
  		"p=i" =>\$port, "port=i" => \$port,
  		"H=s" => \$hostname, "hostname=s" => \$hostname,
! 		"I"	  => \$ifXTable, "ifmib" => \$ifXTable,
! 		"x:s"		=>	\$opt_x,   "exclude:s" => \$opt_x);
  		
  if ($status == 0)
***************
*** 117,120 ****
--- 121,140 ----
  }
  
+ 
+ if (defined $opt_x) {
+ 	my @x = split(",", $opt_x);
+ 	my $x;
+ 	if ( @x) {
+ 		foreach $x (@x){
+ 			$excluded{$x} = 1;
+ 		}
+ 	}else{
+ 		$excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post)
+ 	}
+ 	#debugging
+ 	#foreach $x (keys %excluded) 
+ 	#	{ print "key = $x  val = $excluded{$x}\n";}
+ }
+ 
  if (! utils::is_hostname($hostname)){
  	usage();
***************
*** 160,163 ****
--- 180,185 ----
  push(@snmpoids,$snmpIfType);
  push(@snmpoids,$snmpIfName) if ( defined $ifXTable);
+ push(@snmpoids,$snmpIfAlias) if ( defined $ifXTable);
+ 
  
  
***************
*** 169,173 ****
        $session->close;
        $state = 'CRITICAL';
!       print ("$state: $answer for $snmpoid  with snmp version $snmp_version\n");
        exit $ERRORS{$state};
     }
--- 191,199 ----
        $session->close;
        $state = 'CRITICAL';
! 			if ( ( $snmpoid =~ $snmpIfName ) && defined $ifXTable ) {
! 				print ("$state: Device does not support ifTable - try without -I option\n");
! 			}else{
! 	      print ("$state: $answer for $snmpoid  with snmp version $snmp_version\n");
! 			}
        exit $ERRORS{$state};
     }
***************
*** 187,201 ****
  	# check only if interface is administratively up
      if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
!     	# check only if interface is not of type 23  aka PPP interface
! 		if ($ifStatus{$key}{$snmpIfType} != 23 ) {
  			if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
          	if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
              	$ifdown++ ;
! 				$ifmessage .= sprintf("%s: down -> %s<BR>",
!                                  $ifStatus{$key}{$snmpIfDescr},
! 								 $ifStatus{$key}{$snmpIfName});
  			}
           	if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
  		}
  	}
     
--- 213,237 ----
  	# check only if interface is administratively up
      if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
!     
! 		# check only if interface type is not listed in %excluded
! 		
! 		if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
  			if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
          	if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
              	$ifdown++ ;
! 							if (defined $ifXTable) {
! 								$ifmessage .= sprintf("%s: down -> %s<BR>",
!                                 $ifStatus{$key}{$snmpIfName},
! 								 								$ifStatus{$key}{$snmpIfAlias});
! 							}else{
! 								$ifmessage .= sprintf("%s: down <BR>",
! 																$ifStatus{$key}{$snmpIfDescr});
! 							}
  			}
           	if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
+ 		}else{
+ 			$ifexclude++;
  		}
+ 		
  	}
     
***************
*** 204,224 ****
     if ($ifdown > 0) {
        $state = 'CRITICAL';
!       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d<BR>",
                          $hostname,
  			$ifup,
  			$ifdown,
! 			$ifdormant);
        $answer = $answer . $ifmessage . "\n";
     }
     else {
        $state = 'OK';
!       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d\n",
                          $hostname,
  			$ifup,
  			$ifdown,
! 			$ifdormant);
     }
! 
! print ("$state: $answer");
  exit $ERRORS{$state};
  
--- 240,262 ----
     if ($ifdown > 0) {
        $state = 'CRITICAL';
!       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d<BR>",
                          $hostname,
  			$ifup,
  			$ifdown,
! 			$ifdormant,
! 			$ifexclude);
        $answer = $answer . $ifmessage . "\n";
     }
     else {
        $state = 'OK';
!       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d",
                          $hostname,
  			$ifup,
  			$ifdown,
! 			$ifdormant,
! 			$ifexclude);
     }
! my $perfdata = sprintf("up:%d,down:%d,dormant:%d,excluded:%d",$ifup,$ifdown,$ifdormant,$ifexclude);
! print ("$state: $answer |$perfdata\n");
  exit $ERRORS{$state};
  
***************
*** 237,241 ****
  sub print_help {
  	printf "check_ifstatus plugin for Nagios monitors operational \n";
!   	printf "status of each network interface (except PPP interfaces) on the target host\n";
  	printf "\nUsage:\n";
  	printf "   -H (--hostname)   Hostname to query - (required)\n";
--- 275,279 ----
  sub print_help {
  	printf "check_ifstatus plugin for Nagios monitors operational \n";
!  	printf "status of each network interface on the target host\n";
  	printf "\nUsage:\n";
  	printf "   -H (--hostname)   Hostname to query - (required)\n";
***************
*** 246,251 ****
  	printf "                        SNMP v2c will use get_bulk for less overhead\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";
--- 284,292 ----
  	printf "                        SNMP v2c will use get_bulk for less overhead\n";
  	printf "   -p (--port)       SNMP port (default 161)\n";
! 	printf "   -I (--ifmib)      Agent supports IFMIB ifXTable.  For Cisco - this will provide\n";
! 	printf "                     the descriptive name.  Do not use if you don't know what this is. \n";
! 	printf "   -x (--exclude)    A comma separated list of ifType values that should be excluded \n";
! 	printf "                     from the report (default for an empty list is PPP(23).\n";
! 	printf "                     See the IANAifType-MIB for a list of interface types.\n";
  	printf "   -V (--version)    Plugin version\n";
  	printf "   -h (--help)       usage help \n\n";





More information about the Commits mailing list