gracefully handle lack of dns col on node_ip
This commit is contained in:
@@ -50,7 +50,7 @@ sub dns {
|
|||||||
return $row->get_column('dns')
|
return $row->get_column('dns')
|
||||||
if $row->result_source->has_column('dns');
|
if $row->result_source->has_column('dns');
|
||||||
|
|
||||||
use Net::DNS;
|
use Net::DNS ();
|
||||||
my $q = Net::DNS::Resolver->new->query($row->ip);
|
my $q = Net::DNS::Resolver->new->query($row->ip);
|
||||||
if ($q) {
|
if ($q) {
|
||||||
foreach my $rr ($q->answer) {
|
foreach my $rr ($q->answer) {
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ sub by_ip {
|
|||||||
sub by_name {
|
sub by_name {
|
||||||
my ($set, $archive, $name) = @_;
|
my ($set, $archive, $name) = @_;
|
||||||
return $set unless $name;
|
return $set unless $name;
|
||||||
|
die "do not call by_name unless you have a dns col on the node_ip table."
|
||||||
|
if not $set->has_dns_col;
|
||||||
|
|
||||||
return $set->search(
|
return $set->search(
|
||||||
{
|
{
|
||||||
@@ -55,7 +57,7 @@ sub by_name {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
%$search_attr,
|
%$search_attr,
|
||||||
( $set->has_dns_col ? ('+columns' => 'dns') : () ),
|
'+columns' => 'dns',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Dancer::Plugin::DBIC;
|
|||||||
use NetAddr::IP::Lite ':lower';
|
use NetAddr::IP::Lite ':lower';
|
||||||
use Net::MAC ();
|
use Net::MAC ();
|
||||||
use List::MoreUtils ();
|
use List::MoreUtils ();
|
||||||
|
use Net::DNS ();
|
||||||
|
|
||||||
hook 'before' => sub {
|
hook 'before' => sub {
|
||||||
# make hash lookups of query lists
|
# make hash lookups of query lists
|
||||||
@@ -94,9 +95,33 @@ ajax '/ajax/content/search/node' => sub {
|
|||||||
->by_ip(param('archived'), $ip);
|
->by_ip(param('archived'), $ip);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$node = "\%$node\%" if param('partial');
|
if (schema('netdisco')->resultset('NodeIp')->has_dns_col) {
|
||||||
$set = schema('netdisco')->resultset('NodeIp')
|
if (param('partial')) {
|
||||||
->by_name(param('archived'), $node);
|
$node = "\%$node\%";
|
||||||
|
}
|
||||||
|
elsif (setting('domain_suffix')) {
|
||||||
|
$node .= setting('domain_suffix')
|
||||||
|
if index($node, setting('domain_suffix')) == -1;
|
||||||
|
}
|
||||||
|
$set = schema('netdisco')->resultset('NodeIp')
|
||||||
|
->by_name(param('archived'), $node);
|
||||||
|
}
|
||||||
|
elsif (setting('domain_suffix')) {
|
||||||
|
$node .= setting('domain_suffix')
|
||||||
|
if index($node, setting('domain_suffix')) == -1;
|
||||||
|
my $q = Net::DNS::Resolver->new->query($node);
|
||||||
|
if ($q) {
|
||||||
|
foreach my $rr ($q->answer) {
|
||||||
|
next unless $rr->type eq 'A';
|
||||||
|
$node = $rr->address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$set = schema('netdisco')->resultset('NodeIp')
|
||||||
|
->by_ip(param('archived'), $node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return unless $set->count;
|
return unless $set->count;
|
||||||
|
|
||||||
@@ -205,6 +230,9 @@ get '/search' => sub {
|
|||||||
{ id => 'port', label => 'Port' },
|
{ id => 'port', label => 'Port' },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
var('node_ip_has_dns_col' =>
|
||||||
|
schema('netdisco')->resultset('NodeIp')->has_dns_col);
|
||||||
|
|
||||||
template 'search';
|
template 'search';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
<span class="nd_searchcheckbox uneditable-input">Archived Data <span class="nd_legendlabel label warning">a</span></span>
|
<span class="nd_searchcheckbox uneditable-input">Archived Data <span class="nd_legendlabel label warning">a</span></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
[% IF vars.node_ip_has_dns_col %]
|
||||||
<div class="clearfix input-prepend">
|
<div class="clearfix input-prepend">
|
||||||
<label class="add-on">
|
<label class="add-on">
|
||||||
<input type="checkbox" id="partial" name="partial"[% ' checked="checked"' IF params.partial %]/>
|
<input type="checkbox" id="partial" name="partial"[% ' checked="checked"' IF params.partial %]/>
|
||||||
@@ -32,3 +33,4 @@
|
|||||||
<span class="nd_searchcheckbox uneditable-input">Partial Name</span>
|
<span class="nd_searchcheckbox uneditable-input">Partial Name</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
[% END %]
|
||||||
|
|||||||
Reference in New Issue
Block a user