NAME

RADIUS::XMLParser - Radius log file XML convertor

SYNOPSIS

    use RADIUS::XMLParser;
    use Data::Dumper;
    
    my $radius_file = 'radius.log';
    my @labels = qw(
    Event-Timestamp
    User-Name
    File
    );
    
    my $radius = RADIUS::XMLParser->new(
    	DEBUG=>1, 
    	DAYSFORORPHAN=>1, 
    	AUTOPURGE=>0, 
    	ALLEVENTS=>1, 
    	XMLENCODING=>"us-ascii", 
    	OUTPUTDIR=>'/tmp/radius', 
    	LABELS=>\@labels
    );
    	
    my $xml_file = $radius->convert($radius_file);
    print Dumper($parser->getMetaData());

DESCRIPTION

This module will extract and sort any supported events included into a given radius log file.
Note that your logfile must contain an empty line at its end otherwise its last event will not be analyzed.
Events will be grouped by their session ID and converted into XML sessions.
At this time, supported events are the following:
START
INTERIM-UPDATE
STOP

On first step, any event will be stored on different hash tables (with SessionID as a unique key). Then, for each STOP event, the respective START and INTERIM will be retrieved

[OPTIONAL] Each found START / INTERIM event will be written, final hash will be empty.
[OPTIONAL] Only the newest START / INTERIM events will be kept. Oldest ones will be considered as orphan events and will be dropped

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>

CONSTRUCTOR

Usage:

my $parser = RADIUS::XMLParser->new([%params]);

Return:

A radius parser blessed reference

Options:

DEBUG

Integer (0 by default) enabling Debug mode.
Regarding the amount of lines in a given Radius log file, debug is split into several levels (0,1,2,3).

LABELS

Array reference of labels user would like to see converted into XML.

For instance:

my @labels = qw(
Acct-Output-Packets
NAS-IP-Address
Event-Timestamp);

Will result on the following XML

<stop>
	<Acct-Output-Packets></Acct-Output-Packets>
	<NAS-IP-Address></NAS-IP-Address>
	<Event-Timestamp></Event-Timestamp>
</stop>
If LABELS is not supplied, all the found Key / Values will be written.
Else, only these labels will be written.
FYI, Gettings few LABELS is significantly faster... Think of it when dealing with large files !

AUTOPURGE

Boolean (0 by default) that will purge stored hash reference (Start + Interim) before being used for Event lookup.
Newest events will be kept, oldest will be dropped.
Threshold is defined by below parameter DAYSFORORPHAN

DAYSFORORPHAN

Number of days user would like to keep the orphan Start + Interim events.
Default is 1 day; any event older than 1 day will be dropped.
AUTOPURGE must be set to true

OUTPUTDIR

Output directory where XML file will be created
Default is '${Home Directory}/radius/xml'

ALLEVENTS

Boolean (0 by default).
If 1, all events will be written, including Start, Interim and Stop "orphan" records. Orphan hash should be empty after processing.
If 0, only the events Stop will be written together with the respective Start / Interims for the same session ID. Orphan hash should not be empty after processing.

XMLENCODING

Only utf-8 and us-ascii are supported
default is utf-8

ORPHANDIR

Default directory for orphan hash tables stored structure
Default is '${Home Directory}/radius/orphans'

METHODS

convert

Description:

The convert will parse and convert provided file $log_file.
All its events will be retrieved, sorted and grouped by their unique sessionId.
Then, file will be converted into a XML format.

Usage:

my $xml_file = $parser->convert($log_file);
print "$xml_file is the XML conversion of radius $log_file";

Parameter:

$log_file:
Radius log file that will be parsed.

Return:

The XML $xml_file that has been created.

getMetaData

Description:

The getMetaData will give you back some useful information about the latest XML conversion
This hash will provide you with the number of found events, processed lines, etc...

Usage:

    Using below code:

    use Data::Dumper;
    print Dumper($parser->getMetaData());

    Will result on the following output

    	$VAR1 = {
              'ERRORS' => 0,
              'EVENT_INTERIM' => 130,
              'EVENT_START' => 46,
              'EVENT_STOP' => 46,
              'OUTPUT_FILE' => '/tmp/radius.xml',
              'PROCESSED_LINES' => 5659
            };

Return:

A hash reference including metadata

EXAMPLE:

my @labels = qw(Event-Timestamp User-Name File);
my $radius = RADIUS::XMLParser->new(
	DEBUG=>1, 
	DAYSFORORPHAN=>1, 
	AUTOPURGE=>0, 
	ALLEVENTS=>1, 
	XMLENCODING=>"us-ascii", 
	OUTPUTDIR=>'/tmp/radius',
	LABELS=>\@labels);
	
my $xml = $radius->group('../etc/radius.log');

__END__

<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>

AUTHOR

Antoine Amend <amend.antoine@gmail.com>

MODIFICATION HISTORY

See the Changes file.

COPYRIGHT AND LICENSE

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.