List of channel variables

Is there any way in Asterisk to get a list of channel variables?

The reason I ask is that there a few scenarios where I need to split the call and I need to retain all the channel variables on the caller side of the call. And by split, I mean an entirely new call that is created through a call file. Here’s an example:

[regeneratecall] ; ARG1 = local channel, ARG2 = context, ARG3 = in/out, ARG4 = called #
exten => s,1,System(echo Channel: Local/{ARG1} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Context: {ARG2} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Extension: {callednumber} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Priority: 1 >> /tmp/{UNIQUEID}.call) same => n,System(echo CallerID: "{CALLERID(name)} <{CALLERID(num)}>" >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: calldirection={ARG3} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: __channel={channel} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: __clidverif={clidverif} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: pres={CALLERID(pres)} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: __autovonprioritydigit={autovonprioritydigit} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: __forcesecurechannel={forcesecurechannel} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: __dtlocation={dtlocation} >> /tmp/{UNIQUEID}.call)
same => n,System(echo Setvar: __isup-oli={isup-oli} >> /tmp/{UNIQUEID}.call)
same => n,System(mv /tmp/{UNIQUEID}.call /var/spool/asterisk/outgoing/) same => n,Return({CUT(ARG1,@,1)})

(Some of the stuff above didn’t paste right. There really are $ signs before the { for variables, the editor ate it up.)

This works good for some use cases of mine where the # of variables is relatively small.
I’m now in a different use case where I have a much larger # of channel variables. Is there any way to get an array of channel variables so I can do this dynamically, rather than hardcoding them into a subroutine? I simply want all current channel variables to get written into the call file, so that when the call is split, all existing channel variables are automatically in the new call, which would be much more flexible.

My first thought was ${CHANNEL}, but that’s actually just another channel variable, so I’m a bit stumped on where/how I could access these. Does Asterisk provide this kind of access to memory? I’d need the variable names and values.

Any thoughts or ideas appreciated! If it’s not possible, I’ll simply hardcode again, but potentially that might become large and unwieldy.

core show channel <name>

They are also passed to AGI scripts, which might be a better way of implementing this.

Just to clarify…

Channel variables are not passed to AGI scripts like shell environment variables* (like HOSTNAME or PATH) or in the AGI environment that is passed to the AGI via STDIN (like agi_channel or agi_callerid).

You can ask Asterisk for the value of a variable (get variable "<variable-name>"), but you need to know the name.

If you want to iterate through the pool of channel variables in your AGI you can use AMI to execute 'core show channel <channel-name>’ and then parse the result.

*) Asterisk does add these variables as ‘shell’ environment variables:

AST_AGI_DIR=/var/lib/asterisk/agi-bin/vtpv/
AST_BUILD_DATE=2020-08-06 02:01:29 UTC
AST_BUILD_HOST=vtpv11
AST_BUILD_KERNEL=3.10.0-1127.18.2.el7.x86_64
AST_BUILD_MACHINE=x86_64
AST_BUILD_OS=Linux
AST_BUILD_USER=sedwards
AST_CONFIG_DIR=/etc/asterisk/vtpv/
AST_CONFIG_FILE=/etc/asterisk/vtpv/asterisk.conf
AST_DATA_DIR=/var/lib/asterisk
AST_KEY_DIR=/var/lib/asterisk/keys
AST_LOG_DIR=/var/log/asterisk/
AST_MODULE_DIR=/usr/lib64/asterisk/modules/
AST_MONITOR_DIR=/var/spool/asterisk//monitor
AST_RUN_DIR=/var/run/asterisk/
AST_SPOOL_DIR=/var/spool/asterisk/
AST_SYSTEMNAME=
AST_VAR_DIR=/var/lib/asterisk/
AST_VERSION=17.6.0

Curiously, these variables are not available as channel variables.

Please use ‘preformatted text tags.’

(The '</>' icon when you are editing a post.)

+1

My mistake. I thought it send all the variables, whereas it only sends a special set of variables.

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