[asterisk-users] asterisk realtime and creating "new" contexts

Mike Clark mike at infoanywhere.com
Fri Aug 15 06:49:45 CDT 2008


Todd Fulton wrote:
> Hi,
>
> I'm trying to create a multi-tennant asterisk installation .... where 
> each of my customers has its own context.  Well, I've got asterisk 
> realtime working, and I can add/update extensions to existing contexts 
> in extensions.conf without a problem.  However, when I attempt to 
> create database entries with a context that is NOT in extensions.conf, 
> I get an error "invalid extension".
>
> I've found several posts around the net asking this question, but no 
> answers.  Has anyone out there dealt with this problem?
>
> Any help would be great!
>
>
> Todd
>
Todd:

Unfortunately, new contexts don't seem to show up in "real time". I 
solved this in RAGUI by putting #exec statements in the extensions.cong 
file that scan the extensions table and generate the proper contexts. 
However, you still have to do a reload to get the contexts to be 
available in Asterisk.

Here is an example:

in extensions.conf

#exec /opt/pointcall/asterisk/scripts/load_extensions.rb

I used Ruby, but it could be Perl , PHP or whatever

load_extensions.rb

#!/usr/local/bin/ruby
#

require 'mysql'

hostname = "host"
username = "user"
password = "pass"
database = "rtdb"

my = Mysql.new(hostname, username, password, database)

res = my.query("SELECT DISTINCT context FROM extensions ORDER by context")
#
res.each do |row|
        context = row[0]
        print "\n"
        print '[' + context + "]\n"
        print "Switch => Realtime/" + context + "\n"
end


Thanks,

Mike



More information about the asterisk-users mailing list