diff --git a/Netdisco/Changes b/Netdisco/Changes index 9cf1d369..758538c7 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,5 +1,9 @@ 2.005000_002 - + [ENHANCEMENTS] + + * When linking to devices, use the DNS name in preference to the IP + [BUG FIXES] * Minor fixes to POD diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm index 336aca3e..c18a79af 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Addresses.pm @@ -4,17 +4,19 @@ use Dancer ':syntax'; use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; +use NetAddr::IP::Lite ':lower'; + use App::Netdisco::Web::Plugin; register_device_tab({ id => 'addresses', label => 'Addresses' }); # device interface addresses ajax '/ajax/content/device/addresses' => sub { - my $ip = param('q'); + my $ip = NetAddr::IP::Lite->new(param('q')); return unless $ip; my $set = schema('netdisco')->resultset('DeviceIp') - ->search({ip => $ip}, {order_by => 'alias'}); + ->search({ip => $ip->addr}, {order_by => 'alias'}); return unless $set->count; content_type('text/html'); diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Details.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Details.pm index ab2ffc34..d2303b36 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Details.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Details.pm @@ -4,17 +4,19 @@ use Dancer ':syntax'; use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; +use NetAddr::IP::Lite ':lower'; + use App::Netdisco::Web::Plugin; register_device_tab({ id => 'details', label => 'Details' }); # device details table ajax '/ajax/content/device/details' => sub { - my $ip = param('q'); + my $ip = NetAddr::IP::Lite->new(param('q')); return unless $ip; my $device = schema('netdisco')->resultset('Device') - ->with_times()->find($ip); + ->with_times()->find($ip->addr); return unless $device; content_type('text/html'); diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index b484c2c9..33a184b8 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -4,6 +4,8 @@ use Dancer ':syntax'; use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; +use NetAddr::IP::Lite ':lower'; + use App::Netdisco::Web::Plugin; register_device_tab({ id => 'netmap', label => 'Neighbors' }); @@ -40,8 +42,9 @@ sub _add_children { # d3 seems not to use proper ajax semantics, so get instead of ajax get '/ajax/data/device/netmap' => sub { - my $start = param('q'); - return unless $start; + my $ip = NetAddr::IP::Lite->new(param('q')); + return unless $ip; + my $start = $ip->addr; my @devices = schema('netdisco')->resultset('Device')->search({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator', diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index fa30a353..92baeb15 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -4,6 +4,7 @@ use Dancer ':syntax'; use Dancer::Plugin::Ajax; use Dancer::Plugin::DBIC; +use NetAddr::IP::Lite ':lower'; use App::Netdisco::Util::Web (); # for sort_port use App::Netdisco::Web::Plugin; @@ -12,11 +13,11 @@ register_device_tab({ id => 'ports', label => 'Ports' }); # device ports with a description (er, name) matching ajax '/ajax/content/device/ports' => sub { - my $ip = param('q'); + my $ip = NetAddr::IP::Lite->new(param('q')); return unless $ip; my $set = schema('netdisco')->resultset('DevicePort') - ->search({'me.ip' => $ip}); + ->search({'me.ip' => $ip->addr}); # refine by ports if requested my $q = param('f'); @@ -78,7 +79,7 @@ ajax '/ajax/content/device/ports' => sub { template 'ajax/device/ports.tt', { results => $results, nodes => $nodes_name, - device => $ip, + device => $ip->addr, }, { layout => undef }; }; diff --git a/Netdisco/lib/App/Netdisco/Web/Search.pm b/Netdisco/lib/App/Netdisco/Web/Search.pm index 80fc9bca..61e83f66 100644 --- a/Netdisco/lib/App/Netdisco/Web/Search.pm +++ b/Netdisco/lib/App/Netdisco/Web/Search.pm @@ -97,7 +97,7 @@ get '/search' => sub { if ($nd->count == 1) { # redirect to device details for the one device redirect uri_for('/device', - {tab => 'details', q => $nd->first->ip, f => ''}); + {tab => 'details', q => $nd->first->dns, f => ''}); } params->{'tab'} = 'device'; } diff --git a/Netdisco/share/views/ajax/device/addresses.tt b/Netdisco/share/views/ajax/device/addresses.tt index 984f340e..11d38c13 100644 --- a/Netdisco/share/views/ajax/device/addresses.tt +++ b/Netdisco/share/views/ajax/device/addresses.tt @@ -14,10 +14,10 @@ [% row.alias %] [% row.dns.remove(settings.domain_suffix) %] [% row.port %] + href="[% device_ports %]&q=[% params.q | uri %]&f=[% row.port | uri %]">[% row.port %] [% row.device_port.name %] [% row.subnet %] + href="[% search_device %]&ip=[% row.subnet | uri %]">[% row.subnet %] [% END %] diff --git a/Netdisco/share/views/ajax/device/netmap.tt b/Netdisco/share/views/ajax/device/netmap.tt index 7dab3688..c56b9c4b 100644 --- a/Netdisco/share/views/ajax/device/netmap.tt +++ b/Netdisco/share/views/ajax/device/netmap.tt @@ -60,7 +60,7 @@ function to_class(name) { return 'nd_' + name.replace(/\./g, "_") } // handler for clicking on a circle - redirect to that device's netmap function circleClick(d) { - window.location = '[% uri_for('/device') %]?tab=netmap&q=' + d.ip; + window.location = '[% uri_for('/device') %]?tab=netmap&q=' + (d.name || d.ip); } // handler for mouseover on a circle - show that device's real neighbors diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index d89d9238..40941c09 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -182,7 +182,7 @@ [% IF params.c_neighbors AND row.remote_ip %] [% IF row.neighbor %] + self_options) %]&q=[% row.neighbor.dns || row.neighbor.ip | uri %]&f=[% row.remote_port | uri %]"> [% row.neighbor.dns.remove(settings.domain_suffix) || row.neighbor.ip %] ([% row.remote_port | html_entity %]) [% ELSE %] diff --git a/Netdisco/share/views/ajax/search/device.tt b/Netdisco/share/views/ajax/search/device.tt index d6aaf9b6..f9315b65 100644 --- a/Netdisco/share/views/ajax/search/device.tt +++ b/Netdisco/share/views/ajax/search/device.tt @@ -14,7 +14,7 @@ [% WHILE (row = results.next) %] - [% row.dns.remove(settings.domain_suffix) || row.ip %] + [% row.dns || row.ip %] [% row.contact %] [% row.location %] [% row.name %] diff --git a/Netdisco/share/views/ajax/search/node_by_ip.tt b/Netdisco/share/views/ajax/search/node_by_ip.tt index d8adb1e4..e9811256 100644 --- a/Netdisco/share/views/ajax/search/node_by_ip.tt +++ b/Netdisco/share/views/ajax/search/node_by_ip.tt @@ -38,8 +38,8 @@   [% END %] Switch Port - [% node.switch %] [ [% node.port %] ] - [% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %] + [% node.switch %] [ [% node.port %] ] + [% ' (' _ node.device.dns _ ')' IF node.device.dns %] [% ' A' IF NOT node.active %] [% IF params.stamps %] diff --git a/Netdisco/share/views/ajax/search/node_by_mac.tt b/Netdisco/share/views/ajax/search/node_by_mac.tt index 80c5dd0b..7a76d82a 100644 --- a/Netdisco/share/views/ajax/search/node_by_mac.tt +++ b/Netdisco/share/views/ajax/search/node_by_mac.tt @@ -66,8 +66,8 @@ [% END %] Switch Port - [% node.switch %] [ [% node.port %] ] - [% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %] + [% node.switch %] [ [% node.port %] ] + [% ' (' _ node.device.dns _ ')' IF node.device.dns %] [% ' A' IF NOT node.active %] [% IF params.stamps %] @@ -97,8 +97,8 @@ [% END %] Switch Port - [% port.ip %] [ [% port.port %] ] - [% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %] + [% port.ip %] [ [% port.port %] ] + [% ' (' _ port.device.dns _ ')' IF port.device.dns %] [% IF params.stamps %] [% port.creation %] diff --git a/Netdisco/share/views/ajax/search/port.tt b/Netdisco/share/views/ajax/search/port.tt index 23bf02d0..cfec8d08 100644 --- a/Netdisco/share/views/ajax/search/port.tt +++ b/Netdisco/share/views/ajax/search/port.tt @@ -11,8 +11,8 @@ [% WHILE (row = results.next) %] [% row.name %] - [% row.ip %] [ [% row.port %] ] - [% ' (' _ row.device.dns.remove(settings.domain_suffix) _ ')' IF row.device.dns %] + [% row.ip %] [ [% row.port %] ] + [% ' (' _ row.device.dns _ ')' IF row.device.dns %] [% row.descr %] [% row.vlan %] diff --git a/Netdisco/share/views/ajax/search/vlan.tt b/Netdisco/share/views/ajax/search/vlan.tt index cd2f3f6b..262308e5 100644 --- a/Netdisco/share/views/ajax/search/vlan.tt +++ b/Netdisco/share/views/ajax/search/vlan.tt @@ -13,17 +13,17 @@ [% WHILE (row = results.next) %] [% row.vlan.vlan %] + href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.vlan %] [% row.dns.remove(settings.domain_suffix) || row.ip %] + href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.dns || row.ip %] [% row.vlan.description %] + href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.description %] [% row.model %] + href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.model %] [% row.os %] + href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.os %] [% row.vendor %] + href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.vendor %] [% END %]