Asterisk 的命令列模式稱為 CLI。要了解內部核心的運作流程,必須透過 CLI 的指令或檢視 logs,才能快速作系統除錯的工作。
進入的方式很簡單,使用終端機軟體 putty,以 SSH 連線至主機,且登入為 root 帳號,執行指令:
#asterisk -rvvvvv
Tips:
*參數 v 的個數表示要顯示 logs 的詳細程度,愈多表示 log 愈詳細。
*執行 Asterisk CLI 指令有兩種方式,分為內部執行及外部執行。
內部執行方式 - 在 console 執行 asterisk -rvvvv 即進入內部指令模式,且會出現 CLI> 命令提示字元,同時在此,除了可執行 CLI 指令外,也可檢視系統運作的 logs
外部執行方式 - 不需進入內部指令模式,直接在 Linux console 執行 asterisk -rx "CLI 指令"。
*請閱讀教學 Collecting Debug Information for the Asterisk Issue Tracker
指令不熟時,可以呼叫 help 來協助
CLI> help voicemail voicemail reload Reload voicemail configuration voicemail show users List defined voicemail boxes voicemail show zones List zone message formats
參數 call-limit 可用來限制 incoming calls 的通話數量,要檢查通道的使用數量,可執行以下指令
Asterisk -rx "sip show inuse" * Peer name In use Limit ... provider1 3/0/0 30 provider2 0/0/0 12 ...
(http://www.asteriskdocs.org/en/3rd_E...conf-file.html)
編輯 /etc/asterisk/asterisk.conf
... [options] ... hideconnect=yes ...
更多的參數使用:
%d Date (year-month-date)
%s Asterisk system name (from asterisk.conf)
%h Full hostname
%H Short hostname
%t Time
%% Percent sign
%# '#' if Asterisk is run in console mode, '>' if running as remote console
%Cn[;n] Change terminal foreground (and optional background) color to specified
A full list of colors may be found in include/asterisk/term.h
On Linux systems, you may also use
%l1 Load average over past minute
%l2 Load average over past 5 minutes
%l3 Load average over past 15 minutes
%l4 Process fraction (processes running / total processes)
%l5 The most recently allocated pid
立即關閉/重啟
CLI> core stop now CLI> core restart now
沒有任何通話時才關閉/重啟
CLI> core stop when convenient CLI> core restart when convenient
非強迫性的關閉/重啟
CLI> core stop gracefully CLI> core restart gracefully
當遇到 dtmf 偵錯時,會需要打開 DTMF Debugging 來監看系統訊息,例如:
[2010-05-15 17:33:11] DTMF[24654]: channel.c:2191 __ast_read: DTMF begin '2' received on SIP/osslab-b76020b0 [2010-05-15 17:33:11] DTMF[24654]: channel.c:2195 __ast_read: DTMF begin ignored '2' on SIP/osslab-b76020b0 [2010-05-15 17:33:12] DTMF[24654]: channel.c:2116 __ast_read: DTMF end '2' received on SIP/osslab-b76020b0, duration 60 ms [2010-05-15 17:33:12] DTMF[24654]: channel.c:2172 __ast_read: DTMF end '2' has duration 60 but want minimum 80, emulating on SIP/osslab-b76020b0 [2010-05-15 17:33:12] DTMF[24654]: channel.c:2224 __ast_read: DTMF end emulation of '2' queued on SIP/osslab-b76020b0 [2010-05-15 17:33:12] DTMF[24654]: channel.c:2191 __ast_read: DTMF begin '2' received on SIP/osslab-b76020b0
注意:輸入一個 DTMF 按鍵,會出現兩次一樣的訊息。
開啟方法為 編輯 /etc/asterisk/logger.conf,增加 dtmf
[logfiles] console => dtmf full => notice,warning,error,debug,verbose,dtmf
存檔後,執行
CLI> logger reload CLI> logger show channels CLI> logger set level DTMF off <== only for Asterisk 1.6.x
Tips:
* 依據 BUG#0017922,Asterisk 1.6.x 預設是無法在 console 下顯示 DTMF log,必須執行
logger set level DTMF off 。
使用外部執行方式,直接在 console 執行:
#asterisk -rx "dialplan show" | tr -d "\r" | perl -00 -ne 'print if /Context..outrt/'
CLI>sip show settings
CLI> core show settings
CLI> sip show peers Name/username Host Dyn Nat ACL Port Status voxalot/xxxx 64.34.173.199 N 5060 OK (257 ms) voiptalk/xxxx 77.240.48.94 5060 OK (1311 ms) vbuzzer/xxxx 69.172.204.133 80 OK (257 ms)
以分機 100 為例
CLI> sip show peer 100
CLI> sip show channels
CLI> sip show registry
// 從線上通話列表找出要掛斷通話的 Call ID
#>asterisk -rx "sip show channels" Peer User/ANR Call ID Seq (Tx/Rx) Format Hold Last Message ... xx.xx.xx.xx *600 6faa39db3ca 00103/00000 0x100 (g729) No Tx: ACK xx.xx.xx.xx mypstn b68d164f-e9 00101/00102 0x4 (ulaw) No Rx: ACK
// 以 Call ID 找出相應的 Channel ID
#>asterisk -rx "sip show channel b68d164f-e9" | grep -i "channel id" Owner channel ID: SIP/mypstn-b7d27020
// 執行中斷通話指令
for Asterisk 1.4.x #>asterisk -rx "soft hangup SIP/mypstn-b7d27020" for Asterisk 1.6.x #>asterisk -rx "hangup request SIP/mypstn-b7d27020"
#>asterisk -rx "sip show inuse" * User name In use Limit 221 0 50 214 0 50 213 0 50 212 0 50 ... * Peer name In use Limit mypstn 0/0 1 221 0/0 50 214 0/0 50 213 0/0 50 212 0/0 50 211 0/0 50 210 0/0 50 209 0/0 50 ...
所有sip分機及sip trunk (type=user & friend) 的連線帳號/密碼、預設 context、NAT 設定。
#>asterisk -rx "sip show users" Username Secret Accountcode Def.Context ACL NAT xxxxxx oooooo from-sip-extern No Always xxxxxx oooooo from-trunk No No xxxxxx oooooo from-trunk No RFC3581 xxxxxx oooooo from-trunk No RFC3581
在進入 CLI 模式作除錯工作時,系統所顯示的訊息由於螢幕輸出的限制,經常無法看到全部,這裡有個方法可以一邊監看訊息,同時一邊也將訊息存檔,當要分析 Logs 時,先離開 CLI,用 less 指令就可以慢慢看剛所儲存的訊息內容。
#>asterisk -rvvvvvv | tee /path/to/your.log
文件 | 大小 | 日期 | 附件上傳者 | |||
---|---|---|---|---|---|---|
ast-cli-show_translation.png 無描述 | 17.91 KB | 11:38, 28 Aug 2008 | alang | 動作 | ||
cli-sips_how_settings.png 無描述 | 12.09 KB | 15:50, 6 Sep 2008 | alang | 動作 |