diff --git a/Netdisco/Changes b/Netdisco/Changes index a82cef09..7f2505d7 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -5,6 +5,7 @@ * [#32] Show device layers in Details tab * [#66] Remove reference to "native" VLAN in code and replace with "untagged" * [#66] DB Schema update to add "native" column to PK of device_port_vlan table + * [#64] Addition of Wireshark abbreviations for OUI manufacturers [BUG FIXES] diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy index 04f07ffd..67363c55 100755 --- a/Netdisco/bin/netdisco-deploy +++ b/Netdisco/bin/netdisco-deploy @@ -46,6 +46,7 @@ use Archive::Extract; $Archive::Extract::PREFER_BIN = 1; use HTTP::Tiny; use Try::Tiny; +use Encode; =head1 NAME @@ -168,7 +169,9 @@ sub deploy_oui { if ($line =~ m/^\s*(.{2}-.{2}-.{2})\s+\(hex\)\s+(.*)\s*$/i) { my ($oui, $company) = ($1, $2); $oui =~ s/-/:/g; - $data{lc($oui)} = $company; + my $abbrev = shorten($company); + $data{lc($oui)}{'company'} = $company; + $data{lc($oui)}{'abbrev'} = $abbrev; } } @@ -176,7 +179,12 @@ sub deploy_oui { $schema->txn_do(sub{ $schema->resultset('Oui')->delete; $schema->resultset('Oui')->populate([ - map {{oui => $_, company => $data{$_}}} keys %data + map { + { oui => $_, + company => $data{$_}{'company'}, + abbrev => $data{$_}{'abbrev'} + } + } keys %data ]); }); } @@ -185,6 +193,37 @@ sub deploy_oui { say 'OUI update complete.'; } +# This subroutine is from Wireshark's make-manuf +# http://anonsvn.wireshark.org/wireshark/trunk/tools/make-manuf +sub shorten { + my $manuf = shift; + + $manuf = decode "utf8", $manuf, Encode::FB_CROAK; + $manuf = " " . $manuf . " "; + + # Remove any punctuation + $manuf =~ tr/',.()/ /; + + # & isn't needed when Standalone + $manuf =~ s/ \& / /g; + + # Remove any "the", "inc", "plc" ... + $manuf + =~ s/\s(the|inc|incorporated|plc||systems|corp|corporation|s\/a|a\/s|ab|ag|kg|gmbh|co|company|limited|ltd|holding|spa)(?= )//gi; + + # Convert to consistent case + $manuf =~ s/(\w+)/\u\L$1/g; + + # Remove all spaces + $manuf =~ s/\s+//g; + + # Truncate all names to a reasonable length, say, 8 characters. + # If the string contains UTF-8, this may be substantially more than 8 bytes. + $manuf = substr( $manuf, 0, 8 ); + + return encode( "utf8", $manuf ); +} + sub deploy_mibs { my $mibhome = dir(shift); diff --git a/Netdisco/lib/App/Netdisco/DB.pm b/Netdisco/lib/App/Netdisco/DB.pm index 9bf9a860..7522a478 100644 --- a/Netdisco/lib/App/Netdisco/DB.pm +++ b/Netdisco/lib/App/Netdisco/DB.pm @@ -10,7 +10,7 @@ __PACKAGE__->load_namespaces( default_resultset_class => 'ResultSet', ); -our $VERSION = 32; # schema version used for upgrades, keep as integer +our $VERSION = 33; # schema version used for upgrades, keep as integer use Path::Class; use File::Basename; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Oui.pm b/Netdisco/lib/App/Netdisco/DB/Result/Oui.pm index 059f99f7..a2fe5c16 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Oui.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Oui.pm @@ -14,6 +14,8 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_nullable => 0, size => 8 }, "company", { data_type => "text", is_nullable => 1 }, + "abbrev", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("oui"); diff --git a/Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-32-33-PostgreSQL.sql b/Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-32-33-PostgreSQL.sql new file mode 100644 index 00000000..f296ea39 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-32-33-PostgreSQL.sql @@ -0,0 +1,6 @@ + +BEGIN; + +ALTER TABLE oui ADD COLUMN abbrev text; + +COMMIT;