Asterisk AGI script falls when caller hangup

I'm having the simple AGI script, I need to dial 101 extension by calling 6666 number and calculate answered time after call. Everything works fine when callee hangup, but when caller hangup agi script falls with returning 4.
Sorry for my English)

agi.php

#!/usr/bin/php -q
<?php  
require('include/phpagi.php');
$agi = new AGI();
$agi->answer();
$agi->exec("Dial", "SIP/101");
$result = $agi->get_variable("ANSWEREDTIME");
file_put_contents("/tmp/test.txt", json_encode($result));
$agi->hangup();
?>

**sip.conf**
[general]
externaddr=51.15.53.237:5060
localnet=10.18.222.53/255.255.255.0 ; локальная сеть
language=ru
context=default
allowoverlap=no
udpbindaddr=0.0.0.0
tcpenable=no
tcpbindaddr=0.0.0.0
transport=udp
srvlookup=yes
allowguest=no
limitonpeers=yes

[authentication]

[managers-phones](!)
type=friend
context=call-out
secret=qwerty
host=dynamic
nat=yes
qualify=yes
canreinvite=no
callgroup=1
pickupgroup=1
call-limit=5
dtmfmode=auto
disallow=all
allow=alaw
allow=ulaw
allow=g729
allow=g723
allow=g722

[100](managers-phones)
callerid="Number 100" <100>
[101](managers-phones)
callerid="Number 101" <101>

**extensions.conf**
[general]
static=yes
writeprotect=no
[globals]
[default]

[handup-sip]
exten => _X!,1,HangUp()

[call-out]
exten => 6666,1,AGI(agi.php)
exten => _XXX,1,Dial(SIP/${EXTEN})


include => handup-sip

