Modify number of available channels for a specific day

Hello everyone,

For one of our customers, we set the number of available channels to a limit of 8.

This is what we set up in the extensions.conf file for the purpose:

exten => 1,1,Answer
exten => 1,2,Background(/var/lib/asterisk/sounds/it/custom/benvenuto)
exten => 1,3,Set(GROUP()=chiam_in)
exten => 1,4,Verbose(1,****Number of calls ${GROUP_COUNT(chiam_in)})
exten => 1,5,GotoIf($[${GROUP_COUNT(chiam_in)} > 8]?3,1)
exten => 1,6,WaitExten(2)
exten => 1,7,Queue(Segreteria,t,,,600)
exten => 1,8,Background(/var/lib/asterisk/sounds/it/custom/BusyOperators)
exten => 1,9,Hangup()

exten => 2,1,Answer
exten => 2,2,Dial(SIP/301&SIP/302&SIP/422&SIP/423&SIP/425&SIP/426&SIP/490&SIP/496&SIP/497&SIP/498&SIP/499,30,tTr)
exten => 2,3,Background(/var/lib/asterisk/sounds/it/custom/fuori-orario)
exten => 2,4,Hangup()

exten =>3,1,Verbose(1,***limit exceeded ${GROUP_COUNT(server2Trunkgroup)})
exten =>3,2,Background(/var/lib/asterisk/sounds/it/custom/BusyOperators)
exten =>3,3,Set(DIALSTATUS=CHANUNAVAIL)

Now the customer wants to up this limit to 12 on a specific day, which is the 10th of every month. So, every 10th of the month, that limit should be set to 12; for all the other days of the month, the limit should stay at 8.

Is there a way to implement this functionality?

GotoIfTime().

Note that you will find it much easier to add lines of code if you use “n” as the priority and symbolic labels as the targets of Gotos, as is done in all the non-trivial examples provided with Asterisk.

1 Like

I found ‘same’ as a replacement for the extension and the priority to be a big step up in making my dialplans readable and maintainable. Faster to code as well :slightly_smiling_face: A lot faster to copy blocks of code for reuse :slight_smile: :slight_smile:

Thanks for your help. I now implemented the GotoIfTime() function on the dialplan. The goal is to have a maximum number of channels of 8 everyday, except the 10th day of the month where we should have 12 channels available. If there aren’t any free channels left, hangup.

[code]

exten => 1,1,Answer
exten => 1,2,Background(/var/lib/asterisk/sounds/it/custom/benvenuto)
exten => 1,3,Set(GROUP()=chiam_in)
exten => 1,4,Verbose(1,**** Numero chiamate ${GROUP_COUNT(chiam_in)})

exten => 1,5,GotoIfTime(*|*|10|*?1,8) 
exten => 1,6,GotoIf($[${GROUP_COUNT(chiam_in)} > 8]?3,1)
exten => 1,7,Goto(1,9)

exten => 1,8,GotoIf($[$[GROUP_COUNT(chiam_in)} > 12]?3,1)

exten => 1,9,WaitExten(2)
exten => 1,10,Queue(Segreteria,t,,,600)
exten => 1,11,Background(/var/lib/asterisk/sounds/it/custom/OperatoriOccupati)
exten => 1,12,Hangup()

exten => 2,1,Answer
exten => 2,2,Dial(SIP/301&SIP/302&SIP/422&SIP/423&SIP/425&SIP/426&SIP/490&SIP/496&SIP/497&SIP/498&SIP/499,30,tTr)
exten => 2,3,Background(/var/lib/asterisk/sounds/it/custom/fuori-orario)
exten => 2,4,Hangup()

exten =>3,1,Verbose(1,***limite superato ${GROUP_COUNT(server2Trunkgroup)})
exten =>3,2,Background(/var/lib/asterisk/sounds/it/custom/OperatoriOccupati)
exten =>3,3,Set(DIALSTATUS=CHANUNAVAIL)


Unfortunately the customer is telling us that today (which is the 10th btw) there are too many channels opened and that the pbx is flooded with calls.

