Don't stop Record and/or don't exit from ChanSpy

Don’t stop Record after silence and/or don’t exit from ChanSpy after call hangup.

My dialplan :

[code][check-for-lost-call]
exten => connect,1,Noop(Connect to channel “${check_channel}”)
exten => connect,n,ChanSpy(${check_channel},qoE)
exten => connect,n,Hangup
exten => check,1,Noop(Check channel ${check_channel})
exten => check,n,Record(${file}:wav,120,q)
exten => check,n,System(/usr/local/scripts/asterisk/check_for_lost_call.php disconnect “${check_channel}” “${file}.wav”)
exten => check,n,Hangup

[from-gag-to-pes]
exten => _X.,1,Noop(Call from “${CALLERID(all)}” to “${EXTEN}”)
exten => _X.,n,Set(GROUP()=${CALLERID(num)})
exten => _X.,n,System(/usr/local/scripts/asterisk/check_for_lost_call.php connect “${CHANNEL}”)
exten => _X.,n,Set(route=${FILTER(0123456789,${EXTEN})})
exten => _X.,n,Dial(${ASTBOX}/${route})
exten => _X.,n,Hangup[/code]

check_for_lost_call.php

[code]#!/usr/bin/php -q

<?php $dir_call="/var/spool/asterisk/outgoing/"; $dir_tmp="/var/spool/asterisk/tmp/"; if ($argv[1]=='connect') { $fn=$dir_tmp.str_replace("/","_",$argv[2]); $f = fopen($fn, "w"); fwrite($f, "CallerID: AsteriskPBX\n"); fwrite($f, "Channel: LOCAL/connect@check-for-lost-call\n"); fwrite($f, "Context: check-for-lost-call\nExtension: check\nPriority: 1\n"); fwrite($f, "Set: CHANNEL(language)=ru\n"); fwrite($f, "Set: check_channel=$argv[2]\n"); fwrite($f, "Set: file=$dir_tmp".time()."_".str_replace("/","_",$argv[2])."\n"); fclose($f); rename($fn, $dir_call); } elseif ($argv[1]=='disconnect') { exec("asterisk -rx \"channel request hangup $argv[2]\"",$a); } ?>[/code]

My action :

  1. Make call into “from-gag-to-pes”
  2. “check_for_lost_call.php” make callfile and dial to “LOCAL/connect@check-for-lost-call” and connect with “check-for-lost-call,check,1”
  3. End call

In some cases call form “check_for_lost_call.php” not ended after I hangup and in console I see :

CLI> core show channels concise Local/connect@check-for-lost-call-6777;1!check-for-lost-call!check!2!Up!Record!/var/spool/asterisk/tmp/1343889635_SIP_office-gag-0000064f:wav,120,,q!!!!3!16207!(None)!1343889635.5470 Local/connect@check-for-lost-call-6777;2!check-for-lost-call!connect!2!Up!ChanSpy!SIP/office-gag-0000064f,qoS!!!!3!16207!(None)!1343889635.5471

I have two question :

  1. Why Record don’t stop after 120 seconds of silence ?
  2. Why ChanSpy don’t stop after call hangup ?

Any ideas?

