1package App::Netdisco::Worker::Plugin::Discover::Neighbors::DOCSIS;
2use Dancer ':syntax';
3
4use App::Netdisco::Worker::Plugin;
5use App::Netdisco::Transport::SNMP;
6use aliased 'App::Netdisco::Worker::Status';
7
8use App::Netdisco::Util::Device qw/get_device is_discoverable/;
9use App::Netdisco::JobQueue 'jq_insert';
10
11register_worker({ phase => 'main', driver => 'snmp' }, sub {
12  my ($job, $workerconf) = @_;
13
14  my $device = $job->device;
15  return unless $device->in_storage;
16  my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
17    or return Status->defer("discover failed: could not SNMP connect to $device");
18
19  my $modems = $snmp->docs_if_cmts_cm_status_inet_address() || {};
20
21  return Status->info(" [$device] neigh - no modems (probably not a DOCSIS device)")
22    unless (scalar values %$modems);
23
24  my $count = 0;
25  foreach my $ip (values %$modems) {
26
27    # Some modems may be registered, but not have an IP assigned (they could be offline, disabled, etc)
28    next if $ip eq '';
29
30    my $peer = get_device($ip);
31    next if $peer->in_storage or not is_discoverable($peer);
32    next if vars->{'queued'}->{$ip};
33
34    jq_insert({
35      device => $ip,
36      action => 'discover',
37      subaction => 'with-nodes',
38    });
39
40    $count++;
41    vars->{'queued'}->{$ip} += 1;
42    debug sprintf ' [%s] queue - queued %s for discovery (DOCSIS peer)', $device, $ip;
43  }
44
45  return Status->info(" [$device] neigh - $count DOCSIS peers (modems) added to queue.");
46});
47
48true;
49