From 48996661ceb3ecff52ff79deb5e545694616f401 Mon Sep 17 00:00:00 2001 From: Christian Ramseyer Date: Mon, 20 Apr 2020 12:21:06 +0200 Subject: [PATCH] Add vendor to IP Inventory report (#714) * request on mailing list by Adrian Sevcenco, 08.04.20, "[Netdisco] how to modify report: add column to ip inventory" --- .../Netdisco/Web/Plugin/Report/IpInventory.pm | 32 ++++++++++++------- share/views/ajax/report/ipinventory.tt | 7 ++++ share/views/ajax/report/ipinventory_csv.tt | 3 +- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm b/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm index 0a9e6267..968caad7 100644 --- a/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm +++ b/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm @@ -77,31 +77,37 @@ get '/ajax/content/report/ipinventory' => require_login sub { 'dns', \'true AS active', \'false AS node', - \qq/replace( date_trunc( 'minute', age( now(), device.last_discover ) ) ::text, 'mon', 'month') AS age/ + \qq/replace( date_trunc( 'minute', age( now(), device.last_discover ) ) ::text, 'mon', 'month') AS age/, + 'device.vendor', + ], - as => [qw( ip mac time_first time_last dns active node age)], + as => [qw( ip mac time_first time_last dns active node age vendor)], } )->hri; my $rs2 = schema('netdisco')->resultset('NodeIp')->search( undef, - { columns => [qw( ip mac time_first time_last dns active)], + { join => ['oui'], + columns => [qw( ip mac time_first time_last dns active)], '+select' => [ \'true AS node', - \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ + \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/, + \'oui.company || oui.abbrev' ], - '+as' => [ 'node', 'age' ], + '+as' => [ 'node', 'age', 'vendor' ], } )->hri; my $rs3 = schema('netdisco')->resultset('NodeNbt')->search( undef, - { columns => [qw( ip mac time_first time_last )], + { join => ['oui'], + columns => [qw( ip mac time_first time_last )], '+select' => [ 'nbname AS dns', 'active', \'true AS node', - \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ + \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/, + 'oui.company' ], - '+as' => [ 'dns', 'active', 'node', 'age' ], + '+as' => [ 'dns', 'active', 'node', 'age', 'vendor' ], } )->hri; @@ -115,9 +121,10 @@ get '/ajax/content/report/ipinventory' => require_login sub { { bind => [ $subnet->cidr ], columns => [qw( ip mac time_first time_last dns active)], '+select' => [ \'false AS node', - \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ + \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/, + \'null as vendor' ], - '+as' => [ 'node', 'age' ], + '+as' => [ 'node', 'age', 'vendor' ], } )->hri; @@ -134,11 +141,12 @@ get '/ajax/content/report/ipinventory' => require_login sub { \qq/date_trunc('second', time_first) AS time_first/, 'active', 'node', - 'age' + 'age', + 'vendor' ], as => [ 'ip', 'mac', 'dns', 'time_last', 'time_first', - 'active', 'node', 'age' + 'active', 'node', 'age', 'vendor' ], order_by => [{-asc => 'ip'}, {-desc => 'active'}, {-asc => 'node'}], } diff --git a/share/views/ajax/report/ipinventory.tt b/share/views/ajax/report/ipinventory.tt index 8ff1aab0..9e4c28b9 100644 --- a/share/views/ajax/report/ipinventory.tt +++ b/share/views/ajax/report/ipinventory.tt @@ -3,6 +3,7 @@ IP Address MAC Address + Vendor DNS Last Used @@ -42,6 +43,12 @@ $(document).ready(function() { } return cell_str; } + }, { + "data": 'vendor', + "className": "nd_nowrap nd_center-cell", + "render": function(data, type, row, meta) { + return he.encode(data || ''); + } }, { "data": 'dns', "className": "nd_nowrap nd_center-cell", diff --git a/share/views/ajax/report/ipinventory_csv.tt b/share/views/ajax/report/ipinventory_csv.tt index f5575b16..0e66bfae 100644 --- a/share/views/ajax/report/ipinventory_csv.tt +++ b/share/views/ajax/report/ipinventory_csv.tt @@ -1,10 +1,11 @@ [% USE CSV %] -[% CSV.dump([ 'Node' 'MAC Address' 'DNS' 'Last Used' ]) %] +[% CSV.dump([ 'Node' 'MAC Address' 'Vendor' 'DNS' 'Last Used' ]) %] [% FOREACH row IN results %] [% mylist = [] %] [% mylist.push(row.ip) %] [% mylist.push(row.mac) %] + [% mylist.push(row.vendor) %] [% mylist.push(row.dns) %] [% mylist.push(row.time_last) %] [% CSV.dump(mylist) %]