| 1 |
# $Id$ |
| 2 |
# |
| 3 |
# History: |
| 4 |
# -------- |
| 5 |
# 2009-05-07 created by Andrei Pelinescu-Onciul <[email protected]> |
| 6 |
|
| 7 |
|
| 8 |
Overview |
| 9 |
======== |
| 10 |
|
| 11 |
kamcmd is a unix tool for interfacing with Kamailio using exported RPCs. |
| 12 |
It uses binrpc (a proprietary protocol, designed for minimal packet size and |
| 13 |
fast parsing) over a variety of transports (unix stream sockets, unix datagram |
| 14 |
sockets, udp or tcp). |
| 15 |
For more details on binrpc see the ctl module documentation |
| 16 |
(modules/ctl/README). |
| 17 |
|
| 18 |
kamcmd can work in command line mode (the RPC or command name is just another |
| 19 |
command line parameter) or in interactive mode. The interactive mode supports |
| 20 |
history and tab-completion (if kamcmd was compiled with libreadline support). |
| 21 |
|
| 22 |
On Kamailio side the ctl module must be loaded. |
| 23 |
|
| 24 |
Usage |
| 25 |
===== |
| 26 |
|
| 27 |
kamcmd [options][-s address] [ cmd ] |
| 28 |
|
| 29 |
Options: |
| 30 |
-s address unix socket name or host name to send the commands on |
| 31 |
-R name force reply socket name, for the unix datagram socket mode |
| 32 |
-D dir create the reply socket in the directory <dir> if no reply |
| 33 |
socket is forced (-R) and a unix datagram socket is selected |
| 34 |
as the transport |
| 35 |
-f format print the result using format. Format is a string containing |
| 36 |
%v at the places where values read from the reply should be |
| 37 |
substituted. To print '%v', escape it using '%': %%v. |
| 38 |
-v Verbose |
| 39 |
-V Version number |
| 40 |
-h Help message |
| 41 |
address: |
| 42 |
[proto:]name[:port] where proto is one of tcp, udp, unixs, unix or unixd |
| 43 |
e.g.: tcp:localhost:2049 , unixs:/tmp/ser_ctl |
| 44 |
If the protocol is not specified, unixs will be |
| 45 |
used if name is a filesystem path and udp if not. |
| 46 |
"unixs" or "unix" stand for unix stream sockets |
| 47 |
and "unixd" for unix datagram sockets. |
| 48 |
cmd: |
| 49 |
method [arg1 [arg2...]] |
| 50 |
arg: |
| 51 |
string or number; to force a number to be interpreted as string |
| 52 |
prefix it by "s:", e.g. s:1 |
| 53 |
|
| 54 |
If no address is specified (no -s), kamcmd will use by default |
| 55 |
unixs:/tmp/ser_ctl. This is also the default for the ctl module (if no |
| 56 |
"binrpc" module parameters are present in the config). |
| 57 |
|
| 58 |
|
| 59 |
Command Types |
| 60 |
============= |
| 61 |
|
| 62 |
There are 3 types of commands: "raw" RPC, kamcmd aliases and kamcmd |
| 63 |
builtins. |
| 64 |
|
| 65 |
The "raw" RPC commands work directly with ser with no change on the input or |
| 66 |
the output. |
| 67 |
To list available RPC commands, use "kamcmd help". |
| 68 |
|
| 69 |
The aliases are just easier to remember names for some RPCs, which |
| 70 |
some time include nicer formatting of the RPC result. |
| 71 |
One can see all the defined aliases using: kamcmd help|grep alias: . |
| 72 |
Example: |
| 73 |
ps is an alias for core.ps with the output formatted in a more readable way. |
| 74 |
kamcmd ps is equivalent to kamcmd -f"%v\t%v\n" core.ps. |
| 75 |
Without the formatting, the output of kamcmd core.ps looks like: |
| 76 |
|
| 77 |
11262 |
| 78 |
attendant |
| 79 |
11268 |
| 80 |
udp receiver child=0 sock=127.0.0.1:5060 |
| 81 |
... |
| 82 |
Using kamcmd ps (or kamcmd -f"%v\t%v\n" core.ps) the output looks like: |
| 83 |
|
| 84 |
11262 attendant |
| 85 |
11268 udp receiver child=0 sock=127.0.0.1:5060 |
| 86 |
... |
| 87 |
|
| 88 |
The built-in commands can combine several different rpcs. |
| 89 |
One can see all the built-in commands using: kamcmd help|grep builtin: . |
| 90 |
|
| 91 |
Getting help on a command |
| 92 |
========================= |
| 93 |
|
| 94 |
To get the help message associated with a command use |
| 95 |
kamcmd help <command_name>. |
| 96 |
Example: |
| 97 |
$ kamcmd help ps |
| 98 |
ps is an alias for core.ps with reply formatting: "%v\t%v\n" |
| 99 |
$ kamcmd help core.ps |
| 100 |
Returns the description of running Kamailio processes. |
| 101 |
|
| 102 |
|
| 103 |
Listing all the commands |
| 104 |
======================== |
| 105 |
|
| 106 |
To see all the available commands (ser RPCs, aliases and bultins) use |
| 107 |
kamcmd help. |
| 108 |
To see only the "raw" RPCs, user kamcmd ls. |
| 109 |
Note: since each module can define its own RPCs, the available RPCs depend |
| 110 |
on the loaded modules. |
| 111 |
|
| 112 |
|
| 113 |
Examples |
| 114 |
======== |
| 115 |
|
| 116 |
Using the default socket (requires only loadmodule "ctl" in ser.cfg): |
| 117 |
|
| 118 |
$ kamcmd ps |
| 119 |
11262 attendant |
| 120 |
11268 udp receiver child=0 sock=127.0.0.1:5060 |
| 121 |
11269 udp receiver child=1 sock=127.0.0.1:5060 |
| 122 |
11270 udp receiver child=0 sock=192.168.1.101:5060 |
| 123 |
11271 udp receiver child=1 sock=192.168.1.101:5060 |
| 124 |
11272 slow timer |
| 125 |
11273 timer |
| 126 |
11274 ctl handler |
| 127 |
11275 tcp receiver child=0 |
| 128 |
11276 tcp receiver child=1 |
| 129 |
11277 tcp main process |
| 130 |
|
| 131 |
$ kamcmd help # list all the supported commands |
| 132 |
dst_blocklist.add |
| 133 |
ctl.who |
| 134 |
... |
| 135 |
|
| 136 |
$ kamcmd help core.uptime # help for the core.uptime rpc |
| 137 |
Returns uptime of the Kamailio server. |
| 138 |
|
| 139 |
$ kamcmd cfg.cfg_set_int_now debug 5 # turn debug level to 5 (needs cfg) |
| 140 |
|
| 141 |
$ kamcmd # enters interactive mode |
| 142 |
|
| 143 |
Using a tcp socket |
| 144 |
(assumes modparam("ctl", "binrpc", "tcp:localhost:2049") in kamailio.cfg) |
| 145 |
|
| 146 |
$ kamcmd -s tcp:localhost:2049 core.version |
| 147 |
Server: Kamailio (3.3.2 (i386/linux)) |
| 148 |
|
| 149 |
$ kamcmd -s tcp:localhost:2049 SRV _sip._udp.iptel.org |
| 150 |
name: _sip._udp.iptel.org |
| 151 |
type: SRV |
| 152 |
size (bytes): 104 |
| 153 |
reference counter: 2 |
| 154 |
expires in (s): 67693 |
| 155 |
last used (s): 0 |
| 156 |
error flags: 0 |
| 157 |
rr name: sip.iptel.org |
| 158 |
rr port: 5060 |
| 159 |
rr priority: 0 |
| 160 |
rr weight: 0 |
| 161 |
rr expires in (s): 67693 |
| 162 |
rr error flags: 0 |
| 163 |
|
| 164 |
kamcmd -s tcp:127.0.0.1:2049 # enters interactive mode over tcp |
| 165 |
|
| 166 |
For more examples see utils/kamcmd/EXAMPLES |
| 167 |
[http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=utils/kamcmd/EXAMPLES]. |
| 168 |
|
| 169 |
|
| 170 |
Interactive Mode |
| 171 |
================ |
| 172 |
|
| 173 |
To enter the interactive mode start kamcmd without specifying a command name |
| 174 |
on the command line. |
| 175 |
If kamcmd was compiled with libreadline support (automatically if |
| 176 |
libreadline dev files are installed), the interactive mode will have tab |
| 177 |
completion and history support. |
| 178 |
|
| 179 |
Example: |
| 180 |
|
| 181 |
$ kamcmd |
| 182 |
kamcmd 0.2 |
| 183 |
Copyright 2006 iptelorg GmbH |
| 184 |
This is free software with ABSOLUTELY NO WARRANTY. |
| 185 |
For details type `warranty'. |
| 186 |
kamcmd> core.s<tab> |
| 187 |
core.sctp_info core.sctp_options core.shmmem |
| 188 |
kamcmd> help core.shmmem |
| 189 |
Returns shared memory info. |
| 190 |
kamcmd> core.shmmem |
| 191 |
{ |
| 192 |
total: 33554432 |
| 193 |
free: 33147816 |
| 194 |
used: 190644 |
| 195 |
real_used: 406616 |
| 196 |
max_used: 406616 |
| 197 |
fragments: 2 |
| 198 |
} |
| 199 |
kamcmd> quit |
| 200 |
|
| 201 |
|
| 202 |
Related Stuff |
| 203 |
============= |
| 204 |
|
| 205 |
* ctl module: required, implements binrpc on Kamailio side, without it kamcmd doesn't work. |
| 206 |
|
| 207 |
See modules/ctl/README |
| 208 |
[http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules_s/ctl/README]. |
| 209 |
|
| 210 |
* cfg_rpc module: allows setting or reading configuration parameters on-the-fly. |
| 211 |
For example one could change the tcp connection lifetime to 180s using: |
| 212 |
$ kamcmd cfg.set_now_int tcp.connection_lifetime 180 |
| 213 |
See modules/cfg_rpc/README |
| 214 |
[http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules_s/cfg_rpc/README]. |