System information

our example) using the DB() function. To determine which value the IF() function will
return, we use the DB_EXISTS() function. This function checks whether a value exists
at phones/${NUMBER}/device within the AstDB, and returns either 1 or 0 (true or false).
The DB_EXISTS() function not only returns 1 or 0, but also sets the $
{DB_RESULT} channel variable that contains the value inside the database
if the return value is 1. However, we can’t use that value because the
IF() function is evaluated prior to the condition field being evaluated,
which means ${DB_RESULT} will be blank. Thus, we need to use the
DB() function to look up the value prior to the condition field being
evaluated.
After reloading pbx_dundi.so from the console (module reload pbx_dundi.so), we can
perform a lookup from another server and check out the result:
vancouver*CLI> dundi lookup 1001@extensions bypass
1. 0 SIP/dundi:very_awesome_password/0000FFFF0001 (EXISTS)
from ff:ff:ff:ff:ff:ff, expires in 3600 s
DUNDi lookup completed in 77 ms
With dialplan functions, you can make the responses in your dialplans a lot more dy-
namic. In the next section we’ll look at how you can perform these lookups from the
dialplan using the DUNDILOOKUP(), DUNDIQUERY(), and DUNDIRESULT() functions.
When you perform lookups using the example in this chapter, because
all the peers in your network will return a result (None, or the value you
want), you’ll need to use the DUNDIQUERY() and DUNDIRESULT() functions
to parse through the list of results returned. The alternative would be
to try calling SIP/dundi:very_long_pass@remote_server/None, but this
wouldn’t be very effective. You might even want to handle the extension
None elegantly, in case it gets called.
Performing Lookups from the Dialplan
Performing lookups from the dialplan is really the bread and butter of all of this, because
it allows more dynamic routing from within the dialplan. With DUNDi, you can per-
form lookups and route calls within your cluster using either the DUNDILOOKUP() or
DUNDIQUERY() and DUNDIRESULT() functions.
The DUNDILOOKUP() function replaces the old DUNDiLookup() dialplan application, per-
forming nearly the same functionality. With DUNDILOOKUP(), you perform your lookup
like you would at the Asterisk console, and the result can then be saved into a channel
variable, or used wherever you might use a dialplan function. Here is an example:
[TestContext]
exten => 1001,1,Verbose(2,Look up extension 1001)
same => n,Set(DUNDi_Result=${DUNDILOOKUP(1001,extensions,b)})
Configuring Asterisk for Use with DUNDi | 519