Summary:ASTERISK-13657: [patch] Ability to use DUNDi channel variables when using dynamic weights
Reporter:Joel Vandal (jvandal)Labels:
Date Opened:2009-02-26 10:38:42.000-0600Date Closed:2011-11-07 16:01:15.000-0600
Versions:Frequency of
Environment:Attachments:( 0) __20111107-dundi-varhead.patch.txt
( 1) asterisk-1.6-dundi-varhead.patch
( 2) dund-weight.sh
Description:This patch add the ability to use DUNDi channel variables like ${NUMBER} and ${IPADDR} when using dynamic weights for responses to DUNDi queries.

By example, you can use the SHELL() function to call an external script to determine what the weight in response should be.

e164  => dundi-e164-via-pstn,${SHELL(/tmp/test-dundi ${NUMBER}")},IAX2,dundi:...
Comments:By: Leif Madsen (lmadsen) 2009-02-26 17:40:32.000-0600

Just to verify, this isn't duplicating the functionality of being able to use dialplan functions in the dynamic weights (because that already exists I'm pretty sure).

You're just adding the ability to use the built in variables within the dynamic weight section, like you would have access to in the mapping response?


By: Joel Vandal (jvandal) 2009-02-26 20:42:13.000-0600

The dynamic weights functionality already exist but doesn't parse DUNDi channel variable so yes I just add the ability to use built in variables.

By example, if I do a dundi lookup of 200@e164, it can send the ${NUMBER} (200) to the script.

Variables that can be used are NUMBER, EID, SECRET and IPADDR

By: Joel Vandal (jvandal) 2009-05-05 10:39:54

FYI, I'm using this feature since few month without any problem and found it very useful to do a 'per destination' weight.

By example, I have "Hotdesk" extension shared on multiple server and if the hotdesk is logged or not, I dynamically change the weight.

Not doable without this patch.

By: Leif Madsen (lmadsen) 2009-06-10 13:00:39

Would you mind providing a dialplan snippet of your hot-desking feature so we can see a good usage of this? I'd like to add it as some documentation to Asterisk when we get this in. Thanks!

By: Joel Vandal (jvandal) 2009-06-10 13:19:03

In fact, we are using an AGI script to do Hotdesking feature so the dialplan is very basic. But to resume what the script do is to validate/authenticate the user on Login, define a new key on AstDB when the hotdesk is logged in/out.

On the DUNDi configuration, I use it like :

e164 => dundi-e164-via-pstn,${SHELL(/tmp/test-dundi ${NUMBER}")},IAX2,dundi:...

The /tmp/test-dundi script check the status of the Hotdesk extension specified by the ${NUMBER} variable and if the hotdesk is logged, the weight will be different that if the hotdesk is not logged.

By: Leif Madsen (lmadsen) 2009-12-10 11:35:21.000-0600

Hmmm, this doesn't seem to work for me for some reason.

I patched the remote host, and did a lookup. Without the patch I get a weight of 59999, but with the patch, I get the same weight...

*CLI> dundi lookup 200@testing bypass
 1. 59999 SIP/dundi:JUSJSFCNQhJDpKtT+m+3dQ==@ (EXISTS)
    from 00:00:00:00:00:02, expires in 3600 s

Not sure what I'm doing wrong here, if anything. I had to update the patch on the remote box slightly for trunk as it didn't apply, but once I did that, it compiled fine.

By: Leif Madsen (lmadsen) 2010-01-13 13:33:52.000-0600

Curious if the reporter is still interested in this functionality?

By: Joel Vandal (jvandal) 2010-01-13 13:47:48.000-0600

I'm using the 1.4 version of the patch on Asterisk 1.4.26/27/28/SVN and all work correctly, what look the your dundi.conf for mapping ? You use the ${SHELL(...)} function ?

Probably that the patch no more work with latest 1.6 SVN, I will do some test with latest SVN trunk version.

By: Leif Madsen (lmadsen) 2010-01-13 13:52:08.000-0600

Hmmm, I'm not sure if I have the dundi.conf file. Looks like I wasn't using the SHELL() function -- is that necessary? I think I was just trying to pass back the ${NUMBER} in the weight if this is the same file I was using previously.

By: Joel Vandal (jvandal) 2010-01-13 13:58:26.000-0600

On my /etc/asterisk/dundi.conf file, I have :

e164 => dundi-e164-via-pstn,${SHELL(/tmp/test-dundi ${NUMBER}")},IAX2,dundi:...

I also presume that if you set it like the following, it must also work since it use variable substitution :

e164 => dundi-e164-via-pstn,${NUMBER},IAX2,dundi:...


e164 => dundi-e164-via-pstn,${RAND(100|200)},IAX2,dundi:...

By: Leif Madsen (lmadsen) 2010-03-23 10:00:59

Unfortunately I've run out of time to continue testing this, so rather than allowing it to relish in the feedback status, I'm moving this back to Ready for Testing.

By: Russell Bryant (russell) 2011-05-06 15:57:01

The patch looks right after a quick review.  I'd like to see some testing again though.

By: Leif Madsen (lmadsen) 2011-11-07 15:22:34.087-0600

OK I figured out why the 59999 shows up in my testing today. If either func_shell isn't loaded, or nothing is returned correctly (i.e. the example provided here had an extra double quote), then a null result will end up having the weight value of 59999.

However, on further testing this all works. I'll be uploading a simple sample bash script and an updated patch against trunk.

By: Leif Madsen (lmadsen) 2011-11-07 15:25:56.377-0600

My dundi.conf mapping:

testing => testing-lookup,${SHELL(sh /tmp/dund-weight.txt ${NUMBER})},SIP,dundi:${SECRET}@${IPADDR}/${NUMBER}

And my result

dundi-2*CLI> dundi lookup 200@testing bypass
 1.     1 SIP/dundi:j1Q9axKIuQV1DIQrMsFLEA==@ (EXISTS|CANMATCH)
    from 00:0c:29:af:82:a1, expires in 3600 s
DUNDi lookup completed in 41 ms