#688 Amend vlan search to show number of ports actually using the vlan

This commit is contained in:
Oliver Gorwits
2019-12-22 08:33:11 +00:00
parent d133eb97c2
commit c282a5a565
3 changed files with 21 additions and 10 deletions

View File

@@ -386,7 +386,8 @@ Results are ordered by the Device DNS and IP fields.
=item *
Related rows from the C<device_vlan> table will be prefetched.
Column C<pcount> gives a count of the number of ports on the device
that are actually configured to carry the VLAN.
=back
@@ -404,13 +405,16 @@ sub carrying_vlan {
->search_rs({ 'vlans.vlan' => $cond->{vlan} },
{
order_by => [qw/ me.dns me.ip /],
columns => [
'me.ip', 'me.dns',
'me.model', 'me.os',
'me.vendor', 'vlans.vlan',
'vlans.description'
],
join => 'vlans'
select => [{ count => 'ports.vlan' }],
as => ['pcount'],
columns => [
'me.ip', 'me.dns',
'me.model', 'me.os',
'me.vendor', 'vlans.vlan',
'vlans.description'
],
join => {'vlans' => 'ports'},
distinct => 1,
})
->search({}, $attrs);
}

View File

@@ -4,6 +4,7 @@
<th>VLAN</th>
<th>Device</th>
<th>Description</th>
<th>Ports</th>
<th>Model</th>
<th>OS</th>
<th>Vendor</th>
@@ -31,6 +32,12 @@ $(document).ready(function() {
"render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports | none %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data || '') + '</a>';
}
}, {
"data": 'pcount',
"searchable": false,
"render": function(data, type, row, meta) {
return '<a class="nd_linkcell nd_stealth-link" href="[% device_ports | none %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(row.vlans.vlan) + '">' + he.encode(data.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")) + '</a>';
}
}, {
"data": 'model',
"render": function(data, type, row, meta) {

View File

@@ -1,10 +1,10 @@
[% USE CSV -%]
[% CSV.dump([ 'VLAN' 'Device' 'Description' 'Model' 'OS' 'Vendor' ]) %]
[% CSV.dump([ 'VLAN' 'Device' 'Description' 'Ports' 'Model' 'OS' 'Vendor' ]) %]
[% FOREACH row IN results %]
[% mylist = [] %]
[% device = row.dns || row.ip %]
[% FOREACH col IN [ row.vlans.vlan device row.vlans.description row.model row.os row.vendor ] %]
[% FOREACH col IN [ row.vlans.vlan device row.vlans.description row.pcount row.model row.os row.vendor ] %]
[% mylist.push(col) %]
[% END %]
[% CSV.dump(mylist) %]