Brekeke Forum Index » Brekeke SIP Server Forum

Post new topic   Reply to topic
Access a Variable across the Dialplans
Author Message
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Wed Aug 29, 2018 3:52 pm    Post subject: Access a Variable across the Dialplans Reply with quote

1. Brekeke Product Name and Version:BSS Adv Ver 3.5.2

2. Java version:1.8

3. OS type and the version:RHEL 6.1

4. UA (phone), gateway or other hardware/software involved:SIPP

5. Your problem:
I need to save the value in a variable and use the variable in the next dial plan.
In the first dial plan, I want to run a webget and retrieve the value from a remote server. If the returned value is 404 then I want to get the action to 404. In the next dial plan I want to check if returned value is 503 then I want to set the action as 503. If the length of the retuened value is more than 3 then I wan to terminate the call as explain in the last dial plan.


Matching Patterns
$addr = 192.168.2.180
$request = ^INVITE
To = sip:(.+)@
From = sip:(.+)@
$web.webget("http://192.168.2.100/getValue.php?param1 = %1") = (.+)
Deploy Patterns
$myVariable = %3
$log = TEST-VARIABLE:$myVariable
$log = TEST:%3

$continue

Matching Patterns
$myVariable = 404
Deploy Patterns
$action = 404


Matching Patterns
$myVariable = 503
Deploy Patterns
$action = 503

Matching Patterns
$math.gt($str.length($myVariable),3) = true
Deploy Patterns
To = sip:$myVariable@192.168.2.130
Back to top
View user's profile
Harold
Brekeke Master Guru


Joined: 21 Sep 2008
Posts: 287
Location: Japan

PostPosted: Wed Aug 29, 2018 9:06 pm    Post subject: Reply with quote

Use &VARIABLE_NAME
Refer this: http://wiki.brekeke.com/wiki/Global-and-Local-Variables-in-Dial-Plan

Rule-1: WebGet
Matching Patterns
$request = ^INVITE
$addr = 192.168.2.180
To = sip:(.+)@
$web.webget("http://192.168.2.100/getValue.php?param1 = %1") = (.+)
Deploy Patterns
&my.variable = %2
$log = TEST-VARIABLE:&my.variable
$log = TEST:%2
$continue = true

Rule-2: Return Response
Matching Patterns
&my.variable = ^[456][0-9][0-9]$
Deploy Patterns
$response = %{&my.variable}

Rule-3: Route Call
Matching Patterns
$math.gt($str.length(&my.variable),3) = true
Deploy Patterns
To = sip:%{&my.variable}@192.168.2.130
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Thu Aug 30, 2018 8:09 am    Post subject: Reply with quote

Thanks and appreciate your help.
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Fri Sep 07, 2018 4:26 pm    Post subject: Reply with quote

This works perfectly fine but I am not able to pass on the INVITE Parameters. to Leg-B

for example I recieve the INVITE as :

INVITE sip:+111@192.168.2.5:5060;user=phone SIP/2.0

and I am sending out the INVITE as

INVITE sip:+222@192.168.2.55:5060 SIP/2.0
Back to top
View user's profile
Harold
Brekeke Master Guru


Joined: 21 Sep 2008
Posts: 287
Location: Japan

PostPosted: Fri Sep 07, 2018 9:52 pm    Post subject: Reply with quote

Change Rule-3 as this.

Matching Patterns
$math.gt($str.length(&my.variable),3) = true
Deploy Patterns
To/uri = sip:%{&my.variable}@192.168.2.130
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Mon Sep 10, 2018 6:45 am    Post subject: Reply with quote

Appreciate your response.

One final request. How to enhance the rule-3 with failover option
For example, first attempt should goto 192.168.2.130 and in case .130 does not respond or respond with roll over cause code then second attempt should be attempted to 192.168.2.131
Back to top
View user's profile
janP
Brekeke Master Guru


Joined: 25 Nov 2007
Posts: 336

PostPosted: Mon Sep 10, 2018 10:50 am    Post subject: Reply with quote

FYI:
http://wiki.brekeke.com/wiki/How-to-make-Failover-in-the-Dial-Plan

Deploy Patterns
To/uri = sip:%{&my.variable}@192.168.2.130
$session = failover sip:%{&my.variable}@192.168.2.131
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Mon Sep 10, 2018 12:41 pm    Post subject: Reply with quote

Math.gt function is throwing java exception. Following is the output from the dial plan log.





