#311 added duplicate devices report with option to delete

This commit is contained in:
Oliver Gorwits
2017-06-24 18:11:18 +01:00
parent ba9da2d93c
commit 55edd65734
4 changed files with 120 additions and 1 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -71,6 +71,7 @@ web_plugins:
- AdminTask::SlowDevices
- AdminTask::UndiscoveredNeighbors
- AdminTask::OrphanedDevices
- AdminTask::DuplicateDevices
- AdminTask::TimedOutDevices
- AdminTask::UserLog
- AdminTask::Users

View File

@@ -0,0 +1,77 @@
[% IF NOT results.size %]
<div class="span4 alert alert-info">No duplicate devices found.</div>
[% ELSE %]
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th class="nd_center-cell">Device IP</th>
<th class="nd_center-cell">Contact</th>
<th class="nd_center-cell">Location</th>
<th class="nd_center-cell">System Name</th>
<th class="nd_center-cell">Model</th>
<th class="nd_center-cell">OS Version</th>
<th class="nd_center-cell">Serial</th>
<th class="nd_center-cell">Last Discovered</th>
<th class="nd_center-cell">Delete</th>
</tr>
</thead>
</tbody>
[% FOREACH row IN results %]
<tr>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% uri_for('/device') %]?tab=details&q=[% row.ip | uri %]">[% row.ip | html_entity %]</a>
[% row.dns | html_entity %]</td>
<td class="nd_center-cell">[% row.contact | html_entity %]</td>
<td class="nd_center-cell">[% row.location | html_entity %]</td>
<td class="nd_center-cell">[% row.name | html_entity %]</td>
<td class="nd_center-cell">[% row.model | html_entity %]</td>
<td class="nd_center-cell">[% row.os_ver | html_entity %]</td>
<td class="nd_center-cell">[% row.serial | html_entity %]</td>
<td class="nd_center-cell">[% row.last_discover_stamp | html_entity %]</td>
<td class="nd_center-cell">
<button class="btn btn-danger btn-small"
data-toggle="modal" data-target="#nd_devdel" type="button">
<i class="icon-trash text-danger"></i>
</button>
<div id="nd_devdel" class="nd_modal nd_deep-horizon modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="nd_devdel-label" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="nd_devdel-label">Confirm Delete: [% row.ip || row.dns | html_entity %]</h3>
</div>
<div class="modal-body">
<blockquote>
<ul>
<li><p>This action is immediate and not reversible</p></li>
<li><p>All associated Nodes may be removed from the database</p></li>
</ul>
</blockquote>
<textarea id="nd_devdel-log" class="input-block-level" rows="2" data-form="delete"
placeholder="Enter a log message" name="log"></textarea>
<label class="checkbox" style="display: block">
<input id="nd_devdel-archive" type="checkbox" data-form="delete" name="archive">
<h4 class="nd_unbolden">Archive Nodes</h4>
</label>
<input type="hidden" data-form="delete" value="[% row.ip | html_entity %]" name="ip"/>
</div>
<div class="modal-footer">
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn btn-danger nd_adminbutton" name="delete" data-dismiss="modal">Confirm</button>
</div>
</div>
</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
<script>
$(document).ready(function() {
$('#data-table').dataTable({
[% INCLUDE 'ajax/datatabledefaults.tt' -%]
} );
} );
</script>