node monitor admin panel
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2.028009_001
|
||||
|
||||
[NEW FEATURES]
|
||||
|
||||
* Node Monitor admin panel and netdisco-do action
|
||||
|
||||
2.028008 - 2014-07-22
|
||||
|
||||
[BUG FIXES]
|
||||
|
||||
@@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
use 5.010_000;
|
||||
|
||||
our $VERSION = '2.028008';
|
||||
our $VERSION = '2.028009_001';
|
||||
use App::Netdisco::Configuration;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
@@ -37,7 +37,7 @@ database storage.
|
||||
|
||||
Returns false, and might log a debug level message, if the checks fail.
|
||||
|
||||
Returns a true value if these checks pass:
|
||||
Returns a true value (the MAC address in IEEE format) if these checks pass:
|
||||
|
||||
=over 4
|
||||
|
||||
@@ -67,12 +67,13 @@ MAC address does not belong to an interface on any known Device
|
||||
sub check_mac {
|
||||
my ($device, $node, $port_macs) = @_;
|
||||
my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0);
|
||||
my $devip = (ref $device ? $device->ip : '');
|
||||
$port_macs ||= {};
|
||||
|
||||
# incomplete MAC addresses (BayRS frame relay DLCI, etc)
|
||||
if ($mac->get_error) {
|
||||
debug sprintf ' [%s] check_mac - mac [%s] malformed - skipping',
|
||||
$device->ip, $node;
|
||||
$devip, $node;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
@@ -92,32 +93,32 @@ sub check_mac {
|
||||
# multicast
|
||||
if ($node =~ m/^[0-9a-f](?:1|3|5|7|9|b|d|f):/) {
|
||||
debug sprintf ' [%s] check_mac - multicast mac [%s] - skipping',
|
||||
$device->ip, $node;
|
||||
$devip, $node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
# VRRP
|
||||
if (index($node, '00:00:5e:00:01:') == 0) {
|
||||
debug sprintf ' [%s] check_mac - VRRP mac [%s] - skipping',
|
||||
$device->ip, $node;
|
||||
$devip, $node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
# HSRP
|
||||
if (index($node, '00:00:0c:07:ac:') == 0) {
|
||||
debug sprintf ' [%s] check_mac - HSRP mac [%s] - skipping',
|
||||
$device->ip, $node;
|
||||
$devip, $node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
# device's own MACs
|
||||
if (exists $port_macs->{$node}) {
|
||||
if ($port_macs and exists $port_macs->{$node}) {
|
||||
debug sprintf ' [%s] check_mac - mac [%s] is device port - skipping',
|
||||
$device->ip, $node;
|
||||
$devip, $node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return $node;
|
||||
}
|
||||
|
||||
=head2 check_node_no( $ip, $setting_name )
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package App::Netdisco::Web::Plugin::AdminTask::NodeMonitor;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin::Ajax;
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
use App::Netdisco::Util::Node 'check_mac';
|
||||
|
||||
register_admin_task({
|
||||
tag => 'nodemonitor',
|
||||
label => 'Node Monitor',
|
||||
});
|
||||
|
||||
sub _sanity_ok {
|
||||
return 0 unless param('mac')
|
||||
and check_mac(undef, param('mac'));
|
||||
|
||||
params->{mac} = check_mac(undef, param('mac'));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ajax '/ajax/control/admin/nodemonitor/add' => require_role admin => sub {
|
||||
send_error('Bad Request', 400) unless _sanity_ok();
|
||||
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $monitor = schema('netdisco')->resultset('NodeMonitor')
|
||||
->create({
|
||||
mac => param('mac'),
|
||||
active => (param('active') ? \'true' : \'false'),
|
||||
why => param('why'),
|
||||
cc => param('cc'),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ajax '/ajax/control/admin/nodemonitor/del' => require_role admin => sub {
|
||||
send_error('Bad Request', 400) unless _sanity_ok();
|
||||
|
||||
schema('netdisco')->txn_do(sub {
|
||||
schema('netdisco')->resultset('NodeMonitor')
|
||||
->find({mac => param('mac')})->delete;
|
||||
});
|
||||
};
|
||||
|
||||
ajax '/ajax/control/admin/nodemonitor/update' => require_role admin => sub {
|
||||
send_error('Bad Request', 400) unless _sanity_ok();
|
||||
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $monitor = schema('netdisco')->resultset('NodeMonitor')
|
||||
->find({mac => param('mac')});
|
||||
return unless $monitor;
|
||||
|
||||
$monitor->update({
|
||||
mac => param('mac'),
|
||||
active => (param('active') ? \'true' : \'false'),
|
||||
why => param('why'),
|
||||
cc => param('cc'),
|
||||
date => \'now()',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ajax '/ajax/content/admin/nodemonitor' => require_role admin => sub {
|
||||
my $set = schema('netdisco')->resultset('NodeMonitor')
|
||||
->search(undef, { order_by => [qw/active date mac/] });
|
||||
|
||||
content_type('text/html');
|
||||
template 'ajax/admintask/nodemonitor.tt', {
|
||||
results => $set,
|
||||
}, { layout => undef };
|
||||
};
|
||||
|
||||
true;
|
||||
92
Netdisco/share/views/ajax/admintask/nodemonitor.tt
Normal file
92
Netdisco/share/views/ajax/admintask/nodemonitor.tt
Normal file
@@ -0,0 +1,92 @@
|
||||
<table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="nd_center-cell">Date Added</th>
|
||||
<th class="nd_center-cell">MAC Address</th>
|
||||
<th class="nd_center-cell">Enabled</th>
|
||||
<th class="nd_center-cell">Reason</th>
|
||||
<th class="nd_center-cell">Email</th>
|
||||
<th class="nd_center-cell">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</tbody>
|
||||
<tr>
|
||||
<td class="nd_center-cell"></td>
|
||||
<td class="nd_center-cell"><input data-form="add" name="mac" type="text"></td>
|
||||
<td class="nd_center-cell"><input data-form="add" name="active" type="checkbox" checked></td>
|
||||
<td class="nd_center-cell"><input data-form="add" name="why" type="text"></td>
|
||||
<td class="nd_center-cell"><input data-form="add" name="cc" type="email"></td>
|
||||
<td class="nd_center-cell">
|
||||
<button class="btn btn-small nd_adminbutton" name="add" type="submit"><i class="icon-plus-sign"></i> Add</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
[% SET count = 0 %]
|
||||
[% WHILE (row = results.next) %]
|
||||
[% SET count = count + 1 %]
|
||||
<tr>
|
||||
<td class="nd_center-cell">[% row.date | html_entity %]</td>
|
||||
<td class="nd_center-cell">
|
||||
<input data-form="update" name="mac" type="text" value="[% row.mac | html_entity %]">
|
||||
</td>
|
||||
<td class="nd_center-cell">
|
||||
<input data-form="update" name="active" type="checkbox" [% 'checked="checked"' IF row.active %]>
|
||||
</td>
|
||||
<td class="nd_center-cell">
|
||||
<input data-form="update" name="why" type="text" value="[% row.why | html_entity %]">
|
||||
</td>
|
||||
<td class="nd_center-cell">
|
||||
<input data-form="update" name="cc" type="email" value="[% row.cc | html_entity %]">
|
||||
</td>
|
||||
|
||||
<td class="nd_center-cell">
|
||||
<button class="btn nd_adminbutton" name="update" type="submit"><i class="icon-save text-warning"></i></button>
|
||||
|
||||
<button class="btn" data-toggle="modal"
|
||||
data-target="#nd_devdel-[% count %]" type="button"><i class="icon-trash text-error"></i></button>
|
||||
|
||||
<div id="nd_devdel-[% count %]" class="nd_modal nd_deep-horizon modal hide fade" tabindex="-1"
|
||||
role="dialog" aria-labelledby="nd_devdel-label-[% count %]" 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-[% count %]">Are you sure?</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<blockquote>
|
||||
<p class="text-info">Monitor for "[% row.mac | html_entity %]" will be removed.</p>
|
||||
</blockquote>
|
||||
<input data-form="del" name="mac" type="hidden" value="[% row.mac | html_entity %]">
|
||||
</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="del" data-dismiss="modal">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
[% END %]
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#data-table').dataTable({
|
||||
"stateSave": true,
|
||||
"pageLength": [% settings.table_pagesize %],
|
||||
"language": {
|
||||
"search": 'Filter records: '
|
||||
},
|
||||
"columnDefs": [
|
||||
{
|
||||
"targets": [ 0, 2, 5 ],
|
||||
"searchable": false
|
||||
},
|
||||
{
|
||||
"targets": [ 0, 2, 5 ],
|
||||
"orderable": false
|
||||
}
|
||||
]
|
||||
} );
|
||||
} );
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user