Console output when callee hangup:
== Using SIP RTP CoS mark 5
       > 0x7fabe000deb0 -- Strict RTP learning after remote address set to: 176.213.58.47:7078
    -- Executing [6666@call-out:1] AGI("SIP/100-00000016", "agi.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/agi.php
<SIP/100-00000016>AGI Tx >> agi_request: agi.php
<SIP/100-00000016>AGI Tx >> agi_channel: SIP/100-00000016
<SIP/100-00000016>AGI Tx >> agi_language: ru
<SIP/100-00000016>AGI Tx >> agi_type: SIP
<SIP/100-00000016>AGI Tx >> agi_uniqueid: 1594145722.33
<SIP/100-00000016>AGI Tx >> agi_version: 16.11.1
<SIP/100-00000016>AGI Tx >> agi_callerid: 100
<SIP/100-00000016>AGI Tx >> agi_calleridname: Number 100
<SIP/100-00000016>AGI Tx >> agi_callingpres: 0
<SIP/100-00000016>AGI Tx >> agi_callingani2: 0
<SIP/100-00000016>AGI Tx >> agi_callington: 0
<SIP/100-00000016>AGI Tx >> agi_callingtns: 0
<SIP/100-00000016>AGI Tx >> agi_dnid: 6666
<SIP/100-00000016>AGI Tx >> agi_rdnis: unknown
<SIP/100-00000016>AGI Tx >> agi_context: call-out
<SIP/100-00000016>AGI Tx >> agi_extension: 6666
<SIP/100-00000016>AGI Tx >> agi_priority: 1
<SIP/100-00000016>AGI Tx >> agi_enhanced: 0.0
<SIP/100-00000016>AGI Tx >> agi_accountcode:
<SIP/100-00000016>AGI Tx >> agi_threadid: 140374906681088
<SIP/100-00000016>AGI Tx >>
<SIP/100-00000016>AGI Rx << ANSWER
       > 0x7fabe000deb0 -- Strict RTP switching to RTP target address 176.213.58.47:7078 as source
<SIP/100-00000016>AGI Tx >> 200 result=0
<SIP/100-00000016>AGI Rx << EXEC Dial SIP/101
    -- AGI Script Executing Application: (Dial) Options: (SIP/101)
  == Using SIP RTP CoS mark 5
    -- Called SIP/101
    -- SIP/101-00000017 is ringing
       > 0x7fabd000cb70 -- Strict RTP learning after remote address set to: 176.213.58.47:8000
    -- SIP/101-00000017 answered SIP/100-00000016
    -- Channel SIP/101-00000017 joined 'simple_bridge' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
    -- Channel SIP/100-00000016 joined 'simple_bridge' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
       > Bridge dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b: switching from simple_bridge technology to native_rtp
       > Locally RTP bridged 'SIP/100-00000016' and 'SIP/101-00000017' in stack
       > 0x7fabd000cb70 -- Strict RTP switching to RTP target address 176.213.58.47:8000 as source
       > 0x7fabe000deb0 -- Strict RTP learning complete - Locking on source address 176.213.58.47:7078
    -- Channel SIP/101-00000017 left 'native_rtp' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
    -- Channel SIP/100-00000016 left 'native_rtp' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
<SIP/100-00000016>AGI Tx >> 200 result=-1
<SIP/100-00000016>AGI Rx << GET VARIABLE ANSWEREDTIME
<SIP/100-00000016>AGI Tx >> 200 result=1 (6)
<SIP/100-00000016>AGI Rx << HANGUP
<SIP/100-00000016>AGI Tx >> 200 result=1
    -- <SIP/100-00000016>AGI Script agi.php completed, returning 4
  == Spawn extension (call-out, 6666, 1) exited non-zero on 'SIP/100-00000016'

Console output when caller hangup:
== Using SIP RTP CoS mark 5
       > 0x7fabe000deb0 -- Strict RTP learning after remote address set to: 176.213.58.47:7078
    -- Executing [6666@call-out:1] AGI("SIP/100-0000001e", "agi.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/agi.php
<SIP/100-0000001e>AGI Tx >> agi_request: agi.php
<SIP/100-0000001e>AGI Tx >> agi_channel: SIP/100-0000001e
<SIP/100-0000001e>AGI Tx >> agi_language: ru
<SIP/100-0000001e>AGI Tx >> agi_type: SIP
<SIP/100-0000001e>AGI Tx >> agi_uniqueid: 1594145890.45
<SIP/100-0000001e>AGI Tx >> agi_version: 16.11.1
<SIP/100-0000001e>AGI Tx >> agi_callerid: 100
<SIP/100-0000001e>AGI Tx >> agi_calleridname: Number 100
<SIP/100-0000001e>AGI Tx >> agi_callingpres: 0
<SIP/100-0000001e>AGI Tx >> agi_callingani2: 0
<SIP/100-0000001e>AGI Tx >> agi_callington: 0
<SIP/100-0000001e>AGI Tx >> agi_callingtns: 0
<SIP/100-0000001e>AGI Tx >> agi_dnid: 6666
<SIP/100-0000001e>AGI Tx >> agi_rdnis: unknown
<SIP/100-0000001e>AGI Tx >> agi_context: call-out
<SIP/100-0000001e>AGI Tx >> agi_extension: 6666
<SIP/100-0000001e>AGI Tx >> agi_priority: 1
<SIP/100-0000001e>AGI Tx >> agi_enhanced: 0.0
<SIP/100-0000001e>AGI Tx >> agi_accountcode:
<SIP/100-0000001e>AGI Tx >> agi_threadid: 140374906681088
<SIP/100-0000001e>AGI Tx >>
<SIP/100-0000001e>AGI Rx << ANSWER
       > 0x7fabe000deb0 -- Strict RTP switching to RTP target address 176.213.58.47:7078 as source
<SIP/100-0000001e>AGI Tx >> 200 result=0
<SIP/100-0000001e>AGI Rx << EXEC Dial SIP/101
    -- AGI Script Executing Application: (Dial) Options: (SIP/101)
  == Using SIP RTP CoS mark 5
    -- Called SIP/101
    -- SIP/101-0000001f is ringing
       > 0x7fac0000c120 -- Strict RTP learning after remote address set to: 176.213.58.47:8000
    -- SIP/101-0000001f answered SIP/100-0000001e
    -- Channel SIP/101-0000001f joined 'simple_bridge' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
    -- Channel SIP/100-0000001e joined 'simple_bridge' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
       > Bridge e8f305f8-5d84-4ae7-8be5-babcdefdb5ef: switching from simple_bridge technology to native_rtp
       > Locally RTP bridged 'SIP/100-0000001e' and 'SIP/101-0000001f' in stack
       > 0x7fac0000c120 -- Strict RTP switching to RTP target address 176.213.58.47:8000 as source
    -- Channel SIP/101-0000001f left 'native_rtp' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
    -- Channel SIP/100-0000001e left 'native_rtp' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
<SIP/100-0000001e>AGI Tx >> 200 result=-1
<SIP/100-0000001e>AGI Rx << GET VARIABLE ANSWEREDTIME
<SIP/100-0000001e>AGI Tx >> 200 result=1 (4)
<SIP/100-0000001e>AGI Rx << HANGUP
<SIP/100-0000001e>AGI Tx >> 200 result=1
    -- <SIP/100-0000001e>AGI Script agi.php completed, returning 4
  == Spawn extension (call-out, 6666, 1) exited non-zero on 'SIP/100-0000001e'

As a result when caller hangup there is no file /tmp/test.txt, but when callee hangup there is. Where is problem? Asterisk 16 LTS builded from source PHP 7.2.24-0ubuntu0.18.04.6

Upvotes: 0

Views: 2736

Answers (0)

Related Questions