BGPmon-core-1
view release on metacpan or search on metacpan
lib/BGPmon/Fetch2.pm view on Meta::CPAN
package BGPmon::Fetch2;
our $VERSION = '1.092';
use 5.006;
use strict;
use warnings;
use BGPmon::Fetch::Client2;
use BGPmon::Fetch::File;
use BGPmon::Fetch::Archive;
require Exporter;
our $AUTOLOAD;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(connect_bgpdata read_xml_message close_connection is_connected messages_read uptime connection_endtime get_error_code get_error_message get_error_msg) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
# Flag to determine type of data source we're connecting to
# 0 for live data, 1 for online archive, 2 for local file
our $use_offline_data = -1;
#error code/message
my %error_code;
my %error_msg;
#Error codes and messages
use constant NO_ERROR_CODE => 0;
use constant NO_ERROR_MSG => 'No Error. Life is good.';
use constant ARGUMENT_ERROR_CODE => 101;
use constant ARGUMENT_ERROR_MSG => 'Invalid number of arguments';
use constant UNCONNECTED_CODE => 102;
use constant UNCONNECTED_MSG => 'Not connected to a data source';
use constant INVALID_FUNCTION_SPECIFIED_CODE => 103;
use constant INVALID_FUNCTION_SPECIFIED_MSG => 'Invalid function name given';
my @function_names = ('init_bgpdata', 'connect_bgpdata', 'read_xml_message',
'close_connection', 'is_connected','uptime','connection_endtime');
for my $function_name (@function_names) {
$error_code{$function_name} = NO_ERROR_CODE;
$error_msg{$function_name} = NO_ERROR_MSG;
}
=head1 NAME
BGPmon::Fetch.pm
The BGPmon Fetch module, to connect to a live BGPmon stream,
an online archive of XFB data, or a single XML file. The interface then
supports "streaming" of XML messages from the given data source.
=head1 SYNOPSIS
The BGPmon::Fetch module provides functionality to connect to one of the
following data sources:
1) a live BGPmon instance
2) an archive of XFB data
3) an individual XML file
The user is then able to read XML messages in sequence from the appropriate
data source and get information about the currently-running connection.
use BGPmon::Fetch;
my $ret = init_bgpdata();
my $ret = connect_bgpdata();
my $xml_msg = read_xml_message();
if ( !defined($xml_msg) ){
print get_error_code() . ": " . get_error_msg();
}
my $ret = is_connected();
my $num_read = messages_read();
my $uptime = uptime();
my $ret = close_connection();
my $downtime = connection_endtime();
=head1 EXPORT
init_bgpdata
connect_bgpdata
read_xml_message
close_connection
is_connected
messages_read
uptime
connection_endtime
get_error_code
get_error_message
get_error_msg
=cut
=head1 SUBROUTINES/METHODS
=head2 init_bgpdata
Initialize parameters for any/all of the Fetch submodules.
File and Archive take the same three optional parameters:
scratch_dir - a filesystem location to put a scratch directory in
(default is /tmp)
ignore_incomplete_data - a flag to turn off checking for possible gaps
in the data "stream" (default is to check)
ignore_data_errors - a flag to turn off checking for any other errors
in the data. Using this flag requires setting ignore_incomplete_data.
(default is to check)
Client also accepts the same scratch directory argument described above,
but will ignore the data-integrity flags, as a live stream is, well, live.
( run in 1.960 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )