newspaint

Documenting Problems That Were Difficult To Find The Answer To

Monthly Archives: July 2019

Stop Hangup Executing Default Dialplan in Asterisk

I had an incoming trunk configured from a VoIP provider to my Asterisk server. When somebody called in but hung-up before I answered I’d get the following debug message:

me@host:~$ sudo asterisk -rvvvv

  == Spawn extension (mycontext, myvoip, 5) exited non-zero on 'SIP/myvoip-0000009a'
    -- Executing [h@mycontext:1] ...
    -- Executing [h@mycontext:2] ...
    -- Executing [h@mycontext:3] ...
    -- Executing [h@mycontext:4] ...
    -- Executing [h@mycontext:5] Dial("...")

For whatever reason a call that isn’t picked up and terminated appears to re-run through the entire dialplan but with “h” as the dialled extension.

So how to exclude?

My dialplan was pretty simple:

[mycontext]
exten => _.,1,NoOp()
  same => n,NoOp()
  same => n,NoOp()
  same => n,NoOp()
  same => n,Dial(SIP/123)
  same => n,HangUp()

At first I tried to create a hangup-specific extension:

[mycontext]
exten => h,1,NoOp()
exten => _.,1,NoOp()
  same => n,NoOp()
  same => n,NoOp()
  same => n,NoOp()
  same => n,Dial(SIP/123)
  same => n,HangUp()

But this still also matched my generic catch-all dialplan. This was evident by asking asterisk what would happen if the hangup extension was called:

me@host:~$ sudo asterisk -rvvvv
asterisk*CLI> dialplan reload
asterisk*CLI> dialplan show h@mycontext
[ Context 'mycontext' created by 'pbx_config' ]
  'h' =>            1. NoOp()                                     [pbx_config]
  '_.' =>           1. NoOp()                                     [pbx_config]
                    2. NoOp()                                     [pbx_config]
                    3. NoOp()                                     [pbx_config]
                    4. NoOp()                                     [pbx_config]
                    5. Dial(SIP/123)                              [pbx_config]
                    6. HangUp()                                   [pbx_config]

-= 2 extensions (7 priorities) in 1 context. =-

So what I did was add a test for the “h” extension and if it matched then skip to the end of the dialplan:

[mycontext]
exten => _.,1,NoOp()
  same => n,GotoIf($["${EXTEN}" = "h"]?theend)
  same => n,NoOp()
  same => n,NoOp()
  same => n,NoOp()
  same => n,Dial(SIP/123)
  same => n,HangUp()
  same => n(theend),NoOp()