user2248760
user2248760

Reputation: 83

Asterisk. Get number of active calls in dialplan

I have production asterisk 16.4 with dialplan on LUA and two SIP providers. The first provider give me trunk with maximum 5 connections and the second provider give trunck with 20 connections. I prefer to use the first provider for outgoing calls because it is cheaper, but it have only 5 lines. So, when user makes an outgoing call, I want to check current number of active calls on the trunk of first provider, and if that number is 5 then route the call throught second provider.

The question is - How can I get in dialplan number of active calls? Is there some functions or core variables? I know that I can get list of active channels in CLI by command "core show channels verbose", but how can I get somthing like this in lua dialplan?

Upvotes: 0

Views: 2047

Answers (2)

user2248760
user2248760

Reputation: 83

Thanks to @arheops for the clue. This is a working example on lua.

ext = extension:sub(1); -- Remove leading 9  
local providerA = tonumber(channel['GROUP_COUNT(provA)']:get());  
app.Verbose("Active channels on provider A = "..providerA);
if providerA < 5 then
    channel['GROUP()']:set("provA");
    app.Verbose("Outgoing call throught Provider A "..ext);
    app.Dial("PJSIP/"..ext.."@trunc_providerA");
else
    app.Verbose("Outgoing call throught Provider B "..ext);
    app.Dial("PJSIP/"..ext.."@trunc_providerB");
end;
app.Hangup();

Upvotes: 1

arheops
arheops

Reputation: 15247

You can set GROUP for each channel and after that cont GROUP_COUNT in dialplan

https://www.voip-info.org/asterisk-func-group/

Upvotes: 0

Related Questions