add a remote_dns port property
This commit is contained in:
@@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces(
|
|||||||
);
|
);
|
||||||
|
|
||||||
our # try to hide from kwalitee
|
our # try to hide from kwalitee
|
||||||
$VERSION = 74; # schema version used for upgrades, keep as integer
|
$VERSION = 75; # schema version used for upgrades, keep as integer
|
||||||
|
|
||||||
use Path::Class;
|
use Path::Class;
|
||||||
use File::ShareDir 'dist_dir';
|
use File::ShareDir 'dist_dir';
|
||||||
|
|||||||
@@ -387,6 +387,14 @@ Returns the interface index (C<ifIndex>) of the port.
|
|||||||
|
|
||||||
sub ifindex { return (shift)->get_column('ifindex') }
|
sub ifindex { return (shift)->get_column('ifindex') }
|
||||||
|
|
||||||
|
=head2 remote_dns
|
||||||
|
|
||||||
|
Returns a hostname resolved from C<remote_ip> column.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub remote_dns { return (shift)->get_column('remote_dns') }
|
||||||
|
|
||||||
=head2 remote_inventory
|
=head2 remote_inventory
|
||||||
|
|
||||||
Returns a synthesized description of the remote LLDP device if inventory
|
Returns a synthesized description of the remote LLDP device if inventory
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ __PACKAGE__->add_columns(
|
|||||||
{ data_type => "text", is_nullable => 1 },
|
{ data_type => "text", is_nullable => 1 },
|
||||||
"remote_serial",
|
"remote_serial",
|
||||||
{ data_type => "text", is_nullable => 1 },
|
{ data_type => "text", is_nullable => 1 },
|
||||||
|
"remote_dns",
|
||||||
|
{ data_type => "text", is_nullable => 1 },
|
||||||
"raw_speed",
|
"raw_speed",
|
||||||
{ data_type => "bigint", default_value => 0, is_nullable => 1 },
|
{ data_type => "bigint", default_value => 0, is_nullable => 1 },
|
||||||
"faststart",
|
"faststart",
|
||||||
|
|||||||
@@ -136,6 +136,8 @@ will add the following additional synthesized columns to the result set:
|
|||||||
|
|
||||||
=item remote_is_phone (boolean)
|
=item remote_is_phone (boolean)
|
||||||
|
|
||||||
|
=item remote_dns
|
||||||
|
|
||||||
=item ifindex
|
=item ifindex
|
||||||
|
|
||||||
=back
|
=back
|
||||||
@@ -154,11 +156,12 @@ sub with_properties {
|
|||||||
properties.remote_is_discoverable
|
properties.remote_is_discoverable
|
||||||
properties.remote_is_wap
|
properties.remote_is_wap
|
||||||
properties.remote_is_phone
|
properties.remote_is_phone
|
||||||
|
properties.remote_dns
|
||||||
properties.ifindex
|
properties.ifindex
|
||||||
/],
|
/],
|
||||||
'+as' => [qw/
|
'+as' => [qw/
|
||||||
error_disable_cause
|
error_disable_cause
|
||||||
remote_is_discoverable remote_is_wap remote_is_phone
|
remote_is_discoverable remote_is_wap remote_is_phone remote_dns
|
||||||
ifindex
|
ifindex
|
||||||
/],
|
/],
|
||||||
join => 'properties',
|
join => 'properties',
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App::Netdisco::Transport::SNMP ();
|
|||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
use Encode;
|
use Encode;
|
||||||
|
use App::Netdisco::Util::FastResolver 'hostnames_resolve_async';
|
||||||
use App::Netdisco::Util::Device qw/is_discoverable match_to_setting/;
|
use App::Netdisco::Util::Device qw/is_discoverable match_to_setting/;
|
||||||
|
|
||||||
register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||||
@@ -25,6 +26,17 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
my $device_ports = vars->{'device_ports'}
|
my $device_ports = vars->{'device_ports'}
|
||||||
|| { map {($_->port => $_)} $device->ports->all };
|
|| { map {($_->port => $_)} $device->ports->all };
|
||||||
|
|
||||||
|
my @remote_ips = map {{ip => $_}}
|
||||||
|
grep {defined}
|
||||||
|
map {$_->remote_ip}
|
||||||
|
values %$device_ports;
|
||||||
|
|
||||||
|
debug sprintf ' resolving %d remote_ips with max %d outstanding requests',
|
||||||
|
scalar @remote_ips, $ENV{'PERL_ANYEVENT_MAX_OUTSTANDING_DNS'};
|
||||||
|
|
||||||
|
my $resolved_remote_ips = hostnames_resolve_async(\@remote_ips);
|
||||||
|
$properties{$_}->{remote_dns} = $_->{dns} for @$resolved_remote_ips;
|
||||||
|
|
||||||
my $raw_speed = $snmp->i_speed_raw || {};
|
my $raw_speed = $snmp->i_speed_raw || {};
|
||||||
|
|
||||||
foreach my $idx (keys %$raw_speed) {
|
foreach my $idx (keys %$raw_speed) {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE device_port_properties ADD COLUMN "remote_dns" text;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
Reference in New Issue
Block a user