Upgrade 3CX to v18 and get it hosted free!

Asterisk RealTime Static

Author image

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.

EDIT 09-08-09:
Actually what the note says is that you can have both files but information in the text file overwrites the
information from the database so make sure you erase or blank the file if you have problems to make sure
your database is providing the configuration.

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 `bit_ast_config`
#

CREATE TABLE `bit_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.

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 `bit_ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES (‘0′,’0′,’extensions.conf’, ‘general’, ‘static’, ‘yes’);
INSERT INTO `bit_ast_config` (`cat_metric` , `var_metric` , `filename` , `category` , `var_name` , `var_val` ) VALUES (‘1′,’0′,’extensions.conf’, ‘globals’, ‘Console/dsp’, ‘yes’);
INSERT INTO `bit_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 `bit_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 `bit_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

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.