avoid use of DNS when looking up devices in DB by IP

This commit is contained in:
Oliver Gorwits
2013-02-24 23:15:49 +00:00
parent 8a0311d4c5
commit a94b5a913d
11 changed files with 78 additions and 54 deletions

View File

@@ -4,8 +4,6 @@ use Dancer ':syntax';
use Dancer::Plugin::Ajax;
use Dancer::Plugin::DBIC;
use NetAddr::IP::Lite ':lower';
hook 'before' => sub {
# list of port detail columns
var('port_columns' => [

View File

@@ -4,19 +4,18 @@ 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 = NetAddr::IP::Lite->new(param('q'));
return unless $ip;
my $q = param('q');
my $set = schema('netdisco')->resultset('DeviceIp')
->search({ip => $ip->addr}, {order_by => 'alias'});
my $device = schema('netdisco')->resultset('Device')
->search_for_device($q) or return;
my $set = $device->device_ips->search({}, {order_by => 'alias'});
return unless $set->count;
content_type('text/html');

View File

@@ -4,20 +4,15 @@ 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 = NetAddr::IP::Lite->new(param('q'));
return unless $ip;
my $q = param('q');
my $device = schema('netdisco')->resultset('Device')
->with_times()->find($ip->addr);
return unless $device;
->with_times()->search_for_device($q) or return;
content_type('text/html');
template 'ajax/device/details.tt', {

View File

@@ -4,8 +4,6 @@ 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' });
@@ -42,9 +40,11 @@ sub _add_children {
# d3 seems not to use proper ajax semantics, so get instead of ajax
get '/ajax/data/device/netmap' => sub {
my $ip = NetAddr::IP::Lite->new(param('q'));
return unless $ip;
my $start = $ip->addr;
my $q = param('q');
my $device = schema('netdisco')->resultset('Device')
->search_for_device($q) or return;
my $start = $device->ip;
my @devices = schema('netdisco')->resultset('Device')->search({}, {
result_class => 'DBIx::Class::ResultClass::HashRefInflator',

View File

@@ -4,43 +4,41 @@ 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;
register_device_tab({ id => 'ports', label => 'Ports' });
# device ports with a description (er, name) matching
ajax '/ajax/content/device/ports' => sub {
my $ip = NetAddr::IP::Lite->new(param('q'));
return unless $ip;
my $q = param('q');
my $set = schema('netdisco')->resultset('DevicePort')
->search({'me.ip' => $ip->addr});
my $device = schema('netdisco')->resultset('Device')
->search_for_device($q) or return;
my $set = $device->ports;
# refine by ports if requested
my $q = param('f');
if ($q) {
if ($q =~ m/^\d+$/) {
my $f = param('f');
if ($f) {
if ($f =~ m/^\d+$/) {
$set = $set->search({
-or => {
'me.vlan' => $q,
'port_vlans_tagged.vlan' => $q,
'me.vlan' => $f,
'port_vlans_tagged.vlan' => $f,
},
}, { join => 'port_vlans_tagged' });
return unless $set->count;
}
else {
$q =~ s/\*/%/g if index($q, '*') >= 0;
$q =~ s/\?/_/g if index($q, '?') >= 0;
$q = { '-ilike' => $q };
$f =~ s/\*/%/g if index($f, '*') >= 0;
$f =~ s/\?/_/g if index($f, '?') >= 0;
$f = { '-ilike' => $f };
if ($set->search({'me.port' => $q})->count) {
$set = $set->search({'me.port' => $q});
if ($set->search({'me.port' => $f})->count) {
$set = $set->search({'me.port' => $f});
}
else {
$set = $set->search({'me.name' => $q});
$set = $set->search({'me.name' => $f});
return unless $set->count;
}
}
@@ -79,7 +77,7 @@ ajax '/ajax/content/device/ports' => sub {
template 'ajax/device/ports.tt', {
results => $results,
nodes => $nodes_name,
device => $ip->addr,
device => $device->ip,
}, { layout => undef };
};

View File

@@ -4,8 +4,6 @@ use Dancer ':syntax';
use Dancer::Plugin::Ajax;
use Dancer::Plugin::DBIC;
use NetAddr::IP::Lite ':lower';
hook 'before' => sub {
# view settings for node options
var('node_options' => [