diff --git a/Changes b/Changes index 6249c1e4..25b35fee 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +2.038035 - 2018-02-?? + + [NEW FEATURES] + + * #332 Autodiscovery via BGP and OSPF peers + 2.038034 - 2018-01-31 [NEW FEATURES] diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors/Routed.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors/Routed.pm new file mode 100644 index 00000000..08adf0fb --- /dev/null +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors/Routed.pm @@ -0,0 +1,41 @@ +package App::Netdisco::Worker::Plugin::Discover::Neighbors::Routed; +use Dancer ':syntax'; + +use App::Netdisco::Worker::Plugin; +use App::Netdisco::Transport::SNMP; +use aliased 'App::Netdisco::Worker::Status'; + +use App::Netdisco::Util::Device qw/get_device is_discoverable/; +use App::Netdisco::JobQueue 'jq_insert'; + +register_worker({ phase => 'main', driver => 'snmp' }, sub { + my ($job, $workerconf) = @_; + + my $device = $job->device; + return unless $device->in_storage and $device->has_layer(3); + my $snmp = App::Netdisco::Transport::SNMP->reader_for($device) + or return Status->defer("discover failed: could not SNMP connect to $device"); + + my $ospf_peers = $snmp->ospf_peers || {}; + my $bgp_peers = $snmp->bgp_peer_addr || {}; + + return Status->info("device $device has no BGP or OSPF peers") + unless ((scalar values %$ospf_peers) or (scalar values %$bgp_peers)); + + foreach my $ip ((values %$ospf_peers), (values %$bgp_peers)) { + my $peer = get_device($ip); + next if $peer->in_storage or not is_discoverable($peer); + + jq_insert({ + device => $ip, + action => 'discover', + subaction => 'with-nodes', + }); + + debug sprintf ' [%s] queued discovery of routing peer %s', $device, $ip; + } + + return Status->info(" [$device] Routing peers added to discover queue."); +}); + +true; diff --git a/share/config.yml b/share/config.yml index d723da00..14bc8a0b 100644 --- a/share/config.yml +++ b/share/config.yml @@ -338,6 +338,7 @@ worker_plugins: - 'Discover::CanonicalIP' - 'Discover::Entities' - 'Discover::Neighbors' + - 'Discover::Neighbors::Routed' - 'Discover::PortPower' - 'Discover::Properties' - 'Discover::VLANs'