#48 Node Monitor supports matching on OUI
This commit is contained in:
@@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces(
|
||||
);
|
||||
|
||||
our # try to hide from kwalitee
|
||||
$VERSION = 49; # schema version used for upgrades, keep as integer
|
||||
$VERSION = 50; # schema version used for upgrades, keep as integer
|
||||
|
||||
use Path::Class;
|
||||
use File::ShareDir 'dist_dir';
|
||||
|
||||
@@ -12,6 +12,8 @@ __PACKAGE__->table("node_monitor");
|
||||
__PACKAGE__->add_columns(
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"matchoui",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"active",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"why",
|
||||
|
||||
@@ -16,7 +16,7 @@ SELECT nm.why, nm.cc, trim(trailing '.' from trim(trailing '0123456789' from dat
|
||||
d.name, d.location,
|
||||
dp.name AS portname
|
||||
FROM node_monitor nm, node n, device d, device_port dp
|
||||
WHERE nm.mac = n.mac
|
||||
WHERE ((nm.mac = n.mac) OR (nm.matchoui AND (substring(nm.mac::text from 1 for 8) = n.oui)))
|
||||
AND nm.active
|
||||
AND nm.cc IS NOT NULL
|
||||
AND d.ip = n.switch
|
||||
|
||||
@@ -15,6 +15,7 @@ our %EXPORT_TAGS = (all => \@EXPORT_OK);
|
||||
|
||||
sub _email {
|
||||
my ($to, $subject, $body) = @_;
|
||||
return unless $to;
|
||||
my $domain = setting('domain_suffix') || 'localhost';
|
||||
$domain =~ s/^\.//;
|
||||
|
||||
@@ -31,7 +32,7 @@ sub monitor {
|
||||
my $monitor = schema('netdisco')->resultset('Virtual::NodeMonitor');
|
||||
|
||||
while (my $entry = $monitor->next) {
|
||||
my $body = <<"end_body";
|
||||
my $body = <<"end_body";
|
||||
........ n e t d i s c o .........
|
||||
Node : @{[$entry->mac]} (@{[$entry->why]})
|
||||
When : @{[$entry->date]}
|
||||
@@ -41,11 +42,13 @@ sub monitor {
|
||||
|
||||
end_body
|
||||
|
||||
_email(
|
||||
$entry->cc,
|
||||
"Saw mac @{[$entry->mac]} (@{[$entry->why]}) on @{[$entry->name]} @{[$entry->port]}",
|
||||
$body
|
||||
);
|
||||
debug sprintf ' monitor - reporting on %s at %s:%s',
|
||||
$entry->mac, $entry->name, $entry->port;
|
||||
_email(
|
||||
$entry->cc,
|
||||
"Saw mac @{[$entry->mac]} (@{[$entry->why]}) on @{[$entry->name]} @{[$entry->port]}",
|
||||
$body
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ ajax '/ajax/control/admin/nodemonitor/add' => require_role admin => sub {
|
||||
my $monitor = schema('netdisco')->resultset('NodeMonitor')
|
||||
->create({
|
||||
mac => param('mac'),
|
||||
matchoui => (param('matchoui') ? \'true' : \'false'),
|
||||
active => (param('active') ? \'true' : \'false'),
|
||||
why => param('why'),
|
||||
cc => param('cc'),
|
||||
@@ -54,6 +55,7 @@ ajax '/ajax/control/admin/nodemonitor/update' => require_role admin => sub {
|
||||
|
||||
$monitor->update({
|
||||
mac => param('mac'),
|
||||
matchoui => (param('matchoui') ? \'true' : \'false'),
|
||||
active => (param('active') ? \'true' : \'false'),
|
||||
why => param('why'),
|
||||
cc => param('cc'),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package App::Netdisco::Worker::Plugin::Monitor;
|
||||
package App::Netdisco::Worker::Plugin::NodeMonitor;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use App::Netdisco::Worker::Plugin;
|
||||
Reference in New Issue
Block a user