Asterisk res_config
res_config
A very flexible way of storing configuration information (e.g. users in sip.conf) in an ODBC database (e.g. MySQL).It does, however, require the server to be reloaded to make changes appear.
As of 2004-Jun-10 res_config was available in what was at that point called CVS Head. You will need ODBC development packages installed for your distribution, e.g unixODBC-dev. Res_config is now part of the stable sourcetree e.g. definitely in 1.0.2 and later.
Setup
Create table
Using your normal database tool, create a table to hold the config info:create table ast_config (
id bigint primary key not null auto_increment,
cat_metric int not null default 0,
var_metric int not null default 0,
commented int not null default 0,
filename varchar(128) not null,
category varchar(128) not null default 'default',
var_name varchar(128) not null,
var_val varchar(128) not null
);
Specify how to reach the tables
Create /etc/asterisk/configs/res_odbc.conf and specify how to reach the just-created table:; /etc/asterisk/configs/res_odbc.conf
[mysql1]
dsn = MySQL-asterisk
username = myuser
password = mypass
pre-connect = yes
[mysql2]
dsn = MySQL2-asterisk
username = myuser2
password = mypass2
enabled = no
[ENV]
VAR=VALUE
You can have several sections in this file, e.g. for a production and a staging asterisk. The [ENV] section sets environment variables. Some database drivers need them for their operation.
Therefore, we need a "glue" entry that tells asterisk which one to use.
Outdated! Put lines similar to these into /etc/asterisk/res_config_odbc.conf:
; /etc/asterisk/res_config_odbc.conf
[settings]
table = ast_config
connection = mysql1
Specify what tables are now in the ODBC database
And finally we can re-route the config engine of Asterisk to not use the config file, but our table instead. This is done with /etc/asterisk/extconfig.conf:; /etc/asterisk/extconfig.conf
[settings]
queues.conf => odbc
CVS HEAD as of 2004-10-05 changes format to:
; /etc/asterisk/extconfig.conf
[settings]
queues.conf => odbc,mysql1,ast_config
Also this change means, that res_config_odbc.conf is deprecated. At least in Asterisk v1.0.2 and later extconfig.conf is what you need to use.
Old remarks: For stable you will currently have to stick with the old format, though.
Create sample data
You can also put sample data into the database:insert into ast_config (filename,category,var_name,var_val)
values('queues.conf','kewl','Member','Agent/1000,1234,1');
You still need to issue a "reload" command.
You can upload your current configuration data to mysql with this script: load_res_config.pl
Another script, that i found (for postgresql) is here. He also has some fixes for the postgresql odbc
driver on http://www.gofti.com/
Notes
- Create records with "General" as category in order to define the typical General section in .conf files
- True or not? You need to touch /etc/asterisk/sip.conf - the files still need to exist, but they can (and should) be empty.
Modules overview
- res_config is the thing that allows you to hijack the configs
- res_odbc is the resource to have reusable database handles, globally accessible across multiple apps. It's driven by res_odbc.conf
- res_config_odbc is the part that access the database, driven by processes res_config_odbc.conf - as of 2004-10-05 this file is deprecated. It's functionality has moved to extconfig.conf. It's still needed in the stable tree.
- the build-in config.c code processes the extconfig.conf file
See also
Asterisk | FAQ | Tips & Tricks

Comments
333extconfig formatting
Just a reminder to everyone, If you have everything configured right and the static configuration is still make sure that the extconfig.conf file does NOT contains any spaces. I still wonder why not copied the example!?
BAD : sip_additional.conf => mysql, asterisk, ast_config
GOOD: sip_additional.conf => mysql,asterisk,ast_config
333Insert CDR in database
333Re: ARGH
333ARGH
I can't get this to work! I've updated extconfig.conf, res_config*.conf, updated the Makefile to configure VM from MySQL. I can see the data in the MySQL table (the user table and the ast_config table both have plenty of data). When I restart asterisk, asterisk thinks my mailboxes are not defined.
Maya(:mad:)
333Automatic reload from DB
333SQL Realtime
i've read that the CVS Head of asterisk implements the feature of realtime configuration via mysql database, but I can't find any setting for this. Is there some info how to set this up? Thanks in advance.
333Re: reload?
Also there is an effort in cvs head with app_realtime to make it possible, not having to reload.
Beyond that iax|sip friends doesn't allow you to set codecs and different other stuff, that's why many avoid to use them for production.
333reload?
333missing res_odbc.so and res_config_odbc.so
MODS+=$(shell if -f "/usr/include/odbcinst.h" ; then
echo "res_odbc.so res_config_odbc.so"; fi)
MODS+=$(shell if -f "/usr/local/include/odbcinst.h" ; then echo "res_odbc.so res_config_odbc.so"; fi)
333extconfig.conf