FreeSWITCH CDRs & Contacts

Forum about Domotiga Open Source Home Automation for Linux.

Moderator: RDNZL

Post Reply
djrm
Starting Member
Starting Member
Posts: 8
Joined: Sat Jul 16, 2011 7:02 pm

FreeSWITCH CDRs & Contacts

Post by djrm »

One of my goals with DomotiGa will be to replace my windows callerid database which is monitoring the PTSN telephone line using a serial modem with caller id interface (Old Pace56). I have a FreeSWITCH PBX connected to a Linksys SPS3102 which is also capable of decoding callerid. FreeSWITCH can work with callerid from sip and ptsn and is not tied to my windows PC either.

FreeSWITCH has an installable module to enable it to keep logs of calls made and recieved, I have modified a perl script I found to write the logged values into the domotiga cdr table, this I will automate with a cron task when I'm happy with the results. So far I'm glad to say that it is kind of working and it is linking with the Contacts databse which is what I wanted. Freswitch mod_cdr_csv is used to create the logs using the default settings.

I've copied the perl script below if anybody is interested, some lines are remmed out, they are from the original script, at the end is a remmed out line which will delete the log file if it isnt needed any more. I may need to process the variables a bit inside the script to make the result more domotiga friendly.

Code: Select all

#!/usr/bin/perl

use DBI;
use Text::ParseWords;

#connect to database and define path to your log files
#$dbh = DBI->connect( 'DBI:mysql:freeswitch', 'username', 'password' ) or die "connect error";
$dbh2 = DBI->connect( 'DBI:mysql:domotiga', 'domouser', 'kung-fu' ) or die "connect error";

$LOG_DIR = "/usr/local/freeswitch/log/cdr-csv"; 

#Make Freeswitch rotate the log files
system("killall -HUP freeswitch");

#prepare the insert statement - You may have to change this depending on the log file definintion in your freeswitch config.
#$insert_sql =  $dbh->prepare("insert into cdr          (caller_id_name, caller_id_number, destination_number, context, start_stamp, answer_stamp, end_stamp, duration, billsec, hangup_cause, uuid, bleg_uuid, accountcode) values (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$insert_sql2 = $dbh2->prepare("insert into cdr (calldate, clid, src, dst, dcontext, duration, billsec, disposition, accountcode, uniqueid) values (?,?,?,?,?,?,?,?,?,?)");

# map freeswitch variables to DomotiGa database (asterisk?)
#start_stamp		`calldate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
#caller_id_name  	`clid` varchar(80) DEFAULT NULL,
#caller_id_number  	`src` varchar(80) DEFAULT NULL,
#destination_number  `dst` varchar(80) DEFAULT NULL,
#context		`dcontext` varchar(80) DEFAULT NULL,
#?			`channel` varchar(80) DEFAULT NULL,
#?			`dstchannel` varchar(80) DEFAULT NULL,
#?			`lastapp` varchar(80) DEFAULT NULL,
#?			`lastdata` varchar(80) DEFAULT NULL,
#duration		`duration` int(11) NOT NULL DEFAULT '0',
#billsec		`billsec` int(11) NOT NULL DEFAULT '0',
#hangup_cause		`disposition` varchar(45) DEFAULT NULL,
#?			`amaflags` int(11) NOT NULL DEFAULT '0',
#accoutt_code		`accountcode` varchar(20) DEFAULT NULL,
#?			`userfield` varchar(255) DEFAULT NULL,
#uuid			`uniqueid` varchar(32) DEFAULT NULL,
#			`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

#get a list of all the Master files with a datestamp on the end.  (These are created when log files rotated above)
@log_files = <$LOG_DIR/Master.csv.*>; 

#Loop through the files and insert into the table;
foreach $file (@log_files){

      print "$file\n";
      open(IN, $file) or die "cant open $file\n";

      while (<IN>){
             ($caller_id_name, $caller_id_number, $destination_number, $context, $start_stamp, $answer_stamp, $end_stamp, $duration, $billsec, $hangup_cause, $uuid, $bleg_uuid, $accountcode, $read_codec, $write_codec) = quotewords(",", 0, $_);;

#            $insert_sql->execute($caller_id_name, $caller_id_number, $destination_number, $context, $start_stamp, $answer_stamp, $end_stamp, $duration, $billsec, $hangup_cause, $uuid, $bleg_uuid, $accountcode);
             $insert_sql2->execute($start_stamp, $caller_id_name, $caller_id_number, $destination_number, $context, $duration, $billsec, $hangup_cause, $account_code, $uuid);
      }

      close(IN);

      #Delete the log file since we've finished with it.
      #unlink($file);

}
Best regards, David.
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Re: FreeSWITCH CDRs & Contacts

Post by RDNZL »

Thanks, I have added your script to the SVN repos, in the new scripts directory.
Regards, Ron.
Post Reply

Return to “DomotiGa Forum”