Asterisk RealTime Static
NOTE: You can only store a static config OR a RealTime config. You cannot, for example, store sip.conf and use sipfriends via RealTime.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;
# 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
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)
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:
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)');
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). Someone please who knows what the metric stuff is for please update this example. Thanks - Flobi.
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
Page Changes
Multiple tables
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
Re: Explanation of metric
- 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).
Explanation of metric
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)
Static and realtime + the metrics
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.
Re: I believe you can use a static and realtime config
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!
bad link
I believe you can use a static and realtime config