refactor layer and pseudo checks
This commit is contained in:
@@ -193,6 +193,29 @@ __PACKAGE__->might_have(
|
|||||||
|
|
||||||
=head1 ADDITIONAL METHODS
|
=head1 ADDITIONAL METHODS
|
||||||
|
|
||||||
|
=head2 is_pseudo
|
||||||
|
|
||||||
|
Returns true if the vendor of the device is "netdisco".
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub not_pseudo {
|
||||||
|
my $device = shift;
|
||||||
|
return (defined $device->vendor and $device->vendor eq 'netdisco');
|
||||||
|
}
|
||||||
|
|
||||||
|
=head2 has_layer( $number )
|
||||||
|
|
||||||
|
Returns true if the device provided sysServices and supports the given layer.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub has_layer {
|
||||||
|
my ($device, $layer) = @_;
|
||||||
|
return unless $layer and $layer =~ m/^[1-8]$/;
|
||||||
|
return $device->layers and substr($device->layers, (9-$layer), 1) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
=head2 renumber( $new_ip )
|
=head2 renumber( $new_ip )
|
||||||
|
|
||||||
Will update this device and all related database records to use the new IP
|
Will update this device and all related database records to use the new IP
|
||||||
|
|||||||
@@ -192,12 +192,10 @@ sub is_discoverable_now {
|
|||||||
my ($ip, $remote_type) = @_;
|
my ($ip, $remote_type) = @_;
|
||||||
my $device = get_device($ip) or return 0;
|
my $device = get_device($ip) or return 0;
|
||||||
|
|
||||||
if ($device->in_storage) {
|
if ($device->since_last_discover and setting('discover_min_age')
|
||||||
if ($device->since_last_discover and setting('discover_min_age')
|
and $device->since_last_discover < setting('discover_min_age')) {
|
||||||
and $device->since_last_discover < setting('discover_min_age')) {
|
|
||||||
|
|
||||||
return _bail_msg("is_discoverable: time since last discover less than discover_min_age");
|
return _bail_msg("is_discoverable: time since last discover less than discover_min_age");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_discoverable(@_);
|
return is_discoverable(@_);
|
||||||
@@ -242,9 +240,6 @@ sub is_arpnipable_now {
|
|||||||
my ($ip) = @_;
|
my ($ip) = @_;
|
||||||
my $device = get_device($ip) or return 0;
|
my $device = get_device($ip) or return 0;
|
||||||
|
|
||||||
return _bail_msg("is_arpnipable: cannot arpnip an undiscovered device")
|
|
||||||
if not $device->in_storage;
|
|
||||||
|
|
||||||
if ($device->since_last_arpnip and setting('arpnip_min_age')
|
if ($device->since_last_arpnip and setting('arpnip_min_age')
|
||||||
and $device->since_last_arpnip < setting('arpnip_min_age')) {
|
and $device->since_last_arpnip < setting('arpnip_min_age')) {
|
||||||
|
|
||||||
@@ -293,9 +288,6 @@ sub is_macsuckable_now {
|
|||||||
my ($ip) = @_;
|
my ($ip) = @_;
|
||||||
my $device = get_device($ip) or return 0;
|
my $device = get_device($ip) or return 0;
|
||||||
|
|
||||||
return _bail_msg("is_macsuckable: cannot macsuck an undiscovered device")
|
|
||||||
if not $device->in_storage;
|
|
||||||
|
|
||||||
if ($device->since_last_macsuck and setting('macsuck_min_age')
|
if ($device->since_last_macsuck and setting('macsuck_min_age')
|
||||||
and $device->since_last_macsuck < setting('macsuck_min_age')) {
|
and $device->since_last_macsuck < setting('macsuck_min_age')) {
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ register_worker({ stage => 'check' }, sub {
|
|||||||
unless $device->in_storage;
|
unless $device->in_storage;
|
||||||
|
|
||||||
return Status->defer("arpnip skipped: $device is pseudo-device")
|
return Status->defer("arpnip skipped: $device is pseudo-device")
|
||||||
if $device->vendor and $device->vendor eq 'netdisco';
|
if $device->is_pseudo;
|
||||||
|
|
||||||
|
return Status->defer("arpnip skipped: $device has no layer 3 capability")
|
||||||
|
unless $device->has_layer(3);
|
||||||
|
|
||||||
return Status->defer("arpnip deferred: $device is not arpnipable")
|
return Status->defer("arpnip deferred: $device is not arpnipable")
|
||||||
unless is_arpnipable_now($device);
|
unless is_arpnipable_now($device);
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ register_worker({ stage => 'check', 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("arpnip failed: could not SNMP connect to $device");
|
or return Status->defer("arpnip failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
return Status->defer("Skipped arpnip for device $device without layer 3 capability")
|
|
||||||
unless $snmp->has_layer(3);
|
|
||||||
|
|
||||||
# get v4 arp table
|
# get v4 arp table
|
||||||
my $v4 = get_arps($device, $snmp->at_paddr, $snmp->at_netaddr);
|
my $v4 = get_arps($device, $snmp->at_paddr, $snmp->at_netaddr);
|
||||||
# get v6 neighbor cache
|
# get v6 neighbor cache
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ 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("arpnip failed: could not SNMP connect to $device");
|
or return Status->defer("arpnip failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
return Status->defer("Skipped arpnip for device $device without layer 3 capability")
|
|
||||||
unless $snmp->has_layer(3);
|
|
||||||
|
|
||||||
# get directly connected networks
|
# get directly connected networks
|
||||||
my @subnets = gather_subnets($device, $snmp);
|
my @subnets = gather_subnets($device, $snmp);
|
||||||
# TODO: IPv6 subnets
|
# TODO: IPv6 subnets
|
||||||
|
|||||||
@@ -13,15 +13,13 @@ register_worker({ stage => 'check' }, sub {
|
|||||||
return Status->error('discover failed: unable to interpret device param')
|
return Status->error('discover failed: unable to interpret device param')
|
||||||
unless defined $device;
|
unless defined $device;
|
||||||
|
|
||||||
my $host = $device->ip;
|
|
||||||
|
|
||||||
return Status->error("discover failed: no device param (need -d ?)")
|
return Status->error("discover failed: no device param (need -d ?)")
|
||||||
if $host eq '0.0.0.0';
|
if $device->ip eq '0.0.0.0';
|
||||||
|
|
||||||
return Status->defer("discover skipped: $host is pseudo-device")
|
return Status->defer("discover skipped: $device is pseudo-device")
|
||||||
if $device->vendor and $device->vendor eq 'netdisco';
|
if $device->is_pseudo;
|
||||||
|
|
||||||
return Status->defer("discover deferred: $host is not discoverable")
|
return Status->defer("discover deferred: $device is not discoverable")
|
||||||
unless is_discoverable_now($device);
|
unless is_discoverable_now($device);
|
||||||
|
|
||||||
return Status->done('discover is able to run.');
|
return Status->done('discover is able to run.');
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ register_worker({ stage => 'second' }, sub {
|
|||||||
# arpniped/macsucked, queue those jobs now
|
# arpniped/macsucked, queue those jobs now
|
||||||
if ($device->in_storage
|
if ($device->in_storage
|
||||||
and $job->subaction and $job->subaction eq 'with-nodes') {
|
and $job->subaction and $job->subaction eq 'with-nodes') {
|
||||||
if (!defined $device->last_macsuck) {
|
if (!defined $device->last_macsuck and $device->has_layer(2)) {
|
||||||
jq_insert({
|
jq_insert({
|
||||||
device => $device->ip,
|
device => $device->ip,
|
||||||
action => 'macsuck',
|
action => 'macsuck',
|
||||||
@@ -23,7 +23,7 @@ register_worker({ stage => 'second' }, sub {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined $device->last_arpnip) {
|
if (!defined $device->last_arpnip and $device->has_layer(3)) {
|
||||||
jq_insert({
|
jq_insert({
|
||||||
device => $device->ip,
|
device => $device->ip,
|
||||||
action => 'arpnip',
|
action => 'arpnip',
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ register_worker({ stage => 'check' }, sub {
|
|||||||
unless $device->in_storage;
|
unless $device->in_storage;
|
||||||
|
|
||||||
return Status->defer("macsuck skipped: $device is pseudo-device")
|
return Status->defer("macsuck skipped: $device is pseudo-device")
|
||||||
if $device->vendor and $device->vendor eq 'netdisco';
|
if $device->is_pseudo;
|
||||||
|
|
||||||
|
return Status->defer("arpnip skipped: $device has no layer 2 capability")
|
||||||
|
unless $device->has_layer(2);
|
||||||
|
|
||||||
return Status->defer("macsuck deferred: $device is not macsuckable")
|
return Status->defer("macsuck deferred: $device is not macsuckable")
|
||||||
unless is_macsuckable_now($device);
|
unless is_macsuckable_now($device);
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ register_worker({ stage => 'check', 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("macsuck failed: could not SNMP connect to $device");
|
or return Status->defer("macsuck failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
return Status->defer("Skipped macsuck for device $device without layer 2 capability")
|
|
||||||
unless $snmp->has_layer(2);
|
|
||||||
|
|
||||||
# would be possible just to use now() on updated records, but by using this
|
# would be possible just to use now() on updated records, but by using this
|
||||||
# same value for them all, we can if we want add a job at the end to
|
# same value for them all, we can if we want add a job at the end to
|
||||||
# select and do something with the updated set (see set archive, below)
|
# select and do something with the updated set (see set archive, below)
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ 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("macsuck failed: could not SNMP connect to $device");
|
or return Status->defer("macsuck failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
return Status->defer("Skipped macsuck for device $device without layer 2 capability")
|
|
||||||
unless $snmp->has_layer(2);
|
|
||||||
|
|
||||||
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
||||||
|
|
||||||
my $cd11_txrate = $snmp->cd11_txrate;
|
my $cd11_txrate = $snmp->cd11_txrate;
|
||||||
|
|||||||
Reference in New Issue
Block a user