Turn On SIP Debugging From DialPlan

Home » Asterisk Users » Turn On SIP Debugging From DialPlan
Asterisk Users 12 Comments

I have some troublesome numbers that I would like to capture the SIP
dialogue when I am calling them. When I am about to dial the number, is there any way to turn on SIP debugging in the dial plan before I make the call? (and turn it off after the call is completed?)

12 thoughts on - Turn On SIP Debugging From DialPlan

  • Hi Derek,

    SIP debug can be enabled via Asterisk CLI (console) with the command:

    asterisk> sip set debug on

    If you know via what trunk your call goes, you can use the following command instead:

    asterisk> sip set debug ip xxx.xxx.xxx.xxx

    Where the xxx is the IP of your trunk (voip to pstn provider).

    Affter you make all your test, simply issue:

    asterisk> sip set debug off

    And all the SIP conversation are saved in your full log file.

    More info here:


    If what you want is test your dialplan, simply use the command:

    asterisk> dialplan show xxx@your_context

    Where xxx is the number you want to dial, from the context asigned to your extension.


    El 17/2/2017 19:44, “Derek Andrew” escribió:

  • The SIP trace will be adequate but this is on a remote system with limited disk space.

    I would love to turn on debugging while making the troublesome calls, then turn it off afterward.

    Tcpdump is great, but starting it and stopping it and keeping all that data would still be an issue.


  • You can tell it to just capture SIP traffic and not the RTP traffic. Nice write up of using TCPdump and wireshark can be found here:


    BTW, I have found this works really well in trying to debug RTP traffic as well. Wireshark just does the right thing in putting audio back together. Very helpful in tracking down in and out of band DTMF
    problems that we were having with various carriers.


  • Hi

    I don’t know if works, but you can try this:

    System(tcpdump -nq -s 0 -i eth0 -w /tmp/sip.pcap port 5060
    or udp portrange 10000-20000 &);
    System(pkill tcpdump);

    Or whitout RTP:

    System(tcpdump -nq -s 0 -i eth0 -w /tmp/sip.pcap port 5060
    System(pkill tcpdump);

    Probably the last messages of SIP will be lost, BYE for example.

    2017-02-17 20:43 GMT-02:00 Derek Andrew :

  • But how do you turn on the debugging from the dialplan? What would be cool is:

    same => n,TURN ON DEBUGGING

  • Yes, I agree. Tcpdump is one of my favourite programs. I need to enable it and disable it from the dialplan though.

  • You could use the system() application as suggested before.

    You could also just start a console packet logger and just leave it running:

    sudo ngrep -O ngrep.pcap -W byline -d any port 5060

    This will only capture packets containing your ANI which includes INVITE, Trying, OK, ACK, and BYE — basically, the entire SIP dialog for the call.

    This will only take about 4kB per call, so you can log over 250 calls per mega-byte so I’m guessing that should be possible.

  • Hi,

    If you are ok with starting debug via external system call, why not to use something like this (I used to use something similar, it worked):

    exten => _XXX,1,System(/usr/sbin/asterisk -rx ‘sip set debug peer PEER’)
    same => n,Set(debug_on=1)
    same => n,Dial(SIP/PEER/${EXTEN})

    exten => h,1,GotoIf($[${debug_on} == 1]?undebug)
    same => n,Hangup same => n(undebug),System(( sleep 3 \; /usr/sbin/asterisk -rx ‘sip set debug off’ ) &)
    same => n,Set(debug_on=0)
    same => n,Hangup

    I don’t know your setup, your dialplan logic, but I’m sure you can adapt it to your needs.