Can Asterisk Read From Database Instead Of Conf Files?

First let me say, Asterisk is an amazing project and i am becoming a fan of it each day. Its the power of asterisk that i really like about.

I just have a doubt. Does Asterisk has the capability to read the conf from database instead of sip.conf or extension.conf. So that as a part of the project i am trying to build a clean front end for the editing of conf files, for which i prefer database rather than the file.

My idea is simple, a good front end will capture the information from user, put the formatted information into database in the same format sip/extension conf contains. And asterisk can directly execute it from database.

So can i make asterisk do that? If yes how?

Thanks in advance
Sanju

yes asterisk can get configs from a database - its aclled asterisk realtime. look for more info in the book “Asterisk: The future of Telephony” and or the wiki voip-info.org

That reply has given me a new direction. Thank you so much for the valuable reply swaterhouse.

Also for others, if you are facing the same problem please check out the sites below

konak.biz/kb/asteriskrealtime.html

voip-info.org/wiki/view/Asterisk+RealTime

hostseries.com/asterisk-realtime … ion-guide/

Seems a great introduction for db integration. Cool.
I will try to implement it and will post the steps/result of integration so that it will be a guide for all.

Give me sometime since i will start from today only :wink:

Thanks
Sanju

Its written that etc/asterisk/res_mysql.conf file should contain the db settings like below

[general]
dbhost = localhost
dbname = asterisk
dbuser = asterisk
dbpass = yourpassword
dbport = 3306
dbsock = /var/lib/mysql/mysql.sock

For me MySql lies in a remote machine and i have specifed the ip address of that in the dbhost.

[general]
dbhost = 192.168.0.1
dbname = asterisk
dbuser = asterisk
dbpass = mypassword
dbport = 3306
dbsock = ??

But in dbsock what should i give, since astersik machine do not have any MySql.

Hey guys,

After lot of head scratching and googling, i finally made it work.
For those guys who is still unlucky below is my code.
I am using CentOS and MySQL.

Step 1. Create db named ‘asterisk’

Step 2. Create tables

CREATE TABLE sip_buddies (
id int(11) NOT NULL auto_increment,
name varchar(80) NOT NULL default ‘’,
host varchar(31) NOT NULL default ‘’,
nat varchar(5) NOT NULL default ‘no’,
type enum(‘user’,‘peer’,‘friend’) NOT NULL default ‘friend’,
accountcode varchar(20) default NULL,
amaflags varchar(13) default NULL,
call-limit smallint(5) unsigned default NULL,
callgroup varchar(10) default NULL,
callerid varchar(80) default NULL,
cancallforward char(3) default ‘yes’,
canreinvite char(3) default ‘yes’,
context varchar(80) default NULL,
defaultip varchar(15) default NULL,
dtmfmode varchar(7) default NULL,
fromuser varchar(80) default NULL,
fromdomain varchar(80) default NULL,
insecure varchar(4) default NULL,
language char(2) default NULL,
mailbox varchar(50) default NULL,
md5secret varchar(80) default NULL,
deny varchar(95) default NULL,
permit varchar(95) default NULL,
mask varchar(95) default NULL,
musiconhold varchar(100) default NULL,
pickupgroup varchar(10) default NULL,
qualify char(3) default NULL,
regexten varchar(80) default NULL,
restrictcid char(3) default NULL,
rtptimeout char(3) default NULL,
rtpholdtimeout char(3) default NULL,
secret varchar(80) default NULL,
setvar varchar(100) default NULL,
disallow varchar(100) default ‘all’,
allow varchar(100) default ‘g729;ilbc;gsm;ulaw;alaw’,
fullcontact varchar(80) NOT NULL default ‘’,
ipaddr varchar(15) NOT NULL default ‘’,
port smallint(5) unsigned NOT NULL default ‘0’,
regserver varchar(100) default NULL,
regseconds int(11) NOT NULL default ‘0’,
lastms int(11) NOT NULL default ‘0’,
username varchar(80) NOT NULL default ‘’,
defaultuser varchar(80) NOT NULL default ‘’,
subscribecontext varchar(80) default NULL,
PRIMARY KEY (id),
UNIQUE KEY name (name),
KEY name_2 (name)
)

CREATE TABLE extensions (
id int(11) NOT NULL auto_increment,
context varchar(20) NOT NULL default ‘’,
exten varchar(20) NOT NULL default ‘’,
priority tinyint(4) NOT NULL default ‘0’,
app varchar(20) NOT NULL default ‘’,
appdata varchar(128) NOT NULL default ‘’,
PRIMARY KEY (context,exten,priority),
KEY id (id)
)

Step 3. Insert data into those tables

[i]INSERT into extensions (id, context, exten, priority, app, appdata)
VALUES
(’’,‘incoming’,‘100’,‘1’,‘Answer’,’’),
(’’,‘incoming’,‘100’,‘2’,‘Playback’,‘tt-monkeys’),
(’’,‘incoming’,‘100’,‘3’,‘Hangup’,’’);

INSERT into sip_buddies (id, name, callerid, context, canreinvite, insecure, type, host, secret, allow, nat)
VALUES (’’,‘100’,‘sanju’,‘incoming’,‘no’,‘port,invite’,‘friend’,‘dynamic’,‘test’,‘all’,‘no’);[/i]

Step 4. Assuming you have asterisk-addons downloaded and installed, edit the res_mysql.conf in /etc/asterisk dir

[general]
dbhost = mysqlServerIP
dbname = asterisk
dbuser = root
dbpass = urpassword
dbport = 3306
dbsock = /var/lib/mysql/mysql.sock
; install mysql for this one

Step 5. Edit the extconfig.conf in /etc/asterisk dir

[settings]
sipusers => mysql,general,sip_buddies
sippeers => mysql,general,sip_buddies
extensions => mysql,general,extensions

Step 5. Edit the extensions.conf in /etc/asterisk dir

[i][general]
autofallthrough=no
clearglobalvars=no

[incoming]
switch => Realtime/@extensions[/i]

Step 6. Edit the modules.conf in /etc/asterisk dir

[modules]
autoload=yes
preload => res_realtime.so
preload => res_config_mysql.so

thats it, run your asterisk server and in the *CLI> type the command 'realtime mysql status’ you woul see something like

MySQL RealTime: Connection okay.
general connected to asterisk@xxx.xxx.x.xx, port 3306 with username root for 3 seconds.

try it out, once you are able to pull it , then guys you dont have to edit the text conf files at all, you can put everything in database and may be you can provide some gui just to configure astersik.

Hai sanju,

I have done all the configurations what u mentioned in your post. I followed all the steps what u have given here.
I gave “realtime mysql status” command in my asterisk cli. Finally i got the following thing in my asterisk server cli. That sample result i have given below.
cli > realtime mysql status
No such command ‘realtime mysql status’ (type ‘core show help realtime mysql status’ for other possible commands).

This is what i got when i followed your steps. Can u help me to cliarify my doubt sanju?.

Thanks…