Asterisk Project : Hangup Cause This page last changed on Aug 18, 2012 by mjordan. ## Overview The Hangup Cause family of functions and dialplan applications allow for inspection of the hangup cause codes for each channel involved in a call. This allows a dialplan writer to determine, for each channel, who hung up and for what reason(s). Note that this extends the functionality available in the HANGUPCAUSE channel variable, by allowing a calling channel to inspect all called channel's hangup causes in a variety of dialling situations. Note that this feature replaces the technology specific mechanism of using the MASTER_CHANNEL function to access a SIP channel's SIP_CAUSE, as well as extends similar functionality to a variety of other channel drivers. ## Dialplan Functions and Applications ### HANGUPCAUSE_KEYS Used to obtain a comma separated list of all channels for which hangup causes are available. #### Example The following example shows one way of accessing the channels that have hangup cause related information after a Dial has completed. In this particular example, a parallel dial occurs to both SIP/foo and SIP/bar. A hangup handler has been attached to the calling channel, which executes the subroutine at handler,s,1 when the channel is hung up. This queries the HANGUPCAUSE_KEYS function for the channels with hangup cause information and prints the information as a Verbose message. On the CLI, this would look something like:
    Channels with hangup cause information: SIP/bar-00000002,SIP/foo-00000001
    [default]

    exten =&gt; s,1,NoOp()
    same =&gt; n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
    same =&gt; n,Dial(SIP/foo&amp;SIP/bar,10)
    same =&gt; n,Hangup()

    [handler]

    same =&gt; s,1,NoOp()
    same =&gt; n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
    same =&gt; n,Verbose(0, Channels with hangup cause information: ${HANGUPCAUSE_STRING})
    same =&gt; n,Return()
### HANGUPCAUSE Used to obtain hangup cause information for a specific channel. For a given channel, there are two sources of hangup cause information: The channel technology specific hangup cause information A text description of the Asterisk specific hangup cause Note that in some cases, the hangup causes returned may not be reflected in Hangup Cause Mappings. For example, if a Dial to a SIP UA is cancelled by Asterisk, the SIP UA may not have returned any final responses to Asterisk. In these cases, the last known technology code will be returned by the function. #### Example This example illustrates obtaining hangup cause information for a parallel dial to SIP/foo and SIP/bar. A hangup handler has been attached to the calling channel, which executes the subroutine at handler,s,1 when the channel is hung up. This queries the hangup cause information using the HANGUPCAUSE_KEYS function and the HANGUPCAUSE function. The channels returned from HANGUPCAUSE_KEYS are parsed out, and each is queried for their hangup cause information. The technology specific cause code as well as the Asterisk cause code are printed to the CLI.
    [default]

    exten =&gt; s,1,NoOp()
    same =&gt; n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
    same =&gt; n,Dial(SIP/foo&amp;SIP/bar,10)
    same =&gt; n,Hangup()

    [handler]

    exten =&gt; s,1,NoOp()

    same =&gt; n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})

    ; start loop
    same =&gt; n(hu_begin),NoOp()

    ; check exit condition (no more array to check)
    same =&gt; n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})}=0]?hu_exit)

    ; pull the next item
    same =&gt; n,Set(ARRAY(item)=${HANGUPCAUSE_STRING})
    same =&gt; n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:${LEN(${item})}})

    ; display the channel name and cause codes
    same =&gt; n,Verbose(0, Got Channel ID ${item} with Technology Cause Code ${HANGUPCAUSE(${item},tech)}, Asterisk Cause Code ${HANGUPCAUSE(${item},ast)})

    ; check exit condition (no more array to check)
    same =&gt; n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})}=0]?hu_exit)

    ; we still have entries to process, so strip the leading comma
    same =&gt; n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})

    ; go back to the beginning of the loop
    same =&gt; n,Goto(hu_begin)

    same =&gt; n(hu_exit),NoOp()
    same =&gt; n,Return()
### HangupCauseClear Used to remove all hangup cause information currently stored. #### Example The following example clears the hangup cause information from the channel if SIP/foo fails to answer and execution continues in the dialplan. The hangup handler attached to the channel will thus only report the the name of the last channel dialled.
    exten =&gt; s,1,NoOp()
    same =&gt; n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
    same =&gt; n,Dial(SIP/foo,10)
    same =&gt; n,HangupCauseClear()
    same =&gt; n,Dial(SIP/bar,10)
    same =&gt; n,Hangup()

    [handler]

    same =&gt; s,1,NoOp()
    same =&gt; n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
    same =&gt; n,Verbose(0, Channels with hangup cause information: ${HANGUPCAUSE_STRING})
    same =&gt; n,Return()

Document generated by Confluence on Nov 02, 2012 17:42