no need to pass $snmp around
This commit is contained in:
@@ -18,7 +18,7 @@ register_worker({ stage => 'second', driver => 'snmp' }, sub {
|
|||||||
or return Status->defer("arpnip failed: could not SNMP connect to $device");
|
or return Status->defer("arpnip failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
# get directly connected networks
|
# get directly connected networks
|
||||||
my @subnets = gather_subnets($device, $snmp);
|
my @subnets = gather_subnets($device);
|
||||||
# TODO: IPv6 subnets
|
# TODO: IPv6 subnets
|
||||||
|
|
||||||
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
||||||
@@ -32,9 +32,12 @@ register_worker({ stage => 'second', driver => 'snmp' }, sub {
|
|||||||
|
|
||||||
# gathers device subnets
|
# gathers device subnets
|
||||||
sub gather_subnets {
|
sub gather_subnets {
|
||||||
my ($device, $snmp) = @_;
|
my $device = shift;
|
||||||
my @subnets = ();
|
my @subnets = ();
|
||||||
|
|
||||||
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
|
or die "arpnip failed: could not SNMP connect to $device";
|
||||||
|
|
||||||
my $ip_netmask = $snmp->ip_netmask;
|
my $ip_netmask = $snmp->ip_netmask;
|
||||||
foreach my $entry (keys %$ip_netmask) {
|
foreach my $entry (keys %$ip_netmask) {
|
||||||
my $ip = NetAddr::IP::Lite->new($entry);
|
my $ip = NetAddr::IP::Lite->new($entry);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use List::MoreUtils ();
|
|||||||
use NetAddr::MAC;
|
use NetAddr::MAC;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
=head2 discover_new_neighbors( $device, $snmp )
|
=head2 discover_new_neighbors( )
|
||||||
|
|
||||||
Given a Device database object, and a working SNMP connection, discover and
|
Given a Device database object, and a working SNMP connection, discover and
|
||||||
store the device's port neighbors information.
|
store the device's port neighbors information.
|
||||||
@@ -37,7 +37,7 @@ register_worker({ stage => 'second', driver => 'snmp' }, sub {
|
|||||||
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
or return Status->defer("discover failed: could not SNMP connect to $device");
|
or return Status->defer("discover failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
my @to_discover = store_neighbors($device, $snmp);
|
my @to_discover = store_neighbors($device);
|
||||||
|
|
||||||
# only enqueue if device is not already discovered,
|
# only enqueue if device is not already discovered,
|
||||||
# discover_* config permits the discovery
|
# discover_* config permits the discovery
|
||||||
@@ -64,7 +64,7 @@ register_worker({ stage => 'second', driver => 'snmp' }, sub {
|
|||||||
return Status->done("Ended discover for $device");
|
return Status->done("Ended discover for $device");
|
||||||
});
|
});
|
||||||
|
|
||||||
=head2 store_neighbors( $device, $snmp )
|
=head2 store_neighbors( $device )
|
||||||
|
|
||||||
returns: C<@to_discover>
|
returns: C<@to_discover>
|
||||||
|
|
||||||
@@ -82,11 +82,14 @@ A list of discovererd neighbors will be returned as [C<$ip>, C<$type>] tuples.
|
|||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub store_neighbors {
|
sub store_neighbors {
|
||||||
my ($device, $snmp) = @_;
|
my $device = shift;
|
||||||
my @to_discover = ();
|
my @to_discover = ();
|
||||||
|
|
||||||
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
|
or die "discover failed: could not SNMP connect to $device";
|
||||||
|
|
||||||
# first allow any manually configured topology to be set
|
# first allow any manually configured topology to be set
|
||||||
set_manual_topology($device, $snmp);
|
set_manual_topology($device);
|
||||||
|
|
||||||
if (!defined $snmp->has_topo) {
|
if (!defined $snmp->has_topo) {
|
||||||
debug sprintf ' [%s] neigh - neighbor protocols are not enabled', $device->ip;
|
debug sprintf ' [%s] neigh - neighbor protocols are not enabled', $device->ip;
|
||||||
@@ -283,7 +286,10 @@ sub store_neighbors {
|
|||||||
# take data from the topology table and update remote_ip and remote_port
|
# take data from the topology table and update remote_ip and remote_port
|
||||||
# in the devices table. only use root_ips and skip any bad topo entries.
|
# in the devices table. only use root_ips and skip any bad topo entries.
|
||||||
sub set_manual_topology {
|
sub set_manual_topology {
|
||||||
my ($device, $snmp) = @_;
|
my $device = shift;
|
||||||
|
|
||||||
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
|
or die "discover failed: could not SNMP connect to $device";
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
# clear manual topology flags
|
# clear manual topology flags
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ register_worker({ stage => 'check', driver => 'snmp' }, sub {
|
|||||||
my $interfaces = $snmp->interfaces;
|
my $interfaces = $snmp->interfaces;
|
||||||
|
|
||||||
# get forwarding table data via basic snmp connection
|
# get forwarding table data via basic snmp connection
|
||||||
my $fwtable = walk_fwtable($device, $snmp, $interfaces, $port_macs, $device_ports);
|
my $fwtable = walk_fwtable($device, $interfaces, $port_macs, $device_ports);
|
||||||
|
|
||||||
# ...then per-vlan if supported
|
# ...then per-vlan if supported
|
||||||
my @vlan_list = get_vlan_list($device, $snmp);
|
my @vlan_list = get_vlan_list($device);
|
||||||
foreach my $vlan (@vlan_list) {
|
foreach my $vlan (@vlan_list) {
|
||||||
snmp_comm_reindex($snmp, $device, $vlan);
|
snmp_comm_reindex($snmp, $device, $vlan);
|
||||||
my $pv_fwtable = walk_fwtable($device, $snmp, $interfaces, $port_macs, $device_ports, $vlan);
|
my $pv_fwtable = walk_fwtable($device, $interfaces, $port_macs, $device_ports, $vlan);
|
||||||
$fwtable = {%$fwtable, %$pv_fwtable};
|
$fwtable = {%$fwtable, %$pv_fwtable};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,10 @@ sub store_node {
|
|||||||
|
|
||||||
# return a list of vlan numbers which are OK to macsuck on this device
|
# return a list of vlan numbers which are OK to macsuck on this device
|
||||||
sub get_vlan_list {
|
sub get_vlan_list {
|
||||||
my ($device, $snmp) = @_;
|
my $device = shift;
|
||||||
|
|
||||||
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
|
or die "macsuck failed: could not SNMP connect to $device";
|
||||||
|
|
||||||
return () unless $snmp->cisco_comm_indexing;
|
return () unless $snmp->cisco_comm_indexing;
|
||||||
|
|
||||||
@@ -260,10 +263,13 @@ sub get_vlan_list {
|
|||||||
# walks the forwarding table (BRIDGE-MIB) for the device and returns a
|
# walks the forwarding table (BRIDGE-MIB) for the device and returns a
|
||||||
# table of node entries.
|
# table of node entries.
|
||||||
sub walk_fwtable {
|
sub walk_fwtable {
|
||||||
my ($device, $snmp, $interfaces, $port_macs, $device_ports, $comm_vlan) = @_;
|
my ($device, $interfaces, $port_macs, $device_ports, $comm_vlan) = @_;
|
||||||
my $skiplist = {}; # ports through which we can see another device
|
my $skiplist = {}; # ports through which we can see another device
|
||||||
my $cache = {};
|
my $cache = {};
|
||||||
|
|
||||||
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
|
or die "macsuck failed: could not SNMP connect to $device";
|
||||||
|
|
||||||
my $fw_mac = $snmp->fw_mac;
|
my $fw_mac = $snmp->fw_mac;
|
||||||
my $fw_port = $snmp->fw_port;
|
my $fw_port = $snmp->fw_port;
|
||||||
my $fw_vlan = $snmp->qb_fw_vlan;
|
my $fw_vlan = $snmp->qb_fw_vlan;
|
||||||
|
|||||||
Reference in New Issue
Block a user