The BGPmon::Fetch::File module, to connect to a local XML file and read XML messages one at a time.
The BGPmon::Fetch::File module provides functionality to connect to an XML file and read message at a time.
use BGPmon::Fetch::File; my $ret = init_bgpdata('scratch_dir'=>'path/to/temp/dir', 'ignore_incomplete_data' => 0, 'ignore_data_errors' => 0); my $ret = connect_file('path/to/file'); my $xml_msg = read_xml_message(); my $ret = is_connected(); my $num_read = messages_read(); my $uptime = uptime(); my $ret = close_connection(); my $downtime = connection_endtime(); my $duration = connection_duration();
init_bgpdata connect_file read_xml_message close_connection is_connected messages_read uptime connection_endtime connection_duration get_error_code get_error_message get_error_msg
Initializes the scratch directory and error-checking flags for the next file connection.
Input: The location to create a scratch directory in (default is /tmp) Whether to ignore potentially incomplete data (default is off) Whether to ignore all data errors (must also specify ignore incomplete data flag as well) (default is off)
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);
This function connects to a local file.
Input: the filename to read XML from
Output: 0 on success, 1 on failure
Usage: my $ret = connect_file("path/to/file");
This function reads one XML message at a time from an open file connection.
Input: None, but assumes connect_file has been called
Output: The next available XML message from the file, or undef if the messages are exhausted or some other failure is encountered
Usage: my $next_msg = read_xml_message();
Function to close and delete any files and reset the module's state variables
Function to report whether currently connected to an archive.
Get number of messages read.
Usage: my $msgs_read = messages_read();
Returns number of seconds the connection has been up. If the connection is down, return 0.
Usage: my $uptime = uptime();
Returns the time the connection ended . If the connection is up, return 0.
Usage: my $endtime = connection_endtime();
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 the error code
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 name
Usage: my $err_code = get_error_code("connect_file");
Get the error message
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 name
Usage: my $err_msg = get_error_message("read_xml_message");
Shorthand call for get_error_message
The following error codes and messages are defined:
0: No Error 'No Error' 301: An argument to a function was undefined 'Undefined Argument(s)' 302: There is no active connection to a file 'Not connected to a file' 303: There is a currently-active connection to a file 'Already connected to a file' 304: The filename or directory given does not exist 'Specified file/directory does not exist' 305: A system call failed 'System call failed' 306: Decompressing the file failed 'Failed to decompress file' 307: The file was not opened successfully 'Failed to open file' 308: Initializing the XML Reader failed 'Failed to initialize XML Reader' 309: The XML Reader encountered a fatal error 'XML Parser Error' 310: The XML file passed in did not begin with an <xml> tag 'File must begin with <xml> tag' 311: An invalid function name was passed to get_error_[code/message/msg] 'Invalid function specified' 312: There was an error initializing one or more of the options to init_bgpdata 'Failed to initialize file connection' 313: At least one of the beginning ARCHIVER/OPENING or ARCHIVER/CLOSE messages were missing from the file NOTE: Setting the ignore_data_errors flag will suppress this 'File is missing expected ARCHIVER messages' 314: An additional ARCHIVER/OPENING message was encountered during file processing. This indicates a likely gap in the data. NOTE: Setting the ignore_incomplete_data flag will suppress this 'File may be missing data' 315: User tried to ignore all data errors, but was checking for incomplete data 'Cannot have ignore_incomplete_data off with ignore_data_errors on'
<bartletj at cs.colostate.edu>
Please report any bugs or feature requests to
bgpmon at netsec.colostate.edu, or through the web interface at http://bgpmon.netsec.colostate.edu.
You can find documentation for this module with the perldoc command.
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: File.pm Authors: Jason Bartlett, Kaustubh Gadkari, Dan Massey, Cathie Olschanowsky Date: 13 Jul 2012