From: Stephen L Johnson Date: Wed, 20 Dec 2000 23:32:43 +0000 (+0000) Subject: added ignore_interface facility to allow for skipping of interfaces checks X-Git-Tag: spong-2_7_2~17 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35492781ecbf762c120eacb13902ad694d4c5393;p=spong.git added ignore_interface facility to allow for skipping of interfaces checks --- diff --git a/src/lib/Spong/Network/plugins/check_interfaces b/src/lib/Spong/Network/plugins/check_interfaces index ebebdca..fd69769 100644 --- a/src/lib/Spong/Network/plugins/check_interfaces +++ b/src/lib/Spong/Network/plugins/check_interfaces @@ -10,8 +10,6 @@ on a host by polling via SNMP. It reports any interfaces that are administratively up but operationally not up. =cut -# -# $Id: check_interfaces,v 1.5 2000/11/29 17:12:49 sljohnson Exp $ # Register the routine with the plugin registry $PLUGINS{'interfaces'} = \&check_interfaces; @@ -28,11 +26,21 @@ use Socket; sub check_interfaces { my ($host ) = @_; my ($color, $summary, $message ) = ( "green", "", "" ); - my $snmp_session; + my( $snmp_session, @skipped_interfaces ); + my ($snmp_community) = $HOSTS{$host}->{'snmp_community'} || $HOSTS_DEFAULTS{'snmp_community'} || 'public'; + # Find the list of interfaces to ignore/skip + @skipped_interfaces = @{$HOSTS{$host}{'ignore_interfaces'}}; + @skipped_interfaces = @{$HOSTS_DEFAULTS{'ignore_interfaces'}} + if( ! @skipped_interfaces ); + + # Append mandatory interfaces to skip + @skipped_interfaces = ( @skipped_interfaces, + @{$HOSTS_ALL{'ignore_interfaces'}} ); + $snmp_session = SNMP_Session->open ($host, $snmp_community, 161); if (! $snmp_session ) { @@ -93,6 +101,7 @@ sub check_interfaces { } my $index; + my $redcount = 0; foreach $index ( sort { $a <=> $b } keys %sifdesc) { $message .= "interface $index status:\n"; $message .= "\tifDescr: $sifdesc{$index}\n"; @@ -100,13 +109,22 @@ sub check_interfaces { $message .= "\tifAdminStatus: $sifadminstatus{$index}\n"; $message .= "\tifOperStatus: $sifoperstatus{$index}\n"; # If interface is not up and is admin up, we got a problem - if ($sifoperstatus{$index} != 1 && $sifadminstatus{$index} != 1) { - $color = "red"; + if ($sifoperstatus{$index} != 1 && $sifadminstatus{$index} == 1) { + my $skip = 0; + if( @skipped_interfaces ) { + foreach my $intf (@skipped_interfaces) { + if( $sifdesc{$index} eq $intf ) { + $skip = 1; last; + } + } + } + $redcount++ unless $skip; } } - if ($color eq "red") { - $summary = "some interfaces are down"; + if ($redcount > 0) { + $color = "red"; + $summary = "$redcount interfaces are down"; } else { $summary = "all interfaces up"; } @@ -155,10 +173,26 @@ field will have a detailed description of the cause of an error. =item SNMP Community Name -The default SNMP Community name is I. To override the default name -specify a C attribute in a host's entry in the I<%HOSTS> -variabile of the L configuration file. See the -L<"EXAMPLES"> for a detailed example. +The default SNMP Community name is I. To provide an alternate default +SNMP Community name add it to the +L<$HOSTS_DEFAULTS|spong.conf/"$HOSTS_DEFAULTS"> entry in the B file +(i.e. $HOSTS_DEFAULTS{'snmp_community'} = 'secret';). + +To override the default name on a per host basis, specify a C +attribute in a host's entry in the I<%HOSTS> variabile of the L +configuration file. See the L section for a detailed +example. + +=item Ignored Interfaces + +You can also specify a list of network interfaces for the B +module to ignore. Add an 'ignore_interfaces' attribute to a host entry in +$HOSTS with a list of network interface to ignore. + +A default list of interfaces to ignore is added an 'ignore_interfaces' entry +to the $HOSTS_DEFAULTS variable. A list of interfaces to ignore in all hosts +is created by adding an 'ignore_interfaces' entry to the $HOSTS_ALL varirable. +See the L section for a detailed example. =back @@ -167,15 +201,24 @@ L<"EXAMPLES"> for a detailed example. %HOSTS = ( 'hostname.my-inc.com' => { 'services' => 'interfaces', 'ip_addr' => ['192.168.13.123'], 'community' => 'local-read', + 'ignore_interfaces' => ['ppp1','ppp2']; }, ); + $HOSTS_DEFAULTS{'snmp_community'} = 'mysecret'; + + # Ignore the unused default intefaces on more servers + $HOSTS_DEFAULTS{'ignore_interfaces'} = ['et0','lan0']; + + # Skip the loopback interface on the linux boxes + $HOSTS_ALL('ignore_interfaces} = ['lo0']; + =head1 SEE ALSO L, L, L, -L +L =head1 NOTES