login | register
Tue 09 of Feb, 2010 [21:07 UTC]

voip-info.org

History

Asterisk res_config

Created by: flavour,Last modification on Fri 09 of Oct, 2009 [19:22 UTC] by Nugget

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

Comments Filter
222

333extconfig formatting

by mogyiman, Thursday 30 of July, 2009 [15:05:55 UTC]
Hello,

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

222

333Insert CDR in database

by pepelu, Monday 11 of June, 2007 [11:59:36 UTC]
When Asterisk insert CDR in database, it insert datetime in format MM-dd-yyyy and I need the format dd-MM-yyyy. Someone can help me????
222

333Re: ARGH

by , Sunday 13 of February, 2005 [14:45:57 UTC]
Looks like the file app_voicemail.c is somehow messed up in the SQL that it passes in. MySQL logs indicate that it successfully connects to the db, but then it passes in "SEL" instead of "SELECT * from users ..." or whatever it should be passing. Anyone know anything about this?(:question:)
222

333ARGH

by beonice, Friday 11 of February, 2005 [22:41:07 UTC]
(:mad:)
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:)
222

333Automatic reload from DB

by , Thursday 27 of January, 2005 [14:43:23 UTC]
When is app_realtime slated for release
222

333SQL Realtime

by , Wednesday 08 of December, 2004 [10:03:42 UTC]
Hello,

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.
222

333Re: reload?

by Marlow, Saturday 06 of November, 2004 [07:32:38 UTC]
The sense is for example to have a single repository for the configuration of several servers, still not making the servers dependant on the database.
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.

222

333reload?

by rkarlsba, Thursday 04 of November, 2004 [12:51:10 UTC]
What's the point of having all the config stuff in a database if asterisk needs to be reloaded every time it's using it?!? if this is so, the old (iax|sip)friends were even better :(
222

333missing res_odbc.so and res_config_odbc.so

by teliax, Monday 04 of October, 2004 [04:15:23 UTC]
From the following line you can see that asterisk looks for obdcinst.h which means if you are using unixodbc you will need the odbc development files (unixodbc-dev). Good luck!

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)
222

333extconfig.conf

by jrdutton, Tuesday 29 of June, 2004 [10:42:05 UTC]
I believe that this file should contain 'queues.conf = odbc', NOT 'queues.conf = config_odbc'