These are the logs of a level 9 debug on Asterisk:

 Goto (code,1,1)
    -- Executing [1@code:1] Answer("SIP/0110898XXX-000068XX", "") in new stack
    -- Executing [1@code:2] BackGround("SIP/0110898XXX-000068XX", "/var/lib/asterisk/sounds/it/custom/benvenuto") in new stack
    -- <SIP/0110898XXX-00006841> Playing '/var/lib/asterisk/sounds/it/custom/benvenuto.slin' (language 'it')
    -- Channel SIP/0110898XXX-000067bc left 'simple_bridge' basic-bridge <4a5f5a86-5d85-48c1-af2d-6402e2df8c78>
  == Spawn extension (code, 1, 10) exited non-zero on 'SIP/0110898XXX-000067bc'
    -- Channel SIP/302-000067f8 left 'simple_bridge' basic-bridge <4a5f5a86-5d85-48c1-af2d-6402e2df8c78>
       > 0x7f71440078e0 -- Strict RTP learning complete - Locking on source address 192.168.4.107:60972
    -- Stopped music on hold on SIP/0110898XXX-000067e8
    -- Playing periodic announcement
    -- <SIP/0110898XXX-000067e8> Playing '/var/lib/asterisk/sounds/it/custom/primo-operatore.slin' (language 'it')
       > 0x7f718006b8d0 -- Strict RTP learning complete - Locking on source address 83.211.227.12:51952
[Mar 10 15:21:29] NOTICE[1590][C-00001567]: chan_sip.c:10812 process_sdp: Processed audio crypto attribute without SAVP specified; accepting anyway
    -- Started music on hold, class 'default', on channel 'SIP/0110898XXX-0000681a'
    -- Executing [1@code:3] Set("SIP/0110898XXX-000068XX", "GROUP()=chiam_in") in new stack
    -- Executing [1@code:4] Verbose("SIP/0110898XXX-000068XX", "1,**** Numero chiamate 4") in new stack
 **** Numero chiamate 4
    -- Executing [1@code:5] GotoIfTime("SIP/0110898XXX-000068XX", "*|*|10|*?1,8") in new stack
    -- Goto (code,1,8)
[Mar 10 15:21:30] WARNING[1119][C-00001569]: pbx_variables.c:803 pbx_substitute_variables_helper_full: Error in extension logic (missing ']')
[Mar 10 15:21:30] NOTICE[1119][C-00001569]: ast_expr2.y:761 compose_func_args: argbuf allocated 9 bytes;
[Mar 10 15:21:30] NOTICE[1119][C-00001569]: ast_expr2.y:780 compose_func_args: argbuf uses 8 bytes;
[Mar 10 15:21:30] WARNING[1119][C-00001569]: ast_expr2.fl:470 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected ','; Input:
0?3,1
   ^
[Mar 10 15:21:30] WARNING[1119][C-00001569]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
    -- Executing [1@code:8] GotoIf("SIP/0110898XXX-000068XX", "0") in new stack
    -- Executing [1@code:9] WaitExten("SIP/0110898XXX-000068XX", "2") in new stack
  == SRTCP unprotect failed on SSRC 231985813 because of authentication failure
    -- Timeout on SIP/0110898XXX-000068XX, continuing...
    -- Executing [1@code:10] Queue("SIP/0110898XXX-000068XX", "Segreteria,t,,,600") in new stack
    -- Started music on hold, class 'default', on channel 'SIP/0110898XXX-000068XX'
    -- Stopped music on hold on SIP/0110898XXX-000068XX
    -- Playing periodic announcement
(...)

I’m noticing a concerning warning about a missing ‘]’ or something, but to me the GotoIfTime seems okay.

Am I not seeing something ?

There is an incorrect use of “[” in this.

Personally, I would have made the limit a variable. In fact, if you used ExecIfTime, you could combine the change in limit with the test.

You may find maintaining a ‘list variable’ easier if it is defined like:

[globals]
        host-list                       = sip/301
        host-list                       = ${host-list}&sip/302
        host-list                       = ${host-list}&sip/422

Thanks to everyone for the useful tips.

I was committing a syntax error in the GotoIfTime() as @david551 suggested. Now it works like a charm.

I’ll look into improving the extensions.conf file as soon as I’ll be done with the customer’s requests , as you suggested. :slight_smile:

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