Monday, December 29, 2014

Kamailio 4.2 Tips: #12 - Execute RPC Commands In Config

Although part of a new module in Kamailio v4.2 - jsonrpc-s - this bit worth a special mention: one can now execute RPC commands from kamailio.cfg using the function jsonrpc_exec(...).

The main purpose of these commands was the execution from external applications, but sometimes comes handy to get access to them.

Next example shows how to execute dispatcher.reload:

jsonrpc_exec('{"jsonrpc": "2.0", "method": "dispatcher.reload", "id": 1}');

An useful use case for the above command can be execution in a rtimer route to perform period reload of dispatcher records.

Another example is to terminate an active dialog using h_entry and h_id.

jsonrpc_exec('{"jsonrpc":"2.0","method":"dlg.end_dlg","params":[4,8],"id":2}');

The RPC command has to be given as parameter to jsonrpc_exec() in JSONRPC 2.0 request format.

There are over one hundred RPC commands exported now by Kamailio and the number is increasing with each major release -- no doubt that many of them can be useful to trigger from kamailio.cfg.

Enjoy it!

No comments:

Post a Comment