Routing script tutorial

From TBwiki
(Difference between revisions)
Jump to: navigation, search
(New page: == Introduction == The scripts requires you to define a class that will help you select one of your previously created routes. There are 3 mandatory things to define for your script to wor...)
 
Line 3: Line 3:
 
There are 3 mandatory things to define for your script to work:
 
There are 3 mandatory things to define for your script to work:
  
- Define your new script routing class, which can contain one or many of these methods (route_order,route_match,route_remap)
+
# Define your new script routing class, which can contain one or many of these methods (route_order,route_match,route_remap)
- The 'init_routes' method
+
# The 'init_routes' method
- The 'route' method
+
# The 'route' method
  
For more information about the parameters that can be use within a method go [[knowledgebase:toolpack:script_routing|here]]
+
For more information about the parameters that can be use within a method, go see the [[mini development guide]]
  
 
== Script routing class ==
 
== Script routing class ==
Line 17: Line 17:
 
== What I need to define a script routing class ==
 
== What I need to define a script routing class ==
 
There are 3 methods that can be use
 
There are 3 methods that can be use
- route_order
+
# route_order
- route_match
+
# route_match
- route_remap
+
# route_remap
 
'route_order' will be called before the 'route_match' which will all be called before the 'route_remap'.
 
'route_order' will be called before the 'route_match' which will all be called before the 'route_remap'.
  
Line 25: Line 25:
  
 
'route_order' allows to order routes using one of 3 possible arguments. It is only possible to call 'route_order' once.
 
'route_order' allows to order routes using one of 3 possible arguments. It is only possible to call 'route_order' once.
- :route_field_name - The field name of the **route** to order with. The value of the route field should be an **integer** so that it can be compared.
+
# :route_field_name - The field name of the **route** to order with. The value of the route field should be an **integer** so that it can be compared.
- :proc - A user supplied **proc** to call instead of trying to order internally. It should accept two argument: route list, nap list and return the sorted route list.
+
# :proc - A user supplied **proc** to call instead of trying to order internally. It should accept two argument: route list, nap list and return the sorted route list.
- :method - A user supplied **method** to call instead of trying to order internally. It should accept two argument: route list, nap list and return the sorted route list.
+
# :method - A user supplied **method** to call instead of trying to order internally. It should accept two argument: route list, nap list and return the sorted route list.
  
 
base_routing pre-implemented ordering method:
 
base_routing pre-implemented ordering method:
Line 40: Line 40:
 
'route_match' allows to match a call to one route using one of 4 possible arguments. It is possible to call 'route_match' multiple times to reduce the number of matching routes. Since 'route_match' will return the first matching route it find, there is a possibility that there is more than one route match, therefore it is important to order the routes or prioritize them using 'route_order'.
 
'route_match' allows to match a call to one route using one of 4 possible arguments. It is possible to call 'route_match' multiple times to reduce the number of matching routes. Since 'route_match' will return the first matching route it find, there is a possibility that there is more than one route match, therefore it is important to order the routes or prioritize them using 'route_order'.
  
- :call_field_name - The field name of the call to try to match
+
# :call_field_name - The field name of the call to try to match
- :route_field_name - The field name of the route to try to match with. The default is to use the call field name. If the value of the field is empty, the match is considered positive. The value of the route field can be a regular expression. e.g. /555000./
+
# :route_field_name - The field name of the route to try to match with. The default is to use the call field name. If the value of the field is empty, the match is considered positive. The value of the route field can be a regular expression. e.g. /555000./
- :proc - A user supplied proc to call instead of trying to do the match internally. It should accept three argument: route, call, nap list and return a boolean to indicate the match.
+
# :proc - A user supplied proc to call instead of trying to do the match internally. It should accept three argument: route, call, nap list and return a boolean to indicate the match.
- :method - A user supplied method to call instead of trying to do the match internally. It should accept three argument: route, call, nap list and return a boolean to indicate the match.
+
# :method - A user supplied method to call instead of trying to do the match internally. It should accept three argument: route, call, nap list and return a boolean to indicate the match.
  
 
base_routing pre-implemented matching method:
 
base_routing pre-implemented matching method:
Line 56: Line 56:
 
'route_remap' allows to remap the parameter of the route or the call using one of the 4 possible arguments. There are actually 3 type of remapping that can be done. using the :call_field_name/:route_field_name arguments, the :proc argument and/or the :method argument.  
 
'route_remap' allows to remap the parameter of the route or the call using one of the 4 possible arguments. There are actually 3 type of remapping that can be done. using the :call_field_name/:route_field_name arguments, the :proc argument and/or the :method argument.  
  
- :call_field_name - The field name of the call to remap
+
# :call_field_name - The field name of the call to remap
- :route_field_name - The field name of the route to remap with. The default is to use the call field name. If the value of the field is empty, the incoming call's attribute is used. The value of the route field can be a regular expression remap. e.g. /(555000.)/001\1/
+
# :route_field_name - The field name of the route to remap with. The default is to use the call field name. If the value of the field is empty, the incoming call's attribute is used. The value of the route field can be a regular expression remap. e.g. /(555000.)/001\1/
- :proc - A user supplied proc to call instead of trying to do the remap internally. It should accept four argument: route, call, nap list, remapped fields and return a hash of remapped fields.
+
# :proc - A user supplied proc to call instead of trying to do the remap internally. It should accept four argument: route, call, nap list, remapped fields and return a hash of remapped fields.
- :method - A user supplied method to call instead of trying to do the match internally. It should accept four argument: route, call, nap list, remapped fields and return a hash of remapped fields.
+
# :method - A user supplied method to call instead of trying to do the match internally. It should accept four argument: route, call, nap list, remapped fields and return a hash of remapped fields.
  
  
Line 81: Line 81:
 
