all except body of resolve_node_names()
This commit is contained in:
		@@ -10,7 +10,7 @@ use Time::HiRes 'gettimeofday';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use base 'Exporter';
 | 
					use base 'Exporter';
 | 
				
			||||||
our @EXPORT = ();
 | 
					our @EXPORT = ();
 | 
				
			||||||
our @EXPORT_OK = qw/ do_arpnip store_arp /;
 | 
					our @EXPORT_OK = qw/ do_arpnip store_arp resolve_node_names /;
 | 
				
			||||||
our %EXPORT_TAGS = (all => \@EXPORT_OK);
 | 
					our %EXPORT_TAGS = (all => \@EXPORT_OK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=head1 NAME
 | 
					=head1 NAME
 | 
				
			||||||
@@ -82,16 +82,16 @@ sub _get_arps {
 | 
				
			|||||||
      my $ip = $netaddr->{$arp};
 | 
					      my $ip = $netaddr->{$arp};
 | 
				
			||||||
      next unless defined $ip;
 | 
					      next unless defined $ip;
 | 
				
			||||||
      next unless check_mac($device, $node);
 | 
					      next unless check_mac($device, $node);
 | 
				
			||||||
      push @arps, [$node, $ip, hostname_from_ip($ip)];
 | 
					      push @arps, [$node, $ip];
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return @arps;
 | 
					  return @arps;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=head2 store_arp( $mac, $ip, $name, $now? )
 | 
					=head2 store_arp( $mac, $ip, $now? )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Stores a new entry to the C<node_ip> table with the given MAC, IP (v4 or v6)
 | 
					Stores a new entry to the C<node_ip> table with the given MAC, and IP (v4 or
 | 
				
			||||||
and DNS host name.
 | 
					v6).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Will mark old entries for this IP as no longer C<active>.
 | 
					Will mark old entries for this IP as no longer C<active>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -101,7 +101,7 @@ C<time_last> timestamp, otherwise the current timestamp (C<now()>) is used.
 | 
				
			|||||||
=cut
 | 
					=cut
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sub store_arp {
 | 
					sub store_arp {
 | 
				
			||||||
  my ($mac, $ip, $name, $now) = @_;
 | 
					  my ($mac, $ip, $now) = @_;
 | 
				
			||||||
  $now ||= 'now()';
 | 
					  $now ||= 'now()';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  schema('netdisco')->txn_do(sub {
 | 
					  schema('netdisco')->txn_do(sub {
 | 
				
			||||||
@@ -119,7 +119,6 @@ sub store_arp {
 | 
				
			|||||||
      ->search({'me.mac' => $mac, 'me.ip' => $ip})
 | 
					      ->search({'me.mac' => $mac, 'me.ip' => $ip})
 | 
				
			||||||
      ->update_or_create(
 | 
					      ->update_or_create(
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        dns => $name,
 | 
					 | 
				
			||||||
        active => \'true',
 | 
					        active => \'true',
 | 
				
			||||||
        time_last => \$now,
 | 
					        time_last => \$now,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
@@ -172,4 +171,22 @@ sub _store_subnet {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=head2 resolve_node_names( $device )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Given a Device database object, resolve Node IP (ARP) entries belonging to
 | 
				
			||||||
 | 
					this device into DNS names, and store them in the C<node_ip> database table.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This action is usually queued following C<do_arpip> so that it may run
 | 
				
			||||||
 | 
					asynchronously, and/or on another daemon worker node.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=cut
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sub resolve_node_names {
 | 
				
			||||||
 | 
					  my ($device) = @_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  schema('netdisco')->txn_do(sub {
 | 
				
			||||||
 | 
					    # hostname_from_ip($ip)
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1;
 | 
					1;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ sub capacity_for {
 | 
				
			|||||||
  debug "checking local capacity for action $action";
 | 
					  debug "checking local capacity for action $action";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  my $action_map = {
 | 
					  my $action_map = {
 | 
				
			||||||
    Poller => [qw/discoverall discover arpwalk arpnip macwalk macsuck/],
 | 
					    Poller => [qw/discoverall discover arpwalk arpnip nodeip2name macwalk macsuck/],
 | 
				
			||||||
    Interactive => [qw/location contact portcontrol portname vlan power/],
 | 
					    Interactive => [qw/location contact portcontrol portname vlan power/],
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ my $fqdn = hostfqdn || 'localhost';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
my $role_map = {
 | 
					my $role_map = {
 | 
				
			||||||
  (map {$_ => 'Poller'}
 | 
					  (map {$_ => 'Poller'}
 | 
				
			||||||
      qw/discoverall discover arpwalk arpnip macwalk macsuck/),
 | 
					      qw/discoverall discover arpwalk arpnip nodeip2name macwalk macsuck/),
 | 
				
			||||||
  (map {$_ => 'Interactive'}
 | 
					  (map {$_ => 'Interactive'}
 | 
				
			||||||
      qw/location contact portcontrol portname vlan power/)
 | 
					      qw/location contact portcontrol portname vlan power/)
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,17 @@
 | 
				
			|||||||
package App::Netdisco::Daemon::Worker::Poller::Arpnip;
 | 
					package App::Netdisco::Daemon::Worker::Poller::Arpnip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Dancer::Plugin::DBIC 'schema';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App::Netdisco::Core::Arpnip 'do_arpnip';
 | 
					use App::Netdisco::Core::Arpnip 'do_arpnip';
 | 
				
			||||||
use App::Netdisco::Util::Device 'is_arpnipable';
 | 
					use App::Netdisco::Util::Device qw/get_device is_arpnipable is_nodeip2nameable/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App::Netdisco::Core::Arpnip 'resolve_node_names';
 | 
				
			||||||
 | 
					use App::Netdisco::Daemon::Util ':all';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use NetAddr::IP::Lite ':lower';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Role::Tiny;
 | 
					use Role::Tiny;
 | 
				
			||||||
 | 
					use Class::Method::Modifiers;
 | 
				
			||||||
use namespace::clean;
 | 
					use namespace::clean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
with 'App::Netdisco::Daemon::Worker::Poller::Common';
 | 
					with 'App::Netdisco::Daemon::Worker::Poller::Common';
 | 
				
			||||||
@@ -15,4 +23,43 @@ sub arpnip_layer { 3 }
 | 
				
			|||||||
sub arpwalk { (shift)->_walk_body('arpnip', @_) }
 | 
					sub arpwalk { (shift)->_walk_body('arpnip', @_) }
 | 
				
			||||||
sub arpnip  { (shift)->_single_body('arpnip', @_) }
 | 
					sub arpnip  { (shift)->_single_body('arpnip', @_) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					after 'arpnip' => sub {
 | 
				
			||||||
 | 
					  my ($self, $job) = @_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  my $host = NetAddr::IP::Lite->new($job->device);
 | 
				
			||||||
 | 
					  my $device = get_device($host->addr);
 | 
				
			||||||
 | 
					  my $jobqueue = schema('netdisco')->resultset('Admin');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  schema('netdisco')->txn_do(sub {
 | 
				
			||||||
 | 
					    $jobqueue->create({
 | 
				
			||||||
 | 
					      device => $device->ip,
 | 
				
			||||||
 | 
					      action => 'nodeip2name',
 | 
				
			||||||
 | 
					      status => 'queued',
 | 
				
			||||||
 | 
					      username => $job->username,
 | 
				
			||||||
 | 
					      userip => $job->userip,
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# run a nodeip2name job for one device
 | 
				
			||||||
 | 
					sub nodeip2name {
 | 
				
			||||||
 | 
					  my ($self, $job) = @_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  my $host = NetAddr::IP::Lite->new($job->device);
 | 
				
			||||||
 | 
					  my $device = get_device($host->addr);
 | 
				
			||||||
 | 
					  my $jobqueue = schema('netdisco')->resultset('Admin');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ($device->ip eq '0.0.0.0') {
 | 
				
			||||||
 | 
					      return job_error("nodeip2name failed: no device param (need -d ?)");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  unless (is_nodeip2nameable($device->ip)) {
 | 
				
			||||||
 | 
					      return job_defer("nodeip2name deferred: $host is not nodeip2nameable");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  resolve_node_names($device);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return job_done("Ended nodeip2name for ". $host->addr);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1;
 | 
					1;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@ our @EXPORT_OK = qw/
 | 
				
			|||||||
  check_no
 | 
					  check_no
 | 
				
			||||||
  is_discoverable
 | 
					  is_discoverable
 | 
				
			||||||
  is_arpnipable
 | 
					  is_arpnipable
 | 
				
			||||||
 | 
					  is_nodeip2nameable
 | 
				
			||||||
  is_macsuckable
 | 
					  is_macsuckable
 | 
				
			||||||
/;
 | 
					/;
 | 
				
			||||||
our %EXPORT_TAGS = (all => \@EXPORT_OK);
 | 
					our %EXPORT_TAGS = (all => \@EXPORT_OK);
 | 
				
			||||||
@@ -195,6 +196,32 @@ sub is_arpnipable {
 | 
				
			|||||||
  return 1;
 | 
					  return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=head2 is_nodeip2nameable( $ip )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Given an IP address, returns C<true> if Netdisco on this host is permitted by
 | 
				
			||||||
 | 
					the local configuration to resolve Node IPs to DNS names for the device.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The configuration items C<nodeip2name_no> and C<nodeip2name_only> are checked
 | 
				
			||||||
 | 
					against the given IP.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Returns false if the host is not permitted to do this job for the target
 | 
				
			||||||
 | 
					device.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=cut
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sub is_nodeip2nameable {
 | 
				
			||||||
 | 
					  my $ip = shift;
 | 
				
			||||||
 | 
					  my $device = get_device($ip) or return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return _bail_msg("is_nodeip2nameable: device matched nodeip2name_no")
 | 
				
			||||||
 | 
					    if check_no($device, 'nodeip2name_no');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return _bail_msg("is_nodeip2nameable: device failed to match nodeip2name_only")
 | 
				
			||||||
 | 
					    if check_no($device, 'nodeip2name_only');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=head2 is_macsuckable( $ip )
 | 
					=head2 is_macsuckable( $ip )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Given an IP address, returns C<true> if Netdisco on this host is permitted by
 | 
					Given an IP address, returns C<true> if Netdisco on this host is permitted by
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,6 +86,8 @@ macsuck_min_age: 0
 | 
				
			|||||||
arpnip_no: []
 | 
					arpnip_no: []
 | 
				
			||||||
arpnip_only: []
 | 
					arpnip_only: []
 | 
				
			||||||
arpnip_min_age: 0
 | 
					arpnip_min_age: 0
 | 
				
			||||||
 | 
					nodeip2name_no: []
 | 
				
			||||||
 | 
					nodeip2name_only: []
 | 
				
			||||||
store_wireless_clients: true
 | 
					store_wireless_clients: true
 | 
				
			||||||
store_modules: true
 | 
					store_modules: true
 | 
				
			||||||
ignore_interfaces:
 | 
					ignore_interfaces:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user