I'm currently working on a perl script convert csv logs to a http log
equiv:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""

Right now I have output something similar to this:

111 - - [02/Aug/2003:16:39:15 -0500] "GET /300 HTTP/1.0" 200 6144 "sipext" "ANSWERED"
INCOMING - - [02/Aug/2003:17:30:27 -0500] "GET /9999 HTTP/1.0" 200 40960 "autoattend" 
"ANSWERED"
111 - - [02/Aug/2003:17:33:31 -0500] "GET /800 HTTP/1.0" 200 1024 "sipext" "ANSWERED"
INCOMING - - [02/Aug/2003:17:33:31 -0500] "GET /9999 HTTP/1.0" 200 36864 "autoattend" 
"ANSWERED"


It produces basically what I want but maybe someone out there will refine
this!!

bkw
PS: I can't take full credit for this someone on #asterisk mentioned doing
this.
#!/usr/bin/perl 
#
# Asterisk PBX to weblog converter
# This is just a test to see if we can get usable data from such a script.
#

# timeoffset ie -0500
$timeoffset = "-0500";

open(LOGS,"</home/sites/www.bkw.org/users/brian/Master.csv");
@data = <LOGS>;
close(LOG);

%MONTHS = (
        "01"    => "Jan",
        "02"    => "Feb",
        "03"    => "Mar",
        "04"    => "Apr",
        "05"    => "May",
        "06"    => "Jun",
        "07"    => "Jul",
        "08"    => "Aug",
        "09"    => "Sep",
        "10"    => "Oct",
        "11"    => "Nov",
        "12"    => "Dec"
);

foreach $line (@data) {
        chomp($line);
        my($acctcode, $src, $dest, $destcontext, $callerid, $chan, $destchan, 
$lastapp, $lastapparg, $start, $answer, $end, $duration, $billable, $disposition, 
$amaflags, $uniqueid) = split(",",$line);
        # lets clean this up a bit
        $dest =~ s/\"//g;
        $src =~ s/\"//g;
        $start =~ s/\"//g;
        $disposition =~ s/\"//g;
        $destcontext =~ s/\"//g;
        # not sure but we will convert seconds to kilobytes
        $billable = $billable * 1024;
        # I'm sure we can do this better
        my($date, $time) = split(' ',$start);
        my($year, $month, $day) = split('-',$date);
        # this is for my own needs because we dump calls into asterisk via h323
        if($src eq "") {
                if($dest = 9999) {
                        $src = "INCOMING";
                }
        }
        print "$src - - [$day\/$MONTHS{$month}\/$year:$time -0500] \"GET /$dest 
HTTP/1.0\" 200 $billable \"$destcontext\" \"$disposition\"\n";
        $subtotal = $subtotal + $billable;
}


Reply via email to