[HELP]How can I diferentiate between Incoming and Outgoing?

How can I diferentiate between incoming and outgoing calls?
What is the field responsible for this and what values does it takes?

Do You have CDR in mind ?
in Master.csv there is CDR(channel) and CDR(dstchannel)
and i have “SIP/101-1353”,“SIP/provider-03fe” fo ougoing
and something like “SIP/login.provider-e241”,“SIP/101-4259” for incoming
the same if for DB CDR ther is columns channel and dstchannel
Hou to diferentiate ? - if dstchannel is Your ‘outgoing’ interface then this is outgoing call, id dstchannel is Your internal interface then tis in incoming call…

If You have diffrent context for incoming/outgoing check dcontext in Master.csv/CDRDB

I set accountcode for incoming and internall calls, rest i cout as outgoing.
You can manipulate userfield column as You like.

If this is not answer for Your question… then make a question more detailed.


So CDR(channel) means OUTGOING and CDR(dstchannel) means INCOMING?


Not so easy.

CDR(channel) store channel name that initiate the call
CDR(dstchannel) store the destination channel name

if You made a call from Your SIP phone101 using Zap/1 trunk then
(channel) will have SIP/101 and (dstchannel) will have Zap/1
if You have incoming call from Zap/1 trunk to Your SIP/101 Phone then
(channel) will have Zap/1 and (dstchannel) will have SIP/101


src dst dcontext channel dstchannel
7102 7103 from-internal SIP/7102-1520 SIP/7103-3312
7102 8774436 from-internal SIP/7102-5fa2 SIP/callmgr-esa
7102 111866744 from-internal SIP/7102-f974 SIP/primus-7ac5
7102 7112 from-sip SIP/7102-1285 SIP/7112-b17c
7102 111866744 from-sip SIP/7102-7ad4 SIP/sip.broadvoice.com

Can you help me out with this cause from examples I learn best… :smile:
What are outgoings and what are incomings?

Short path
src = number initiating a call
dst = destination
src dst
7102 to 7103 - internal
7102 to 8774436 - i don’k know what SIP/callmgr is… is it something for outgoing or internal user ?
7102 to 111866744 - looks like outgoing for me using “primus” SIP provider
7102 to 7112 - internal
7102 to 111866744 - looks like outgoing for me using “sip.broadvoce.com” SIP provider


I am not using this Astersik…If I would I probably wouldn’t post such stupid questions.

I am trying to write a code to differentiate Outgoings and Incomings. I believe this is very easy…it can be done by checking 1 one or 2 strings (channel and dstchannel) and compare them with what should be. But I am not sure.

Anyway…thanks for you answers. You have “iluminated” me a bit :smile:

if configs uses accountcode and write there incoming/outgoing string (i do that) there is no problem.
if outgoing calls are placed in one context then cdr(dcontext) is useful
if full numbers are placed in cdr(dst/src) then You know who calls and where
comparing cdr(channel) with cdr(dstchannel) will give You what was incoming/outgoing/internal


:question: What do you mean: “if config uses accountcode and write there incoming/outgoing string there is no problem”? How can this be done?

Is there a way to modify the dial plan to use the CDR Userfield to store there one of the folowing strings: OUTGOING, INCOMING, INTERNAL?

If someone makes an outgoing call I need Asterisk to write OUTGOING in the Userfield of that call in Master.csv.
If someone receives an INCOMING call I need Asterisk to write INCOMING in the Userfield of that call in Master.csv.
If someone makes an INTERNAL call I need the Asterisk to write INTERNAL in the Userfield of that call in Master.csv.
Is this possible? How?

Thank you very much!

there should be entries in .conf files:
load=> cdr_custom.conf

cdr_custom.conf (i have this)
Master.csv => “${CDR(clid)}”,"${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(callend)}","${CDR(duration)}","${CDR(billsec)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
at the end there is CDR(userfield)

extensions.conf (only very short examples here)
exten => s,1,set(CDR(userfield)=incoming)
exten => s,2,…
exten => _X.,1,set(CDR(userfield)=outgoing)
exten => _X.,2,…
exten => _XXX,1,set(CDR(userfield)=internal)
exten => _XXX,2,…

then /var/log/asterisk/cdr-custom/Master.csv should contain cdr(userfield) entries (i have this):
"“TSG4” <068XXXXXX>",“068XXXXXX”,“s”,“rozmowa”,“Zap/1-1”,“SIP/101-1888”,“Dial”,“SIP/101|17|t”,“2006-02-15 10:57:52”,“2006-02-15 10:57:52”,"",“589”,“589”,“AN

it was incoming call from 068XXX number, TSG4 was added for presentation on phone, the destination was phone number 101
and i use accountcode for specyfing incoming/outgoing/internal calls
accountcode canbe set like userfield.

for gathering CDR information i’m using postgresql

-hope thats will help You.

–> edited:
in modules.conf
load=> cdr_custom.so

That was exactly what I needed. You answer is perfect.
Thank you very much! :smiley: