POSSA / freepbx-trunk-balancing

Restrict outbound calls or balance calls over multiple trunks based on user specified parameters
http://pbxossa.org/files/trunkbalance/
37 stars 30 forks source link

Max different phone in a billing period #9

Closed taphawane closed 11 years ago

taphawane commented 11 years ago

Hi have FreePBX 2.10 and asterisk and asterisk 1.8.18, Trunk Balancing module version 1.0.0. I just set billing Period to 1 for the system to reset every day, and set Max. Different Calls 20. But I realized, that if the trunk reach 20, if I use a phone number that have been called with those 20, The trunk reject the call. In my understanding it's should accept, any same number that have been called within the billing period and reject any other new phone number that trying to dial out.

Can someone please help me about this issue?

lgaetz commented 11 years ago

Have you seen the wiki: https://github.com/POSSA/freepbx-trunk-balancing/wiki/Using-the-Module

there is maximum number of calls and maximum different number of calls

taphawane commented 11 years ago

Yes, I know for the the feature of maximum different number of call is not working

lgaetz commented 11 years ago

I see now what you are saying. I agree with you, if you select "maximum number of different calls" it should allow repeated calls to one of the previous numbers but it doesn't. The code that handles this starts at line 281 of /agi-bin/trunkbalance.php. It just counts the number of different calls and compares it to the maximum set by the user, but doesn't do anything else. A rough plan to fix:

taphawane commented 11 years ago

Can please help to get it, work, I am not a program, and I am not that good with mysql code. I need even if the trunk reach the max different number, to pass the call if a same number has been called within the billing period. and any other new number to fail.

lgaetz commented 11 years ago

I have made some changes that are working for me, hopefully I have not broken anything else in the process. You can download the file from here: https://raw.github.com/POSSA/freepbx-trunk-balancing/working/agi-bin/trunkbalance.php

taphawane commented 11 years ago

Hi I have done all the instruction as you indicated, I am testing it right now, for now it is working, please just me sometimes, I will test it again and give you results.

taphawane commented 11 years ago

Hi, I have done a full test with different days, and settings, I have seen some improvement, the module is not counting same number dialed as a new number anymore, which is great. But if the rules reach its max different numbers, a same number that have been dialed in the billing period does not goes trough. You said that have worked for you, I do not know if you tested when max different number has been reach if you a number that have been dialed can goes trough.

lgaetz commented 11 years ago

I'm not sure you are using the module correctly. I have made some more minor changes, so please do the same steps above to get the new version of trunkbalance.php then do some more testing. If you still think you have a problem, give me the asterisk log output from a failed call that you think should be passing.

taphawane commented 11 years ago

Hello,

I have test it.

I number that I have dialed is 7046466083966 and 7046466083971.

I setup the trunk for 2 Max different calls. but when its reach 2 number, the same number cannot go trought anymore, here are my freepbx logs.

[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [7046466083966@from-internal:1] Macro("IAX2/06001-2500", "user-callerid,LIMIT,") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:1] Set("IAX2/06001-2500", "AMPUSER=06001") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:2] GotoIf("IAX2/06001-2500", "0?report") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:3] ExecIf("IAX2/06001-2500", "0?Set(REALCALLERIDNUM=06001)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:4] Set("IAX2/06001-2500", "AMPUSER=06001") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:5] Set("IAX2/06001-2500", "AMPUSERCIDNAME=06Expresso") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:6] GotoIf("IAX2/06001-2500", "0?report") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:7] Set("IAX2/06001-2500", "AMPUSERCID=06001") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:8] Set("IAX2/06001-2500", "CALLERID(all)="06Expresso" <06001>") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:9] GotoIf("IAX2/06001-2500", "0?limit") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:10] ExecIf("IAX2/06001-2500", "1?Set(GROUP(concurrency_limit)=06001)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:11] ExecIf("IAX2/06001-2500", "0?Set(CHANNEL(language)=)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:12] GosubIf("IAX2/06001-2500", "7?sub-ccss,s,1(from-internal,)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-ccss:1] ExecIf("IAX2/06001-2500", "0?Return()") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-ccss:2] Set("IAX2/06001-2500", "CCSS_SETUP=TRUE") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-ccss:3] GosubIf("IAX2/06001-2500", "0?monitor_config,1(from-internal,):monitor_default,1(from-internal,)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [monitor_default@sub-ccss:1] GotoIf("IAX2/06001-2500", "0?is_exten") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [monitor_default@sub-ccss:2] StackPop("IAX2/06001-2500", "") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [monitor_default@sub-ccss:3] Return("IAX2/06001-2500", "FALSE") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:13] GotoIf("IAX2/06001-2500", "1?continue") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Goto (macro-user-callerid,s,26)
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:26] Set("IAX2/06001-2500", "CALLERID(number)=06001") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:27] Set("IAX2/06001-2500", "CALLERID(name)=06Expresso") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-user-callerid:28] Set("IAX2/06001-2500", "CHANNEL(language)=en") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [7046466083966@from-internal:2] Set("IAX2/06001-2500", "MOHCLASS=default") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [7046466083966@from-internal:3] ExecIf("IAX2/06001-2500", "0?Set(TRUNKCIDOVERRIDE=TestOutRulesTrunkBalance)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [7046466083966@from-internal:4] Set("IAX2/06001-2500", "_NODEST=") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [7046466083966@from-internal:5] Gosub("IAX2/06001-2500", "sub-record-check,s,1(out,7046466083966,)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:1] GotoIf("IAX2/06001-2500", "1?check") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Goto (sub-record-check,s,6)
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:6] Set("IAX2/06001-2500", "__MON_FMT=wav") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:7] GotoIf("IAX2/06001-2500", "1?next") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Goto (sub-record-check,s,10)
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:10] ExecIf("IAX2/06001-2500", "0?Return()") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:11] GotoIf("IAX2/06001-2500", "0?out,1") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:12] Set("IAX2/06001-2500", "__REC_STATUS=INITIALIZED") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:13] ExecIf("IAX2/06001-2500", "0?Set(__REC_POLICY_MODE=)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:14] Set("IAX2/06001-2500", "NOW=1367270740") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:15] Set("IAX2/06001-2500", "__DAY=29") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:16] Set("IAX2/06001-2500", "__MONTH=04") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:17] Set("IAX2/06001-2500", "__YEAR=2013") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:18] Set("IAX2/06001-2500", "__TIMESTR=20130429-152540") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:19] Set("IAX2/06001-2500", "__FROMEXTEN=06001") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:20] Set("IAX2/06001-2500", "__CALLFILENAME=out-7046466083966-06001-20130429-152540-1367270740.1746") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-record-check:21] Goto("IAX2/06001-2500", "out,1") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Goto (sub-record-check,out,1)
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [out@sub-record-check:1] ExecIf("IAX2/06001-2500", "1?Set(__REC_POLICY_MODE=dontcare)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [out@sub-record-check:2] GosubIf("IAX2/06001-2500", "0?record,1(exten,7046466083966,06001)") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [out@sub-record-check:3] Return("IAX2/06001-2500", "") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [7046466083966@from-internal:6] Macro("IAX2/06001-2500", "dialout-trunk,13,706083966,5512") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-dialout-trunk:1] Set("IAX2/06001-2500", "DIAL_TRUNK=13") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-dialout-trunk:2] AGI("IAX2/06001-2500", "trunkbalance.php,13") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/trunkbalance.php
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- trunkbalance.php,13: This trunk TestTrunkBakance is balanced. Evaluating rules
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- trunkbalance.php,13: Time condition passed
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- trunkbalance.php,13: billing period 1
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- trunkbalance.php,13: 2 max different calls. This trunk has now 2 calls not including unknown - Rule failed
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- trunkbalance.php,13: At least one condition failed. Call refused.
[2013-04-29 15:25:40] VERBOSE[23478] res_agi.c: -- <IAX2/06001-2500>AGI Script trunkbalance.php completed, returning 0
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@macro-dialout-trunk:3] GosubIf("IAX2/06001-2500", "1?sub-pincheck,s,1()") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] pbx.c: -- Executing [s@sub-pincheck:1] Authenticate("IAX2/06001-2500", "5512,") in new stack
[2013-04-29 15:25:40] VERBOSE[23478] file.c: -- <IAX2/06001-2500> Playing 'agent-pass.gsm' (language 'en')
lgaetz commented 11 years ago

What version of Asterisk are you running? I can see from your log, this is the problem line: trunkbalance.php,13: 2 max different calls. This trunk has now 2 calls not including unknown - Rule failed When I run this script using Asterisk 1.8, the word 'unknown' would show the number being dialled.

Perhaps @tm1000 can steer me right, I am using this line to get the outgoing dialed digits using phpagi: $exten = $AGI->request['agi_dnid']; are there different ways of doing this depending on the Asterisk version?

taphawane commented 11 years ago

I had Asterisk. 1.8.18 and FreePBX 2.10. I just update that Asterisk 1.8.21 and FreePBX 2.11, hoping that will fix the issue. but I am always 'unknown', I as indicated $exten is a variable it should show something but in my system its showing 'unknown'. Also I want to notice that I am using IAX trunk does that have anything to do with that?

lgaetz commented 11 years ago

in /var/lib/asterisk/agi-bin (or wherever your agi files are stored) should be a file called phpagi.php I don't know much about this, but there are several versions of that file, and I am using version 2.0, check the first few lines of that file and tell me what version you are using.

lgaetz commented 11 years ago

I made some more changes with how the script collects the dialed digits. Follow the steps above to update (again!) and let me know how it goes. I am using Asterisk 11 which may account for the differences between our two systems. When I dial a number to a balanced trunk that is already full, I get one of the following messages in the full log: Trunk has exceeded call count of 2 and dialed number 1111111 is not included in this count - Rule failed or Trunk has exceeded call count of 2 but dialed number 1111111 is included in this count - Rule passed

if the system is unable to figure out what digits you dial, and the balanced trunk is full you will get this log entry:

Cannot determine dialed number and trunk has exceeded call count of 2 - Rule failed

taphawane commented 11 years ago

Hello after my test in Asterisk 11. its worked Great! Here is what I am getting with Asterisk 11:

[2013-04-30 21:22:40] VERBOSE[4947][C-0000428f] res_agi.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/trunkbalance.php
[2013-04-30 21:22:40] VERBOSE[4947][C-0000428f] res_agi.c: -- trunkbalance.php,24: This trunk TestTrunkBalance is balanced. Evaluating rules
[2013-04-30 21:22:40] VERBOSE[4947][C-0000428f] res_agi.c: -- trunkbalance.php,24: Time condition passed
[2013-04-30 21:22:40] VERBOSE[4947][C-0000428f] res_agi.c: -- trunkbalance.php,24: Trunk has exceeded call count of 2 but dialed number 47477202699386 is included in this count - Rule passed
[2013-04-30 21:22:40] VERBOSE[4947][C-0000428f] res_agi.c: -- trunkbalance.php,24: Call authorized. The new trunk number is 19
[2013-04-30 21:22:40] VERBOSE[4947][C-0000428f] res_agi.c: -- <SIP/100-00004ffa>AGI Script trunkbalance.php completed, returning 0

Here is what I am getting with Asterisk 1.8:

[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/trunkbalance.php
[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- trunkbalance.php,13: This trunk TestTrunkBakance is balanced. Evaluating rules
[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- trunkbalance.php,13: Time condition passed
[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- trunkbalance.php,13: billing period 1
[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- trunkbalance.php,13: Cannot determine dialed number and trunk has exceeded call count of 2 - Rule failed
[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- trunkbalance.php,13: At least one condition failed. Call refused.
[2013-05-01 08:02:42] VERBOSE[15692] res_agi.c: -- <IAX2/06001-4037>AGI Script trunkbalance.php completed, returning 0

Its could't dertemine the dialed number. I though that is problem is DTMF mode but as my trunk are in IAX tech, they don't use DTMF mode,

I want to support this module, because I find it very interesting. Do you know where can I donate?

lgaetz commented 11 years ago

Glad you got things working! I am surprised there is such a difference between 1.8 and 11. It doesn't have anything to do with dtmf, it has to do with how the phpagi class and Asterisk interact. I don't understand it very well, and there may well be a way to do with with Asterisk 1.8, I just don't know how.

I'm happy to see you are willing to donate. This ticket has taken a lot of my time. Please direct your donation to PBX in a Flash via paypal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5RPE6RBHXDRWJ If paypal doesn't work for you, please contact me by email and I will forward whatever you need.

Issue is being closed. If anyone has a fix for Asterisk 1.8 please reopen and post.

taphawane commented 11 years ago

I have tried Paypal but I got this error "We cannot process this transaction because there is a problem with the PayPal email address supplied by the seller. Please contact the seller to resolve the problem. If this payment is for an eBay listing, you can contact the seller via the "Ask Seller a Question" link on the listing page. When you have the correct email address, payment can be made at www.paypal.com."

If you have any other method that I can donate you let me know

lgaetz commented 11 years ago

I just confirmed that it works for me. It may be that you're trying to send from an 'unverified' address. Please try sending your donation to support@pbxinaflash.com and if it still doesn't work, contact Ward Mundy at that email address for help.

Thanks.

taphawane commented 11 years ago

The problem was not about the version of Asterisk. It about the server who has originate the call. I have 2 Server BOX A and BOX B. When I register my extension in BOX A where Trunk Balancing is installed, and I originate a call, its work Great. I will get this :"Trunk has exceeded call count of 2 but dialed number 47477202699386 is included in this count - Rule passed" This thing When I register a extension in BOX B where Trunk Balancing module is install its work too. I get this: "Trunk has exceeded call count of 2 but dialed number 47477202699386 is included in this count - Rule passed" Which is very good.

The main issue is when I register my Extension to BOX A and with no rules of Trunk Balancing, and I want the call go trough BOX B, when The call arrived at BOX B where I setup my Trunk Balancing rules I got " Cannot determine dialed number and trunk has exceeded call count of 2 - Rule failed".

lgaetz commented 11 years ago

Ah, that finally explains the mystery.My testing on Asterisk 1.8 was working fine and couldn't figure out why you were seeing something different.

This module uses the value of the ${EXTEN} variable which must not be getting set when the call arrives at the remote PBX. I assume you have a peer trunk between BOX A and BOX B, what context do remote calls arrive in?

taphawane commented 11 years ago

Yes you are correct, I have peer Trunk between A and B, the context I used was "from-trunk"

lgaetz commented 11 years ago

I have just done some testing with an IAX2 peer trunk between two machines. It seems to work okay if I set the context to from-internal, is that an option for you?

taphawane commented 11 years ago

I have tested with context=from-internal, still " Cannot determine dialed number and trunk has exceeded call count of 2 - Rule failed".

unless, I have some update in the code that I am not aware of or we have different config.

Here is my config

In BOX A, I create A IAX2 Tunk with PEER Details:

[trunk-name] disallow=all username=box-b-extension-number type=peer secret=box-b-extension-pass qualify=yes port=4569 host=box-b-ip-address context=from-internal allow=ulaw

In BOX B, I create a IAX2 Extension

[extension-number] deny=0.0.0.0/0.0.0.0 disallow=all secret=extension-password transfer=yes context=from-internal host=dynamic type=friend port=4569 qualify=yes allow=ulaw dial=IAX2/extension-number mailbox=extension-number@device permit=0.0.0.0/0.0.0.0 requirecalltoken=no callerid=extension-name setvar=REALCALLERIDNUM=extension-number

lgaetz commented 11 years ago

When I made my peer trunk between two boxes I created an IAX trunk on both boxes and filled in the user details. The method as outlined in this page: http://www.cadvision.com/blanchas/Asterisk/IAX2Trunk.html

taphawane commented 11 years ago

I have two of my box connected using IAX2 as indicated in the link you sent me but it's still do not work.

lgaetz commented 11 years ago

By email, please send me the full log entries when a problem call arrives on the peer trunk. Leave IP addresses and phone numbers intact. Nothing I do can reproduce the issue you are reporting.

lgaetz commented 11 years ago

I got your logs by email, and I think I have finally tracked down this issue once and for all. Can you download the newest tarball from here: http://pbxossa.org/files/trunkbalance/trunkbalance-1.0.2.tgz and install directly over top of the old version, reload and retest.

taphawane commented 11 years ago

Thank You! You are best its worked GREAT!, even with asterisk 1.8. Where was the issue?

lgaetz commented 11 years ago

Yeah, the problems had nothing to do with asterisk version.

The issue was the way this module was using the FreePBX dialout-trunk macro. FreePBX dials out by passing arguments to the [macro-dialout-trunk] context. Until today, the balanced trunks created by this module were not passing the dialed number as an argument. I was trying to get that information from the phpagi class via $agi->request, but for some reason it was not working for all cases (as you discovered).

Glad things are working, ticket closed (again).