When linking to devices, use the DNS name in preference to the IP

This commit is contained in:
Oliver Gorwits
2013-02-10 15:31:55 +00:00
parent b7e971074f
commit 4d832cb2a5
14 changed files with 41 additions and 29 deletions

View File

@@ -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

View File

@@ -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');

View File

@@ -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');

View File

@@ -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',

View File

@@ -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 };
};

View File

@@ -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';
}

View File

@@ -14,10 +14,10 @@
<td>[% row.alias %]</a>
<td>[% row.dns.remove(settings.domain_suffix) %]</a>
<td class="center_cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.port %]">[% row.port %]</a></td>
href="[% device_ports %]&q=[% params.q | uri %]&f=[% row.port | uri %]">[% row.port %]</a></td>
<td>[% row.device_port.name %]</td>
<td><a class="nd_linkcell"
href="[% search_device %]&ip=[% row.subnet %]">[% row.subnet %]</a></td>
href="[% search_device %]&ip=[% row.subnet | uri %]">[% row.subnet %]</a></td>
</tr>
[% END %]
</tbody>

View File

@@ -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

View File

@@ -182,7 +182,7 @@
[% IF params.c_neighbors AND row.remote_ip %]
[% IF row.neighbor %]
<a href="[% uri_for('/device',
self_options) %]&q=[% row.neighbor.ip | uri %]&f=[% row.remote_port | uri %]">
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 %])</a>
[% ELSE %]

View File

@@ -14,7 +14,7 @@
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td><a href="[% uri_for('/device') %]?q=[% row.ip %]">[% row.dns.remove(settings.domain_suffix) || row.ip %]</a></td>
<td><a href="[% uri_for('/device') %]?q=[% row.dns || row.ip %]">[% row.dns || row.ip %]</a></td>
<td>[% row.contact %]</td>
<td>[% row.location %]</td>
<td>[% row.name %]</td>

View File

@@ -38,8 +38,8 @@
<td>&nbsp;</td>
[% END %]
<td>Switch Port</td>
<td><a href="[% device_ports %]&q=[% node.switch | url %]&f=[% node.port | url %]&c_nodes=on&c_neighbor=on">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
<td><a href="[% device_ports %]&q=[% node.device.dns || node.switch %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns _ ')' IF node.device.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT node.active %]
</td>
[% IF params.stamps %]

View File

@@ -66,8 +66,8 @@
</td>
[% END %]
<td>Switch Port</td>
<td><a href="[% device_ports %]&q=[% node.switch | url %]&f=[% node.port | url %]&c_nodes=on&c_neighbor=on">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
<td><a href="[% device_ports %]&q=[% node.device.dns || node.switch %]&f=[% node.port %]&c_nodes=on&c_neighbors=on">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns _ ')' IF node.device.dns %]
[% ' <span class="label label-warning">A</span>' IF NOT node.active %]
</td>
[% IF params.stamps %]
@@ -97,8 +97,8 @@
</td>
[% END %]
<td>Switch Port</td>
<td><a href="[% device_ports %]&q=[% port.ip | url %]&f=[% port.port | url %]&c_nodes=on&c_neighbor=on">[% port.ip %] [ [% port.port %] ]</a>
[% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %]
<td><a href="[% device_ports %]&q=[% port.device.dns || port.ip %]&f=[% port.port %]&c_mac=on&c_nodes=on&c_neighbors=on">[% port.ip %] [ [% port.port %] ]</a>
[% ' (' _ port.device.dns _ ')' IF port.device.dns %]
</td>
[% IF params.stamps %]
<td>[% port.creation %]</td>

View File

@@ -11,8 +11,8 @@
[% WHILE (row = results.next) %]
<tr>
<td>[% row.name %]</td>
<td><a href="[% device_ports %]&q=[% row.ip %]&f=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
[% ' (' _ row.device.dns.remove(settings.domain_suffix) _ ')' IF row.device.dns %]
<td><a href="[% device_ports %]&q=[% row.device.dns || row.ip %]&f=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
[% ' (' _ row.device.dns _ ')' IF row.device.dns %]
</td>
<td>[% row.descr %]</td>
<td>[% row.vlan %]</td>

View File

@@ -13,17 +13,17 @@
[% WHILE (row = results.next) %]
<tr>
<td><a class="nd_linkcell nd_stealthlink"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
<td><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.dns.remove(settings.domain_suffix) || row.ip %]</a></td>
href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.dns || row.ip %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.model %]</a></td>
href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.model %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.os %]</a></td>
href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.os %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="[% device_ports %]&q=[% row.ip %]&f=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
href="[% device_ports %]&q=[% row.dns || row.ip %]&f=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
</tr>
[% END %]
</tbody>