diff --git a/Changes b/Changes index 6332ad65..d573a5ab 100644 --- a/Changes +++ b/Changes @@ -3,12 +3,13 @@ [ENHANCEMENTS] * #319 better fix for acceping ACL names or values in check_acl_* + * #311 added duplicate devices report with option to delete [BUG FIXES] * #320 DNS subroutines are redefined * #318 ACLs with RegExp are very slow - aggressive resolver timeouts - * #317 when renumbering on discover, delete likely duplicate devices + * #317 #265 #311 when renumbering on discover, delete likely duplicate devices * #316 Neighbor map should fall back to device sysname after dns 2.036001 - 2017-06-22 diff --git a/lib/App/Netdisco/Web/Plugin/AdminTask/DuplicateDevices.pm b/lib/App/Netdisco/Web/Plugin/AdminTask/DuplicateDevices.pm new file mode 100644 index 00000000..bd50dc9f --- /dev/null +++ b/lib/App/Netdisco/Web/Plugin/AdminTask/DuplicateDevices.pm @@ -0,0 +1,40 @@ +package App::Netdisco::Web::Plugin::AdminTask::DuplicateDevices; + +use Dancer ':syntax'; +use Dancer::Plugin::Ajax; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_admin_task({ + tag => 'duplicatedevices', + label => 'Duplicate Devices', +}); + +ajax '/ajax/control/admin/duplicatedevices/delete' => require_role admin => sub { + my $ip = NetAddr::IP::Lite->new(param('ip')); + send_error('Bad Request', 400) unless ($ip and $ip->addr ne '0.0.0.0'); + forward '/ajax/control/admin/delete', { device => param('ip') }; +}; + +ajax '/ajax/content/admin/duplicatedevices' => require_role admin => sub { + my @set = schema('netdisco')->resultset('Device')->search({ + serial => { '-in' => schema('netdisco')->resultset('Device')->search({ + '-and' => [serial => { '!=', undef }, serial => { '!=', '' }], + }, { + group_by => ['serial'], + having => \'count(*) > 1', + columns => 'serial', + })->as_query + }, + }, { columns => [qw/ip dns contact location name model os_ver serial/] }) + ->with_times->hri->all; + + content_type('text/html'); + template 'ajax/admintask/duplicatedevices.tt', { + results => \@set + }, { layout => undef }; +}; + +true; diff --git a/share/config.yml b/share/config.yml index a594c44f..0425f214 100644 --- a/share/config.yml +++ b/share/config.yml @@ -71,6 +71,7 @@ web_plugins: - AdminTask::SlowDevices - AdminTask::UndiscoveredNeighbors - AdminTask::OrphanedDevices + - AdminTask::DuplicateDevices - AdminTask::TimedOutDevices - AdminTask::UserLog - AdminTask::Users diff --git a/share/views/ajax/admintask/duplicatedevices.tt b/share/views/ajax/admintask/duplicatedevices.tt new file mode 100644 index 00000000..5b7f76bf --- /dev/null +++ b/share/views/ajax/admintask/duplicatedevices.tt @@ -0,0 +1,77 @@ +[% IF NOT results.size %] +
No duplicate devices found.
+[% ELSE %] + + + + + + + + + + + + + + + + [% FOREACH row IN results %] + + + + + + + + + + + + + [% END %] + +
Device IPContactLocationSystem NameModelOS VersionSerialLast DiscoveredDelete
[% row.ip | html_entity %] + [% row.dns | html_entity %][% row.contact | html_entity %][% row.location | html_entity %][% row.name | html_entity %][% row.model | html_entity %][% row.os_ver | html_entity %][% row.serial | html_entity %][% row.last_discover_stamp | html_entity %] + + + +
+[% END %] + +