[Asterisk-Users] cdr translation

Jean-Michel Hiver jhiver at ykoz.net
Tue Jan 17 02:51:44 MST 2006


Carlos Alperin a écrit :

> Did someone made or implement an script to move all the info from the 
> standar cdr format to a PostgreSQL or MySQL?
>

Here's what I did:


To create a CDR table:

create table cdr (
        accountcode varchar (30) NOT NULL,
        src varchar(64),
        dst varchar(64),
        dcontext varchar(32),
        clid varchar(32),
        channel varchar(32),
        dstchannel varchar(32),
        lastapp varchar(32),
        lastdata varchar(64),
        calldate timestamp NOT NULL,
        callpickup timestamp ,
        callhangup timestamp ,
        duration int(8) unsigned default NULL,
        billsec int(8) unsigned default NULL,
        status varchar(32),
        userfield varchar(128),
        PRIMARY KEY (accountcode)
);


To update the CDR table from the Master.csv file

cat /var/log/asterisk/cdr-csv/Master.csv | \
egrep -v '^"",' | \
sed 's/,,/,"",/;s/\(^.*$\)/REPLACE INTO cdr VALUES\(\1\);/' | \
mysql -u root <your_db_name>


Cheers,
Jean-Michel.




More information about the asterisk-users mailing list