[#193] DBI Exception for Cisco ACE MacAddr format
Also standardise on IEEE MAC format now that NetAddr::MAC has that corrected.
This commit is contained in:
@@ -7,6 +7,7 @@ use App::Netdisco::Util::Node 'check_mac';
|
||||
use App::Netdisco::Util::DNS ':all';
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
use Time::HiRes 'gettimeofday';
|
||||
use NetAddr::MAC ();
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = ();
|
||||
@@ -119,9 +120,11 @@ sub store_arp {
|
||||
my ($hash_ref, $now) = @_;
|
||||
$now ||= 'now()';
|
||||
my $ip = $hash_ref->{'ip'};
|
||||
my $mac = $hash_ref->{'node'};
|
||||
my $mac = NetAddr::MAC->new($hash_ref->{'node'});
|
||||
my $name = $hash_ref->{'dns'};
|
||||
|
||||
return if !defined $mac or $mac->errstr;
|
||||
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $current = schema('netdisco')->resultset('NodeIp')
|
||||
->search(
|
||||
@@ -131,7 +134,7 @@ sub store_arp {
|
||||
schema('netdisco')->resultset('NodeIp')
|
||||
->update_or_create(
|
||||
{
|
||||
mac => $mac,
|
||||
mac => $mac->as_ieee,
|
||||
ip => $ip,
|
||||
dns => $name,
|
||||
active => \'true',
|
||||
|
||||
@@ -756,7 +756,7 @@ sub store_neighbors {
|
||||
if (!defined $neigh) {
|
||||
my $mac = NetAddr::MAC->new(mac => $remote_id);
|
||||
if ($mac and not $mac->errstr) {
|
||||
$neigh = $devices->single({mac => $mac->as_microsoft()});
|
||||
$neigh = $devices->single({mac => $mac->as_ieee});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,8 +770,8 @@ sub store_neighbors {
|
||||
if ($mac and not $mac->errstr) {
|
||||
info sprintf
|
||||
'[%s] neigh - found neighbor %s by MAC %s',
|
||||
$device->ip, $remote_id, $mac->as_microsoft();
|
||||
$neigh = $devices->single({mac => $mac->as_microsoft()});
|
||||
$device->ip, $remote_id, $mac->as_ieee;
|
||||
$neigh = $devices->single({mac => $mac->as_ieee});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ sub check_mac {
|
||||
}
|
||||
else {
|
||||
# lower case, hex, colon delimited, 8-bit groups
|
||||
$node = lc $mac->as_microsoft;
|
||||
$node = lc $mac->as_ieee;
|
||||
}
|
||||
|
||||
# broadcast MAC addresses
|
||||
|
||||
@@ -49,7 +49,7 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
|
||||
my @where_mac =
|
||||
($using_wildcards ? \['me.mac::text ILIKE ?', $likeval]
|
||||
: ((!defined $mac or $mac->errstr) ? \'0=1' : ('me.mac' => $mac->as_microsoft)) );
|
||||
: ((!defined $mac or $mac->errstr) ? \'0=1' : ('me.mac' => $mac->as_ieee)) );
|
||||
|
||||
my $sightings = schema('netdisco')->resultset('Node')
|
||||
->search({-and => [@where_mac, @active, @times]}, {
|
||||
|
||||
@@ -6,6 +6,7 @@ use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Util::Web 'sql_match';
|
||||
use NetAddr::MAC ();
|
||||
|
||||
hook 'before' => sub {
|
||||
# view settings for node options
|
||||
@@ -78,6 +79,7 @@ get '/search' => require_login sub {
|
||||
else {
|
||||
my $nd = $s->resultset('Device')->search_fuzzy($q);
|
||||
my ($likeval, $likeclause) = sql_match($q);
|
||||
my $mac = NetAddr::MAC->new($q);
|
||||
|
||||
if ($nd and $nd->count) {
|
||||
if ($nd->count == 1) {
|
||||
@@ -96,8 +98,9 @@ get '/search' => require_login sub {
|
||||
->search({
|
||||
-or => [
|
||||
{name => $likeclause},
|
||||
(length $q == 17 ? {mac => $q}
|
||||
: \['mac::text ILIKE ?', $likeval]),
|
||||
((!defined $mac or $mac->errstr)
|
||||
? \['mac::text ILIKE ?', $likeval]
|
||||
: {mac => $mac->as_ieee}),
|
||||
],
|
||||
})->count) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user