jump to navigation

Using multiple servers and one database with regserver July 24, 2007

Posted by bbarrett in Asterisk, VoIP, realtime.
trackback

Asterisk’s Realtime is a favourite subject of ours apparently. We have a phone system here in the TSSG, which consists of one Asterisk machine inside our network and another external to the network peered with it. They both share the same database so a user can register on either machine.

Until today I used the simplest way to ring a user, when a call comes in for a user ring both boxes at the same time. Asterisk will bridge the call to the first channel that picks up, which works. However today I was perusing some of the documentation and came across a SIP realtime database field – regserver.

You need to set a couple of things for this to work.

  1. Have a systemname => whatever in asterisk.conf under [options]
  2. Set rtsavesysname=yes in sip.conf under [general]
  3. Have a column called “regserver” in the SIP peer database

If these conditions are met then when a user registers on a given Asterisk box then the regserver field will be set to the systemname value in asterisk.conf. Using this, it would be simple enough to write a func_odbc function that figures out where the user is and which Asterisk server to call them through. When I have time I will actually implement this and post any dial-plan logic needed to get it working. I have yet to find any built-in Asterisk way of doing the query rather than relying on func_odbc, if I find something I will post information on it instead.

Comments»

1. Vic - January 5, 2008

Can you post the dial plan logic here? I would like to try it. Thanks

2. bbarrett - January 5, 2008

I would like to, but I’m no longer working in the TSSG so I no longer have access to the files. In any case they were rather cluttered with internal stuff. I haven’t worked with Asterisk for almost 6 months so bear with me, but ill try to recall.

IIRC, first of all you would have to configure func_odbc. Then add a func_odbc entry like so:

[GET_REGISTER_SERVER]
dsn=sipaccounts
read=select regserver from sipaccounts where name = '${SQL_ESC(${ARG1})}'

Then something like the following in extensions.conf

exten =>_XXX,1,Answer()
; somehow extract the name from the caller.. there was a function
; to do this... something like SIP_CHANINFO
exten => _XXXX,n,Set(regserver="${GET_REGISTER_SERVER(${name})})
exten => _XXXX,n,GotoIf($[ "${regserver}" != "" ]?${regserver},${EXTEN})
exten => _XXXX,n,Hangup()

Then you can add different contexts with the names of your various sip servers, as defined in asterisk.conf. Or, you could do a direct dial if the server names map to sip servers in a one-to-one fashion like so:

exten =>_XXX,1,Answer()
; somehow extract the name from the caller.. there was a function
; to do this... something like SIP_CHANINFO
; we store it in a channel variable called "name"
exten => _XXXX,n,Set(regserver="${ODBC_GET_REGISTER_SERVER(${name})})
exten => _XXXX,n,Dial(${regserver}/${EXTEN})
exten => _XXXX,n,Hangup()

It all depends on what kind of access control you need (we wanted some) and how your servers are set up. I recommend using a few virtual machines to setup a test bed before trying to do this on a real server.

3. Singleton - June 19, 2008

Somehow i missed the point. Probably lost in translation :) Anyway … nice blog to visit.

cheers, Singleton!!