Table of Contents
List of Examples
load
parameterjsdt_run
usageTable of Contents
This module allows executing Ruby scripts from the Kamailio configuration file. It exports all KEMI functions to Ruby in order to access the currently processed SIP message. These functions are available within the Ruby module 'KSR'.
IMPORTANT: because of Ruby language policy (which require that a public submodule name has to start with an uppercase letter), the KSR submodule names are with all letters uppercase. For example, what is documented as KSR.sl in KEMI docs, must be used as KSR::SL in Ruby scripts.
Set the path to the Ruby file to be loaded at startup. Then you can use Ruby_run(function, params) to execute a function from the script at runtime. If you use it for KEMI configuration, then it has to include the requited functions.
Default value is “null”.
Example 1.1. Set load
parameter
... modparam("app_ruby", "load", "/usr/local/etc/kamailio/ruby/myscript.rb") ...
Execute the Ruby function 'func' giving params as parameters. There can be up to 3 string parameters. The function must exist in the script loaded at startup via parameter 'load'. Parameters can be strings with pseudo-variables that are evaluated at runtime.
Example 1.2. jsdt_run
usage
... if(!ruby_run("rb_append_fu_to_reply")) { xdbg("SCRIPT: failed to execute ruby function!\n"); } ... ruby_run("rb_funcx", "$rU", "2"); ...
Marks the need to reload the js script. The actual reload is done by every working process when the next call to ruby_run() function or KEMI config is executed.
Name: app_ruby.reload
Parameters: none
Example:
... kamcmd app_ruby.reload ...
Create your Ruby script and store it on the file system, say: '/usr/local/etc/kamailio/ruby/myscript.rb'.
... def ksr_sl_reply() KSR.dbg("==== from ruby - src ip: " + KSR::PV.get("$si") + "\n") KSR::SL.sl_send_reply(200, "OK-Ruby") end ...
Load the script via parameter 'load' and execute function via ruby_run(...).
... modparam("app_ruby", "load", "/usr/local/etc/kamailio/ruby/myscript.rb") ... request_route { ... if(!ruby_run("ksr_sl_reply")) { xdbg("SCRIPT: failed to execute ruby function!\n"); } ... } ...