Question

Is it possible to log SIP requests to a database in asterisk? I am interested in these details:

  • timestamp
  • SIP method
  • status code
  • source number/extension
  • destination number/extension

I am pretty sure that it's possible to translate queue_log events to SIP requests and get the above information from it. However, as not every call goes through calling queues, this solution does not work for me.

Perhaps it's possible to achieve by using AMI? Or writing custom dialplan? Please share your thoughts on this issue.

Was it helpful?

Solution

No way to do that.

Asterisk does not record sip messages unless you have sip debug turned on.

If you need control on message level, check out kamailio/opensips project.

OTHER TIPS

I used to work for a customer who demanded very exhaustive real-time statistics. To get everything right, we had to combine the CDRs, CELs, and queue_logs. In the end this was a very complicated system but at the time being we didn't see another way to go. Well, we did but it wasn't feasible.

One of the simplest questions you can ask is: Who (A) called who (B) and who answered the call (C) in the end. If you can answer this question you can basically answer which customer (A), calls which extension (B) which may reflect the customer's interest. To find out where the workload occurred you have to have the final extension (C).

As simple as this sounds, it is very hard to do, depending on the customer's setup. If you have mixed technologies like ISDN for outbound calls, and SIP (asterisk/freeswitch) for inbound (in-company) calls, you might find that there's even no usable Call Detail Record at all.

Even for inbound SIP telephony, I can tell you that there are scenarios where just finding out the right A,B,C extensions is very tough!!! First, you have to know that Asterisk internally knows about two so called "legs", where two legs represent a bridge between two channels (please, correct me if I'm wrong). I'm not an expert here, but consider it as two endpoints talking to each other. In that terminology, there is no "initially called extension B". Also, the CEL and CDR don't relfect that. There're "dst" and "src" fields in a CDR but really the "channel" and "dstchannel" are of more value to you. The "dstchannel" sometimes look like "SIP/dialnumber@foobar", but only if your SIP accounts somehow relate to to the given number (extension=dialnumber). Note, that customers often don't care about the difference between an extension or a dialnumber, but in SIP you must care.

What really helps is if you use custom CDR variables. Configure your asterisk to use the "custom_cdr" driver for CDR logging and maybe "custom_cel" for CEL logging. Then you can set CDR variables in your dialplan and they are automatically written to the CDR/CEL backend logging facility (e.g. ODBC).

As a last point to think about: Consider a A, B, and C to be persons. Let A call B. Let B put A on hold and ask back at person C if she can take over due to her experience. Transfer the call from A<->B to A<->C (B hangs up). How many CDRs and how many CELs do you think you get from this? And how are the fields filled? In CDRs, this looks like A talked to B for the whole time. Only by looking at the CELs you'll notice that there was a TRANSFER event which gives you hint. (Sorry this if from my memory, it might be completely different now).

With this rather scary answer, I urge you to spend a very long time on requirements engineering rather than starting with asterisk and kamailio. Ask what use cases the customer wants to cover with your solution. Believe me, you cannot cover everything. Think about having a flexible data format for storing your statistics in. Think about document based databases like MongoDB.

If you want to start with pure Asterisk, you should use the AMI. Maybe have some custom process listening to the events, aggregate them and make them available through a cache, so you don't have to query the AMI and put load on the Asterisk.

I hope this helps, but probably you're trying to achieve something completely different. :)

Have fun.

Let's connect asterisk server using asterisk -r

then type the command sip set debug on. You can find running logs and all sip request.

Can you please clear one thing. Do you want only logs? If it is then follow the below steps,

  1. open sip.conf and make sipdebug = yes so that sip messages are logged in debug file
  2. open asterisk.conf and check for astlogdir. it will give you debug file location. If you want you can change the location.
  3. open logger.conf and add log types whatever log you want to have under debug => e.g. debug => notice,warning,error,verbose,dtmf
  4. Restart the asterisk process to make this changes effective.

Apart from this if I need to store extra data or if I want to do something with the call then I write my own dial plan with custom function and I use mysql database to store my required data. If you want to write your own application then asterisk and asterisk-addon need to be installed on your system and start writing your own application under asterisk-addon/apps dir and place the shared library in lib or lib64, depending your system type. Don't forget to restart asterisk after making any type of changes. Let me know if I am able to clear your doubt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top