This module can be used by the opensips-cli
tool to execute JSON-RPC
commands and display the result in the console.
This module exports all the commands that are exported by the OpenSIPS
instance that opensips-cli
points to. It fetches the available commands by
running the OpenSIPS MI which
command. When running a command, it returns
the raw, unprocessed data from OpenSIPS.
Commands using this module can be run in two manners:
- using positional parameters: this is similar to the old way the
opensipsctl
tool was working: the parameters passed to the function are specified in the same order to the MI interface, in a JSON-RPC array - using named parameters: parameters should be specified using their name
Note: due to the new OpenSIPS MI interface, some functions (such as
sip_trace
,dlg_list
) can no longer be used using positional parameters, and they have to be specified using named parameters.
This module can accept the following parameters in the config file:
output_type
: indicates the format of the output printed. Possible values are:pretty-print
- (default) prints the output in a pretty-prited JSON formatdictionary
- prints the output as a JSON dictionarylines
- prints the output on indented linesyaml
- prints the output in a YAML formatnone
- does not print anything
The mi
module can receive a set of modifiers for its commands that influence
the communication with OpenSIPS. Available modifiers are:
-j
: the modifier instructs the module to avoid converting the parameters as strings and treat them as JSON values, if possible.
Fetch the OpenSIPS uptime
in a YAML format:
opensips-cli -o output_type=yaml -x mi uptime
Now: Wed Feb 20 13:37:25 2019
Up since: Tue Feb 19 14:48:41 2019
Display the load and networking statistics one on each line:
Note: the get_statistics
command receives the statistics as an array
parameter
opensips-cli -o output_type=lines -x mi get_statistics load net:
load:load: 0
net:waiting_udp: 0
net:waiting_tcp: 0
net:waiting_tls: 0
The command ran is similar to the following one, but parameters are specified using their names:
opensips-cli -o output_type=lines -x mi get_statistics statistics='load net:'
load:load: 0
net:waiting_udp: 0
net:waiting_tcp: 0
net:waiting_tls: 0
Use the -j
modifier for specifying array params as well as json:
opensips-cli -x -- mi -j raise_event E_TEST '["127.0.0.1", 5060]'
opensips-cli -x -- mi -j raise_event event=E_TEST params='{"ip":"127.0.0.1", "port":5060}}'
Some commands in OpenSIPS (such as get_statistics
, or dlg_push_var
)
require array parameters. Since the current OpenSIPS MI interface does not
allow us to query which parameter is an array, this is currently statically
provisioned in the mi module, the
MI_ARRAY_PARAMS_COMMANDS
parameter. Note: if a new command that requires
array arguments is defined in OpenSIPS, this array has to be updated!.