X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fcdr-opensips.import;h=b8169d5236f44f708e666c15a48c947455eb1114;hp=54f06824cd52c92f229d7d6a0c0099c210ee2cee;hb=88e9a56677d343392416c262f976f069157b06cb;hpb=7158dc63b1acfc65b7b856a9f58821f6242ece31 diff --git a/bin/cdr-opensips.import b/bin/cdr-opensips.import index 54f06824c..b8169d523 100755 --- a/bin/cdr-opensips.import +++ b/bin/cdr-opensips.import @@ -10,7 +10,7 @@ use DBI; use Getopt::Std; my %opt; -getopts('H:U:P:D:T:s:e:', \%opt); +getopts('H:U:P:D:T:s:e:c:', \%opt); my $user = shift or die &usage; my $dsn = 'dbi:mysql'; @@ -79,8 +79,32 @@ while ( $row = $sth->fetchrow_hashref ) { warn $row->{'time'} . ": no callid, skipped.\n"; next; } - my ($src) = $row->{'caller_id'} =~ /^sip:(\d+)@/; - my ($dst) = $row->{'callee_id'} =~ /^sip:(\d+)@/; + + #i guess now we're NANPA-centric, but at least we warn on non-numeric numbers + my $src = ''; + my $src_ip = ''; + if ( $row->{'caller_id'} =~ /^sip:(\+1?)?(\w+)@(.*)/ ) { + $src = $2; + my $rest = $3; + if ($rest =~ /^([\d\.]{7,15})/) { + # canonicalize it so that ascii sort order works + $src_ip = sprintf('%03d.%03d.%03d.%03d', split('\.', $1)); + } + } else { + warn "unparseable caller_id ". $row->{'caller_id'}. "\n"; + } + + my $dst = ''; + my $dst_ip = ''; + if ( $row->{'callee_id'} =~ /^sip:(\+1?)?(\w+)@(.*)/ ) { + $dst = $2; + my $rest = $3; + if ($rest =~ /^([\d\.]{7,15})/) { + $dst_ip = sprintf('%03d.%03d.%03d.%03d', split('\.', $1)); + } + } else { + warn "unparseable callee_id ". $row->{'callee_id'}. "\n"; + } my $cdr = $cdrs{$callid}; if ( !$cdr ) { @@ -88,12 +112,15 @@ while ( $row = $sth->fetchrow_hashref ) { uniqueid => $callid, cdrbatchnum => $cdrbatchnum, }); + $cdr->cdrtypenum($opt{c}) if $opt{c}; } my $date = str2time($row->{'time'}); if ( $row->{'method'} eq 'INVITE' ) { $cdr->startdate($date); $cdr->src($src); $cdr->dst($dst); + $cdr->src_ip_addr($src_ip); + $cdr->dst_ip_addr($dst_ip); } elsif ( $row->{'method'} eq 'ACK' ) { $cdr->answerdate($date); @@ -132,7 +159,7 @@ if ( keys(%cdrs) ) { $mysql->disconnect; sub usage { - "Usage: \n cdr-opensips.import\n\t[ -H host ]\n\t-D database\n\t-U user\n\t-P password\n\t[ -s start ] [ -e end ]\n\tfreesideuser\n"; + "Usage: \n cdr-opensips.import\n\t[ -H host ]\n\t-D database\n\t-U user\n\t-P password\n\t[ -s start ] [ -e end ] [ -c cdrtypenum ] \n\tfreesideuser\n"; } sub check_cdr {