login | register
Fri 03 of Jul, 2009 [21:14 UTC]

voip-info.org

History

Asterisk RealTime Static

Created by: utdrmac,Last modification on Mon 27 of Apr, 2009 [13:25 UTC] by eriklat

Asterisk RealTime Static


EDIT 04-24-09:
 I do not believe this is true. On asterisk 1.4 I have sip.conf, as well as SIP extensions defined 
within a MySQL database. Both means of authentication work. Even using #include "/etc/asterisk/sip.d/"
lines within sip.conf work in combination with RealTime database.

NOTE: If you store sip.conf in the RealTime database, you need to rename/remove the text file otherwise the text file will superceed RealTime.


Extconfig.conf Setup

Add the following line, swapping your own personal values if you wish:


sip.conf => mysql,asterisk,ast_config


You can change mysql to odbc if you want to use odbc.
You can change asterisk to be the name of your database.
You can change ast_config to be the name of the table we will create below.

NOTE: You can bind multiple filenames to the same table, but any tables using RealTime static need to use the format below, not the format shown on the respective non-static RealTime page for that file. The files will be filtered by the `filename` field.

Database Table

NOTE: You can use any table name you wish, just make sure the table name matches what you have the family name bound to.

#
# Table structure for table `ast_config`
#

CREATE TABLE `ast_config` (
 `id` int(11) NOT NULL auto_increment,
 `cat_metric` int(11) NOT NULL default '0',
 `var_metric` int(11) NOT NULL default '0',
 `commented` int(11) NOT NULL default '0',
 `filename` varchar(128) NOT NULL default '',
 `category` varchar(128) NOT NULL default 'default',
 `var_name` varchar(128) NOT NULL default '',
 `var_val` varchar(128) NOT NULL default '',
 PRIMARY KEY  (`id`),
 KEY `filename_comment` (`filename`,`commented`)
) TYPE=MyISAM;



NOTE: The index created on the columns 'filename' and 'commented' is because RealTime does its SELECT query using those 2 columns everytime. That column id must also be unique.

The easiest way to get existing *.conf files into the database is by using bwk's perl script.

http://www.krisk.org/asterisk/ast2sql.pl

It actually doesn't remove inline comments, and Asterisk can be confused by them. Please remove them before you use the script.


Examples

To enable realtime static on your extensions file...let's say it looked like this:
[general]
static=yes

[globals]
CONSOLE=Console/dsp ; Console interface for demo

[default]
exten=_.,1,SetVar(extension=${EXTEN})
exten=_.,2,Macro(dial_agi_ver.1.0.0,${EXTEN},${channel})
exten=h,1,Goto(done,${extension},1)
and let's say you're using the table as defined above with an odbc defined as asterisk in your res_odbc.conf, you could use these insert statments to
INSERT INTO `ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES ('0','0','extensions.conf', 'general', 'static', 'yes');
INSERT INTO `ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES ('1','0','extensions.conf', 'globals', 'Console/dsp', 'yes');
INSERT INTO `ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES ('2','0','extensions.conf', 'default', 'exten', '_.,1,SetVar(extension=${EXTEN})');
INSERT INTO `ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES ('2','1','extensions.conf', 'default', 'exten', '_.,2,Macro(dial_agi_ver.1.0.0,${EXTEN},${channel})');
INSERT INTO `ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES ('2','2','extensions.conf', 'default', 'exten', 'h,1,Goto(done,${extension},1)');
and add this line to your extconfig.conf:
extensions.conf => odbc,asterisk,ast_config


Note: The table structure for realtime static[sic] is much different than the structure for other realtime tables. You must use the structure above for ALL config files using static. Commented records (where commented != 0) are ignored (or should be, honestly I haven't checked). The fields `cat_metric' and `var_metric' defines the order: a lower metric means it appears higher in the file. This is useful for things like codec order in sip.conf or iax.conf where you want 'disallow=all' to appear first (metric of 0), followed by 'allow=ulaw' (metric of 1), then by 'allow=gsm' (metric of 2).

Testing


Throw some data into the above table and issue an 'asterisk reload'. This should get the *.conf info you bound out from database. The /var/log/asterisk/debug should give info on any problems.

Cheers,
Matthew



See Also


Comments

Comments Filter
222

333Multiple tables

by Lord_Lele, Monday 27 of November, 2006 [17:02:55 UTC]
You can also use different tables for each configuration file:

File: extconfig.conf

extensions.conf => mysql,databasename,extensions_conf
iax.conf => mysql,databasename,iax_conf
sip.conf => mysql,databasename,sip_conf
voicemail.conf => mysql,databasename,voicemail_conf

And then use the same SQL to create multiple tables:

