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

Ver. 0.0.4.2 no support for DAHDI trunks #3

Closed lgaetz closed 11 years ago

lgaetz commented 11 years ago

User request from PIAF forum to use this module on DAHDI trunks [dead link removed]

lgaetz commented 11 years ago

Some back and forth from patrick_elx by PM:

Lorne: module works fine for balance sip/iax trunks but fails on dahdi trunks. There is a note in readme.txt that says it is not working with dahdi. I have done a preliminary run thru and I can't see anything that prevents it from working with a dahdi trunk, can you give me a pointer?

Patrick: If my memory serves, the issue was for zap/dahdi trunk that they were not recorded the same way than the other channels in the mysql database, and the module was not able to query data stats for these trunks. I don't know if newer version of freepbx have changed this situation. If not, the AGI should be rewritten to make a different sql query specifically for zap/dahdi.

Lorne: In case you have some insight, when I define a balanced trunk with a SIP channel, this line shows up in the log: 20 max calls. This trunk has now only 4 calls - Rule passed

now when I take that same balanced trunk and change to a dahdi channel it always shows zero like this: 20 max calls. This trunk has now only 0 calls - Rule passed

the same balanced trunk changed back to a SIP channel will preserve the counter: 20 max calls. This trunk has now only 4 calls - Rule passed

I think it should be a pretty basic thing to fix, the counter is preserved it just always returns a zero when using dahdi.

Patrick: There is no counter in the module, it's only a sql query to the asterisk/freepbx mysql call database. Whatever trunk you choose, the module will query the number of calls for that trunk. However, as the dahdi trunks are not logged in the same table as the other trunks, the query of the dahdi trunk number/name in a table where it does not exist, will always return a 0 occurrence.

lgaetz commented 11 years ago

Looks like the problem is near the $channel_filter variable which is defined at lines 240-249 in /agi-bin/trunkbalance.php

ver. 0.0.4.3 has a partial fix for the problem, it works for DAHDI trunks defined by channel number only, but not by group. Since DAHDI trunks are defined outside of FreePBX, I don't know of any way to determine which DAHDI channels are included in a group. The rules are checked against a cdr query that includes the name of the trunk definition, ie: SELECT COUNT(*) FROMcdrWHERE disposition='ANSWERED' AND dstchannel LIKE XXXXX AND calldate>'2012-08-01 00:00' where the XXXX is the name shown in the dstchannel of the CDR. When this is a DAHDI channel it will take the form of: DAHDI/3-1 so the name can be fomatted to always include the 'DAHDI/', the next number is the dahdi channel and the rest is ignored. If we define the trunk with the DAHDI channel the query will work, but if the trunk is defined as a group, the query name becomes: DAHDI/g0% which will never match the CDR entries

lgaetz commented 11 years ago

Note from old Patrick's old readme.txt file: the cdrb query for calls on a dahdi channel will not work (trunk referenced as zap in the trunk database and calls as dahdi in the cdrb).

I could not reproduce this. It was probably true on older systems with DAHDI set to 'Zap Compatibility Mode'. I will not be making any effort to support 'zap compatibility mode'

lgaetz commented 11 years ago

I found the asterisk command that lists all DAHDI channels in a group: dahdi show channels group [digit]

column output, doesn't appear to be a concise listing

lgaetz commented 11 years ago

Support for DAHDI trunks defined by channel was committed. No support for trunks defined by DAHDI group.

lgaetz commented 10 years ago

The problems with DAHDI trunks defined by group is that you can't query the cdr by DAHDI group directly, only by DAHDI channel. This function accepts a DAHDI group, and returns an array of DAHDI channels for that group:

https://gist.github.com/lgaetz/8626154

The channels can be used to build a regex to query the cdr, i.e:

SELECT * FROM `cdr` WHERE `channel` REGEXP '^DAHDI\[1|2|3]-'