allow vlan search by name
This commit is contained in:
@@ -110,4 +110,21 @@ sub carrying_vlan {
|
||||
);
|
||||
}
|
||||
|
||||
sub carrying_vlan_name {
|
||||
my ($set, $name) = @_;
|
||||
return $set unless $name;
|
||||
$name = "\%$name\%" if $name !~ m/\%/;
|
||||
|
||||
return $set->search(
|
||||
{
|
||||
'vlans.description' => { '-ilike' => $name },
|
||||
},
|
||||
{
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
columns => [qw/ me.ip me.dns me.model me.os me.vendor /],
|
||||
prefetch => 'vlans',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -30,17 +30,6 @@ hook 'before' => sub {
|
||||
var('query_defaults' => { map { ($_ => "tab=$_") } qw/node/ });
|
||||
var('query_defaults')->{node} .= "\&$_=". (param($_) || '')
|
||||
for qw/stamps vendor archived partial/;
|
||||
|
||||
# set up property lists for device search
|
||||
var('model_list' => [
|
||||
schema('netdisco')->resultset('Device')->get_distinct('model')
|
||||
]);
|
||||
var('os_ver_list' => [
|
||||
schema('netdisco')->resultset('Device')->get_distinct('os_ver')
|
||||
]);
|
||||
var('vendor_list' => [
|
||||
schema('netdisco')->resultset('Device')->get_distinct('vendor')
|
||||
]);
|
||||
};
|
||||
|
||||
# device with various properties or a default match-all
|
||||
@@ -50,16 +39,15 @@ ajax '/ajax/content/search/device' => sub {
|
||||
my $set;
|
||||
|
||||
if ($has_opt) {
|
||||
$set = schema('netdisco')->resultset('Device')->by_field(scalar params);
|
||||
return unless $set->count;
|
||||
$set = schema('netdisco')->resultset('Device')->by_field(scalar params);
|
||||
}
|
||||
else {
|
||||
my $q = param('q');
|
||||
return unless $q;
|
||||
my $q = param('q');
|
||||
return unless $q;
|
||||
|
||||
$set = schema('netdisco')->resultset('Device')->by_any($q);
|
||||
return unless $set->count;
|
||||
$set = schema('netdisco')->resultset('Device')->by_any($q);
|
||||
}
|
||||
return unless $set->count;
|
||||
|
||||
content_type('text/html');
|
||||
template 'ajax/device.tt', {
|
||||
@@ -99,14 +87,13 @@ ajax '/ajax/content/search/node' => sub {
|
||||
# by_ip() will extract cidr notation if necessary
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->by_ip(param('archived'), $ip);
|
||||
return unless $set->count;
|
||||
}
|
||||
else {
|
||||
$node = "\%$node\%" if param('partial');
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->by_name(param('archived'), $node);
|
||||
return unless $set->count;
|
||||
}
|
||||
return unless $set->count;
|
||||
|
||||
template 'ajax/node_by_ip.tt', {
|
||||
results => $set,
|
||||
@@ -117,9 +104,15 @@ ajax '/ajax/content/search/node' => sub {
|
||||
# devices carrying vlan xxx
|
||||
ajax '/ajax/content/search/vlan' => sub {
|
||||
my $vlan = param('q');
|
||||
return unless $vlan and $vlan =~ m/^\d+$/;
|
||||
return unless $vlan;
|
||||
my $set;
|
||||
|
||||
my $set = schema('netdisco')->resultset('Device')->carrying_vlan($vlan);
|
||||
if ($vlan =~ m/^\d+$/) {
|
||||
$set = schema('netdisco')->resultset('Device')->carrying_vlan($vlan);
|
||||
}
|
||||
else {
|
||||
$set = schema('netdisco')->resultset('Device')->carrying_vlan_name($vlan);
|
||||
}
|
||||
return unless $set->count;
|
||||
|
||||
content_type('text/html');
|
||||
@@ -147,6 +140,17 @@ get '/' => sub {
|
||||
};
|
||||
|
||||
get '/search' => sub {
|
||||
# set up property lists for device search
|
||||
var('model_list' => [
|
||||
schema('netdisco')->resultset('Device')->get_distinct('model')
|
||||
]);
|
||||
var('os_ver_list' => [
|
||||
schema('netdisco')->resultset('Device')->get_distinct('os_ver')
|
||||
]);
|
||||
var('vendor_list' => [
|
||||
schema('netdisco')->resultset('Device')->get_distinct('vendor')
|
||||
]);
|
||||
|
||||
my $q = param('q');
|
||||
if ($q and not param('tab')) {
|
||||
# pick most likely tab for initial results
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</tbody>
|
||||
[% WHILE (row = results.next) %]
|
||||
<tr>
|
||||
<td><a href="/device?q=[% row.ip %]">[% row.dns.remove(settings.domain_suffix) %]</a></td>
|
||||
<td><a href="/device?ip=[% row.ip %]">[% row.dns.remove(settings.domain_suffix) %]</a></td>
|
||||
<td>[% row.contact %]</td>
|
||||
<td>[% row.location %]</td>
|
||||
<td>[% row.name %]</td>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<td> </td>
|
||||
[% END %]
|
||||
<td>Switch Port</td>
|
||||
<td><a href="/device?q=[% node.switch | url %]&port=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
|
||||
<td><a href="/device?ip=[% node.switch | url %]&port=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
|
||||
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
|
||||
[% ' <span class="label warning">a</span>' IF NOT node.active %]
|
||||
</td>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<td> </td>
|
||||
[% END %]
|
||||
<td>Switch Port</td>
|
||||
<td><a href="/device?q=[% node.switch | url %]&port=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
|
||||
<td><a href="/device?ip=[% node.switch | url %]&port=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
|
||||
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
|
||||
[% ' <span class="label warning">a</span>' IF NOT node.active %]
|
||||
</td>
|
||||
@@ -70,7 +70,7 @@
|
||||
<td> </td>
|
||||
[% END %]
|
||||
<td>Switch Port</td>
|
||||
<td><a href="/device?q=[% port.ip | url %]&port=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
|
||||
<td><a href="/device?ip=[% port.ip | url %]&port=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
|
||||
[% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %]
|
||||
</td>
|
||||
[% IF params.stamps %]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<table class="bordered-table condensed-table zebra-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Vlan</th>
|
||||
<th>Device</th>
|
||||
<th>Description</th>
|
||||
<th>Model</th>
|
||||
@@ -11,16 +12,18 @@
|
||||
</tbody>
|
||||
[% WHILE (row = results.next) %]
|
||||
<tr>
|
||||
<td><a class="nd_linkcell nd_stealthlink"
|
||||
href="/device?ip=[% row.ip %]&vlan=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
|
||||
<td><a class="nd_linkcell"
|
||||
href="/device?q=[% row.ip %]&vlan=[% params.q %]">[% row.dns %]</a></td>
|
||||
href="/device?ip=[% row.ip %]&vlan=[% row.vlan.vlan %]">[% row.dns %]</a></td>
|
||||
<td><a class="nd_linkcell nd_stealthlink"
|
||||
href="/device?q=[% row.ip %]&vlan=[% params.q %]">[% row.vlan.description %]</a></td>
|
||||
href="/device?ip=[% row.ip %]&vlan=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
|
||||
<td><a class="nd_linkcell nd_stealthlink"
|
||||
href="/device?q=[% row.ip %]&vlan=[% params.q %]">[% row.model %]</a></td>
|
||||
href="/device?ip=[% row.ip %]&vlan=[% row.vlan.vlan %]">[% row.model %]</a></td>
|
||||
<td><a class="nd_linkcell nd_stealthlink"
|
||||
href="/device?q=[% row.ip %]&vlan=[% params.q %]">[% row.os %]</a></td>
|
||||
href="/device?ip=[% row.ip %]&vlan=[% row.vlan.vlan %]">[% row.os %]</a></td>
|
||||
<td><a class="nd_linkcell nd_stealthlink"
|
||||
href="/device?q=[% row.ip %]&vlan=[% params.q %]">[% row.vendor %]</a></td>
|
||||
href="/device?ip=[% row.ip %]&vlan=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
|
||||
</tr>
|
||||
[% END %]
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user