From: Stephen L Johnson Date: Thu, 4 May 2000 20:53:18 +0000 (+0000) Subject: fixed some problems with error checking code. It would get stuck after any error X-Git-Tag: spong-2_7-alpha6~2 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39a97ae7b2eeecd1cfec1391c1ac1bd4a7c7a3a8;p=spong.git fixed some problems with error checking code. It would get stuck after any error --- diff --git a/src/lib/Spong/Network/plugins/check_interfaces b/src/lib/Spong/Network/plugins/check_interfaces index a529871..da01cc0 100644 --- a/src/lib/Spong/Network/plugins/check_interfaces +++ b/src/lib/Spong/Network/plugins/check_interfaces @@ -1,16 +1,3 @@ -=head1 NAME - -B - spong-network module to check for down intefaces via SNMP - -=head1 DESCRIPTION - -This is a plugin module for the Spong L program. It is a core -Spong module. The B module checks for down network interfaces -on a host by polling via SNMP. It reports any interfaces that are -administratively up but operationally not up. - -=cut - # Register the routine with the plugin registry $PLUGINS{'interfaces'} = \&check_interfaces; @@ -19,6 +6,7 @@ use SNMP_Session "0.59"; # should be in eval use SNMP_util "0.57"; # should be in eval use Socket; + # This check will connect to a unit and ask it to return the system group # If it can do that, then we assume it is ok - if it can't then something is wrong. @@ -26,9 +14,9 @@ sub check_interfaces { my ($host ) = @_; my ($color, $summary, $message ) = ( "green", "", "" ); my $snmp_session; - my ($community) = $HOSTS{$host}->{'snmp_community'} || 'public'; + my ($snmp_community) = $HOSTS{$host}->{'snmp_community'} || 'public'; - $snmp_session = SNMP_Session->open ($host, $community, 161); + $snmp_session = SNMP_Session->open ($host, $snmp_community, 161); if (! $snmp_session ) { $color = 'red'; @@ -41,12 +29,12 @@ sub check_interfaces { $SNMP_Session::suppress_warnings = 2; my ($ifNumber) = - snmpget("$community\@$host", + snmpget("$snmp_community\@$host", 'ifNumber'); - if ( $SNMP_Session::errmsg ) { + if ( ! defined $ifNumber ) { $color = 'red'; - $summary = 'Error retreiving ifNumber'; + $summary = 'Error retrieving ifNumber'; $message = $SNMP_Session::errmsg . "\n"; return ( $color, $summary, $message ); } @@ -60,9 +48,9 @@ sub check_interfaces { return ($color, $summary, $message ); } - my (%sifdesc, %siftype, %sifadminstatus, %sifoperstatus); + my (%sifdesc, %siftype, %sifadminstatus, %sifoperstatusi, $res); - $snmp_session->map_table ([ + $res = $snmp_session->map_table ([ [1,3,6,1,2,1,2,2,1,1], # ifIndex [1,3,6,1,2,1,2,2,1,2], # ifDescr [1,3,6,1,2,1,2,2,1,3], # ifType @@ -80,7 +68,7 @@ sub check_interfaces { $sifoperstatus{$index} = $ifoperstatus; }); - if ( $SNMP_Session::errmsg ) { + if ( ! defined $res ) { $color = 'red'; $summary = 'Error retreiving ifNumber'; $message = $SNMP_Session::errmsg . "\n"; @@ -109,87 +97,3 @@ sub check_interfaces { debug ("interfaces - $host - $color, $summary", 4 ); return ($color, $summary, $message ); } - -__END__ - -=head2 Output Returned - -=over 4 - -=item Status - -If all interfaces are operationally up, a 'green' status is returned. If a host -is found to have no interfaces a 'yellow' status is returned. Any interfaces -that are operationally down and administratively up, a 'red' status is -returned. Any SNMP session problems will also result in a 'red' status being -returned. - -=item Summary Field - -In normal operation, the status field will show "all interfaces up". If one or -more network interfaces are down, it will show "some interfaces are down". -Otherwise the summary field will have a description of what the problem or -anamoly is. - -=item Detail Message Field - -In normal opereration the detail message field will have a list of all of the -network interfaces in the I table along with the interface -description (I), type (I), administrative status -(I) and operational status (I). Otherwise this -field will have a detailed description of the cause of an error. - -=back - -=head2 Configuration - -=over 4 - -=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 { 'services' => 'interfaces', - 'ip_addr' => ['192.168.13.123'], - 'snmp_community' => 'local-read', - }, - ); - - -=head1 SEE ALSO - -L, L, -L, -L - -=head1 NOTES - -The B module use SNMP to poll a host. It retrieves the -B, B, B, B, and B fields -for every entry in the B table. The module then scans all of all of -the network interfaces inretrieved from the table. Any interface that is -administratively up and is not operationally up will result in an critical -status (red) being return. - -=head1 RESTRICTIONS - -B uses the C, C and C modules -from the B package. The B package must be installed -in order for this module to work. - -The latest version of B package can be obtained from: - - http://www.switch.ch/misc/leinen/snmp/perl/index.html - -=head1 AUTHOR - -The original author is Mike Bayliss >. Extra debug code -and enhancements added by Stephen L Johnson >. - diff --git a/src/lib/Spong/Network/plugins/check_snmp b/src/lib/Spong/Network/plugins/check_snmp index 9068c11..52f86a3 100644 --- a/src/lib/Spong/Network/plugins/check_snmp +++ b/src/lib/Spong/Network/plugins/check_snmp @@ -1,22 +1,3 @@ -=head1 NAME - -B - spong-network module to check for proper SNMP agent operation - -=head1 DESCRIPTION - -This is a plugin module for the Spong L program. It is a core -Spong module. The B module checks for the SNMP agent running -in the host for proper operation. - -The module check SNMP by issuing an I operation for the I -table of the host. If the operation is sucessfully, snmp service is deemed -OK. The module also has an option check for the I. An expected -I value can be specified to be checked against the I -value retrieved in the snmpget operation. If the values don't agree, a -critical (red) status is reported - -=cut - # Register the routine with the plugin registry $PLUGINS{'snmp'} = \&check_snmp; @@ -33,7 +14,7 @@ sub check_snmp { my ($color, $summary, $message ) = ( "green", "", "" ); my $snmp_session; my ($community) = $HOSTS{$host}->{'snmp_community'} || 'public'; - my ($expect) = $HOSTS{$host}->{'expect_objid'}; + my ($expect) = $HOSTS{$host}->{'expect_oid'}; $snmp_session = SNMP_Session->open ($host, $community, 161); @@ -56,7 +37,7 @@ sub check_snmp { 'sysLocation', 'sysObjectID'); - if ( $SNMP_Session::errmsg ) { + if ( ! defined $sysDescr ) { $color = 'red'; $summary = 'Error retreiving System Group information'; $message = $SNMP_Session::errmsg . "\n"; @@ -91,98 +72,7 @@ sub check_snmp { return ($color, $summary, $message ); } -1; - -__END__ - -=head2 Output Returned - -=over 4 - -=item Status - -If the I operation is successfully, 'green' status is return. If an -SNMP error occurs a 'red' status is returned. - -If an C is specified for the host, a 'green' status is returned -if the I operation is successful and the I value matches -the C. If the values don't match, a 'red' status is returned. - -=item Summary Field - -If there are no problems, "snmp ok" is returned. Otherwise the summary field -will have a short description of that the problem or anamoly is. - -=item Detail Message Field - -If normal operation the detail message will have the values of the system -description (B), uptime (B), contact (B), name -(B), location (B), and object id (B) fields -from the System Group. If an C. To override the default name -specify a C attribute in a host's entry in the I<%HOSTS) -variable in the L configuration file. See the L value to be checked against the -retrieved. Specify a C attribute in a host's entry in the -I<%HOSTS> variable in the L configuration file. See the -L section for a detailed example. - -=back - -=head1 EXAMPLES - - %HOSTS = ( 'hostname.my-inc.com' => { 'services' => 'snmp', - 'ip_addr' => ['192.168.13.123'], - 'snmp_community' => 'local-read', - 'expect_objid' => - '1.3.6.1.4.1.2021.250.10', - ); - -=head1 SEE ALSO - -L, L, -L, -L - -=head1 NOTES - -The B module uses an SNMP I operation to poll a host. -It retrieves the values of the system description (B), uptime -(B), contact (B), name (B), location -(B), and object id (B) fields from the System Group. -If the I operation was successful, the snmp service is deemed OK. - -If an optional C value is specified for the host, it will be -compared to the I value retrieved from the host. If the values -don't match a critical ('red') status is generated. - -=head1 RESTRICTIONS - -B uses the C, C and C modules -from the B package. The B package must be installed -in order for this module to work. - -The latest version of B package can be obtained from: - - http://www.switch.ch/misc/leinen/snmp/perl/index.html - -=head1 AUTHOR - -The original author is Mike Bayliss >. Extra debug code -and enhancements added by Stephen L Johnson >. +1;