Download this file fs-load-cdr-mysql.pl.gz and run through cron every minute if you like …
Someone with a little knowledge of perl could probably fix up all the system() and other hacks and lack of error checking …
make sure <param name=”rotate-on-hup” value=”true”/> is uncommented in /usr/local/freeswitch/conf/autoload_configs/cdr_csv.conf.xml
–snip–
#!/usr/bin/perl -w
# Convergence FreeSWITCH Tools Version 7.0
# (c) MMII Convergence. All rights reserved.
# <info@convergence.pk> http://www.convergence.pk
# This program is free software, distributed under the terms of
# the GNU General Public License.http://www.gnu.org/licenses.html
use strict;
use DBI();
use File::Copy;
# this commands HUPS fs, she creates new cdr.csv files, so we can load the old ones up
my @cc = (“killall”, “-HUP”, “freeswitch”);
system(@cc) == 0
or die “$0: system @cc failed: $?”;
my $dbh = DBI->connect(“DBI:mysql:database=freeswitch;host=localhost”,”fsdbuser”,”fsdbpass”) or die “$0: Couldn’t connect to database: ” . DBI->errstr;
# this is the standard location of the cdr-csv
my @LS = `ls -1t /usr/local/freeswitch/log/cdr-csv/Master.csv.*`;
foreach my $line (@LS) {
chop($line);
my $stm = “LOAD DATA LOW_PRIORITY LOCAL INFILE ‘$line’ INTO TABLE cdr FIELDS ENCLOSED BY ‘\”‘ TERMINATED BY ‘,’”;
my $ul = $dbh->prepare($stm)
or die “$0: Couldn’t prepare statement $stm: ” . $dbh->errstr;;
$ul->execute();
$ul->finish;
system(“cat $line >> /usr/local/freeswitch/log/cdr-csv/FULL_Master.csv”);
unlink $line;
}
# one silly thing is that each accountcode has its own cdr.csv as well, either handle those here, by loading them into their own tables, or rm them
my @BS = (“xtec”,”megaphone”,”mafcom”,”xeivacom”);
foreach my $code (@BS) {
@LS = `ls -1t /usr/local/freeswitch/log/cdr-csv/$code.csv.*`;
foreach my $line (@LS) {
chop($line);
move($line, “/usr/local/freeswitch/log/cdr-csv/trash/$code/”);
}
}
exit 0;
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
You must log in to post a comment.