Thread: [Netpass-devel] NetPass/lib/SNMP/Device BayStack.pm,1.6,1.7 BayStack3.pm,1.3,1.4 Cisco.pm,1.3,1.4
Brought to you by:
jeffmurphy
From: jeff m. <jef...@us...> - 2006-01-05 21:02:44
|
Update of /cvsroot/netpass/NetPass/lib/SNMP/Device In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32033/lib/SNMP/Device Modified Files: BayStack.pm BayStack3.pm Cisco.pm Log Message: various changes to reporting, nothing major Index: Cisco.pm =================================================================== RCS file: /cvsroot/netpass/NetPass/lib/SNMP/Device/Cisco.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Cisco.pm 3 Aug 2005 00:42:58 -0000 1.3 +++ Cisco.pm 5 Jan 2006 21:02:35 -0000 1.4 @@ -402,4 +402,25 @@ return ($res->{$oid} == 1) ? 1 : 0; } + +=head2 B<get_if_info($port)> + +=over 8 + +This will return a hash with all interfaces (or just the one +you specified) and their information, including unit, port, admin status, +operational status, autonegotiation, duplex, speed, fcs errors, vlan +tagged/untagged, PVID, and member VLANS. The B<$port> parameter +is the final digit of the OID, not really the port number. + +=back + +=cut + +sub get_if_info { + my $self = shift; + my $port = shift; + die "not implemented"; +} + 1; Index: BayStack3.pm =================================================================== RCS file: /cvsroot/netpass/NetPass/lib/SNMP/Device/BayStack3.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- BayStack3.pm 15 Oct 2004 15:49:35 -0000 1.3 +++ BayStack3.pm 5 Jan 2006 21:02:35 -0000 1.4 @@ -123,13 +123,15 @@ } -=head2 B<get_if_info()> +=head2 B<get_if_info($port)> =over 8 -This will return a hash with all interfaces and their information, -including unit, port, admin status, operational status, autonegotiation, -duplex, speed, fcs errors, vlan tagged/untagged, PVID, and member VLANS. +This will return a hash with all interfaces (or just the one +you specified) and their information, including unit, port, admin status, +operational status, autonegotiation, duplex, speed, fcs errors, vlan +tagged/untagged, PVID, and member VLANS. The B<$port> parameter +is the final digit of the OID, not really the port number. =back @@ -137,6 +139,7 @@ sub get_if_info { my $self = shift; + my $port = shift; my $port_info = {}; @@ -153,6 +156,27 @@ 'fcs_errors' => '.1.3.6.1.2.1.10.7.2.1.3', }; + if ($port) { + my @vbl; + my $oid2name = {}; + foreach my $name (keys %$oids) { + push @vbl, $oids->{$name}.".$port"; + $oid2name->{$oids->{$name}.".$port"} = $name; + } + + my $r = $self->snmp->get_request(-varbindlist => \@vbl); + + if ($self->snmp->error) { + $port_info->{$port}->{'error'} = $self->snmp->error; + } else { + foreach my $oid (keys %$oid2name) { + $port_info->{$port}->{$oid2name->{$oid}} = $r->{$oid}; + } + } + return $port_info; + } + + foreach my $oid (keys %$oids) { $self->_loadTable($oids->{$oid}, $oid, $port_info); } Index: BayStack.pm =================================================================== RCS file: /cvsroot/netpass/NetPass/lib/SNMP/Device/BayStack.pm,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- BayStack.pm 12 Apr 2005 17:02:37 -0000 1.6 +++ BayStack.pm 5 Jan 2006 21:02:35 -0000 1.7 @@ -128,13 +128,15 @@ } -=head2 B<get_if_info()> +=head2 B<get_if_info($port)> =over 8 -This will return a hash with all interfaces and their information, -including unit, port, admin status, operational status, autonegotiation, -duplex, speed, fcs errors, vlan tagged/untagged, PVID, and member VLANS. +This will return a hash with all interfaces (or just the one +you specified) and their information, including unit, port, admin status, +operational status, autonegotiation, duplex, speed, fcs errors, vlan +tagged/untagged, PVID, and member VLANS. The B<$port> parameter +is the final digit of the OID, not really the port number. =back @@ -142,6 +144,7 @@ sub get_if_info { my $self = shift; + my $port = shift; my $port_info = {}; @@ -164,9 +167,33 @@ 'fcs_errors' => '.1.3.6.1.2.1.10.7.2.1.3', 'vlan_port_type' => '.1.3.6.1.4.1.2272.1.3.3.1.4', + # 1 = not trunk, 2 = trunk 'vlan_default_id' => '.1.3.6.1.4.1.2272.1.3.3.1.7' }; + if ($port) { + my @vbl; + my $oid2name = {}; + foreach my $name (keys %$oids) { + push @vbl, $oids->{$name}.".$port"; + $oid2name->{$oids->{$name}.".$port"} = $name; + } + + my $r = $self->snmp->get_request(-varbindlist => \@vbl); + + if ($self->snmp->error) { + $port_info->{$port}->{'error'} = $self->snmp->error; + } else { + foreach my $oid (keys %$oid2name) { + $port_info->{$port}->{$oid2name->{$oid}} = $r->{$oid}; + } + } + return $port_info; + } + + + # otherwise, we need to fetch all of the ports and do a bigger hash + foreach my $oid (keys %$oids) { $self->_loadTable($oids->{$oid}, $oid, $port_info); } @@ -876,20 +903,20 @@ =cut sub HexMac2DecMac { + my $hex_mac = shift; # hexadecimal mac in raw 12-character format (no : or - separators). + my $dec_mac = ''; # rv - my $hex_mac = shift; # hexadecimal mac in raw 12-character format (no : or - separators). - my $dec_mac = ''; # rv - - my ($m1, $m2, $m3, $m4, $m5, $m6) = ($hex_mac =~ /^(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})$/); # MAC pieces, base 16. - - $m1 = hex($m1); - $m2 = hex($m2); - $m3 = hex($m3); - $m4 = hex($m4); - $m5 = hex($m5); - $m6 = hex($m6); - - return "$m1.$m2.$m3.$m4.$m5.$m6"; # decimal equivalent of hexadecimal mac address. + my ($m1, $m2, $m3, $m4, $m5, $m6) = + ($hex_mac =~ /^(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})$/); # MAC pieces, base 16. + + $m1 = hex($m1); + $m2 = hex($m2); + $m3 = hex($m3); + $m4 = hex($m4); + $m5 = hex($m5); + $m6 = hex($m6); + + return "$m1.$m2.$m3.$m4.$m5.$m6"; # decimal equivalent of hexadecimal mac address. } =head1 AUTHOR |