Get Channel Variables Via ARI/AMI

Home » Asterisk Users » Get Channel Variables Via ARI/AMI
Asterisk Users 18 Comments

I am connecting to the ARI with subscribe all, so I can see channels being created. I now want to extract a variety of header variables (at the moment the from and to tag). I tried to read them from the ARI but Asterisk refuses since the channel is not in a stasis app.

Is there a way to read these from either the ARI or AMI ? I’m trying not to modify the dialplan.

Thanks

Brian

18 thoughts on - Get Channel Variables Via ARI/AMI

  • It looks like if I call Getvar and pass PJSIP_HEADERS() I can get the entire SIP header for a channel. I also read (on stackoverflow) that the PJSIP_HEADER function will only return the headers from the INVITE of the inbound channel.

    If that’s correct, how would I get the headers from the outbound channel (second leg of the bridged call) INVITE ? Or will PJSIP_HEADERS() in fact return the header from either inbound out outbound legs?

    Thanks

    Brian

    From: asterisk-users [mailto:asterisk-users-bounces@lists.digium.com] I am connecting to the ARI with subscribe all, so I can see channels being created. I now want to extract a variety of header variables (at the moment the from and to tag). I tried to read them from the ARI but Asterisk refuses since the channel is not in a stasis app.

    Is there a way to read these from either the ARI or AMI ? I’m trying not to modify the dialplan.

    ARI, No.

    AMI, Yes[1].

    [1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+ManagerAction_Getvar

  • I think that’s getting me close. I’m trying to get (or recreate) the FROM and TO lines of the header, from a system running PJSIP. I think if I use CHANNEL to get local_uri and local_tag I can recreate a FROM line like:

    FROM=;tag=TAG

    And if I use CHANNEL to get remote_uri and remote_tag I can recreate a FROM line like:

    TO=;tag=TAG

    Would it be correct to assume that with this info (and ip:port info) I should be able to send a UDP SIP message from the PBX to the UA which appears to be part of the current call dialog? I realize this is an odd thing to do, but I’m just interested in technical feasibility at this point. Before I try to code this I want to ensure I’m not missing something stupid.

    Thanks

    Brian

    From: asterisk-users [mailto:asterisk-users-bounces@lists.digium.com] It looks like if I call Getvar and pass PJSIP_HEADERS() I can get the entire SIP header for a channel. I also read (on stackoverflow) that the PJSIP_HEADER function will only return the headers from the INVITE of the inbound channel.

    If that’s correct, how would I get the headers from the outbound channel (second leg of the bridged call) INVITE ? Or will PJSIP_HEADERS() in fact return the header from either inbound out outbound legs?

    The answer is, you can’t. There are SOME protocol level things accessible using CHANNEL[1] but that’s it.

    [1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+Function_CHANNEL

  • According to RFC3261 :

    It is possible for the CSeq sequence number to be higher than the remote sequence number by more than one. This is not an error condition, and a UAS SHOULD be prepared to receive and process requests with CSeq values more than one higher than the previous received request.

    So if I use a high value integer (maxint) I’m hoping the UAC will accept my message (though this will mess up future transactions, so other than BYE this is not a viable solution for an ongoing dialog). The other problem I see is that I can’t get the route set, so this this would work only with UAC’s on the same network (not NAT/proxies/etc). If I needed to traverse NAT I would need something like Kamilio as Eric points out, to get the route set). Or…maybe PJSIP_HEADERS will give me the route set..I need to experiment with that one).

    Since this is just for my learning, I want to see if I can hangup a call in progress, running through the asterisk server. This is fun for my learning, so I realize there is of little practical value 🙂

    Brian

    From: asterisk-users [mailto:asterisk-users-bounces@lists.digium.com] I think that’s getting me close. I’m trying to get (or recreate) the FROM and TO lines of the header, from a system running PJSIP. I think if I use CHANNEL to get local_uri and local_tag I can recreate a FROM line like:

    FROM=;tag=TAG

    And if I use CHANNEL to get remote_uri and remote_tag I can recreate a FROM line like:

    TO=;tag=TAG

    Would it be correct to assume that with this info (and ip:port info) I should be able to send a UDP SIP message from the PBX to the UA which appears to be part of the current call dialog? I realize this is an odd thing to do, but I’m just interested in technical feasibility at this point. Before I try to code this I want to ensure I’m not missing something stupid.

    Probably not. Sequence number also matters.

  • I’m curious what the actual application is here – you want to connect to AMI to pull information that you will use to pretend to be a leg, just to send “BYE”, when you could just hangup the leg with AMI (or do just about anything else you might think of). Sometimes it is better to fully explain what you are trying to accomplish, and some folks here can try to steer you towards a workable solution.  It almost sounds… nefarious.

    Cheers,

  • I’m in training, so I have to demonstrate something SIP related. I figure it would be cool to hack a call, hanging it up while in progress from outside Asterisk. Doing so will demonstrate use/knowledge of ARI, AMI, SIP, route-sets, UDP, etc.

    Practical value: zero

    🙂

    Who knows, maybe this will have an actual application for someone someday. In practical terms I think building a proxy would be the right way to manipulate the SIP for a call in progress, but that sounds like a huge project. I’ve got to demonstrate something by end of week.

    From: asterisk-users [mailto:asterisk-users-bounces@lists.digium.com] I am connecting to the ARI with subscribe all, so I can see channels being created. I now want to extract a variety of header variables (at the moment the from and to tag). I tried to read them from the ARI but Asterisk refuses since the channel is not in a stasis app.

    Is there a way to read these from either the ARI or AMI ? I’m trying not to modify the dialplan.

    ARI, No.

    AMI, Yes[1].

    [1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+ManagerAction_Getvar

    I’m curious what the actual application is here – you want to connect to AMI to pull information that you will use to pretend to be a leg, just to send “BYE”, when you could just hangup the leg with AMI (or do just about anything else you might think of). Sometimes it is better to fully explain what you are trying to accomplish, and some folks here can try to steer you towards a workable solution. It almost sounds… nefarious.

    Cheers,

  • And I have to admit, I have learned a lot just investigating this. (And appreciate the advice)

    From: asterisk-users [mailto:asterisk-users-bounces@lists.digium.com] I am connecting to the ARI with subscribe all, so I can see channels being created. I now want to extract a variety of header variables (at the moment the from and to tag). I tried to read them from the ARI but Asterisk refuses since the channel is not in a stasis app.

    Is there a way to read these from either the ARI or AMI ? I’m trying not to modify the dialplan.

    ARI, No.

    AMI, Yes[1].

    [1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+ManagerAction_Getvar

    I’m curious what the actual application is here – you want to connect to AMI to pull information that you will use to pretend to be a leg, just to send “BYE”, when you could just hangup the leg with AMI (or do just about anything else you might think of). Sometimes it is better to fully explain what you are trying to accomplish, and some folks here can try to steer you towards a workable solution. It almost sounds… nefarious.

    Meant that towards TTT, not Josh, in case that wasn’t clear.

  • I need to get hooked up with this class, I could have students doing projects for homework 🙂 Interested in RTCP?

    j

  • I am trying to use the CHANNEL function listed above from the AMI. Since it is not an AMI “action”, but rather a dialplan “function”, I’m trying to figure out how to call this from the AMI. Using a telnet session to the AMI I’ve tried variations of:

    action: command

    actionid: id123

    command: channel(PJSIP/240000-1a)

    but they don’t work. Is the basic concept correct that I can using the “command” action to run a statement that would work in the dialplan? If not, how would I call “channel” from the AMI ?

    Thanks

    Brian

  • I actually tried that, and although I get “success” I never get useful data. For example:

    action: Getvar

    actionid: act1

    channel: PJSIP/Twilio-NA-W-2-In-00000025

    Variable: channel(pjsip,call-id)

    Response: Success

    ActionID: act1

    Variable: channel(pjsip,call-id)

    Value:

    And the channel in use was I from a call in progress.

    Thanks

    Brian

  • The uppercase command made a difference. I now get a call-id as show below. However, does the call-id look valid? The @0.0.0.0 seems strange.

    action: Getvar

    actionid: act1

    channel: PJSIP/Twilio-NA-W-3-In-00000028

    Variable: CHANNEL(pjsip,call-id)

    Response: Success

    ActionID: act1

    Variable: CHANNEL(pjsip,call-id)

    Value: 4decf884e3ae74595906283a74f7154e@0.0.0.0

    As well, can I request many pieces of data at once? The syntax on this page (https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+Function_CHANNEL) seems to suggest you pass a single parameter, “item”, yet passing just call-id did not work. I had to pass “pjsip,call-id”. Is the first parameter a category and the second the detailed item? What if I want to retrieve multiple items (or all “pjsip” items)?

  • Call-ID within a SIP dialog is completely opaque. It is what it is.

    You can not request multiple at once. Some things require an initial specifier such as pjsip, some things don’t.