support for discover_min_age
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
* Display port descriptions in topology editing form
|
* Display port descriptions in topology editing form
|
||||||
* Support store_modules config (default true)
|
* Support store_modules config (default true)
|
||||||
|
* Support for discover_min_age
|
||||||
|
|
||||||
2.013001 - 2013-08-23
|
2.013001 - 2013-08-23
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ requires 'List::MoreUtils' => 0.33;
|
|||||||
requires 'MIME::Base64' => 3.13;
|
requires 'MIME::Base64' => 3.13;
|
||||||
requires 'Moo' => 1.001000;
|
requires 'Moo' => 1.001000;
|
||||||
requires 'MCE' => 1.408;
|
requires 'MCE' => 1.408;
|
||||||
|
requires 'Net::Domain' => 1.23;
|
||||||
requires 'Net::DNS' => 0.72;
|
requires 'Net::DNS' => 0.72;
|
||||||
requires 'Net::MAC' => 2.103622;
|
requires 'Net::MAC' => 2.103622;
|
||||||
requires 'NetAddr::IP' => 4.068;
|
requires 'NetAddr::IP' => 4.068;
|
||||||
|
|||||||
@@ -250,4 +250,28 @@ between the date stamp and time stamp. That is:
|
|||||||
|
|
||||||
sub last_arpnip_stamp { return (shift)->get_column('last_arpnip_stamp') }
|
sub last_arpnip_stamp { return (shift)->get_column('last_arpnip_stamp') }
|
||||||
|
|
||||||
|
=head2 since_last_discover
|
||||||
|
|
||||||
|
Number of seconds which have elapsed since the value of C<last_discover>.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub since_last_discover { return (shift)->get_column('since_last_discover') }
|
||||||
|
|
||||||
|
=head2 since_last_macsuck
|
||||||
|
|
||||||
|
Number of seconds which have elapsed since the value of C<last_macsuck>.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub since_last_macsuck { return (shift)->get_column('since_last_macsuck') }
|
||||||
|
|
||||||
|
=head2 since_last_arpnip
|
||||||
|
|
||||||
|
Number of seconds which have elapsed since the value of C<last_arpnip>.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub since_last_arpnip { return (shift)->get_column('since_last_arpnip') }
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -37,8 +37,11 @@ sub with_times {
|
|||||||
uptime_age => \("replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', "
|
uptime_age => \("replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', "
|
||||||
."timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')"),
|
."timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')"),
|
||||||
last_discover_stamp => \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')",
|
last_discover_stamp => \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')",
|
||||||
last_macsuck_stamp => \"to_char(last_macsuck, 'YYYY-MM-DD HH24:MI')",
|
last_macsuck_stamp => \"to_char(last_macsuck, 'YYYY-MM-DD HH24:MI')",
|
||||||
last_arpnip_stamp => \"to_char(last_arpnip, 'YYYY-MM-DD HH24:MI')",
|
last_arpnip_stamp => \"to_char(last_arpnip, 'YYYY-MM-DD HH24:MI')",
|
||||||
|
since_last_discover => \"extract(epoch from (age(now(), last_discover)))",
|
||||||
|
since_last_macsuck => \"extract(epoch from (age(now(), last_macsuck)))",
|
||||||
|
since_last_arpnip => \"extract(epoch from (age(now(), last_arpnip)))",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package App::Netdisco::Daemon::Worker::Manager;
|
|||||||
use Dancer qw/:moose :syntax :script/;
|
use Dancer qw/:moose :syntax :script/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
use App::Netdisco::Util::Device 'is_discoverable';
|
|
||||||
use Net::Domain 'hostfqdn';
|
use Net::Domain 'hostfqdn';
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
|
|
||||||
@@ -57,10 +56,6 @@ sub worker_body {
|
|||||||
while (my $job = $rs->next) {
|
while (my $job = $rs->next) {
|
||||||
my $jid = $job->job;
|
my $jid = $job->job;
|
||||||
|
|
||||||
# filter for discover_*
|
|
||||||
next unless is_discoverable($job->device);
|
|
||||||
debug sprintf "mgr (%s): job %s is discoverable", $wid, $jid;
|
|
||||||
|
|
||||||
# check for available local capacity
|
# check for available local capacity
|
||||||
next unless $self->do('capacity_for', $job->action);
|
next unless $self->do('capacity_for', $job->action);
|
||||||
debug sprintf "mgr (%s): processing node has capacity for job %s (%s)",
|
debug sprintf "mgr (%s): processing node has capacity for job %s (%s)",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use Dancer qw/:moose :syntax :script/;
|
|||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
use App::Netdisco::Util::SNMP 'snmp_connect';
|
use App::Netdisco::Util::SNMP 'snmp_connect';
|
||||||
use App::Netdisco::Util::Device 'get_device';
|
use App::Netdisco::Util::Device qw/get_device is_discoverable/;
|
||||||
use App::Netdisco::Core::Discover ':all';
|
use App::Netdisco::Core::Discover ':all';
|
||||||
use App::Netdisco::Daemon::Util ':all';
|
use App::Netdisco::Daemon::Util ':all';
|
||||||
|
|
||||||
@@ -59,7 +59,11 @@ sub discover {
|
|||||||
|
|
||||||
if ($device->in_storage
|
if ($device->in_storage
|
||||||
and $device->vendor and $device->vendor eq 'netdisco') {
|
and $device->vendor and $device->vendor eq 'netdisco') {
|
||||||
return job_done("Skipped discover for pseudo-device $host");
|
return job_done("discover skipped: $host is pseudo-device");
|
||||||
|
}
|
||||||
|
|
||||||
|
unless (is_discoverable($device->ip)) {
|
||||||
|
return job_defer("discover deferred: $host is not discoverable");
|
||||||
}
|
}
|
||||||
|
|
||||||
my $snmp = snmp_connect($device);
|
my $snmp = snmp_connect($device);
|
||||||
|
|||||||
@@ -305,6 +305,13 @@ but don't talk SNMP. For example:
|
|||||||
- 'cisco\s+AIR-LAP'
|
- 'cisco\s+AIR-LAP'
|
||||||
- '(?i)Cisco\s+IP\s+Phone'
|
- '(?i)Cisco\s+IP\s+Phone'
|
||||||
|
|
||||||
|
=head3 C<discover_min_age>
|
||||||
|
|
||||||
|
Value: Number. Default: 0.
|
||||||
|
|
||||||
|
Sets the minimum amount of time in seconds which must elapse between any two
|
||||||
|
discover jobs for a device.
|
||||||
|
|
||||||
=head3 C<macsuck_all_vlans>
|
=head3 C<macsuck_all_vlans>
|
||||||
|
|
||||||
Value: Boolean. Default: C<false>.
|
Value: Boolean. Default: C<false>.
|
||||||
@@ -590,10 +597,6 @@ C<col_xxx_show>
|
|||||||
|
|
||||||
=item *
|
=item *
|
||||||
|
|
||||||
C<discover_min_age>
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
C<expire_devices>
|
C<expire_devices>
|
||||||
|
|
||||||
=item *
|
=item *
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ sub get_device {
|
|||||||
->search({alias => $ip})->first;
|
->search({alias => $ip})->first;
|
||||||
$ip = $alias->ip if defined $alias;
|
$ip = $alias->ip if defined $alias;
|
||||||
|
|
||||||
return schema('netdisco')->resultset('Device')
|
return schema('netdisco')->resultset('Device')->with_times
|
||||||
->find_or_new({ip => $ip});
|
->find_or_new({ip => $ip});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,13 +71,15 @@ Returns false if the host is not permitted to discover the target device.
|
|||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
sub _bail_msg { debug $_[0]; return 0; }
|
||||||
|
|
||||||
sub is_discoverable {
|
sub is_discoverable {
|
||||||
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 ($remote_type) {
|
if ($remote_type) {
|
||||||
return 0 if
|
return _bail_msg("is_discoverable: device matched discover_no_type")
|
||||||
scalar grep {$remote_type =~ m/$_/}
|
if scalar grep {$remote_type =~ m/$_/}
|
||||||
@{setting('discover_no_type') || []};
|
@{setting('discover_no_type') || []};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +90,8 @@ sub is_discoverable {
|
|||||||
if (scalar @$discover_no) {
|
if (scalar @$discover_no) {
|
||||||
foreach my $item (@$discover_no) {
|
foreach my $item (@$discover_no) {
|
||||||
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
||||||
return 0 if $ip->contains($addr);
|
return _bail_msg("is_discoverable: device matched discover_no")
|
||||||
|
if $ip->contains($addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +101,16 @@ sub is_discoverable {
|
|||||||
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
my $ip = NetAddr::IP::Lite->new($item) or return 0;
|
||||||
++$okay if $ip->contains($addr);
|
++$okay if $ip->contains($addr);
|
||||||
}
|
}
|
||||||
return 0 if not $okay;
|
return _bail_msg("is_discoverable: device failed to match discover_only")
|
||||||
|
if not $okay;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $discover_since = setting('discover_min_age') || 0;
|
||||||
|
|
||||||
|
if ($device->since_last_discover
|
||||||
|
and $device->since_last_discover < $discover_since) {
|
||||||
|
|
||||||
|
return _bail_msg("is_discoverable: last discovered less than discover_min_age");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user