AMI Redirect Action

Hi,

I am Using AMI Redirect action on Asterisk 1.8.8. I am using following code:-

$file = fsockopen(“localhost”,“5038”);
fwrite($file, “Action: Login\r\n”);
fwrite($file, “UserName: admin\r\n”);
fwrite($file, “Secret: alliance\r\n”);
$actionid=rand(000000000,9999999999);
fwrite($file, “ActionID: $actionid\r\n\r\n”);
stream_set_timeout($file, 1);
$response = stream_get_contents($file);
fwrite($file, “Action: Redirect\r\n”);
fwrite($file, “Channel: $callerchannel\r\n”); //Caller Channel—DAHDI
fwrite($file, “ExtraChannel: $extn\r\n”); //SIP Extension
fwrite($file, “Exten: 1009\r\n”);
fwrite($file, “ExtraExten: 1009\r\n”);
fwrite($file, “Context: konfer\r\n”);
fwrite($file, “ExtraContext: konfer\r\n”);
fwrite($file, “Priority: 1\r\n”);
fwrite($file, “ExtraPriority: 1\r\n”);
$actionid2=rand(000000000,9999999999);
fwrite($file, “ActionID: $actionid2\r\n\r\n”);
echo $response = stream_get_contents($file);
fwrite($file, “Action: Logoff\r\n”);
$actionid3=rand(000000000,9999999999);
fwrite($file, “ActionID: $actionid3\r\n\r\n”);
$response = stream_get_contents($file);
fclose($file);

Sometimes it works perfectly and some times it gives following error:

-- Executing [1009@konfer:1] Set("DAHDI/i1/01140517729-2b", "hex=1009") in new stack
-- Executing [1009@konfer:2] Set("DAHDI/i1/01140517729-2b", "type=konfer") in new stack
-- Executing [1009@konfer:3] Set("DAHDI/i1/01140517729-2b", "MEETME_RECORDINGFILE=/var/www/callcenter/recording/konfer-1009-132622028387") in new stack
-- Executing [1009@konfer:4] MeetMe("DAHDI/i1/01140517729-2b", "1009,1rq") in new stack

[Jan 10 10:32:50] WARNING[24550]: channel.c:5795 __ast_channel_masquerade: Can’t setup masquerade. One or both channels is dead. (AsyncGoto/SIP/110-0000002d <-- SIP/110-0000002d)
[Jan 10 10:32:50] WARNING[24550]: cdr.c:940 ast_cdr_end: CDR on channel ‘AsyncGoto/SIP/110-0000002d’ has no answer time but is ‘ANSWERED’

== Parsing ‘/etc/asterisk/meetme.conf’: == Found
– Created MeetMe conference 1023 for conference ‘1009’
> Starting recording of MeetMe Conference 1009 into file /var/www/callcenter/recording/konfer-1009-132622028387.wav.
== Manager ‘admin’ logged off from 127.0.0.1
== Manager ‘admin’ logged on from 127.0.0.1

I have analyze it… It gives above error in first attempt and start working fine after 2nd or 3rd try. If I try it after 2-3 hours again it gives error on 1st attempt. Can Anybody help me on this issue. why this problem is coming do i need to make some configuration changes.

Thanks in Advance

If one of the channels hasn’t really hung up, it is a bug, and not a configuration error.

It is possible that a co-factor in such a bug would be that a previous masquerade had not yet completed, so knowing the pre-conditions you are using might help.

Hi Devid,

I am not geeting what you want to say? What should I do now? When I am trying to Redirect 2 bridged channels to a conference room using AMI. sometime one channel (Sip Extension) gets hangup and some time works fine. What could be possible causes of this issue?

Case 1: Someone really did hangup.

Case 2: There is a bug in Asterisk.

Case 2a: That bug results in the channel name lookup finding an old version of the channel structure because of a race involving the previous action on the channel.

Case 2b: That bug manifests even when the channel is in a stable state.

In case 2a, knowing what the previous action on the channel was, and how your program tries to ensure that it is complete may lead to a suggestion of the correct method for ensuring it is complete, and therefore avoiding the race.

Case 2b can only be fixed by fixing the source code.

Hi Devid,

Thanks for your reply.

In case of 2a, how to ensure that last action was complete? i am not checking the last action. how to check it and how to resolve it? Is there any way to forcefully mark it complete?

