Chan spy with uniqueid

Hi Every one
To chanspy the channel sample prefix or clid I used uniqueid
this is my context
[trunk52] → context recive inbound call
exten => 1000,1,answer()
exten => 1000,n,set(bien2=${CDR(uniqueid)})
exten => 1000,n,dial(SIP/1000,30)
exten => 1000,n,hangup

[mayle]
exten => 700,1,ChanSpy(${bien2},w)

but when i call log like this
– Executing [1000@trunk52:1] Answer(“SIP/trunkto52-00000065”, “”) in new stack
– Executing [1000@trunk52:2] Set(“SIP/trunkto52-00000065”, “bien2=1649992329.160”) in new stack
– Executing [1000@trunk52:3] Dial(“SIP/trunkto52-00000065”, “SIP/1000,30”) in new stack
== Using SIP RTP CoS mark 5
– Called SIP/1000
– SIP/1000-00000066 is ringing
– SIP/1000-00000066 answered SIP/trunkto52-00000065
– Channel SIP/1000-00000066 joined ‘simple_bridge’ basic-bridge <3c9e7e1c-f699-4881-b23b- d65fd565245f>
– Channel SIP/trunkto52-00000065 joined ‘simple_bridge’ basic-bridge <3c9e7e1c-f699-4881- b23b-d65fd565245f>
== Using SIP RTP CoS mark 5
– Executing [700@mayle:1] ChanSpy(“SIP/3000-00000067”, “,w”) in new stack

It doesn’t chanspy my channel with uniqueid i wan’t
Please show help me where I wrong
THanks!!

You need to use a shared variable or astDB’ if you want to use the value in a diffrent call
also stop use exten for evey line
alternative use ExtenSpy
https://wiki.asterisk.org/wiki/display/AST/Asterisk+18+Application_ExtenSpy
also how do you want to handle the situation where there are more than 1 call to SIP/1000
and why are you using" uniqueid" where did that come from, do ChanSpy use that ???

[trunk52] ; context recive inbound call
exten => 1000,1,answer()
same => n,Set(DB(spy/bien2)=${CDR(uniqueid)})
same => n,Dial(SIP/1000,30)
same => n,hangup

