System information

Because the other end is just going to request an extension number and won’t neces-
sarily know the location of the device on our system, we can use the DB() and
DB_EXISTS() functions within the mapping to perform a lookup from our AstDB for the
device to call.
Prior to Asterisk version 1.8.3, the maximum length of the destina
tion field (see “Creating Mapping Contexts” on page 510) was 80 char-
acters, which made the use of nested dialplan functions nearly impos-
sible. As of Asterisk 1.8.3, the maximum length is 512 characters.
First we need to make sure our database is populated with the information we might
respond with. While this would normally be done by the dialplan written for the hot-
desking implementation, we’ll just add the content directly from the Asterisk console
for demonstration purposes:
*CLI> database put phones 1001/device 0000FFFF0001
Updated database successfully
With our database populated, we need to modify our mapping to utilize some dialplan
functions that will take the value requested, perform a lookup to our database for that
value, and return a value. If no value exists in the database, we’ll return the value of None.
Our existing mapping looks like this:
[mappings]
; The mapping exists on a single line
extensions => RegisteredDevices,0,SIP,
dundi:very_secret_secret@toronto.example.com/${NUMBER},nopartial
Our current example simply reflects back the same extension number that was reques-
ted, along with some authentication information. The number requested is the exten-
sion the peer is looking for. However, because we’re using hot-desking, the extension
number may be located at various phone locations, so we may want to return the device
identifier directly.
We can do this by being clever with the use of dialplan functions
in our response. While we may not have the full power of the dialplan (multiple lines,
complex logic, etc.) at our disposal, we can at least use some of the simpler dialplan
functions, such as DB(), DB_EXISTS(), and IF().
We’re going to replace ${NUMBER} with the following bit of dialplan logic:
${IF($[${DB_EXISTS(phones/${NUMBER}/device)}]?${DB(phones/${NUMBER}/device)}:None)}
If we break this down, we end up with an IF() statement that will return either true or
false. If false, we return the value of None. If true, we return the value located in the
database at phones/${NUMBER}/device (where ${NUMBER} contains the value of 1001 for
† …or func_odbc, or func_curl, or res_ldap (using the REALTIME_FIELD() function).
‡ We’ve also looked at using the GROUP() and GROUP_COUNT() functions for looking up the current channel usage
on a remote system to determine which location to route calls to (the one with the lowest channel usage) as
a simple load balancer.
518 | Chapter 23:Distributed Universal Number Discovery (DUNDi)