RADIUS::XMLParser - Radius log file XML convertor
use RADIUS::XMLParser; my %labels = ( 'Event-Timestamp' => 'Time', # name of tag "Event-Timestamp" 'User-Name' => 'User', # name of tag "User-Name" 'File' => '' # default name (i.e. File) for tag File ); my $radius = RADIUS::XMLParser->new( { VERBOSE => 1, DAYSFORORPHAN => 1, AUTOPURGE => 0, ALLEVENTS => 1, OUTPUTDIR => '/tmp/', MAP => \%labels } ); my ($xml, $stop, $start, $interim, $processed) = $radius->convert('radius.log');
START INTERIM-UPDATE STOP
Any event will be stored on different hash (with SessionID as a unique key). Then, for each STOP event, the respective START and INTERIM event will be retrieved (based on same session ID)
Final XML will get the following structure:
<?xml version="1.0" encoding="UTF-8"?> <sessions> <session sessionId=$sessionId> <start></start> <interims> <interim id1></interim> </interims> <stop></stop> </session> </sessions>
my $parser = RADIUS::XMLParser->new({%params});
A radius parser blessed reference
Hash reference including below Options
A reference to below Array passed as an input parameter...
my %map = ( "Acct-Output-Packets" => "Output", "NAS-IP-Address" => "Address", "Event-Timestamp" => "" );
...will result on the following XML structure
<stop> <Output></Output> <Address></Address> <Event-Timestamp></Event-Timestamp> </stop>
File::Spec-
utf-8
us-ascii
convert
$radius_file
my ($xml, $stop, $start, $interim, $processed) = $parser->convert($radius_file);
$xml
$stop
$start
$interim
$processed
flush
new
$parser->flush();
use RADIUS::XMLParser; my $radius_file = 'radius.log'; my %map = ( "NAS-User-Name" => "User-Name", "Event-Timestamp" => "", "File" => "File" ); my $radius = RADIUS::XMLParser->new( { VERBOSE => 1, DAYSFORORPHAN => 1, AUTOPURGE => 0, ALLEVENTS => 1, XMLENCODING => "utf-8", OUTPUTDIR => '/tmp/', MAP => \%map } ); my ($xml, $stop, $start, $interim, $processed) = $radius->convert($radius_file);
Here is how the generated XML file will look like
<?xml version="1.0" encoding="UTF-8"?> <session sessionId="d537cca0d43c95dc"> <start> <Event-Timestamp>1334560899</Event-Timestamp> <User-Name>User1</User-Name> <File>radius.log</File> </start> <interims> <interim id="1"> <Event-Timestamp>1334561024</Event-Timestamp> <User-Name>User1</User-Name> <File>radius.log</File> </interim> <interim id="2"> <Event-Timestamp>1334561087</Event-Timestamp> <User-Name>User1</User-Name> <File>radius.log</File> </interim> </interims> <stop> <Event-Timestamp>1334561314</Event-Timestamp> <User-Name>User1</User-Name> <File>radius.log</File> </stop> </session>
Antoine Amend <amend.antoine@gmail.com>
See the Changes file.
Copyright (c) 2013 Antoine Amend. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install RADIUS::XMLParser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RADIUS::XMLParser
CPAN shell
perl -MCPAN -e shell install RADIUS::XMLParser
For more information on module installation, please visit the detailed CPAN module installation guide.