=== Examples and tutorials ===
 
=== Examples and tutorials ===
  
* script routing class tutorial [[knowledgebase:toolpack:script_routing:routing_class_tutorial|here]]
+
* [[Routing_script_tutorial:Routing_Class_Tutorial|script routing class tutorial]]
* 'route_order' tutorial [[knowledgebase:toolpack:script_routing:route_order_tutorial|here]].
+
* [[Routing_script_tutorial:route_order_Tutorial|'route_order' tutorial]].
* 'route_match' tutorial [[knowledgebase:toolpack:script_routing:route_match_tutorial|here]].
+
* [[Routing_script_tutorial:route_match_Tutorial|'route_match' tutorial]].
* 'route_remap' tutorial [[knowledgebase:toolpack:script_routing:route_remap_tutorial|here]].
+
* [[Routing_script_tutorial:route_remap_Tutorial|'route_remap' tutorial]].
 
* pre-made routing script are also available through the web portal in the script routing menu.
 
* pre-made routing script are also available through the web portal in the script routing menu.
 +
 +
 +
----
 +
Back to the [[Scriptable_Routing_Engine|Scriptable Routing Engine]] page.

Revision as of 11:13, 20 May 2009

Contents

Introduction

The scripts requires you to define a class that will help you select one of your previously created routes. There are 3 mandatory things to define for your script to work:

  1. Define your new script routing class, which can contain one or many of these methods (route_order,route_match,route_remap)
  2. The 'init_routes' method
  3. The 'route' method

For more information about the parameters that can be use within a method, go see the mini development guide

Script routing class

The scripting class is use to define on which call/nap parameters the call need to match the route or to remap the call parameter. You also need to define all new methods required by your script routing class. It is highly recommended to derive your new class for the 'base_routing' class, because it give your a lot of functionality.

What I need to define a script routing class

There are 3 methods that can be use

  1. route_order
  2. route_match
  3. route_remap

'route_order' will be called before the 'route_match' which will all be called before the 'route_remap'.

'route_order' method

'route_order' allows to order routes using one of 3 possible arguments. It is only possible to call 'route_order' once.

  1.  :route_field_name - The field name of the **route** to order with. The value of the route field should be an **integer** so that it can be compared.
  2.  :proc - A user supplied **proc** to call instead of trying to order internally. It should accept two argument: route list, nap list and return the sorted route list.
  3.  :method - A user supplied **method** to call instead of trying to order internally. It should accept two argument: route list, nap list and return the sorted route list.

base_routing pre-implemented ordering method:

  • 'order_by_asr', this method will order the routes according to the asr(average success rate). This method requires to add a custom **nap** parameter called ':asr_type', its value can be: global, last_24h, current_hour, last_hour. It can be use in your custom class like this:
 route_order :method => :order_by_asr


'route_match' method

'route_match' allows to match a call to one route using one of 4 possible arguments. It is possible to call 'route_match' multiple times to reduce the number of matching routes. Since 'route_match' will return the first matching route it find, there is a possibility that there is more than one route match, therefore it is important to order the routes or prioritize them using 'route_order'.

  1.  :call_field_name - The field name of the call to try to match
  2.  :route_field_name - The field name of the route to try to match with. The default is to use the call field name. If the value of the field is empty, the match is considered positive. The value of the route field can be a regular expression. e.g. /555000./
  3.  :proc - A user supplied proc to call instead of trying to do the match internally. It should accept three argument: route, call, nap list and return a boolean to indicate the match.
  4.  :method - A user supplied method to call instead of trying to do the match internally. It should accept three argument: route, call, nap list and return a boolean to indicate the match.

base_routing pre-implemented matching method:

  • 'match_nap_availability', this method will verify the availability through the nap status.
 route_match :method => :match_nap_availability
  • 'match_asr_threshhold', this method will verify will match any route who's destination nap has a higher asr than the treshold stored for that nap. This method requires to add 2 custom **nap** parameters called. First is 'asr_threshhold_type', its values can be : global, last_24h, current_hour, last_hour. The second is 'asr_threshhold', its value needs to be an **integer** between 0 and 100.
 route_match :method => :match_asr_threshhold


'route_remap' method

'route_remap' allows to remap the parameter of the route or the call using one of the 4 possible arguments. There are actually 3 type of remapping that can be done. using the :call_field_name/:route_field_name arguments, the :proc argument and/or the :method argument.

  1.  :call_field_name - The field name of the call to remap
  2.  :route_field_name - The field name of the route to remap with. The default is to use the call field name. If the value of the field is empty, the incoming call's attribute is used. The value of the route field can be a regular expression remap. e.g. /(555000.)/001\1/
  3.  :proc - A user supplied proc to call instead of trying to do the remap internally. It should accept four argument: route, call, nap list, remapped fields and return a hash of remapped fields.
  4.  :method - A user supplied method to call instead of trying to do the match internally. It should accept four argument: route, call, nap list, remapped fields and return a hash of remapped fields.


'init_routes' method

The 'init_routes' is a mandatory method that is call every time the script is loaded ( think loading the configuration ). This can be use at your advantage to do some pre-processing like ordering your routes, that way the routes will not be re-ordered at every call that comes in.

'route' method

The 'route' is a mandatory method that is call at every call that comes in. This is where you can do the dynamic routing part.

What else?

There are numerous possibilities:

  • Add new methods for route selection.
  • Add new columns in the nap or route.
  • Create scripts that includes other scripts to help make the routing more modular.


Examples and tutorials



Back to the Scriptable Routing Engine page.

Personal tools