From 7d5c3f31918a28de052f093af993c7c1fde5c818 Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Thu, 29 May 2014 20:30:28 -0400 Subject: [PATCH] DataTables for nodes with multiple active IP addresses report --- .../lib/App/Netdisco/DB/ResultSet/Node.pm | 64 ------------------- .../Web/Plugin/Report/NodeMultiIPs.pm | 26 ++++++-- .../share/views/ajax/report/nodemultiips.tt | 56 +++++++++++----- 3 files changed, 60 insertions(+), 86 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm index 3da9fe9c..3a143243 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/Node.pm @@ -125,68 +125,4 @@ sub delete { } } -=head2 with_multi_ips_as_hashref - -This is a modifier for C which returns a list of hash references -for nodes within the search criteria with multiple IP addresses. Each hash -reference contains the keys: - -=over 4 - -=item mac - -Node MAC address. - -=item switch - -IP address of the device where the node is attached. - -=item port - -Port on the device where the node is attached. - -=item dns - -DNS name of the device where the node is attached. - -=item name - -C of the device where the node is attached. - -=item ip_count - -Count of IP addresses associated with the node. - -=item vendor - -Vendor string based upon the node OUI. - -=back - -=cut - -sub with_multi_ips_as_hashref { - my ( $rs, $cond, $attrs ) = @_; - - my @return = $rs->search( - {}, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator', - select => [ 'mac', 'switch', 'port' ], - join => [qw/device ips oui/], - '+columns' => [ - { 'dns' => 'device.dns' }, - { 'name' => 'device.name' }, - { 'ip_count' => { count => 'ips.ip' } }, - { 'vendor' => 'oui.company' } - ], - group_by => - [qw/ me.mac me.switch me.port device.dns device.name oui.company/], - having => \[ 'count(ips.ip) > ?', [ count => 1 ] ], - order_by => { -desc => [qw/count/] }, - } - )->all; - - return \@return; -} - 1; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/NodeMultiIPs.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/NodeMultiIPs.pm index 4a1dccab..d295a69d 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/NodeMultiIPs.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/NodeMultiIPs.pm @@ -15,19 +15,35 @@ register_report( ); get '/ajax/content/report/nodemultiips' => require_login sub { - my $results = schema('netdisco')->resultset('Node') - ->with_multi_ips_as_hashref; + my @results = schema('netdisco')->resultset('Node')->search( + {}, + { select => [ 'mac', 'switch', 'port' ], + join => [qw/device ips oui/], + '+columns' => [ + { 'dns' => 'device.dns' }, + { 'name' => 'device.name' }, + { 'ip_count' => { count => 'ips.ip' } }, + { 'vendor' => 'oui.company' } + ], + group_by => [ + qw/ me.mac me.switch me.port device.dns device.name oui.company/ + ], + having => \[ 'count(ips.ip) > ?', [ count => 1 ] ], + order_by => { -desc => [qw/count/] }, + } + )->hri->all; - return unless scalar $results; + return unless scalar @results; if ( request->is_ajax ) { - template 'ajax/report/nodemultiips.tt', { results => $results, }, + my $json = to_json( \@results ); + template 'ajax/report/nodemultiips.tt', { results => $json }, { layout => undef }; } else { header( 'Content-Type' => 'text/comma-separated-values' ); template 'ajax/report/nodemultiips_csv.tt', - { results => $results, }, + { results => \@results }, { layout => undef }; } }; diff --git a/Netdisco/share/views/ajax/report/nodemultiips.tt b/Netdisco/share/views/ajax/report/nodemultiips.tt index a35872fb..aba904dc 100644 --- a/Netdisco/share/views/ajax/report/nodemultiips.tt +++ b/Netdisco/share/views/ajax/report/nodemultiips.tt @@ -1,24 +1,46 @@ [% USE Number.Format %] - +
- - - - + + + + - - [% FOREACH row IN results %] - - - - - - [% END %] -
MACVendorLocationIPsMACVendorLocationIPs
- [% row.mac.upper | html_entity %] - [% row.vendor | html_entity %] - [% row.dns || row.name || row.switch | html_entity %] ([% row.port | html_entity %])[% row.ip_count | format_number %]
+ +