The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

BGPmon::Fetch::Archive

The BGPmon::Fetch::Archive module, to connect to an online archive of BGP files, download XML files and read XML messages one at a time.

SYNOPSIS

The BGPmon::Fetch::Archive module provides functionality to connect to an BGP archive and read one XML message at a time.

    use BGPmon::Fetch::Archive;
    my $ret = init_bgpdata('scratch_dir' => '/tmp/',
'ignore_incomplete_data' => 1, 'ignore_data_errors' => 0);
    my $ret = connect_archive('archive.netsec.colostate.edu/collectors/bgpdata-netsec/',
1234567890,2345678901);
    my $xml_msg = read_xml_message();
    my $ret = is_connected();
    my $num_read = messages_read();
    my $num_files = files_read();
    my $uptime = uptime();
    my $ret = close_connection();
    my $downtime = connection_endtime();
    my $duration = connection_duration();

EXPORT

init_bgpdata connect_archive read_xml_message close_connection is_connected messages_read files_read uptime connection_endtime connection_duration get_error_code get_error_message get_error_msg

SUBROUTINES/METHODS

init_bgpdata

Initializes the scratch directory and error-checking flags for the next archive connection. Input: The location to create a scratch directory in (default is /tmp) Whether to ignore potentially incomplete data (default is to check) Whether to ignore all data errors (must also specify ignore incomplete data flag as well) (default is to check) Output: 0 if initialization fails 1 if initialization succeeds Usage: my $ret = init_bgpdata('scratch_dir' => '/tmp', 'ignore_incomplete_data' => 1, 'ignore_data_errors' => 0);

connect_archive

Connects to an online archive.

Input: archive URL page for some collector (i.e. "archive.netsec.colostate.edu/bgpdata-netsec/") start/end (UNIX timestamps corresponding to the data interval the user wants)

Output: 0 on success, 1 on failure

Usage: my $ret = connect_archive( 'archive.netsec.colostate.edu/collectors/bgpdata-netsec', 1234567890, 2345678901);

read_xml_message

Reads the next XML message from the data source that is in the interval.

Input: None, but assumes connect_archive has been called

Output: The next XML message from the archive "stream" or undef

Usage: my $msg = read_xml_message();

close_connection

Function to close and delete any files and reset the module's state variables

Usage: close_connection();

is_connected

Function to report whether currently connected to an archive.

messages_read

Get number of messages read.

Usage: my $num_msgs = messages_read();

files_read

Get the number of files read.

Usage: my $num_files = files_read();

uptime

Returns number of seconds the connection has been up. If the connection is down, return 0.

Usage: my $time = uptime();

connection_endtime

Returns the time the connection ended . If the connection is up, return 0.

Usage: my $time = connection_endtime();

connection_duration

Returns the total time the last connection was up for. If the connection is up, returns 0.

NOTE: If a connection is currently established, call uptime().

Usage: my $dur = connection_duration();

get_error_code

Get the error code for a given function

Input : the name of the function whose error code we should report

Output: the function's error code or UNDEFINED_ARGUMENT if the user did not supply a function or INVALID_FUNCTION_SPECIFIED if the user provided an invalid function

Usage: my $err_code = get_error_code("connect_archive");

get_error_message

Get the error message of a given function

Input : the name of the function whose error message we should report

Output: the function's error message or UNDEFINED_ARGUMENT if the user did not supply a function or INVALID_FUNCTION_SPECIFIED if the user provided an invalid function

Usage: my $err_msg = get_error_message("read_xml_message");

get_error_msg

Shorthand call for get_error_message

ERROR CODES AND MESSAGES The following error codes and messages are defined:

    0:  No Error
        'No Error'

    401:    A subroutine was missing an expected argument
            'Undefined Argument(s)'

    402:    There is no active connection to an archive
            'Not connected to an archive'

    403:    There is a currently-active connection to an archive
            'Already connected to an archive'

    404:    The module was unable to find an HTML index page
                or any download links on the index page
            'Unable to find an index page'

    405:    A system call failed
            'System call failed'

    406:    An invalid value was passed to a subroutine as an argument
            'Invalid value given for argument'

    407:    The connection could not be initialized, either by a failure
                to set the scratch directory, ignore-error flags, or
                the first update file could not be loaded.
            'Failed to initialize connection to archive'

    408:    A filesystem 'open' command failed
            'File operation failed'

    409:    There was a failure trying to download a file
            'Failed to download file'

    410:    An invalid XML message was read, or the end of the archive was read
            'Invalid message read'

    411:    An invalid function name was passed to get_error_[code/message/msg]
            'Invalid function specified'

    412:    User tried to ignore all data errors, but was checking for
                incomplete data
            'Cannot have ignore_incomplete_data off with ignore_data_errors on'

AUTHOR

Jason Bartlett, <bartletj at cs.colostate.edu>

BUGS

Please report any bugs or feature requests to bgpmon at netsec.colostate.edu , or through the web interface at http://bgpmon.netsec.colostate.edu.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc BGPmon::Fetch::Archive

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: Archive.pm

    Authors: Jason Bartlett, Kaustubh Gadkari, Dan Massey, Cathie Olschanowsky
    Date: 13 Jul 2012