summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlevinse <levinse>2011-06-09 22:11:04 +0000
committerlevinse <levinse>2011-06-09 22:11:04 +0000
commit7f4e4fddb595f5c825a18c88ed79029160650dc9 (patch)
treee0ad5e02d1916aa3c1f0165725fd4ec1a9e9c1fc
parentfdc247b504359ca9e74f63daa771f49393fd70ed (diff)
SMSC CDRs (Kannel) and cdrtypenum option on cdr sftp import script, RT10991
-rw-r--r--FS/FS/Record.pm4
-rw-r--r--FS/FS/cdr.pm8
-rw-r--r--FS/FS/cdr/kannel.pm43
-rwxr-xr-xFS/bin/freeside-cdr-sftp_and_import17
4 files changed, 66 insertions, 6 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index e7440feb5..ffeabcb17 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1853,10 +1853,12 @@ sub batch_import {
next if $line =~ /^\s*$/; #skip empty lines
$line = &{$row_callback}($line) if $row_callback;
+
+ next if $line =~ /^\s*$/; #skip empty lines
$parser->parse($line) or do {
$dbh->rollback if $oldAutoCommit;
- return "can't parse: ". $parser->error_input();
+ return "can't parse: ". $parser->error_input() . " " . $parser->error_diag;
};
@columns = $parser->fields();
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index e7b6e6cd3..36721a81a 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -948,6 +948,14 @@ sub batch_import {
my $iopt = _import_options;
$opt->{$_} = $iopt->{$_} foreach keys %$iopt;
+ if ( defined $opt->{'cdrtypenum'} ) {
+ $opt->{'preinsert_callback'} = sub {
+ my($record,$param) = (shift,shift);
+ $record->cdrtypenum($opt->{'cdrtypenum'});
+ '';
+ };
+ }
+
FS::Record::batch_import( $opt );
}
diff --git a/FS/FS/cdr/kannel.pm b/FS/FS/cdr/kannel.pm
new file mode 100644
index 000000000..3e2e5653a
--- /dev/null
+++ b/FS/FS/cdr/kannel.pm
@@ -0,0 +1,43 @@
+package FS::cdr::kannel;
+
+use strict;
+use vars qw( @ISA %info );
+use FS::cdr qw( _cdr_date_parser_maker );
+
+@ISA = qw(FS::cdr);
+
+%info = (
+ 'name' => 'Kannel',
+ 'weight' => 25,
+ 'header' => 1,
+ 'type' => 'csv',
+ 'row_callback' => sub { my $row = shift;
+ return ' ' if $row =~ /.*Log (begins|ends)$/;
+ die "invalid row format" unless
+ $row =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([A-Za-z ]+) (\[SMSC:\w+\] \[SVC:\w*\] \[ACT:\w*\] \[BINF:\w*\] \[FID:\w*\]) \[from:(|\+)(\d+)\] \[to:(|\+)(\d+)\] (\[flags:.*?\]) \[msg:(\d+):(.*?)\] (\[udh:.*?\])$/;
+ $row = "$1,$2,$3,$5,$7,$8,$9,$11";
+ $row;
+ },
+ 'import_fields' => [
+ _cdr_date_parser_maker('startdate'),
+ 'disposition',
+ 'userfield', # [SMSC: ... FID...], five fields
+ 'src',
+ 'dst',
+
+ sub { my($cdr, $flags) = @_;
+ $cdr->userfield($cdr->userfield." $flags");
+ },
+
+ # setting billsec to the msg length as we need billsec set non-zero
+ 'billsec',
+
+ sub { my($cdr, $udh) = @_;
+ $cdr->userfield($cdr->userfield." $udh");
+ },
+ ],
+);
+
+sub skip { map {''} (1..$_[0]) }
+
+1;
diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import
index ba9d6f3cc..9a71ab96c 100755
--- a/FS/bin/freeside-cdr-sftp_and_import
+++ b/FS/bin/freeside-cdr-sftp_and_import
@@ -11,8 +11,8 @@ use FS::cdr;
# parse command line
###
-use vars qw( $opt_m $opt_p $opt_r $opt_e $opt_d $opt_v $opt_P $opt_a );
-getopts('m:p:r:e:d:v:P:a');
+use vars qw( $opt_m $opt_p $opt_r $opt_e $opt_d $opt_v $opt_P $opt_a $opt_c );
+getopts('c:m:p:r:e:d:v:P:a');
$opt_e ||= 'csv';
#$opt_e = ".$opt_e" unless $opt_e =~ /^\./;
@@ -20,6 +20,8 @@ $opt_e =~ s/^\.//;
$opt_p ||= '';
+die "invalid cdrtypenum" if $opt_c && $opt_c !~ /^\d+$/;
+
my %options = ();
my $user = shift or die &usage;
@@ -92,12 +94,15 @@ foreach my $filename ( @$ls ) {
warn "Processing $filename\n" if $opt_v;
- my $error = FS::cdr::batch_import( {
+ my $import_options = {
'file' => "$cachedir/$filename",
'format' => $format,
'batch_namevalue' => $filename,
'empty_ok' => 1,
- } );
+ };
+ $import_options->{'cdrtypenum'} = $opt_c if $opt_c;
+
+ my $error = FS::cdr::batch_import($import_options);
die $error if $error;
if ( $opt_d ) {
@@ -161,7 +166,7 @@ cdr.sftp_and_import - Download CDR files from a remote server via SFTP
cdr.sftp_and_import [ -m method ] [ -p prefix ] [ -e extension ]
[ -r remotefolder ] [ -d donefolder ] [ -v level ] [ -P port ]
- [ -a ] user format [sftpuser@]servername
+ [ -a ] [ -c cdrtypenum ] user format [sftpuser@]servername
=head1 DESCRIPTION
@@ -185,6 +190,8 @@ or FTP and then import them into the database.
-v: set verbosity level; this script only has one level, but it will
be passed as the 'debug' argument to the transport method
+-c: cdrtypenum to set, defaults to none
+
user: freeside username
format: CDR format name