[mayle]
exten => 700,1,ChanSpy(${DB(spy/bien2},w)
exten => 701,1,ChanSpy(SIP/1000,w)
exten => 702,1,ExtenSpy(1000@trunk52,w)

https://wiki.asterisk.org/wiki/display/AST/Asterisk+18+Function_DB

https://wiki.asterisk.org/wiki/display/AST/Asterisk+18+Function_SHARED

This is an overcomplicated way of getting the unique ID. ${CHANNEL(uniqueid)} would be more direct. However, unless it has been removed, in favour of the CHANNEL function, you should be able to get it directly as ${UNIQUEID}.

Whilst it is true that, but little known, in many cases, you can use UniqueID to reference a channel, instead of using its channel name, and there are cases where this is more appropriate, the intention of having prefix matching on chan_spy is that you should use the normal channel name, and I’m not sure if the unique ID will actually work. Normally when you use it to access a channel, you are going from name to channel, and it doesn’t matter that there are two name, but for chan_spy I’m not sure whether the same matching logic is used.

As already pointed out, you need a variable with more than current channel scope.

Also note that chan_sip is no longer supported.

Hi every body
I try with your adviceand use functuon SHARED, my idea is get two channel name and write it in mysql by ODBC
My call flow is ext2000–> server A → serverB → server A → ext1000
This is my context:
[mayle] → context permit ext2000 call out to 1000
exten => 1000,1,Set(__kenhnghelen=${CHANNEL})
exten => 1000,n,set(SHARED(kenh33,${kenhnghelen})=${CHANNEL})
exten => 1000,n,dial(SIP/${EXTEN}@trunkto52,45)

[trunk52]–> context recive call in 1000 from server B
exten => 1000,1,dial(SIP/1000,30,M(nghelen^s))
exten => 1000,n,hangup
[macro-nghelen]
exten => s,1,set(bien3=${SHARED(kenh33,${kenhnghelen})})
exten => s,n,set(bien2=${CHANNEL})
exten => s,n,set(ODBC_test1(${bien3},${bien2})=)

Call can connect normaly but i can’t get variable ${bien3}
So please tell me where I wrong
Thanks!!!

There is nothing in your dial plan which would ever cause it to reach this line!

Also this:

looks strange as, anywhere where __kenhnghelenis in scope, you could use it directly. (It isn’t in scope here, because the trunk52 cntext is not reached when you do the dial.)

I think you are confusing extensions and devices and are also copying and pasting without understanding.

Hi David
follow my diagram, i can share variable between two channel but it only share when call hang up by use symbol “h”

I want to share variable when call actived
Can you give me a sugesstive
Thanks!!!

question what do this var contain"${kenhnghelen}" in this line
my guess it that it empty as it is newer set for that context

exten => s,1,set(bien3=${SHARED(kenh33,${kenhnghelen})})

also this line is more complicatet thant it neet to be

exten => 1000,n,set(SHARED(kenh33,${kenhnghelen})=${CHANNEL})

cleanup, also ODBC_test1 is only cleared

[mayle] ;context permit ext2000 call out to 1000
exten => 1000,1,Set(SHARED(kenh33)=${CHANNEL})
same => n,dial(SIP/${EXTEN}@trunkto52,45)

[trunk52] ;context recive call in 1000 from server B
exten => 1000,1,dial(SIP/1000,30,M(nghelen^s))
same => n,hangup

[macro-nghelen]
exten => s,1,Set(ODBC_test1(${SHARED(kenh33)},${CHANNEL}=)

Hi Mark
Thanks for your help
I try config follow you idea but it still get variable ${SHARED(kenh33)}
I sent with log after config, I can’t find where us wrong

Executing [1000@mayle:1] Set(“SIP/2000-0000014f”, “SHARED(kenh33)=SIP/2000-0000014f”) in new stack
– Executing [1000@mayle:2] Dial(“SIP/2000-0000014f”, “SIP/1000@trunkto52,45”) in new stack
== Using SIP RTP CoS mark 5
– Called SIP/1000@trunkto52
– SIP/trunkto52-00000150 answered SIP/2000-0000014f
– Channel SIP/trunkto52-00000150 joined ‘simple_bridge’ basic-bridge <394546fc-d518-45a2-9be1-5a62bc90b830>
– Channel SIP/2000-0000014f joined ‘simple_bridge’ basic-bridge <394546fc-d518-45a2-9be1-5a62bc90b830>
== Using SIP RTP CoS mark 5
– Executing [1000@trunk52:1] Dial(“SIP/trunkto52-00000151”, “SIP/1000,30,M(nghelen)”) in new stack
== Using SIP RTP CoS mark 5
– Called SIP/1000
– SIP/1000-00000152 is ringing
– SIP/1000-00000152 answered SIP/trunkto52-00000151
– Executing [s@macro-nghelen:1] Set(“SIP/1000-00000152”, “ODBC_test1(,SIP/1000-00000152=)”) in new stack

If there is no causal relation between the channels, you need to use GLOBAL, rather than SHARED.

ups, yes your right
Forgot about GLOBAL as I normally just use astDB, as that will survive a reboot

Hi all
I try user GLOBAL but it can exactly with 1 call, it doesn’t exactly with multi call in same time
Follow my model, i check log and test, I think reason is two channel insite two bridge different

So, can we get variable from channel different bridge???

Thank all

You can use IMPORT() if you know the channel name or unique ID but then that’s what you are trying to find.

You could set a global variable that has the device name (or extension) as part of its name. The dialplan interpreter is a macro processor, and variable names can be based on other variable names. You can also do that with astDB and keys that contain the device name.

also have you taken a look at this one as an alternative

ExtenSpy(exten[@context][,options])

also what is your use case for using Spy
is it a specifik user or …
the more we know the better we can guide you
what if the user have more that 1 call … and so one

With my diagram
I think very difficult when get channel to spy because if i have 1 call server A will have 4 channel and it in 2 bridge. so I check on server B and see it only 2 channel that in 1 bridge, I think it will easy to select channel, but how can I get variable for server A from server B

Plesed tell me, if you know
Thanks every one

there is no build-in functions for that
you will need to create an external script or web service that can interact with the remote server
and then use System() or CURL() to access the information

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