Exchange data between Asterisk and OpenSER via SIP

From Etel

Jump to: navigation, search

Contents

Title

Exchange data between Asterisk and OpenSER via SIP

Problem

You have a central SIP proxy in front of several Asterisk servers doing load balancing, additional security, etc. You want to do DB lookups from a central location (OpenSER SIP proxy) and you want to do able to hand that data to Asterisk.

Solution

We will be doing our DB lookups from OpenSER. I feel that OpenSER has better database support than Asterisk, and this way you don't need to install and setup DB support on every Asterisk server. We will be using custom SIP headers to exchange data. This recipe assumes you've already got calls flowing between OpenSER and the Asterisk server(s).

OpenSER code:

# Lookup the value from the DB, store it in an avp.
# Append a custom header - ALWAYS begin SIP custom headers with X-
# If we fail, write error to log and reply to client with error.
if (avp_db_query("select value from database.table where key='$rU'","$avp(s:custom1)")) {
  append_hf("X-etel-custom1: $avp(s:destid)\r\n");
} else {
  xlog("I couldn't look up that data\n");
  sl_send_reply("500", "I couldn't look up that data");
  return(0);
}
# Forward to the Asterisk server(s)
route(5);

Asterisk code (extensions.conf):

[sip-in]
exten => _NXX,1,SIPGetHeader(CUSTOM1=X-etel-custom1)
exten => _NXX,n,Goto(${CUSTOM1},s,1)

Discussion

Any pseudo variable from OpenSER can be used to customize the DB lookup and any value can be stored in an AVP. This value can then set a variable in the Asterisk dialplan for use by any Asterisk application - including the dialplan itself!

See Also:

http://www.openser.org/docs/modules/1.2.x/avpops.html

Metadata

By: Kristian Kielhofner

Personal tools