NAME
Device::Network::ConfigParser - harness for parsing network configurations.
VERSION
version 0.005
SYNOPSIS
Device::Network::ConfigParser is a harness for parsing network device configuration. It exports a single subroutine - app()
- which takes command line arguments and runs the harness. This module is used by the ncp
command line utility. For information on how to use the command line utility, refer to the ncp, or following installation type perldoc ncp
at the command line.
The harness supports specific parsing modules by:
Dynamically loading a specific parsing module based on command line arguments.
Slurping in the device configuration from STDIN or from a number of files.
Opening the required output filehandles.
CURRENT PARSER MODULES
- Device::Network::ConfigParser::Cisco::ASA
- Device::Network::ConfigParser::CheckPoint::Gaia
- Device::Network::ConfigParser::CheckPoint::Expert
DEVELOPING MODULES
Parsing modules exist within the Device::Network::ConfigParser::
namespace. For a vendor and type of device, the module is defined as Device::Network::ConfigParser::vendor::type
.
The harness takes care of parsing the command line arguments, opening files (or STDIN/STDOUT) and slurping in their contents. It calls specified subroutines exported by the specified parsing module. All modules must export the following subroutines:
get_parser
my $module_parser = get_parser();
This sub receives no arguments, and must return a reference to an object or subroutine that parses the configuration. This is most likely going to be a Parse::RecDescent object, but you're not limited to this.
parse_config
my $parsed_config = parse_config($module_parser, $device_config);
This sub receives the reference returned by the get_parser
sub, and the full contents of a file specified on the command line. It should return a reference a data structure that represents the parsed configuration.
post_process
my $processed_config = post_process($parsed_config);
This sub receives the reference to the data structure returned by parse_config
. It allows for some post-processing of the data structure. If no processing is required, it can be defined as sub post_process { return @_; }
.
get_output_drivers
open($fh, ">>:encoding(UTF-8)", $output_filename);
my $output_drivers = get_output_drivers();
$output_drivers->{csv}->($fh, $output_filename, $processed_config);
This sub takes no arguments, and must return a HASHREF of subroutines used to output the parsed configurationm keyed on the command line argument. For example the sub may return:
{
csv => \&csv_output_driver,
}
The drivers themselves take a filehandle to write the output to (this may be STDOUT), the output filename, and the post-processed configuration.
The driver called is based on the --output csv
as a command line argument
There is a default 'raw' driver, which uses Data::Dumper to serialise the structure. A module may return its own 'raw' driver which will override this default.
SUBROUTINES
app
The app
subroutine in general takes @ARGV
(although it could be any list) and runs the harness.
AUTHOR
Greg Foletta, <greg at foletta.org>
BUGS
Please report any bugs or feature requests to bug-device-network-configparser at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-Network-ConfigParser. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Device::Network::ConfigParser
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Device-Network-ConfigParser
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2017 Greg Foletta.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.