Kamctl scripts

From open-voip.org

Jump to: navigation, search

Contents

Kamctl commands

-- command 'start|stop|restart'

restart ............................ restart Kamailio
start .............................. start Kamailio
stop ............................... stop Kamailio

-- command 'acl' - manage access control lists (acl) used to add users to groups for examples "Local calls", "Long distance calls" or "International calls"

acl show [<username>] .............. show user membership
acl grant <username> <group> ....... grant user membership (*)
acl revoke <username> [<group>] .... grant user membership(s) (*)

-- command 'lcr' - manage least cost routes (lcr)

  * IP addresses must be entered in dotted quad format e.g. 1.2.3.4   *
  * <uri_scheme> and <transport> must be entered in integer or text,  *
  * e.g. transport '2' is identical to transport 'tcp'.               *
  *   scheme: 1=sip, 2=sips;   transport: 1=udp, 2=tcp, 3=tls, 4=sctp *
  * Examples:  lcr addgw level3 1.2.3.4 5080 sip tcp 1                *
  *            lcr addroute +1  1 1                                 *
lcr show .......... show gateways and routes tables
lcr dump .......... show in memory gateways and routes tables
lcr reload ........ reload lcr gateways and routes
lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> <flags> <tag> <strip> <weight> <hostname> <ping>
          ......... add a gateway with flags, tag, strip, weight, hostname, and ping
          ......... (flags, tag, strip, weight, hostname, and ping are optional)
lcr rmgw <gw_name> delete a gateway
lcr addroute <prefix> <from> <grp_id> <prio>
          ......... add a route ( use  to match anything in <from> )
lcr rmroute <prefix> <from> <grp_id> <prio>
          ......... delete a route

-- command 'cr' - manage carrierroute tables

cr show ....................................................... show tables
cr reload ..................................................... reload tables
cr dump ....................................................... show in memory tables
cr addcn <carrier id> <carrier name> .......................... add a carrier name
cr rmcn  <carrier id> ......................................... rm a carrier name
cr adddn <domain id> <domain name> ............................ add a domain name
cr rmdn  <domain id> .......................................... rm a domain name
cr addcarrier <carrier> <scan_prefix> <domain> <rewrite_host> ................
              <prob> <strip> <rewrite_prefix> <rewrite_suffix> ...............
              <flags> <mask> <comment> .........................add a carrier
              (prob, strip, rewrite_prefix, rewrite_suffix,...................
               flags, mask and comment are optional arguments) ...............
cr rmcarrier  <carrier> <scan_prefix> <domain> ................ rm a carrier

-- command 'rpid' - manage Remote-Party-ID (RPID)

rpid add <username> <rpid> ......... add rpid for a user (*)
rpid rm <username> ................. set rpid to NULL for a user (*)
rpid show <username> ............... show rpid of a user

-- command 'add|passwd|rm' - manage subscribers

add <username> <password> .......... add a new subscriber (*)
passwd <username> <passwd> ......... change user's password (*)
rm <username> ...................... delete a user (*)

-- command 'add|dump|reload|rm|show' - manage trusted

trusted show ...................... show db content
trusted dump ...................... show cache content
trusted reload .................... reload db table into cache
trusted add <src_ip> <proto> <from_pattern> <tag>
            ....................... add a new entry
            ....................... (from_pattern and tag are optional arguments)
trusted rm <src_ip> ............... remove all entres for the given src_ip

-- command 'dispatcher' - manage dispatcher

  * Examples:  dispatcher addgw 1 sip:1.2.3.1:5050 1 'outbound gateway'
  *            dispatcher addgw 2 sip:1.2.3.4:5050 3 
  *            dispatcher rmgw 4
dispatcher show ..................... show dispatcher gateways
dispatcher reload ................... reload dispatcher gateways
dispatcher dump ..................... show in memory dispatcher gateways
dispatcher addgw <setid> <destination> <flags> <description>
           .......................... add gateway
dispatcher rmgw <id> ................ delete gateway

-- command 'dialplan' - manage dialplans

dialplan show <dpid> .............. show dialplan tables
dialplan reload ................... reload dialplan tables
dialplan addrule <dpid> <prio> <match_op> <match_exp>
               <match_len> <subst_exp> <repl_exp> <attrs>
               .................... add a rule
dialplan rm ....................... removes the entire dialplan table
dialplan rmdpid <dpid> ............ removes all the gived dpid entries
dialplan rmrule <dpid> <prio> ..... removes all the gived dpid/prio entries