CREATE TABLE `sip_conf` (
`id` int(11) NOT NULL auto_increment,
`cat_metric` int(11) NOT NULL default '0',
`var_metric` int(11) NOT NULL default '0',
`commented` int(11) NOT NULL default '0',
`filename` varchar(128) NOT NULL default 'sip.conf', 
`category` varchar(128) NOT NULL default 'default',
`var_name` varchar(128) NOT NULL default '',
`var_val` varchar(128) NOT NULL default '',
PRIMARY KEY  (`id`),
KEY `filename_comment` (`filename`,`commented`)
) TYPE=MyISAM;

CREATE TABLE `iax_conf` (
`id` int(11) NOT NULL auto_increment, 
`cat_metric` int(11) NOT NULL default '0', 
`var_metric` int(11) NOT NULL default '0', 
`commented` int(11) NOT NULL default '0', 
`filename` varchar(128) NOT NULL default 'iax.conf', 
`category` varchar(128) NOT NULL default 'default', 
`var_name` varchar(128) NOT NULL default '', 
`var_val` varchar(128) NOT NULL default '', 
PRIMARY KEY  (`id`), 
KEY `filename_comment` (`filename`,`commented`) 
) TYPE=MyISAM;

...and similar for extensions.conf and voicemail.conf

222

333Re: Explanation of metric

by waba, Saturday 22 of July, 2006 [12:54:56 UTC]
I've had a look at the * source code and behaviour on this topic. My conclusions (all this is per-filename, the rows are independent if their filename differs):

- If you are ever going to use var_metric, then do set cat_metric to something different per category. It's like what Jens explained, but the numbers don't have to follow any order (eg, 42, 1 and 999 are all fine)

- You can use var_metric to force the ordering of variables within a category (useful for example with sip.conf allow/disallow). In this case, variables with a lower metric will be evaluated first. So to get "disallow=all" then "allow=alaw", you can give 0 to disallow and 1 to allow.

- If you have some sets of variables for the same category, but with different cat_metric, then the set with the highest metric will entirely overwrite the other ones ("joe|secret|42" cat_metric=0, "joe|type|friend" cat_metric=1 -> there is no joe|secret).

222

333Explanation of metric

by radcliff, Thursday 06 of April, 2006 [00:11:55 UTC]
By looking at the source @ http://www.krisk.org/asterisk/ast2sql.pl it is clear that metric can be explained as follows:

cat_metric: each [category] in a config will have its own value, 0 for the first, 1 for the second and so on
var_metric: each variable inside each [category] will have its own value same a cat_metric.

in the example below:
CONSOLE in [globals] will have cat_metric=1 and var_metric=0

[general]
static=yes

[globals]
CONSOLE=Console/dsp ; Console interface for demo

[default]
exten=_.,1,SetVar(extension=${EXTEN})
exten=_.,2,Macro(dial_agi_ver.1.0.0,${EXTEN},${channel})
exten=h,1,Goto(done,${extension},1)

222

333Static and realtime + the metrics

by PBXNoobie, Monday 06 of February, 2006 [13:21:52 UTC]
Hi I am experimenting loading zapata.conf from realtime/MySQL.

I have had some luck, infact it has worked, I too could do with knowing what the metric stuff is, the comment out does work by the way.

The problem I am having is with the groups, they atill come under the channels section, but they do not as such have their own section, I am figuring that by adding a metric one can associate the various groups? This is quite hard to explain without a sample. But if the first group had a metric of 1 then all the relevant options (context, channel, callerid)in that group should share the same metric, and then group 2 will have a metric of 2 and so on and on??? This is 100% guess work.

I did get this working, then broke it again without making proper config notes/backup.....

Any help would be much appreciated, now have a very nice config. Multiple servers centrally configured. Works a treat excepting zapata.conf, will soon be post a blow by blow how to from the install to the config. Have spent much time figuring all this out and tuning it..... Too many install guides make assumptions that this or that is done and working, they are not that helpful.....

You can definately use static and realtime with the switch statement.






222

333Re: I believe you can use a static and realtime config

by rob314, Friday 13 of May, 2005 [16:44:34 UTC]
Can you document how you have the static configs for extensions.conf setup? Table structure and an example of the data would be really helpful.

I am running into the same problem where I have multiple contexts that I combine into one. In the past I would just build a context and then issue "include" statements to pull them all together. I can still do that in extensions.conf by building individual contexts with the "switch => Realtime/...." and then building my larger contexts with includes in the flat file but that kinda defeats the purpose of me using RealTime.

My goal is to be able to build my larger contexts using includes in my DB so that I can form my front end around a DB entirely — which I would obviously make available here when I have it completed.

Any input would be greatly appreciated!
222

333bad link

by gmillerd, Wednesday 27 of April, 2005 [10:03:54 UTC]
Anyone have a source for this 'http://asterisk.bkw.org/load.txt'?
222

333I believe you can use a static and realtime config

by , Monday 13 of December, 2004 [02:57:49 UTC]
I store extensions.conf in the static config (since you have to contexts to put the switch => statements in), and also use it for realtime extensions with no problems.