[2012-08-17 17:57:05] DEBUG[2699] pbx.c: Launching 'ChanSpy' [2012-08-17 17:57:05] VERBOSE[2699] pbx.c: -- Executing [connect@check-for-lost-call:4] ChanSpy("Local/connect@check-for-lost-call-d1a6;2", "DAHDI/i2/12345678-12ea,qobE") in new stack [2012-08-17 17:57:05] DEBUG[2698] pbx.c: Launching 'NoOp' [2012-08-17 17:57:05] VERBOSE[2698] pbx.c: -- Executing [check@check-for-lost-call:1] NoOp("Local/connect@check-for-lost-call-d1a6;1", "Check channel DAHDI/i2/12345678-12ea") in new stack [2012-08-17 17:57:05] DEBUG[2698] pbx.c: Launching 'Record' [2012-08-17 17:57:05] VERBOSE[2698] pbx.c: -- Executing [check@check-for-lost-call:2] Record("Local/connect@check-for-lost-call-d1a6;1", "/var/spool/asterisk/tmp/1345211779_DAHDI_i2_12345678-12ea.wav,120,864000,qs") in new stack [2012-08-17 17:57:05] DEBUG[2698] dsp.c: Setup tone 1100 Hz, 500 ms, block_size=160, hits_required=21 [2012-08-17 17:57:05] DEBUG[2698] dsp.c: Setup tone 2100 Hz, 2600 ms, block_size=160, hits_required=116 [2012-08-17 17:57:05] VERBOSE[11620] sig_pri.c: -- Span 2: Channel 0/20 got hangup request, cause 16 [2012-08-17 17:57:05] DEBUG[2691] channel.c: Didn't get a frame from channel: DAHDI/i2/12345678-12ea [2012-08-17 17:57:05] DEBUG[2691] channel.c: Bridge stops bridging channels DAHDI/i2/12345678-12ea and SIP/office-gag-0000123f [2012-08-17 17:57:05] DEBUG[2691] channel.c: Hanging up channel 'SIP/office-gag-0000123f' [2012-08-17 17:57:05] DEBUG[2691] chan_sip.c: Hangup call SIP/office-gag-0000123f, SIP callid 043faf27562a3d1b3acac41e221dd1d6@10.252.0.246:5060 [2012-08-17 17:57:05] DEBUG[2691] chan_sip.c: update_call_counter(09876543) - decrement call limit counter on hangup [2012-08-17 17:57:05] DEBUG[2691] chan_sip.c: Call to peer 'office-gag' removed from call limit 50 [2012-08-17 17:57:05] DEBUG[2691] res_rtp_asterisk.c: Setting RTCP address on RTP instance '0xe905a88' [2012-08-17 17:57:05] VERBOSE[2691] chan_sip.c: Scheduling destruction of SIP dialog '043faf27562a3d1b3acac41e221dd1d6@10.252.0.246:5060' in 6400 ms (Method: INVITE) [2012-08-17 17:57:05] DEBUG[2691] chan_sip.c: Session timer stopped: 252750 - 043faf27562a3d1b3acac41e221dd1d6@10.252.0.246:5060 [2012-08-17 17:57:05] DEBUG[2691] chan_sip.c: Strict routing enforced for session 043faf27562a3d1b3acac41e221dd1d6@10.252.0.246:5060 [2012-08-17 17:57:05] VERBOSE[2691] chan_sip.c: set_destination: Parsing <sip:09876543@10.252.0.254:5060> for address/port to send to [2012-08-17 17:57:05] VERBOSE[2691] chan_sip.c: set_destination: set destination to 10.252.0.254:5060 [2012-08-17 17:57:05] VERBOSE[2691] chan_sip.c: Reliably Transmitting (NAT) to 10.252.0.254:5060: [2012-08-17 17:57:05] DEBUG[2691] chan_sip.c: Trying to put 'BYE sip:089' onto UDP socket destined for 10.252.0.254:5060 [2012-08-17 17:57:05] DEBUG[2691] app_dial.c: Exiting with DIALSTATUS=ANSWER. [2012-08-17 17:57:05] DEBUG[2691] pbx.c: Spawn extension (from-gagarina75,09876543,5) exited non-zero on 'DAHDI/i2/12345678-12ea' [2012-08-17 17:57:05] VERBOSE[2691] pbx.c: == Spawn extension (from-gagarina75, 09876543, 5) exited non-zero on 'DAHDI/i2/12345678-12ea' [2012-08-17 17:57:05] DEBUG[2691] channel.c: Soft-Hanging up channel 'DAHDI/i2/12345678-12ea' [2012-08-17 17:57:05] DEBUG[2691] channel.c: Hanging up channel 'DAHDI/i2/12345678-12ea' [2012-08-17 17:57:05] DEBUG[2691] chan_dahdi.c: dahdi_hangup(DAHDI/i2/12345678-12ea) [2012-08-17 17:57:05] DEBUG[2691] chan_dahdi.c: Set option AUDIO MODE, value: ON(1) on DAHDI/i2/12345678-12ea [2012-08-17 17:57:05] DEBUG[2691] sig_pri.c: sig_pri_hangup 51 [2012-08-17 17:57:05] DEBUG[2691] sig_pri.c: Channel 'DAHDI/i2/12345678-12ea' MOH-Event: SIG_PRI_MOH_EVENT_RESET in state SIG_PRI_MOH_STATE_IDLE [2012-08-17 17:57:05] DEBUG[2691] sig_pri.c: Channel 'DAHDI/i2/12345678-12ea' MOH-Next-State: $ [2012-08-17 17:57:05] DEBUG[2691] sig_pri.c: Not yet hungup... Calling hangup with cause 16, and clearing call [2012-08-17 17:57:05] DEBUG[2691] chan_dahdi.c: Disabled echo cancellation on channel 51 [2012-08-17 17:57:05] DEBUG[2691] chan_dahdi.c: Set option TDD MODE, value: OFF(0) on DAHDI/i2/12345678-12ea [2012-08-17 17:57:05] DEBUG[2691] chan_dahdi.c: Updated conferencing on 51, with 0 conference users [2012-08-17 17:57:05] DEBUG[2691] chan_dahdi.c: Set option AUDIO MODE, value: OFF(0) on DAHDI/i2/12345678-12ea [2012-08-17 17:57:05] VERBOSE[2691] chan_dahdi.c: -- Hungup 'DAHDI/i2/12345678-12ea'

Call ‘12345678-12ea’ is hangup, but ChanSpy dont’t exit and Record dont’t stop after 120 sec of silence.

likely it is shown in the case when a call СhanSpy occurs simultaneously with the completion of the call

I modified

exten => check,1,Noop(Check channel ${check_channel}) exten => check,n,Record(${file}:wav,120,,q) exten => check,n,System(/usr/local/scripts/asterisk/check_for_lost_call.php disconnect "${check_channel}" "${file}.wav") exten => check,n,Hangup
toexten => check,1,Noop(Check channel ${check_channel}) exten => check,n,Set(time=${EPOCH}) exten => check,n,Record(${file}:wav,120,,q) exten => check,n,Noop(RECORD_STATUS ${RECORD_STATUS}) exten => check,n,Set(time=${MATH(${EPOCH}-${time},int)}) exten => check,n,System(/usr/local/scripts/asterisk/check_for_lost_call.php disconnect "${check_channel}" "${file}.wav") exten => check,n,Hangup
and see that sometime RECORD_STATUS=TIMEOUT and time=126 and sometimes RECORD_STATUS=HANGUP and time=121. In all cases the channel which ChanSpy is connected has long been completed.

I think that this is not normal