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

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