-- command 'htable' - manage htables

  * key_name - can be 'simple' or 'array'          *
  * key_type - can be 'str' or 'int'               *
  * Examples:                                      *
  *    htable addkey my_key simple str key1        *
  *    htable rmkey my_key                         *
  *    htable reload mytable                       *
  *           mytable declared as:                 *
  *           modparam("htable", "htable",         *
  *                    "mytable=>size=4;           *
  *                              autoexpire=0;     *
  *                              dbtable=htable;") *
htable show <key_name> ........... show htable table
htable reload <htable> ........... reload htable table
htable addkey <key_name> <key_type> <value_type> <key_value>
              .................... add a key/value pair
htable rmkey <key_name> .......... remove the given key_name

-- command 'db' - database operations

db exec <query> ..................... execute SQL query
db roexec <roquery> ................. execute read-only SQL query
db run <id> ......................... execute SQL query from $id variable
db rorun <id> ....................... execute read-only SQL query from 
                                      $id variable
db show <table> ..................... display table content

-- command 'speeddial' - manage speed dials (short numbers)

speeddial show <speeddial-id> ....... show speeddial details
speeddial list <sip-id> ............. list speeddial for uri
speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ... 
          ........................... add a speedial (*)
speeddial rm <sip-id> <sd-id> ....... remove a speeddial (*)
speeddial help ...................... help message
   - <speeddial-id>, <sd-id> must be an AoR (username@domain)
   - <sip-id> must be an AoR (username@domain)
   - <new-uri> must be a SIP AoR (sip:username@domain)
   - <desc> a description for speeddial

-- command 'avp' - manage AVPs

avp list [-T table] [-u <sip-id|uuid>]
    [-a attribute] [-v value] [-t type] ... list AVPs
avp add [-T table] <sip-id|uuid>
    <attribute> <type> <value> ............ add AVP (*)
avp rm [-T table]  [-u <sip-id|uuid>]
    [-a attribute] [-v value] [-t type] ... remove AVP (*)
avp help .................................. help message
   - -T - table name
   - -u - SIP id or unique id
   - -a - AVP name
   - -v - AVP value
   - -t - AVP name and type (0 (str:str), 1 (str:int),
                             2 (int:str), 3 (int:int))
   - <sip-id> must be an AoR (username@domain)
   - <uuid> must be a string but not AoR

-- command 'alias_db' - manage database aliases

alias_db show <alias> .............. show alias details
alias_db list <sip-id> ............. list aliases for uri
alias_db add <alias> <sip-id> ...... add an alias (*)
alias_db rm <alias> ................ remove an alias (*)
alias_db help ...................... help message
   - <alias> must be an AoR (username@domain)"
   - <sip-id> must be an AoR (username@domain)"

-- command 'domain' - manage local domains

domain reload ....................... reload domains from disk
domain show ......................... show current domains in memory
domain showdb ....................... show domains in the database
domain add <domain> ................. add the domain to the database
domain rm <domain> .................. delete the domain from the database

-- command 'cisco_restart' - restart CISCO phone (NOTIFY)

cisco_restart <uri> ................ restart phone configured for <uri>

-- command 'online' - dump online users from memory

online ............................. display online users

-- command 'monitor' - show internal status

monitor ............................ show server's internal status

-- command 'ping' - ping a SIP URI (OPTIONS)

ping <uri> ......................... ping <uri> with SIP OPTIONS

-- command 'ul|alias' - manage user location or aliases

ul show [<username>]................ show in-RAM online users
ul show --brief..................... show in-RAM online users in short format
ul rm <username> [<contact URI>].... delete user's usrloc entries
ul add <username> <uri> ............ introduce a permanent usrloc entry
ul add <username> <uri> <expires> .. introduce a temporary usrloc entry

-- command 'fifo'

fifo ............................... send raw FIFO command

Add users to the MySQL exaple

kamctl add 1000 1000
kamctl add 2000 2000

you can see that the users were added to the subscrber MySQL table

Monitor the MySQL example

list all online users:

kamctl online

show in-RAM online users

kamctl ul show
Domain:: location table=512 records=1 max_slot=1
       AOR:: 2000
               Contact:: sip:2000@192.168.0.165:4428;rinstance=e133b34b04b78574 Q=
                       Expires:: 1961
                       Callid:: OTYyMGYyZTMyMWMxOWVhZDAyYWFiOGIyNmM4OGY4NjM.
                       Cseq:: 4
                       User-agent:: X-Lite release 1104o stamp 56125
                       Received:: sip:192.168.0.165:4428
                       State:: CS_NEW
                       Flags:: 0
                       Cflag:: 0
                       Socket:: udp:192.168.0.148:5060
                       Methods:: 5951

monitor the kamailio status

kamctl monitor
Server:: Kamailio (1.5.2-notls (i386/linux))
Build:: mi/mi_core.c compiled on 19:42:33 Apr 14 2010 with gcc 4.3.0
Flags:: STATISTICS, USE_IPV6, USE_TCP, DISABLE_NAGLE, USE_MCAST, SHM_MMAP, PKG_MALLOC, F_MALLOC, FAST_LOCK-ADAPTIVE_WAIT
SVN:: unknown
Now:: Tue Apr 20 18:42:06 2010
Up since:: Sat Apr 17 17:21:57 2010
Up time:: 264009 [sec] 

Transaction Statistics: 
tm:UAS_transactions = 0
tm:UAC_transactions = 0
tm:inuse_transactions = 0

Stateless Server Statistics: 
sl:sent_replies = 8
sl:sent_err_replies = 0
sl:received_ACKs = 0

UsrLoc Stats: 
usrloc:registered_users = 1
usrloc:location-users = 1
usrloc:location-contacts = 1
usrloc:location-expires = 0

Add aliases to the MySQL example

Lets say we want to have 1000 as david and 2000 john. Aliases also can be used for adding DIDs to account. to support aliases change the following in the kamailio.cfg file:

/* uncomment next line for aliases support
   NOTE: a DB (like db_mysql) module must be also loaded */
loadmodule "alias_db.so"

and (make sure the Mysql user pass are correct):

# ----- alias_db params -----
/* uncomment the following lines if you want to enable the DB based
   aliases */
modparam("alias_db", "db_url",
       "mysql://openser:asterisk@localhost/openser")

and

# apply DB based aliases (uncomment to enable)
alias_db_lookup("dbaliases");

now add the aliases as follow:

kamctl alias_db add david@domain.com 1000@domain.com
kamctl alias_db add john@domain.com 2000@domain.com

now you can can call "david" instead of 1000, and "john" instead of 2000

Personal tools