Outrt question

I have a SIP trunking provider that requires me to append a diversion header for outbound calls. They use the number in the diversion header for their call billing records. I have other SIP trunks to a local gateway which has problems when it sees the diversion header. The trunk group that requires the header is 9_outside and the one without is 8_outside.

I’m appending the header in outrt-001-9_outside-custom. The problem is that even if we’re doing a 8+ dial, the outrt-001-9_outside-custom still get included via outbound-allroutes. Is there a better place to do that?

Perhaps if I hook in outbound-allroutes-custom is there a way to tell which trunk is about to be dialed? Better yet: is there a variable I can test and only add the header if it’s using the trunk when it needs it? I could drop the 8_outside route altogether then!

Describe what you need to append and then show us the code you have so far.

extensions_custom.conf:
[outrt-001-8_outside-custom]
exten => _X.,1,Noop(Nothing added here)

[outrt-001-9_outside-custom]
exten => _X.,n,SIPAddHeader(Diversion: sip:[email protected];reason=unconditional;screen=no;privacy=off)

Then, whether I dial 8+ or 9+ both of these are called. I’d “expect” that only the 8_outside-custom would be called if an 8+ were dialed and only 9_outside-custom would be called if 9+ were dialed.

Is there a trunk var that I can evaluate in the 9_outside-custom to only then append the diversion header if that var matches the trunk that needs the header?

I spent a lot of time avoiding the macro-dialout-trunk-predial-hook because the comments in extensions.conf are ominous. Upon using it I’m in awe of wonders you can do in it.

In my trunk definition I have:

Trunk Name: 8005551212

Then in extensions_custom.conf I have:

[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Need Diversion Header Check)
exten => s,n,Set(TRUNK_FOUND=${OUT_${DIAL_TRUNK}:4})
exten => s,n,Set(TRUNK_TARGET=8005551212)
exten => s,n,ExecIf($["${TRUNK_FOUND}" = "${TRUNK_TARGET}"],SIPAddHeader,"Diversion: <sip:[email protected]>\;reason=unconditional\;screen=no\;privacy=off")
exten => s,n,MacroExit()

If the call is happening on the trunk where the trunk name matches TRUNK_TARGET (maintained in the file manually) the diversion header is then added. If they don’t match nothing gets changed.

New question: Is it possible to define a value in PEER Details that I can then evaluate in macro-dialout-trunk-predial-hook?

Thus far you’ve been talking about originating outbound calls. The SIP-PEER is at the end of the dial plan. What are you looking to Set/Test? Do you mean Set/Test a CHANNEL VARIABLE along the dial plan’s outbound progress?

If so, you may want to look at using the underscore (“_”) in front of your variable(s) to increase the forward scope of the variable’s inheritance.

Set(myVar1="foo")
Set(_myVar1="foo")
Set(__myVar1="foo")

Each have different (longer) forward scope as the call (channel) advances through the dial plan.

Alternatively, you can add a custom sip header, where custom (application private, non-sip signaling) headers are prefixed “X-” (e.g. “X-myHEADER:”). Use the SipAddHeader(“X-myHEADER: ”), like you’ve done with the diversion header. Subsequently, this can be read back using, SipGetHeader().

/S

Yes, I think so. I’m only looking to evaluate this variable during outbound calls. (At the same time I’m learning how all this fits together, but obviously not quite there yet. I’m still a little unsure about terminology.)

I see that values inserted in the “Edit SIP Trunk” page’s “PEER Details” appear in extensions_additional.conf like:

[code]Trunk name: c2800

PEER Details:
host=10.1.250.11
type=peer
secret=c2800pw
qualify=yes
username=c2800
fromuser=c2800
dtmfmode=auto
[/code]

results in:

/etc/asterisk/extensions_additional.conf [c2800] host=10.1.250.11 type=peer secret=c2800pw qualify=yes username=c2800 fromuser=c2800 dtmfmode=auto context=from-trunk-sip-c2800

In the above solution for determining when to add the diversion header I have to manually maintain the trunk in two locations: Edit SIP Trunk and extensions_custom.conf.

I’m wondering what it takes to add a key/value pair to the “PEER Details” such that I can simply match that key in macro-dialout-trunk-predial-hook.

The resulting macro-dialout-trunk-predial-hook could then be (apologies in advance for bogus pseudo-coding):

[macro-dialout-trunk-predial-hook] exten => s,1,Noop(Need Diversion Header Check) exten => s,n,ExecIf($["${${SIP CHAN}.SOMEKEY}"!=""],SIPAddHeader,"${${SIP CHAN}.SOMEKEY}" exten => s,n,MacroExit()

Then the resulting PEER details would be changed to:

host=10.1.250.11
type=peer
secret=c2800pw
qualify=yes
username=c2800
fromuser=c2800
dtmfmode=auto
context=from-trunk-sip-c2800
SOMEKEY=Diversion: <sip:[email protected]>\;reason=unconditional\;screen=no\;privacy=off

To better restate the question: if I put SOMEKEY in the peer details, how would I access to test for that key’s value in macro-dialout-trunk-predial-hook?

Thank you for your help!

Taking the easier part first … at the point of macro-dialout-trunk-predial-hook, you haven’t reached the PEER selection – YET. You are just about to commit the call to a specific TRUNK, and that TRUNK is going to use one (or more) SIP PEER (or FRIENDs) as configured in the TRUNKs page.

As such, a PEER (or FRIEND) level variable, if there were one, isn’t yet in play.

/S

Yes.

[VOIPMS-PEER]
type=peer
...
setvar=YourPeerVarNameHere=1234
...

RELOAD.

Then, in the dial plan, it’s just another variable

${YourPeerVarNameHere}

You can use the CLI,

$ asterisk -r
fpbx*CLI> sip show peer VOIPMS-PEER 

  * Name       : VOIPMS-PEER
  Secret       : <Not Set>
  MD5Secret    : <Set>
  Context      : from-trunk-sip-VOIPMS-PEER
  Subscr.Cont. : myhint-context
  Language     : 
  ...
  Variables    :
                 YourPeerVarNameHere = 1234
  ...

See “Variables” section above.

In my mind (dense as it may be), I’m still not so sure how this PEER (or FRIEND) variable facility helps you on an OUTBOUND call at a point in the dial plan two-or-more-steps before the PEER (or FRIEND) is reached. … but, 1) the variable function is there for you to try, and 2) perhaps I just don’t quite grasp the problem your solving (my bad, not yours).

Good luck,

So sad I can’t reach ahead into the trunk, but I can work with it.

Thanks for the example of how to set variables in the PEER.

Maybe if you described the problem your trying to solve, rather then the syntax you’re after?

/S

I’m good to go. As you note, there isn’t a PEER to play in at the point I’d like.

Thank you very much for your help with this!

:slight_smile:

/S