README 6.4 KB

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