Unable to get Hangup Handler to execute

I’ve just installed a fresh FreePBX 17 machine today and I’m unable to get a basic hangup handler to run. Can you point out what I might be doing wrong? As of now, i simply want to print lines in the Asterisk log, but that’s not happening.

[from-internal-custom]
exten => _X.,1,Set(CHANNEL(hangup_handler_push)=hangup-handler,s,1)
exten => _X.,n,Return()

[hangup-handler]
exten => s,1,NoOp(Hangup Handler Executed for ${CDR(uniqueid)})
exten => s,n,System(echo "Call ended: ${CDR(src)} to ${CDR(dst)} at $(date)" >> /var/log/asterisk/hangup.log)
exten => s,n,Return()

After this, I reload the dialplan with asterisk -rx "dialplan reload" and then I give the system a call, answer, and hangup.

Then, I try to run cat /var/log/asterisk/full | grep "Hangup Handler" and there’s no results.

Here’s the full log snippet from the call:

[2025-06-18 17:24:50] VERBOSE[17219][C-00000019] app_dial.c: Called PJSIP/201/sip:201@--------;x-ast-orig-host=-------
[2025-06-18 17:24:50] VERBOSE[17219][C-00000019] app_dial.c: PJSIP/201-00000021 is ringing
[2025-06-18 17:24:52] VERBOSE[17219][C-00000019] app_dial.c: PJSIP/201-00000021 answered PJSIP/flowroute-00000020
[2025-06-18 17:24:52] VERBOSE[17239][C-00000019] bridge_channel.c: Channel PJSIP/201-00000021 joined 'simple_bridge' basic-bridge <048f2216-e5c1-4430-b712-037439e06967>
[2025-06-18 17:24:52] VERBOSE[17219][C-00000019] bridge_channel.c: Channel PJSIP/flowroute-00000020 joined 'simple_bridge' basic-bridge <048f2216-e5c1-4430-b712-037439e06967>
[2025-06-18 17:24:54] VERBOSE[17219][C-00000019] bridge_channel.c: Channel PJSIP/flowroute-00000020 left 'simple_bridge' basic-bridge <048f2216-e5c1-4430-b712-037439e06967>
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] bridge_channel.c: Channel PJSIP/201-00000021 left 'simple_bridge' basic-bridge <048f2216-e5c1-4430-b712-037439e06967>
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] app_stack.c: PJSIP/201-00000021 Internal Gosub(app-missedcall-hangup,201,1) start
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:1] NoOp("PJSIP/201-00000021", "Dialed: 201") in new stack
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:2] NoOp("PJSIP/201-00000021", "Caller: ") in new stack
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:3] GotoIf("PJSIP/201-00000021", "0?exit") in new stack
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:4] Set("PJSIP/201-00000021", "EXTENNUM=201") in new stack
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:5] Set("PJSIP/201-00000021", "FEXTENNUM=201") in new stack
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:6] GotoIf("PJSIP/201-00000021", "0?exit") in new stack
[2025-06-18 17:24:54] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:7] AGI("PJSIP/201-00000021", "agi://127.0.0.1/missedcallnotify.php,201,,201,0,,PJSIP/201-00000021,,,,") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Spawn extension (dialOne-with-exten, 201, 2) exited non-zero on 'PJSIP/flowroute-00000020'
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [h@dialOne-with-exten:1] Gosub("PJSIP/flowroute-00000020", "macro-hangupcall,s,1()") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@macro-hangupcall:1] Set("PJSIP/flowroute-00000020", "__MCVMSTATUS=") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@macro-hangupcall:2] Gosub("PJSIP/flowroute-00000020", "app-missedcall-hangup,s,1()") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:1] NoOp("PJSIP/flowroute-00000020", "Dialed: s") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:2] NoOp("PJSIP/flowroute-00000020", "Caller: ") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:3] GotoIf("PJSIP/flowroute-00000020", "0?exit") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:4] Set("PJSIP/flowroute-00000020", "EXTENNUM=s") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:5] Set("PJSIP/flowroute-00000020", "FEXTENNUM=s") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:6] GotoIf("PJSIP/flowroute-00000020", "0?exit") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:7] AGI("PJSIP/flowroute-00000020", "agi://127.0.0.1/missedcallnotify.php,s,,s,0,,PJSIP/flowroute-00000020,ANSWER,,,") in new stack
[2025-06-18 17:24:55] VERBOSE[17239][C-00000019] res_agi.c: <PJSIP/201-00000021>AGI Script agi://127.0.0.1/missedcallnotify.php completed, returning 0
[2025-06-18 17:24:55] VERBOSE[17239][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:8] Return("PJSIP/201-00000021", "") in new stack
[2025-06-18 17:24:55] VERBOSE[17239][C-00000019] app_stack.c: Spawn extension (from-internal, , 1) exited non-zero on 'PJSIP/201-00000021'
[2025-06-18 17:24:55] VERBOSE[17239][C-00000019] app_stack.c: PJSIP/201-00000021 Internal Gosub(app-missedcall-hangup,201,1) complete GOSUB_RETVAL=
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] res_agi.c: <PJSIP/flowroute-00000020>AGI Script agi://127.0.0.1/missedcallnotify.php completed, returning 0
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@app-missedcall-hangup:8] Return("PJSIP/flowroute-00000020", "") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@macro-hangupcall:3] GotoIf("PJSIP/flowroute-00000020", "1?theend") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx_builtins.c: Goto (macro-hangupcall,s,5)
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@macro-hangupcall:5] ExecIf("PJSIP/flowroute-00000020", "0?Set(CDR(recordingfile)=)") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [s@macro-hangupcall:6] Hangup("PJSIP/flowroute-00000020", "") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Spawn extension (macro-hangupcall, s, 6) exited non-zero on 'PJSIP/flowroute-00000020'
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] app_stack.c: PJSIP/flowroute-00000020 Internal Gosub(app-missedcall-hangup,201,1) start
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:1] NoOp("PJSIP/flowroute-00000020", "Dialed: 201") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:2] NoOp("PJSIP/flowroute-00000020", "Caller: ") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:3] GotoIf("PJSIP/flowroute-00000020", "0?exit") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:4] Set("PJSIP/flowroute-00000020", "EXTENNUM=201") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:5] Set("PJSIP/flowroute-00000020", "FEXTENNUM=201") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:6] GotoIf("PJSIP/flowroute-00000020", "0?exit") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:7] AGI("PJSIP/flowroute-00000020", "agi://127.0.0.1/missedcallnotify.php,201,,201,0,,PJSIP/flowroute-00000020,ANSWER,,,") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] res_agi.c: <PJSIP/flowroute-00000020>AGI Script agi://127.0.0.1/missedcallnotify.php completed, returning 0
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] pbx.c: Executing [201@app-missedcall-hangup:8] Return("PJSIP/flowroute-00000020", "") in new stack
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] app_stack.c: Spawn extension (macro-hangupcall, s, 6) exited non-zero on 'PJSIP/flowroute-00000020'
[2025-06-18 17:24:55] VERBOSE[17219][C-00000019] app_stack.c: PJSIP/flowroute-00000020 Internal Gosub(app-missedcall-hangup,201,1) complete GOSUB_RETVAL=
[2025-06-18 17:24:55] VERBOSE[17234][C-00000019] app_mixmonitor.c: MixMonitor close filestream (mixed)
[2025-06-18 17:24:55] VERBOSE[17234][C-00000019] app_mixmonitor.c: End MixMonitor Recording PJSIP/flowroute-00000020

You can’t add _X. to from-internal-custom and expect it to do anything useful, it will actually break a lot of things. Revert that change and follow the instructions in this thread for using a dialplan hook: Hooking for fun and income

1 Like

Using the macro hook [macro-dialout-one-predial-hook], I’m only able to get the hangup handler to run for inbound calls. Outbound calls do not execute this. Do you know why that might be?

The post linked above shows how to hook outbound calls, it’s a different context.

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