[Nagiosplug-devel] check_ifstatus patch to allow specifying a list of unused ports

Hannu Liljemark hannu.liljemark at laurea.fi
Fri Jan 3 13:31:07 CET 2003


Hai,

The excellent check_ifstatus plugin was getting on my nerves as the
24-port switch I use for testing doesn't have all interface in use.
The plugin ends up giving a list in its output that is too long for
Nagios to show completely, and I get unwanted emails :-) (Well I could
disable notifications...)

So I tried patching the plugin to accept a list of ports that are
known to be unused (and down):

$ ./check_ifstatus -H router -u 2
OK: host 'router', interfaces up: 1, down: 0, dormant: 0, unused: 1

Okay that output isn't from the switch I usually use... Anyhow, you
give a comma-separated list of the ports by using -u or --unused.

I'm not completely sure if this patch is any use for others, but I
attached the diff anyway to this mail. Hope someone finds it useful.

-- 
(Mr.) Hannu Liljemark  |  Appelsiini Finland Oy  |  http://appelsiini.com
-------------- next part --------------
*** check_ifstatus~	Thu Dec 19 10:30:25 2002
--- check_ifstatus	Thu Jan  2 15:50:17 2003
***************
*** 63,68 ****
--- 63,70 ----
  my $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28';
  my $snmpIfType = '1.3.6.1.2.1.2.2.1.3';
  my $hostname;
+ my @unused_ports;
+ my $unused_ports = "";
  my $session;
  my $error;
  my $response;
***************
*** 97,102 ****
--- 99,105 ----
  		"C=s" =>\$community,"community=s" => \$community,
  		"p=i" =>\$port, "port=i" => \$port,
  		"H=s" => \$hostname, "hostname=s" => \$hostname,
+ 		"u=s" => \$unused_ports, "unused_ports=s" => \$unused_ports,
  		"I"	  => \$ifXTable, "ifmib" => \$ifXTable );
  		
  if ($status == 0)
***************
*** 105,110 ****
--- 108,114 ----
  	exit $ERRORS{'OK'};
  }
  
+ @unused_ports = split(/,/, $unused_ports);
  
  if ($opt_V) {
  	print_revision($PROGNAME,'$Revision: 1.2 $ ');
***************
*** 182,189 ****
--- 186,196 ----
  
  $session->close;
  
+ foreach $key (@unused_ports) { $ifStatus{$key}{'notInUse'}++ ;}
  foreach $key (keys %ifStatus) {
  
+ 	# skip unused interfaces
+ if (!defined($ifStatus{$key}{'notInUse'})) { 
  	# check only if interface is administratively up
      if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
      	# check only if interface is not of type 23  aka PPP interface
***************
*** 202,222 ****
  
     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};
--- 209,233 ----
  
     if ($ifdown > 0) {
        $state = 'CRITICAL';
!       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, unused: %d<BR>",
                          $hostname,
  			$ifup,
  			$ifdown,
! 			$ifdormant,
! 			scalar(@unused_ports));
        $answer = $answer . $ifmessage . "\n";
     }
     else {
        $state = 'OK';
!       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, unused: %d\n",
                          $hostname,
  			$ifup,
  			$ifdown,
! 			$ifdormant,
! 			scalar(@unused_ports));
     }
+ }
+ }
  
  print ("$state: $answer");
  exit $ERRORS{$state};
***************
*** 246,251 ****
--- 257,263 ----
  	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 "   -u (--unused)     Comma-separated list of unused ports known to be down\n";
  	printf "   -V (--version)    Plugin version\n";
  	printf "   -h (--help)       usage help \n\n";
  	print_revision($PROGNAME, '$Revision: 1.2 $');


More information about the Devel mailing list