System information

Additional scenarios and information about Local channels and the modifier flags
(/n, /j, /m, /b) are available at https://wiki.asterisk.org/wiki/display/AST/Local+Chan
nel. If you will be making any sort of regular use of Local channels, that is a very im-
portant document to read.
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 16 for 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, we would 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
database 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.
214 | Chapter 10:Deeper into the Dialplan