System information
A Word About Metrics
The metrics in static realtime are used to control the order in which objects are read
into memory. Think of the cat_metric and var_metric as the original line numbers in
the flat file. A higher cat_metric is processed first, because Asterisk matches categories
from bottom to top. Within a category, through, a lower var_metric is processed first,
because Asterisk processes the options top-down (e.g., disallow=all should be set to
a value lower than the allow’s value within a category to make sure it is processed first).
A simple file we can load from static realtime is the musiconhold.conf
‖
file. Let’s start
by moving this file to a temporary location:
$ cd /etc/asterisk
$ mv musiconhold.conf musiconhold.conf.old
In order for the classes to be removed from memory, we need to restart Asterisk. Then
we can verify that our classes are blank by running moh show classes:
*CLI> core restart now
*CLI> moh show classes
*CLI>
Let’s put the [default] class back into Asterisk, but now we’ll load it from the database.
Connect to your database and execute the following INSERT statements:
> INSERT INTO ast_config (filename,category,var_name,var_val)
VALUES ('musiconhold.conf','default','mode','files');
> INSERT INTO ast_config (filename,category,var_name,var_val)
VALUES ('musiconhold.conf','default','directory','/var/lib/asterisk/moh');
You can verify that your values have made it into the database by running a SELECT
statement:
asterisk=# SELECT filename,category,var_name,var_val FROM ast_config;
filename | category | var_name | var_val
------------------+----------------+--------------+------------------------
musiconhold.conf | default | mode | files
musiconhold.conf | default | directory | /var/lib/asterisk/moh
(2 rows)
There’s one last thing to modify in the extconfig.conf file in the /etc/asterisk directory
to tell Asterisk to get the data for musiconhold.conf from the database using the ODBC
connection. The first column states that we’re using the ODBC drivers to connect
(res_odbc.conf) and that the connection name is asterisk (as defined with [asterisk]
in res_odbc.conf). Add the following line to the end of the extconfig.conf file, and then
save it:
‖ The musiconhold.conf file can also be loaded via dynamic realtime, but we’re using it statically as it’s a simple
file that makes a good example.
370 | Chapter 16: Relational Database Integration