No matching results Documentation Forum
Asterisk Tutorial 26 - The Asterisk Database

Asterisk Tutorial 26 - The Asterisk Database

Introducing Asterisk Phone Systems – How to Use The Asterisk Database & Asterisk Functions

Over the next few tutorials we will be getting much more professional with our dynamic queues and dynamic members. However, as this is quite complicated, that does mean that we need to introduce a few new concepts starting with demonstrating how to add entries to the Asterisk Database and then using Asterisk functions with your dialplan to query the database.

What you need to know

First things first, it is important to understand that the Asterisk Database is a “Key Value” database, meaning that the “keys” are listed on the left and their corresponding “values” on the right. Moreover, the Asterisk Database is a persistent database, which means that when you stop your Asterisk service, a record of the database is stored and then recovered when Asterisk is restarted. This is particularly useful as it means you can copy the database to different Asterisk instances and create backups.

In order to access the Asterisk Database, simply log into the Asterisk CLI and use the command database followed by the appropriate command such as show. Additional commands can be see in the image below, however starting with the show command is a good idea as it provides you with an overview of existing entries within the Asterisk Database.

Asterisk phone system database

Adding Asterisk Database Entries

In order to add an entry to the Asterisk database, you will need to use the command database put and by pressing return you will get a read out of the syntax required to add your entry:

asterisk*CLI> database put
Usage: database put <family> <key> <value>
Adds or updates an entry in the Asterisk database for a given family, key, and value.

Therefore, to finish adding your entry to the database, use the command database put . In our example, this translates to:

database put pascom james ok. 

Once you are done, it is worth checking that everything worked correctly by using the database show command.

The family part of the string is an essential component of the database entry as it groups entries with similar characteristics together, thus providing an clearer database overview as well as making database management much simpler as highlighted when removing entries.

Removing Asterisk Database Entries

The role of the components of adding an entry become much clearer, when looking at removing entries. In order to remove an entry, two options are available. Firstly, to remove a single entry use the command database del . Should you wish to remove a whole family group you will need to use the database deltree command.

Introducing Asterisk Functions

Just like there being an application for everything within Asterisk, there is also a function for everything. In order to view all the available functions in Asterisk, use the command core show functions. For the purposes of this tutorial, we are interested in the function DB_EXISTS as this will allow us to get our dialplan to query if an agent can be found within the Asterisk Database or not, and therefore is already logged into the queue or not when building our dynamic queues.

In our test setup, we created a new extension in our dialplan, and then used the DB_EXISTS function as follows (${DB_EXISTS(family/key)}? followed by our new extension number plus actions concerning what the dailplan should do should the query return a true or false answer, as shown below:

exten => *300,1,NoOp(database test)
same => n,GotoIf(${DB_EXISTS(pascom/james)}?*300-ok,1)
same => n,Hangup

exten => *300-ok,1,NoOp(james exists)
same => n,Answer()
same => n,Playback(beep)
same => n,Hangup

So there you have it, how to use the Asterisk Database, add and remove entries as well as how to use functions to query the database. Next time we will take our dynamic queues even further, so stay tuned! Word to the wise, a very special event is coming up in the life of the VoIP Guys, which could mean we are off air for a short while, but rest assured we will be back very soon!

pascom hosted PBX - start upgrading your business communications today

Final Word

A well-configured business phone system that oozes useful tools, delivers excellent audio quality and intuitive call flows will leave callers with a highly professional impression. The configuration options, available applications and how well they are utilized will have a decisive impact on how professionally you manage your calls and therefore how your customers view your company. The switch to a pascom VoIP phone system solution provides the opportunity to not only upgrade your internal employee collaboration but also to redefine your business telephony.

If you would like more information regarding pascom and our Asterisk based PBX software, please visit our website or give the pascom team a call on +49 991 29691 0 to discuss your requirements and get started within minutes using our free hosted business VoIP phone system edition.