CDR to specific tables

My extensions.conf file contains many incoming did’s that are routed to different contexts. I got a MySQL db going to record cdr info and I can’t seem to find a way to filter which table the CDR info is logged into based on what did was dialed. I don’t see a filter that will work in the cdr_adaptive_odbc.conf to use what did was called. Is there a way in the extensions.conf to tell it which table the CDR should go into, or another way?

My end goal is to have a table for each did with it’s own CDR info.


why don’t you use views ?

I read the docs and I still have no idea how you would use them for what I need.


Would you happen to know where I could find docs on using Views in this way, I can’t find any.

I feel the last post was a bump and 24 hours weren’t up.

Any book on RDBMS’s will tell you how to use views in general, to access selected subsets of tables, as they are a fundamental part of such databases.

Either your requirement is not clearly specified, or generalising the above to your requirement should be trivial.

I have not tried this myself, but I was wondering…

If the DIDs go to different contexts, could you use a filter in the config file like ‘filter dcontext => departmenta’ where ‘departmenta’ is the name of the context you want in a specific table. You would have a section defined for each context with different values for filters.

If that does not work, perhaps you could userfield or even define you own column as a filter.

HOWEVER, I believe David may have been hinting at using a single table to store the data and use different views for retrieval. It would make the dial plan and configuration simpler and rely on a database feature to provide access to a subset of the data. For instance…

create view departmenta as select * from cdr where dst in ( ‘did1’,‘did2’,‘did3’,‘did4’);

Then ‘select * from departmenta’ is limited to just those 4 dids.

This approach has the benefit that Asterisk is already handling the writing of CDRs and the selection of a subset is handled by the database. If a new DID is created, the data will still be written by asterisk, you simply recreate the view or create a new on if the new DID is for a new Department/Group/Customer. Doing this via config files, in my opinion, would be… inconvenient.

I hope this helps.


Thanks Dale and David, that helped a ton. At first I couldn’t figure out views because for some reason I had it in my head that they were for when data was going into the table… now it makes sense and seems to be the obvious solution.

Of course there is a snag >.< I can’t find a CDR variable that can get the did that was called into my db. My setup looks like this:
exten => 18xxxxxxxxx,1,Goto(store_one,s,1)

exten => s,1,Answer()
exten => s,n,Background(/var/spool/asterisk/voicemail/store_one/001/unavail)
exten => s,n,WaitExten()

I tried using the dst variable but that outputs “s”.

Thanks for the help

How about…

exten => 18xxxxxxxxx,1,Goto(store_one,${EXTEN:-9},1)

exten => _XXXXXXXXX,1,Answer()
exten => _XXXXXXXXX,n,Background(/var/spool/asterisk/voicemail/store_one/001/unavail)
exten => _XXXXXXXXX,n,WaitExten()

That did the trick!

Thanks everyone for the help!