Regards

Only you know what the last action was. You wait until you see the event associated with the completion of that action.

I am seeing the same behaviour with ConfBridge. About every 5th call fails with one of the redirected channels hanging up before it arrives in the [meetme-build] context. I am trying to put 3 channels into a ConfBridge. The first is placed from the context [phones] then the other two are sent to the [meetme-build] context from an AMI Redirect. I have tried to change the Wait() times for up to 1 second with no luck.

– Executing [2@phones:7] UserEvent(“SIP/CO999x1001.1-000000fe”, “ConfJoin,Conf: 577,Channel: SIP/CO999x1001.1-000000fe,Meetme: 245596759646139577,Uniqueid: 1328840340.1063”) in new stack
== Spawn extension (meetme-build, 577, 1) exited non-zero on ‘SIP/audiocodes-1-000000fc’
– Executing [577@meetme-build:1] Answer(“SIP/audiocodes-1-000000fc”, “”) in new stack
– Executing [577@meetme-build:2] ConfBridge(“SIP/audiocodes-1-000000fc”, “245596759646139577,1q”) in new stack
– Executing [2@phones:8] ConfBridge(“SIP/CO999x1001.1-000000fe”, “245596759646139577,1q”) in new stack
[Feb 9 19:19:00] WARNING[26185]: channel.c:5843 __ast_channel_masquerade: Can’t setup masquerade. One or both channels is dead. (AsyncGoto/SIP/CO999x1002.3-000000fd <-- SIP/CO999x1002.3-000000fd)
– Executing [h@phones:1] NoOp(“Bridge/SIP/CO999x1001.1-000000fe”, “phones”) in new stack
– Executing [h@phones:2] Hangup(“Bridge/SIP/CO999x1001.1-000000fe”, “”) in new stack
== Spawn extension (phones, h, 2) exited non-zero on ‘Bridge/SIP/CO999x1001.1-000000fe’
– Executing [h@meetme-build:1] NoOp(“Bridge/SIP/audiocodes-1-000000fc”, “meetme-build”) in new stack
– Executing [h@meetme-build:2] Hangup(“Bridge/SIP/audiocodes-1-000000fc”, “”) in new stack
== Spawn extension (meetme-build, h, 2) exited non-zero on ‘Bridge/SIP/audiocodes-1-000000fc’

[meetme-build]
exten => _XXX,1,Answer()
exten => _XXX,n,Wait(0.1)
exten => XXX,n,ConfBridge(${Conf${EXTEN}},1q)
exten => _XXX,n,Hangup()

This is in the lab,

exten => s,1,Hangup()
exten => h,1,Noop(meetme-build)
exten => h,n,Hangup()

[phones]
exten => _Z,1,Answer()
exten => _Z,2,MacroExclusive(SetCONFJOINPOSITION, ${EXTEN})
exten => _Z,3,GotoIf($[${Conf}=ErrorConference]?10)
exten => _Z,4,GotoIf($[${Conf}=ErrorExtension]?13)
exten => _Z,5,GotoIf($[${Conf}=ErrorExtensionRedial]?16)
exten => _Z,6,GotoIf($[${Conf}=ErrorExit]?21)
exten => Z,7,UserEvent(ConfJoin,Conf: ${Conf},Channel: ${CHANNEL},Meetme: ${Conf$[${Conf:}]},Uniqueid: UNIQUEID})
exten => Z,8,ConfBridge(${Conf${Conf}},1q)
exten => _Z,9,Hangup()
exten => _Z,10,SayDigits(${EXTEN})
exten => _Z,11,Playback(conf-invalid)
exten => _Z,12,Hangup()
exten => _Z,13,SayDigits(${EXTEN})
exten => _Z,14,Playback(invalid)
exten => _Z,15,Hangup()
exten => _Z,16,SayDigits(${EXTEN})
exten => _Z,17,Playback(invalid)
exten => _Z,18,UserEvent(RingBack,extension: ${EXTEN},Channel: ${CHANNEL},Position: ${Posn},ControllerCallID: ${ControllerCallID},Uniqueid: ${UNIQUEID})
exten => _Z,19,Gosub(ExtenReDial,s,1(${Posn},${Line}))
exten => _Z,20,Hangup()
exten => _Z,21,Playback(conf-errormenu)
exten => _Z,22,Hangup()