[asterisk-users] date - outgoing call
A J Stiles
asterisk_list at earthshod.co.uk
Tue Dec 11 05:36:51 CST 2012
On Tuesday 11 December 2012, Joseph wrote:
> On 12/10/12 20:45, Steve Edwards wrote:
> >On Mon, 10 Dec 2012, Joseph wrote:
> >> When a call comes in asterisk records the date correctly but when I cake
> >> a call out I get only something like:
> >> Date: 60
> >> here is an example:
> >>
> >> From: "7807560785"
> >> To: "s"
> >> Date: "2012-12-11 00:46:04"
> >> Status: "ANSWERED"
> >> ----------------
> >>
> >> From: "5"
> >> To: "4331235"
> >> Date: 60
> >> Status: 4
> >
> >What version of Asterisk?
> >
> >Where are you seeing the data you display above?
>
> I'm using this command to pull the records of the cvs:
> grep -P '\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}'
> /var/log/asterisk/cdr-csv/*.csv | cut -d, -f2,3,10,15 | awk -F"," {'print
> "From:\t"$1"\nTo:\t"$2"\nDate:\t"$3"\nStatus:\t"$4"\n----------------\n"'}
> |tail -60
>
> the actual last records in Master.csv is:
> "","5","218","internal","""Cerra""
> <5>","IAX2/192.168.141.1:4569-4374","SIP/11-00000180","Dial","SIP/11&SIP/3
> 21&SIP/218,25,m(penguin)w","2012-12-11 02:58:53","2012-12-11
> 02:58:59","2012-12-11
> 03:00:00",67,61,"ANSWERED","DOCUMENTATION","1355194733.524",""
>
> but with the above command it display:
> From: "5"
> To: "218"
> Date: 25
> Status: 67
Your problem is, the parameter string to "Dial" contains embedded commas
(although they are in between speech marks, and therefore perfectly valid in
the context of a CSV file). Your naïve split on commas is failing to account
for these. So "SIP/11&SIP/321&SIP/218,25,m(penguin)w" appears to be three
separate fields: "\"SIP/11&SIP/321&SIP/218" , "25" and "m(penguin)w\"" -- and
this is what is throwing your simple script out.
You almost certainly will need to use a better scripting language and proper
CSV parsing library. In Perl, there is Text::CSV, which is available from
CPAN or (in Debian / Ubuntu) using
$ sudo apt-get install libtext-csv-perl
and there must be similar things in other scripting languages.
Alternatively, you could use MySQL for CDR, and SELECT only the fields you want
-- but for licensing reasons you will have to compile the MySQL extension
yourself, from Source Code.
--
AJS
Answers come *after* questions.
More information about the asterisk-users
mailing list