BGPmon-Analytics-db-1
view release on metacpan or search on metacpan
bin/bgpmon_analytics_db_import view on Meta::CPAN
BGPmon::Log
BGPmon::Translator::XFB2PerlHash::Simple
BGPmon::Configure
POSIX
Data::Dumper
In addition, a Postgres database cluster must be installed and a database
set up via the reset.pl script.
=cut
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2012 Colorado State University
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.\
File: database_import.pl
Authors: Jason Bartlett
Date: 17 August 2012
=cut
use BGPmon::Log qw/log_info log_warn log_err debug/;
use BGPmon::Translator::XFB2PerlHash::Simple qw/get_peering get_nlri
get_mp_nlri get_withdrawn get_mp_withdrawn get_timestamp get_as_path
get_as4_path/;
use BGPmon::Fetch;
use BGPmon::Configure qw/configure parameter_value/;
use POSIX qw/strftime/;
use Data::Dumper;
BEGIN{
our $VERSION = '1.07';
};
#step 1: set up script args (DB name/credentials, data source, log file name,
#config file name)
#step 2: fetch data from the specified data source
#step 3: convert the XML to hashes
#step 4: grab the fields I'm interested in
#step 5: insert fields into DB staging table
#step 6: inject updates into main DB tables
my $db_name = 'bgpmon_db';
#This hash is for IP addresses to be mapped to collector names for
#disambiguation when importing updates
my %aliases = (
'128.223.51.15' => 'route-views4',
'2001:468:d01:33::80df:330f' => 'route-views4',
'129.82.138.6' => 'colostate-bgpmon'
);
use constant MAX_UPDATES_PER_INJECT => 1000;
#Define parameters for logging (filename, level, use syslog)
#Define parameters for system state (DB name,DB credentials, config filename)
#Define parameters for data retrieval (source, Fetch parameters)
my @params = (
{
'Name' => BGPmon::Configure::CONFIG_FILE_PARAMETER_NAME,
'Type' => BGPmon::Configure::FILE,
'Default' => './database-import.conf',
'Description' => 'The configuration file to use'
},
{
'Name' => 'database-name',
'Type' => BGPmon::Configure::STRING,
'Default' => "$db_name",
'Description' => 'The name of the database to import updates into'
},
{
'Name' => 'database-username',
'Type' => BGPmon::Configure::STRING,
'Default' => "bgpmon_db_user",
'Description' => 'The username to provide to the database server'
},
{
'Name' => 'log_file',
'Type' => BGPmon::Configure::FILE,
'Default' => '../log/database-import.log',
'Description' => 'Log file to use'
},
{
'Name' => 'use_syslog',
'Type' => BGPmon::Configure::BOOLEAN,
'Default' => 0,
'Description' => 'Presence indicates use of syslog to log messages'
},
{
'Name' => 'log_level',
'Type' => BGPmon::Configure::UNSIGNED_INT,
'Default' => 7 #LOG_DEBUG
},
{
'Name' => 'scratch_dir',
'Type' => BGPmon::Configure::STRING,
'Default' => '/tmp/',
'Description' => 'Directory to create a scratch directory in'
},
{
'Name' => 'source',
'Type' => BGPmon::Configure::STRING,
'Description' => 'Type of source to get data from'
},
{
'Name' => 'URL',
'Type' => BGPmon::Configure::STRING,
'Description' => 'The URL to fetch data from an online XFB archive'
},
{
'Name' => 'start-time',
'Type' => BGPmon::Configure::UNSIGNED_INT,
'Description' => 'The starting UNIX timestamp to import archived data from'
},
{
'Name' => 'end-time',
( run in 0.915 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )