update OUI data when DB schema is updated

This commit is contained in:
Oliver Gorwits
2012-12-16 17:17:31 +00:00
parent 369a235ff8
commit bf79b10664
5 changed files with 37 additions and 3 deletions

View File

@@ -1,5 +1,9 @@
2.00_009 - 2.00_009 -
[NEW FEATURES]
* Update OUI data when the DB schema is deployed/upgraded
2.00_008 - 2012-12-16 2.00_008 - 2012-12-16
[NEW FEATURES] [NEW FEATURES]

View File

@@ -9,7 +9,7 @@ use Dancer::Plugin::DBIC 'schema';
use Netdisco::DB; use Netdisco::DB;
use Getopt::Long; use Getopt::Long;
=head1 create_netdisco_schema_version =head1 nd-dbic-versions
This script creates SQL DDL files of the Netdisco database schema. This script creates SQL DDL files of the Netdisco database schema.

View File

@@ -6,9 +6,10 @@ use warnings FATAL => 'all';
use Dancer ':script'; use Dancer ':script';
use Dancer::Plugin::DBIC 'schema'; use Dancer::Plugin::DBIC 'schema';
use HTTP::Tiny;
use Try::Tiny; use Try::Tiny;
=head1 upgrade_netdisco_schema_version =head1 netdisco-db-deploy
This script upgrades or initialises a Netdisco database schema. This script upgrades or initialises a Netdisco database schema.
@@ -22,6 +23,10 @@ interaction. If there's no Nedisco schema, it is deployed. If there's an
unversioned schema then versioning is added, and updates applied. Otherwise unversioned schema then versioning is added, and updates applied. Otherwise
only necessary updates are applied to an already versioned schema. only necessary updates are applied to an already versioned schema.
Additionally this script will download the latest MAC address vendor prefix
data from the Internet, and update the OUI table in the database. Hence
Internet access is required to run the script.
=head2 Versions =head2 Versions
=over 4 =over 4
@@ -70,4 +75,29 @@ try {
# upgrade from whatever dbix_class_schema_versions says, to $VERSION # upgrade from whatever dbix_class_schema_versions says, to $VERSION
$schema->txn_do(sub { $schema->upgrade }); $schema->txn_do(sub { $schema->upgrade });
# now populate/update the OUI data
my $url = 'http://standards.ieee.org/develop/regauth/oui/oui.txt';
my $resp = HTTP::Tiny->new->get($url);
my %data = ();
if ($resp->{success}) {
foreach my $line (split /\n/, $resp->{content}) {
if ($line =~ m/^(.{2}-.{2}-.{2})\s+\(hex\)\s+(.*)\s*$/i) {
my ($oui, $company) = ($1, $2);
$oui =~ s/-/:/g;
$data{lc($oui)} = $company;
}
}
if ((scalar keys %data) > 15_000) {
$schema->txn_do(sub{
$schema->resultset('Oui')->delete;
$schema->resultset('Oui')->populate([
map {{oui => $_, company => $data{$_}}} keys %data
]);
});
}
}
exit 0; exit 0;

View File

@@ -47,6 +47,7 @@ install Perl dependencies into a custom library path:
Role::Tiny \ Role::Tiny \
List::MoreUtils \ List::MoreUtils \
Socket6 \ Socket6 \
HTTP::Tiny \
HTML::Entities \ HTML::Entities \
Template::Toolkit \ Template::Toolkit \
YAML YAML

1
TODO
View File

@@ -1,5 +1,4 @@
* bootstrap/setup script to install perl modules and db schema * bootstrap/setup script to install perl modules and db schema
* OUI.txt added into db schema upgrade
* frontend plugin design and support * frontend plugin design and support
* document how the templates and JS fit together * document how the templates and JS fit together
* add poller to daemon (scheduling automatically?) * add poller to daemon (scheduling automatically?)