Scripts for Call calculations based on CDR

Hi, I’m really a newbie on asterisk and programming. The only that I have created for my system is ome monitoring scripts. I would like to if somebody could share me some scripts on computating calculating, all calls(successful and unsucessfull) based on the cdr records of asterisk. Will I’ll be concatenating the csv file?WHat would be the best programming language to use?I hope somebody could help me on this one. It would be very grateful if someone can share this scripts. Thank you very much in advance.

Best Regards,
newbie_aste

very simply bash script

#!/bin/bash
DATE=$1
NOANSWER=`cat /var/log/asterisk/cdr-csv/Master.csv | grep $DATE | grep "NO ANSWER" | wc -l`
echo "NO ANSWERED: $NOANSWER"
ANSWERED=`cat /var/log/asterisk/cdr-csv/Master.csv | grep $DATE | grep "ANSWERED" | wc -l`
echo "ANSWERED: $ANSWERED"
FAILED=`cat /var/log/asterisk/cdr-csv/Master.csv | grep $DATE | grep "FAILED" | wc -l`
echo "FAILED: $FAILED"
BUSY=`cat /var/log/asterisk/cdr-csv/Master.csv | grep $DATE | grep "BUSY" | wc -l`
echo "BUSY: $BUSY"

result (example)

usage: script.name YYYY-MM-DD
script can be run in cron and result mailed

hi, here is my Perl script named save.agi:

#!/usr/bin/perl
use warnings;
use strict;
use Asterisk::AGI;
use File::Copy;
use POSIX;
use Number::Format qw(:subs);

$|=1;

my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();

my $status = $ARGV[0];
my $caller = $ARGV[1];
my $destination = $ARGV[2];
my $time = $ARGV[3];
my $billsec = $ARGV[4];

open (file_1, “>> /xxx/$caller”);
print file_1 ("$status $destination $time $billsec\n");
close file_1;
#END

in extensions.conf

exten => h,1,DeadAGI(/xxx/scripts/save.agi|${DIALSTATUS}|${CALLERIDNUM}|${DNID}|${CDR(answer)}|${ANSWEREDTIME})


this script record information in $caller file. I have another Perl scrip who read this file and show the result in web page.

newbie_aste i’m using cdr in database and php. all results are shown on www

Thanks for the help. One last thing, I wanted to compute for the calls in an hour?Is this possible? And does any one have the documentation on the cvs file.I dont know what is the use or what does it mean/represent some column on the cvs file. Thank you very much

Best Regards,
newbie_aste

#!/bin/bash

date=$1
time=$2
seconds=0
summary=0
minutes=0
time1=0
for a in `cat /var/log/asterisk/cdr-csv/Master.csv | grep $date | grep $time: | grep -v :$time |  cut -d"," -f13`
do
summary=$(($summary+$a))
done
minutes=$(($summary/60))
time1=$(($minutes*60))
seconds=$(($summary-$time1))
echo "we talk $minutes minutes $seconds seconds in $date between $time - $(($time+1))"

this will add whole CDR(billsec) values for one day and one specified hour ($1 parameter for example 2006-08-30 $2 parameter for example 12)
script isn’t very accurate becous when call is starded at 11:59 and ends 12:01 it will be counted for 11 and 12 as $2. But it’s not so hard to repair that bug (a task for You)
http://www.voip-info.org/wiki/view/Asterisk+cdr+csv