Compare commits

..

9 Commits

Author SHA1 Message Date
Max Baker
bd457307ff Module did not return 1 and failed to load under specify() 2003-06-18 16:25:08 +00:00
Max Baker
f988cecc4d version 0.5 prep 2003-06-10 16:50:44 +00:00
Max Baker
d2f67b2db2 Added partial table lookup capabilities 2003-05-30 21:04:56 +00:00
Max Baker
c4a4c3d5e6 *** empty log message *** 2003-05-30 21:04:06 +00:00
Max Baker
fa38fdbc2b Added IP Route Table 2003-05-30 19:22:15 +00:00
Max Baker
2e03e3faca added undef checking in os_*() 2003-05-27 15:38:59 +00:00
Max Baker
e448915e0b Added SUPPORT section 2003-05-14 01:07:28 +00:00
Max Baker
37836bedac minor undef warnings 2003-05-12 21:20:48 +00:00
Max Baker
a60663b238 doc change 2003-04-29 18:24:23 +00:00
23 changed files with 392 additions and 43 deletions

View File

@@ -1,6 +1,13 @@
SNMP::Info - Perl5 OO Interface to Network Devices and SNMP MIBs
ChangeLog $Id$
version 0.5 (06/10/03)
* Added ability to get paritial tables. For example to get the
IP routing table for 128.114.* you can do
$ipr = $dev->ipr_dest('128.114');
* Added IP Routing Table entries from RFC1213 to SNMP::Info
* minor bug fixes
version 0.4 (04/29/03)
* BIG CHANGE ! Internal Data structure has changed.
* Added clear_cache() method
@@ -24,11 +31,11 @@ version 0.3 (03/06/03)
and _load_attr
* Added more debugging
* Added info and munging for c_capabilities in SNMP::Info::CD
Thanks to Martin Lorensen <martin@lorensen.dk>
Thanks to Martin Lorensen <martin /at- lorensen.dk>
* Removed requirement for SNMP in the Makefile.PL and moved it to t/prereq.t
so that the Module will install via CPAN without trying to install the old
4.2.0 version of SNMP on CPAN. Will now fail in the test phase.
Thanks again to Martin Lorensen <martin@lorensen.dk>
Thanks again to Martin Lorensen <martin /at- lorensen.dk>
* Moved tests from test.pl to t/*
version 0.2 (02/19/03)

228
Info.pm
View File

@@ -7,7 +7,7 @@
# See COPYRIGHT at bottom
package SNMP::Info;
$VERSION = 0.4;
$VERSION = 0.5;
use strict;
use Exporter;
@@ -27,7 +27,7 @@ SNMP::Info - Object Oriented Perl5 Interface to Network devices and MIBs through
=head1 VERSION
SNMP::Info - Version 0.4
SNMP::Info - Version 0.5
=head1 AUTHOR
@@ -85,6 +85,11 @@ SNMP::Info was created at UCSC for the netdisco project (www.netdisco.org)
}
=head1 SUPPORT
Please direct all support, help, and bug requests to the snmp-info-users Mailing List
at L<http://lists.sourceforge.net/lists/listinfo/snmp-info-users>
=head1 DESCRIPTION
SNMP::Info gives an object oriented interface to information obtained through SNMP.
@@ -799,6 +804,7 @@ correspond with the number of physical ports
Each of these methods returns a hash_reference to a hash keyed on the interface index in SNMP.
Example : $info->interfaces() might return
{ '1.12' => 'FastEthernet/0',
'2.15' => 'FastEthernet/1',
'9.99' => 'FastEthernet/2'
@@ -807,6 +813,20 @@ Example : $info->interfaces() might return
The key is what you would see if you were to do an snmpwalk, and in some cases changes between reboots of
the network device.
=head2 Partial Table Fetches
If you want to get only a part of an SNMP table and you know the IID for the part of the table that you
want, you can specify it in the call:
$local_routes = $info->ipr_route('192.168.0');
This will only fetch entries in the table that start with C<192.168.0>, which in this case are routes on the local
network.
Remember that you must supply the partial IID (a numeric OID).
Partial table results are not cached.
=head3 Interface Information
=over
@@ -996,6 +1016,139 @@ Gives broadcast address for IP table entry.
=back
=head3 IP Routing Table
=over
=item $info->ipr_route()
The route in question. A value of 0.0.0.0 is the default gateway route.
(C<ipRouteDest>)
=item $info->ipr_if()
The interface (IID) that the route is on. Use interfaces() to map.
(C<ipRouteIfIndex>)
=item $info->ipr_1()
Primary routing metric for this route.
(C<ipRouteMetric1>)
=item $info->ipr_2()
If metrics are not used, they should be set to -1
(C<ipRouteMetric2>)
=item $info->ipr_3()
(C<ipRouteMetric3>)
=item $info->ipr_4()
(C<ipRouteMetric4>)
=item $info->ipr_5()
(C<ipRouteMetric5>)
=item $info->ipr_dest()
From RFC1213:
"The IP address of the next hop of this route.
(In the case of a route bound to an interface
which is realized via a broadcast media, the value
of this field is the agent's IP address on that
interface.)"
(C<ipRouteNextHop>)
=item $info->ipr_type()
From RFC1213:
other(1), -- none of the following
invalid(2), -- an invalidated route
-- route to directly
direct(3), -- connected (sub-)network
-- route to a non-local
indirect(4) -- host/network/sub-network
"The type of route. Note that the values
direct(3) and indirect(4) refer to the notion of
direct and indirect routing in the IP
architecture.
Setting this object to the value invalid(2) has
the effect of invalidating the corresponding entry
in the ipRouteTable object. That is, it
effectively disassociates the destination
identified with said entry from the route
identified with said entry. It is an
implementation-specific matter as to whether the
agent removes an invalidated entry from the table.
Accordingly, management stations must be prepared
to receive tabular information from agents that
corresponds to entries not currently in use.
Proper interpretation of such entries requires
examination of the relevant ipRouteType object."
(C<ipRouteType>)
=item $info->ipr_proto()
From RFC1213:
other(1), -- none of the following
-- non-protocol information,
-- e.g., manually configured
local(2), -- entries
-- set via a network
netmgmt(3), -- management protocol
-- obtained via ICMP,
icmp(4), -- e.g., Redirect
-- the remaining values are
-- all gateway routing
-- protocols
egp(5),
ggp(6),
hello(7),
rip(8),
is-is(9),
es-is(10),
ciscoIgrp(11),
bbnSpfIgp(12),
ospf(13),
bgp(14)
(C<ipRouteProto>)
=item $info->ipr_age()
Seconds since route was last updated or validated.
(C<ipRouteAge>)
=item $info->ipr_mask()
Subnet Mask of route. 0.0.0.0 for default gateway.
(C<ipRouteMask>)
=item $info->ipr_info()
Reference to MIB definition specific to routing protocol.
(C<ipRouteInfo>)
=back
=head2 Setting data via SNMP
This section explains how to use SNMP::Info to do SNMP Set operations.
@@ -1126,7 +1279,21 @@ These are table entries, such as the IfIndex
'i_pkts_multi_out64' => 'ifHCOutMulticastPkts',
'i_pkts_bcast_in64' => 'ifHCInBroadcastPkts',
'i_pkts_bcast_out64' => 'ifHCOutBroadcastPkts',
'i_alias' => 'ifAlias'
'i_alias' => 'ifAlias',
# IP Routing Table
'ipr_route'=> 'ipRouteDest',
'ipr_if' => 'ipRouteIfIndex',
'ipr_1' => 'ipRouteMetric1',
'ipr_2' => 'ipRouteMetric2',
'ipr_3' => 'ipRouteMetric3',
'ipr_4' => 'ipRouteMetric4',
'ipr_5' => 'ipRouteMetric5',
'ipr_dest' => 'ipRouteNextHop',
'ipr_type' => 'ipRouteType',
'ipr_proto'=> 'ipRouteProto',
'ipr_age' => 'ipRouteAge',
'ipr_mask' => 'ipRouteMask',
'ipr_info' => 'ipRouteInfo',
);
=item %MIBS
@@ -1751,20 +1918,37 @@ Called from $info->load_METHOD();
=cut
sub _load_attr {
my $self = shift;
my ($attr,$leaf) = @_;
my ($attr,$leaf,$partial) = @_;
my $ver = $self->snmp_ver();
my $nosuch = $self->nosuch();
my $sess = $self->session();
my $store = $self->store();
my $munge = $self->munge();
return undef unless defined $sess;
# Get the callback hash for data munging
my $munge = $self->munge();
# Deal with partial entries.
my $varleaf = $leaf;
if (defined $partial) {
# If we aren't supplied an OID translate
if ($leaf !~ /^[.\d]*$/) {
# VarBind will not resolve mixed OID and leaf entries like
# "ipRouteMask.255.255". So we convert to full OID
my $oid = &SNMP::translateObj($leaf);
unless (defined $oid) {
$self->error_throw("SNMP::Info::_load_attr: Can't translate $leaf.$partial. Missing MIB?\n");
return undef;
}
$varleaf = "$oid.$partial";
} else {
$varleaf = "$leaf.$partial";
}
}
$self->debug() and print "SNMP::Info::_load_attr $attr : $leaf\n";
$self->debug() and print "SNMP::Info::_load_attr $attr : $leaf",
defined $partial ? "($partial)" : '', "\n";
my $var = new SNMP::Varbind([$leaf]);
my $var = new SNMP::Varbind([$varleaf]);
# So devices speaking SNMP v.1 are not supposed to give out
# data from SNMP2, but most do. Net-SNMP, being very precise
@@ -1776,11 +1960,13 @@ sub _load_attr {
if ($ver == 1 and $nosuch and $errornum and $sess->{ErrorStr} =~ /nosuch/i){
$errornum = 0;
}
my $localstore = undef;
while (! $errornum ){
$sess->getnext($var);
$errornum = $sess->{ErrorNum};
#print "$var->[0] $var->[1] $var->[2] $var->[3]\n";
last if $var->[0] ne $leaf;
my $iid = $var->[1];
my $val = $var->[2];
@@ -1788,6 +1974,13 @@ sub _load_attr {
$self->error_throw("SNMP::Info::_load_attr: $attr not here");
next;
}
# Check to make sure we are still in partial land
if (defined $partial and $iid !~ /^$partial$/ and $iid !~ /^$partial\./){
#print "$iid makes us leave partial land.\n";
last;
}
if ($val eq 'NOSUCHOBJECT'){
$self->error_throw("SNMP::Info::_load_atr: $attr : NOSUCHOBJECT");
next;
@@ -1804,13 +1997,16 @@ sub _load_attr {
$val = &$subref($val);
}
$store->{$attr}->{$iid}=$val;
$localstore->{$iid}=$val;
}
# mark data as loaded
$self->{"_${attr}"}++;
# Cache data if we are not getting partial data:
if (!defined $partial){
$self->{"_${attr}"}++;
$store->{$attr}=$localstore;
}
return $store->{$attr};
return $localstore;
}
=item $info->_show_attr()
@@ -1911,9 +2107,9 @@ sub AUTOLOAD {
# Otherwise we must be listed in %FUNCS
# Load data if not already cached
$self->_load_attr( $attr, $funcs{$attr} )
unless defined $self->{"_${attr}"};
# Load data if it both not cached and we are not requesting partial info.
return $self->_load_attr( $attr, $funcs{$attr},@_ )
unless (defined $self->{"_${attr}"} and !scalar(@_));
return $self->_show_attr($attr);
}

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Bridge;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::CDP;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::CiscoStats;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Entity;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::EtherLike;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer1;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer1::Allied;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer1::Asante;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;
@@ -208,7 +208,7 @@ Asante device through SNMP.
Download from http://www.mibdepot.com
=items MIBs listed in SNMP::Info::Layer1
=item MIBs listed in SNMP::Info::Layer1
=back

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::Aironet;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::Bay;
$VERSION = 0.4;
$VERSION = 0.6;
# $Id$
use strict;
@@ -80,6 +80,7 @@ sub os {
sub os_ver {
my $bay = shift;
my $descr = $bay->description();
return undef unless defined $descr;
# 303 / 304
if ($descr =~ m/Rev: \d+\.\d+\.\d+\.\d+-(\d+\.\d+\.\d+\.\d+)/){
@@ -96,6 +97,7 @@ sub os_ver {
sub os_bin {
my $bay = shift;
my $descr = $bay->description();
return undef unless defined $descr;
# 303 / 304
if ($descr =~ m/Rev: \d+\.(\d+\.\d+\.\d+)-\d+\.\d+\.\d+\.\d+/){
@@ -152,7 +154,9 @@ sub i_mac {
sub model {
my $bay = shift;
my $id = $bay->id();
return undef unless defined $id;
my $model = &SNMP::translateObj($id);
return $id unless defined $model;
$model =~ s/^sreg-//i;
my $descr = $bay->description();
@@ -257,7 +261,7 @@ sub c_platform {
return \%c_platform;
}
1;
__END__
=head1 NAME

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::C1900;
$VERSION = 0.4;
$VERSION = 0.6;
# $Id$
use strict;
@@ -189,6 +189,8 @@ sub i_name {
return $i_name;
}
1;
__END__
=head1 NAME

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::C2900;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::Catalyst;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::HP;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer3;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer3::Aironet;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer3::C3550;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer3::Foundry;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

View File

@@ -28,7 +28,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::MAU;
$VERSION = 0.4;
$VERSION = 0.5;
# $Id$
use strict;

146
README
View File

@@ -5,7 +5,7 @@ NAME
VERSION
SNMP::Info - Version 0.4
SNMP::Info - Version 0.5
AUTHOR
@@ -64,6 +64,12 @@ SYNOPSIS
}
SUPPORT
Please direct all support, help, and bug requests to the snmp-info-users
Mailing List at
http://lists.sourceforge.net/lists/listinfo/snmp-info-users
DESCRIPTION
SNMP::Info gives an object oriented interface to information obtained
@@ -477,12 +483,30 @@ USAGE
Each of these methods returns a hash_reference to a hash keyed on the
interface index in SNMP.
Example : $info->interfaces() might return { '1.12' => 'FastEthernet/0',
'2.15' => 'FastEthernet/1', '9.99' => 'FastEthernet/2' }
Example : $info->interfaces() might return
{ '1.12' => 'FastEthernet/0',
'2.15' => 'FastEthernet/1',
'9.99' => 'FastEthernet/2'
}
The key is what you would see if you were to do an snmpwalk, and in some
cases changes between reboots of the network device.
Partial Table Fetches
If you want to get only a part of an SNMP table and you know the IID for
the part of the table that you want, you can specify it in the call:
$local_routes = $info->ipr_route('192.168.0');
This will only fetch entries in the table that start with "192.168.0",
which in this case are routes on the local network.
Remember that you must supply the partial IID (a numeric OID).
Partial table results are not cached.
Interface Information
$info->interfaces()
@@ -638,6 +662,122 @@ USAGE
(ipAdEntBcastAddr)
IP Routing Table
$info->ipr_route()
The route in question. A value of 0.0.0.0 is the default gateway
route.
("ipRouteDest")
$info->ipr_if()
The interface (IID) that the route is on. Use interfaces() to map.
("ipRouteIfIndex")
$info->ipr_1()
Primary routing metric for this route.
("ipRouteMetric1")
$info->ipr_2()
If metrics are not used, they should be set to -1
("ipRouteMetric2")
$info->ipr_3()
("ipRouteMetric3")
$info->ipr_4()
("ipRouteMetric4")
$info->ipr_5()
("ipRouteMetric5")
$info->ipr_dest()
From RFC1213:
"The IP address of the next hop of this route.
(In the case of a route bound to an interface
which is realized via a broadcast media, the value
of this field is the agent's IP address on that
interface.)"
("ipRouteNextHop")
$info->ipr_type()
From RFC1213:
other(1), -- none of the following
invalid(2), -- an invalidated route
-- route to directly
direct(3), -- connected (sub-)network
-- route to a non-local
indirect(4) -- host/network/sub-network
"The type of route. Note that the values
direct(3) and indirect(4) refer to the notion of
direct and indirect routing in the IP
architecture.
Setting this object to the value invalid(2) has
the effect of invalidating the corresponding entry
in the ipRouteTable object. That is, it
effectively disassociates the destination
identified with said entry from the route
identified with said entry. It is an
implementation-specific matter as to whether the
agent removes an invalidated entry from the table.
Accordingly, management stations must be prepared
to receive tabular information from agents that
corresponds to entries not currently in use.
Proper interpretation of such entries requires
examination of the relevant ipRouteType object."
("ipRouteType")
$info->ipr_proto()
From RFC1213:
other(1), -- none of the following
-- non-protocol information,
-- e.g., manually configured
local(2), -- entries
-- set via a network
netmgmt(3), -- management protocol
-- obtained via ICMP,
icmp(4), -- e.g., Redirect
-- the remaining values are
-- all gateway routing
-- protocols
egp(5),
ggp(6),
hello(7),
rip(8),
is-is(9),
es-is(10),
ciscoIgrp(11),
bbnSpfIgp(12),
ospf(13),
bgp(14)
("ipRouteProto")
$info->ipr_age()
Seconds since route was last updated or validated.
("ipRouteAge")
$info->ipr_mask()
Subnet Mask of route. 0.0.0.0 for default gateway.
("ipRouteMask")
$info->ipr_info()
Reference to MIB definition specific to routing protocol.
("ipRouteInfo")
Setting data via SNMP
This section explains how to use SNMP::Info to do SNMP Set operations.