implement port search
This commit is contained in:
@@ -21,5 +21,23 @@ sub by_mac {
|
||||
);
|
||||
}
|
||||
|
||||
# confusingly the "name" field is set using IOS "descrption"
|
||||
# command but should not be confused with the "descr" field
|
||||
sub by_name {
|
||||
my ($set, $name) = @_;
|
||||
return $set unless $name;
|
||||
|
||||
return $set->search(
|
||||
{
|
||||
'me.name' => { '-ilike' => $name },
|
||||
},
|
||||
{
|
||||
order_by => [qw/ me.ip me.port /],
|
||||
columns => [qw/ ip port descr name vlan device.dns /],
|
||||
join => 'device',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package Netdisco::Web;
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin::Ajax;
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Exception ':all';
|
||||
|
||||
use Digest::MD5 ();
|
||||
use Socket6 (); # to ensure dependency is met
|
||||
@@ -43,8 +42,9 @@ ajax '/ajax/content/search/node' => sub {
|
||||
return unless $node;
|
||||
content_type('text/html');
|
||||
|
||||
try {
|
||||
my $mac = Net::MAC->new(mac => $node);
|
||||
my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0);
|
||||
if (eval { $mac->as_IEEE }) {
|
||||
|
||||
my $ips = schema('netdisco')->resultset('NodeIp')
|
||||
->by_mac(param('archived'), $mac->as_IEEE);
|
||||
return unless $ips->count;
|
||||
@@ -61,7 +61,7 @@ ajax '/ajax/content/search/node' => sub {
|
||||
ports => $ports,
|
||||
}, { layout => undef };
|
||||
}
|
||||
catch {
|
||||
else {
|
||||
my $set;
|
||||
|
||||
if (my $ip = NetAddr::IP::Lite->new($node)) {
|
||||
@@ -80,7 +80,7 @@ ajax '/ajax/content/search/node' => sub {
|
||||
template 'ajax/node_by_ip.tt', {
|
||||
results => $set,
|
||||
}, { layout => undef };
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
# devices carrying vlan xxx
|
||||
@@ -97,6 +97,20 @@ ajax '/ajax/content/search/vlan' => sub {
|
||||
}, { layout => undef };
|
||||
};
|
||||
|
||||
# device ports with a description (er, name) matching
|
||||
ajax '/ajax/content/search/port' => sub {
|
||||
my $name = param('q');
|
||||
return unless $name;
|
||||
|
||||
my $set = schema('netdisco')->resultset('DevicePort')->by_name($name);
|
||||
return unless $set->count;
|
||||
|
||||
content_type('text/html');
|
||||
template 'ajax/port.tt', {
|
||||
results => $set,
|
||||
}, { layout => undef };
|
||||
};
|
||||
|
||||
get '/search' => sub {
|
||||
my $q = param('q');
|
||||
if ($q and not param('tab')) {
|
||||
|
||||
22
Netdisco/views/ajax/port.tt
Normal file
22
Netdisco/views/ajax/port.tt
Normal file
@@ -0,0 +1,22 @@
|
||||
<table class="bordered-table condensed-table zebra-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Vlan</th>
|
||||
<th>Port</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</tbody>
|
||||
[% WHILE (row = results.next) %]
|
||||
<tr>
|
||||
<td>[% row.name %]</td>
|
||||
<td>[% row.descr %]</td>
|
||||
<td>[% row.vlan %]</td>
|
||||
<td><a href="/device?q=[% row.ip %]&port=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
|
||||
[% ' (' _ row.device.dns.remove(settings.domain_suffix) _ ')' IF row.device.dns %]
|
||||
</td>
|
||||
</tr>
|
||||
[% END %]
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user