Remove outbound route prefix from CDR


How can I remove the prefix used on outbound route from CDR. The rule is: prefix 0 and match pattern ..
When the dialed number 088884444 is used, asterisk send to trunk Dial(“SIP/1002-00000086”, “SIP/9999/88884444,300,T”) in new stack, the CDR ticket is generated with 088884444 and the number 088884444 is received on the trunk.
The help says: Prefix to remove on a successful match. The dialed number is compared to this and the subsequent columns for a match. Upon a match, this prefix is removed from the dialed number before sending it to the trunks.
Is it possible to remove this 0 from the ticket?


The Call Detail Record call entry is based on what you dialed and what is sent by the outbound route, not what the trunk dials, so what you are seeing is consistent with what I would expect.

There are two places that modify the outbound number. You can do this in the outbound route or in the trunk. It looks like you are modifying the number in the trunk configuration. Changing the output so that it modified the number in the outbound route might make the difference you are looking for.

AFAIK it’s always based on the number dialed, before any modifications made by the Outbound Route (or the trunk).

@jgilson : What country is the system in question in? If the 0 that you are removing is an ‘outside line’ prefix, possibly you can set up the system so it’s not needed. That way, your users will dial the same way as they would from a mobile phone or home phone, so there will be fewer errors. However, if the 0 is a ‘national number’ prefix (you would dial 088884444 from a mobile) but your trunking provider requires that you delete it, I suggest not removing it from the CDRs, so destination numbers will match the format of incoming caller ID, DID numbers, etc. What is the range of extension numbers on your system?

1 Like

@cynjut and @Stewart1, thanks for reply.
I made changes on trunk and outbound routes and the 0 is always present in the CDR (asteriskcdrdb rows), so I think the asterisk registers it after the dialed number and before outbound route validations (or trunk).
I use the 0 in the prefix because it’s the number that is used for external calls. If the user dial 099998888 redirects to a specific trunk and if the dialed number is 299998888 the call is redirected to another trunk. The range of extensions is between 1000 and 3000.
Is it possible to configure the system to remove this prefix and where can I do that?
Thank you!

I was unable to simply rewrite the CDR destination, because ‘dst’ is read-only in the Asterisk CDR function. However, this code:

exten => s,1,Noop(Setting CDR userfield to ${DIAL_NUMBER})
exten => s,n,Set(CDR(userfield)=${DIAL_NUMBER})
exten => s,n,MacroExit()

added to extensions_custom.conf (using Admin -> Config Edit) did put the number sent to the trunk into the CDR Userfield, which may be adequate for your application. If not, you could explicitly update the database from the dialplan or post-process the CDR file. Or, another member may know of a way to do this easily.

Why is that? Is there a good reason why you can’t just dial 99998888? In most places, that works out better. These days, numbers are rarely dialed manually. We have CRM systems, company directories, contact lists, click-to-call, speed dials, etc. If your Contact entry for John Doe is 099998888, then when he calls, his caller ID will be 99998888 and won’t match, so his name won’t be displayed. And if you try to call him back from your phone’s Call History or Missed Calls, the call won’t go through.

If your country has short codes for large organizations and government agencies, you could require an initial 0 just for those. For example, in Thailand we call for McDonald’s delivery on 1711 . That would conflict with your extension 1711, so your system in Thailand might require dialing 01711 for McDelivery, but ordinary landlines and mobiles could be dialed without prefixing a 0.

Next, when do you dial 29999888 for an alternate trunk? If that’s just rarely, e.g. to work around a problem, it’s not an issue. But if you do it regularly to select the best route to a specific destination, IMO that’s better handled by Outbound Routes, so your users don’t have to think about it (and make mistakes). If it’s e.g. to change the outbound caller ID because you make and answer calls for multiple organizations, IMO that’s better handled by using multiple line appearances on the phones (select Line 1 to call from Acme Widgets, Line 2 to call from Awesome Hosting).

Thanks all for answers. I didn’t find a solution for this in asterisk, so I created an app to do this.

If you can, please share it, it might help future visitors.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.