Warning: plug-in = public static boolean com.brekeke.net.sip.sv.rule.matching.plugins.math.gt(java.lang.String[],com.brekeke.net.sip.SIPpacket,java.util.Properties) throws java.lang.Exception message=java.lang.NumberFormatException: For input string: ""
DialPlan: Exception: 09/10/18 15:39:12.004
java.lang.NumberFormatException: For input string: "": (depth=14)
java.lang.NumberFormatException.forInputString (NumberFormatException.java:65)
java.lang.Long.parseLong (Long.java:601)
java.lang.Long.parseLong (Long.java:631)
com.brekeke.net.sip.sv.rule.matching.plugins.math.gt (null:-1)
sun.reflect.GeneratedMethodAccessor3.invoke (null:-1)
sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke (Method.java:498)
com.brekeke.net.sip.sv.rule.RuleTable.invokeMethod (null:-1)
com.brekeke.net.sip.sv.rule.RuleTable.execMatchingPlugin (null:-1)
com.brekeke.net.sip.sv.rule.RuleTable.getSpecialValue (null:-1)
com.brekeke.net.sip.sv.rule.RuleTable.getValue (null:-1)
com.brekeke.net.sip.sv.rule.RuleTable.evalRule (null:-1)
com.brekeke.net.sip.sv.rule.RuleTable.getMatch (null:-1)
com.brekeke.net.sip.sv.Dispatcher.run (null:-1)

Pattern: $math.gt($str.length(&my.variable),3) = true
Input: $math.gt($str.length(&my.variable),3) = null
Result: false
Back to top
View user's profile
janP
Brekeke Master Guru


Joined: 25 Nov 2007
Posts: 336

PostPosted: Mon Sep 10, 2018 4:08 pm    Post subject: Reply with quote

put a double-quotation around 3.

$math.gt($str.length(&my.variable),"3")
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Tue Sep 11, 2018 12:06 pm    Post subject: Reply with quote

Math.gt problem got resolved, thanks for your help.

Following helps to fix the parameters in the TO header but it does not help to replay the paramaters in the INVITE request.

Deploy Patterns
To/uri = sip:%{&my.variable}@192.168.2.130


Incoming Packet INVITE sip:+11111@192.168.2.5:5060;user=phone SIP/2.0
Outgoing Packet INVITE sip:+22222@192.168.2.130 SIP/2.0

How can I main the INVITE params?
Back to top
View user's profile
Tata
Brekeke Master Guru


Joined: 27 Jan 2008
Posts: 223

PostPosted: Tue Sep 11, 2018 2:58 pm    Post subject: Reply with quote

Something wrong in SIP packet or settings.
Check the DialPlan history whether "user=phone" exists or not.

Also can you paste all of DialPlan rules here?
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Tue Sep 11, 2018 3:08 pm    Post subject: Reply with quote

Here is complete rule-3


Matching Patterns
$math.gt($str.length(&my.variable),"3") = true
Deploy Patterns
To/uri = sip:%{&my.variable}@192.168.2.130
$session = failover sip:%{&my.variable}@192.168.2.131
&failover.timer.inviting = 1
$b2bua = true
$rtp = false
$ifdst = 192.168.2.5
$ifsrc = 192.168.2.6
Back to top
View user's profile
Tata
Brekeke Master Guru


Joined: 27 Jan 2008
Posts: 223

PostPosted: Tue Sep 11, 2018 4:07 pm    Post subject: Reply with quote

Did you check the DialPlan history to see whether "user=phone" exists originally?

If yes, enable "DialPlan" at [Diagnostics]->[Debug Logs] page and check why it is removed.
Back to top
View user's profile
skb007
Brekeke Guru


Joined: 05 Oct 2015
Posts: 152
Location: USA

PostPosted: Tue Sep 11, 2018 4:11 pm    Post subject: Reply with quote

Yes, I did. I copy/pasted from the the dialplan history.
Back to top
View user's profile
Tata
Brekeke Master Guru


Joined: 27 Jan 2008
Posts: 223

PostPosted: Tue Sep 11, 2018 6:44 pm    Post subject: Reply with quote

Have you checked the log too?
Back to top
View user's profile
Tata
Brekeke Master Guru


Joined: 27 Jan 2008
Posts: 223

PostPosted: Tue Sep 11, 2018 7:27 pm    Post subject: Reply with quote

Add the line below at [Configuration]->[Advanced] page
---------------------------------------
net.sip.keep.uri-param=true
---------------------------------------
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    Brekeke Forum Index » Brekeke SIP Server Forum All times are GMT - 7 Hours
Page 1 of 1