Setting a dialplan variable with asterisk cli output

I would like to use some out put from core show channels count in a dial plan variable.
1 active channels
1 active calls
4 calls processed

I can’t see a dedicated dialplan variable which shows me active channels. Is there a way to execute an asterisk cli command from the dialplan and set the results as a dialplan variable?

create a AGI with three variables phone_number,start_time and end_time at the beginning of the dialplan call this agi which will update the mysql with phone_number and start_time but end_time as null.
now at hangup i.e(h exten)u will call the same agi to update the mysql with end_time

now when you select count the DATABASE with end_time as NULL you will get all the active calls and store the result in AGI variable and call the variable as per you requirement in the dialplan . now other parameters you can get mathematically in the same dialplan…

Thanks for the idea but it’s not realtime.

I’m interested to know how many calls are inprgress whilst still in the call.

I have done somthing similare but writted to SQL via odbc but again this not real time.

I’m surprised I can’t find a dialplan varable which simply shows how many calls are in progress!!

There is a function that will return the output of shell command. Run that with asterisk -rx.

I don’t think you requirement is common. Why do you need this value?

I’ll look into that idea.

Initial investigation looks like I may have to use the set command to set a returned agi response.

What I was looking to do is have the dialplan have some knowledge of the current number of calls from a capacity point of view and maybe react in some way.

For example if there are 50 active calls I may like to say to the 51st caller that there are already 50 calls in progress. Perhaps they would like to call back.

I may want to run a script based on high capacity.

I identified the asterisk command line returned the current number of active channels but can’t find an alternative dialplan variable.

i think this one can help you out…

edit the below given code as per your manager.conf
and run this PHP script.

<?php $strHost="127.0.0.1"; $strUser="obdadmin";//USE YOUR MANAGER.conf USERID $strSecret="admin";//MANAGER.conf PASSWORD $token = md5(uniqid(rand())); $strWaitTime="10"; $wrets=""; $oSocket = @fsockopen($strHost, 5038, $errnum, $errdesc) or die("Connection to host failed"); fputs($oSocket, "Action: login\r\n"); fputs($oSocket, "Events: off\r\n"); fputs($oSocket, "Username: $strUser\r\n"); fputs($oSocket, "Secret: $strSecret\r\n\r\n"); fputs($oSocket, "Action: command\r\n"); fputs($oSocket, "ActionID: $token\r\n"); fputs($oSocket, "command: core show channels count\r\n\r\n"); fputs($oSocket, "WaitTime: $strWaitTime\r\n"); fputs($oSocket, "Action: Logoff\r\n\r\n"); while (!feof($oSocket)) { $wrets .= fread($oSocket, 8192); } fclose($oSocket); preg_match('/(.*) active channels/',$wrets,$matches); $active_channels = $matches[1]; echo 'active : '.$active_channels.chr(10); $active_channels; $total_channel=60;// change this value to the total number of E1,s multiplied by 30 you have. $active_channels=$active_channels; $free_channels=$total_channel-$active_channels; echo"free channels: ".$free_channels; preg_match('/ActionID: (.*)/',$wrets,$matches); $ActionId = $matches[1]; ?>

Hi

If all you want to do is [quote]For example if there are 50 active calls I may like to say to the 51st caller that there are already 50 calls in progress. Perhaps they would like to call back.[/quote] then use group count and count the incoming and outgoing calls.

viewtopic.php?f=1&t=83177&p=175030&hilit=groupcount&sid=ba49101398d27b8a7270c630fccc134e#p175030

I was expecting this to work

exten => 7000,1,Answer()
exten => 7000,2,Set(CHANACTIVE=${SHELL(/usr/sbin/asterisk -rx ‘core show channels’ | grep channels)})
exten => 7000,3,Verbose(${CHANACTIVE})
exten => 7000,4,Hangup

Or even better

exten => 7000,1,Answer()
exten => 7000,2,Set(CHANACTIVE=${SHELL(/usr/sbin/asterisk -rx ‘core show channels’ | grep ‘channels’ | cut -d’ ’ -f1)})
exten => 7000,3,Verbose(${CHANACTIVE})
exten => 7000,4,Hangup

I get some output with

exten => 7000,1,Answer()
exten => 7000,2,Set(CHANACTIVE=${SHELL(/usr/sbin/asterisk -rx ‘core show channels’ )})
exten => 7000,3,Verbose(${CHANACTIVE})
exten => 7000,4,Hangup exten => 7000,1,Answer()

I have also tried

exten => 7000,1,Answer()
exten => 7000,2,Set(TES=${SHELL(/etc/config/activechannels.sh)})
exten => 7000,3,Verbose(${TES})
exten => 7000,4,Hangup

activechannels.sh
asterisk -rx ‘core show channels’ | grep ‘channels’ | cut -d’ ’ -f1

and I do not get an out put to the dial plan

I think I am missing somthing simple here

It would also apear that I can recive simple text back from a command or a script like

${SHELL(echo 123):0:-1}
or
${SHELL(/test.sh):0:-1}

test.sh
echo “123”

but nothing more complicated

After much poking and proding I got to this which works but what a mess.

exten => 7000,1,Answer()
exten => 7000,2,Set(NUM=${SHELL(/usr/sbin/asterisk -rx ‘core show channels’ | grep ‘active call’ | cut -d’ ’ -f1 | tr “\n” " " | sed -e “s/ //g”)})
exten => 7000,3,Verbose(${NUM})
exten => 7000,4,Hangup

anyone see a simpler way of doing it?

1 Like

Thats fine but it is system wide and not fine grained to specific queues and will also include incoming and outgoing, Groupcount that I pointed out earlier lets you count different queues and different types of calls. So is more scalable