Page 188 - Asterisk™: The Future of Telephony
P. 188
This macro depends on a nice side effect of the Dial() application: when you use the
Dial() application, it sets the DIALSTATUS variable to indicate whether the call was suc-
cessful or not. In this case, we’re handling the NOANSWER and BUSY cases, and treating all
other result codes as a NOANSWER.
Using the Asterisk Database (AstDB)
Having fun yet? It gets even better!
Asterisk provides a powerful mechanism for storing values called the Asterisk database
(AstDB). The AstDB provides a simple way to store data for use within your dialplan.
For those of you with experience using relational databases such as
PostgreSQL or MySQL, the Asterisk database is not a traditional rela-
tional database. It is a Berkeley DB Version 1 database. There are several
ways to store data from Asterisk in a relational database. Check out
Chapter 12 for a more about relational databases.
The Asterisk database stores its data in groupings called families, with values identified
by keys. Within a family, a key may be used only once. For example, if we had a family
called test, we could store only one value with a key called count. Each stored value
must be associated with a family.
Storing Data in the AstDB
#
To store a new value in the Asterisk database, we use the Set() application, but instead
of using it to set a channel variable, we use it to set an AstDB variable. For example, to
assign the count key in the test family with the value of 1, write the following:
exten => 456,1,Set(DB(test/count)=1)
If a key named count already exists in the test family, its value will be overwritten with
the new value. You can also store values from the Asterisk command line, by running
the command database put family key value. For our example, you would type data
base put test count 1.
Retrieving Data from the AstDB
To retrieve a value from the Asterisk database and assign it to a variable, we use the
Set() application again. Let’s retrieve the value of count (again, from the test family),
assign it to a variable called COUNT, and then speak the value to the caller:
# Previous versions of Asterisk had applications called DBput() and DBget() that were used to set values in and
retrieve values from the AstDB. If you’re using an old version of Asterisk, you’ll want to use those applications
instead.
160 | Chapter 6: More Dialplan Concepts