浅谈一下如何使用CLI监查Asterisk的运行

  CLI, 就是Command Line Interface的缩写,直译的话就是“命令行界面”。顾名思义,我们可以在CLI下执行Asterisk的命令。在查找问题,监视运行时,CLI十分迅速便捷,因此是我的故障排查的首选工具。

(一)如何进入和退出CLI
首先SSH(或Telnet)到你的TrixBox,以root登陆。这时Asterisk已经在运行中。键入命令:
[root@asterisk1 ~]# asterisk -r

回车,看到:

[root@asterisk1 ~]# asterisk -r
Asterisk 1.2.12.1, Copyright (C) 1999 - 2006 Digium, Inc. and others.
Created by Mark Spencer <[email protected]>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'show license' for details.
=========================================================================
Connected to Asterisk 1.2.12.1 currently running on asterisk1 (pid = 2443)
Verbosity is at least 1
asterisk1*CLI>

这时,你就已经成功地进入了CLI。
要退出CLI, 只需在CLI 下键入命令:
asterisk1*CLI> exit


(二)CLI命令一览
在CLI下,键入 help, 回车后就会看到所有的CLI命令。初次看到这些命令可能会令你头晕目眩!接触时间长了就会慢慢适应。(我就不在此逐一诠释了,否则我也要骨断筋折了 )

(三)用CLI监视Asterisk运行
这时我最常用的功能。它可以让我看到Asterisk的一举一动!下面用一个实例说明一下:
这一次,我们用
asterisk -r -cvvvvv
进入CLI
其中, Asterisk 是主程序名, -r 表示要重新连接(r=reconnect), 最后面的 -cvvvvv 决定CLI 显示的信息量。这了我用了5个v,你也可以酌情增加或减少,v越多,CLI显示的信息量就越大!( 在CLI下,用 set verbose 5也可以设定其信息量为5)

进入CLI后,让这个SSH窗口开着,我打开一个softphone(112 IAX分机),并拨打7777(模拟外线拨入),电话接通到IVR后,接驳111分机。下面就是CLI的输出信息:


asterisk1*CLI>
asterisk1*CLI>
-- Accepting AUTHENTICATED call from 192.168.1.148:
> requested format = gsm,
> requested prefs = (),
> actual format = ulaw,
> host prefs = (ulaw|alaw|gsm),
> priority = mine
-- Executing Goto("IAX2/192.168.1.148:4569-2", "from-pstn|s|1") in new stack
-- Goto (from-pstn,s,1)
-- Executing Set("IAX2/192.168.1.148:4569-2", "FROM_DID=s") in new stack
-- Executing Gosub("IAX2/192.168.1.148:4569-2", "app-blacklist-check|s|1") in new stack
-- Executing LookupBlacklist("IAX2/192.168.1.148:4569-2", "") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "0?blacklisted") in new stack
-- Executing Return("IAX2/192.168.1.148:4569-2", "") in new stack
-- Executing Goto("IAX2/192.168.1.148:4569-2", "ivr-2|s|1") in new stack
-- Goto (ivr-2,s,1)
-- Executing Set("IAX2/192.168.1.148:4569-2", "LOOPCOUNT=0") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "__DIR-CONTEXT=default") in new stack
-- Executing Answer("IAX2/192.168.1.148:4569-2", "") in new stack
-- Executing Wait("IAX2/192.168.1.148:4569-2", "1") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "TIMEOUT(digit)=3") in new stack
-- Digit timeout set to 3
-- Executing Set("IAX2/192.168.1.148:4569-2", "TIMEOUT(response)=10") in new stack
-- Response timeout set to 10
-- Executing BackGround("IAX2/192.168.1.148:4569-2", "custom/welcome_1") in new stack
-- Playing 'custom/welcome_1' (language 'en')
== CDR updated on IAX2/192.168.1.148:4569-2
-- Executing Goto("IAX2/192.168.1.148:4569-2", "ivr-3|s|1") in new stack
-- Goto (ivr-3,s,1)
-- Executing Set("IAX2/192.168.1.148:4569-2", "LOOPCOUNT=0") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "__DIR-CONTEXT=default") in new stack
-- Executing Answer("IAX2/192.168.1.148:4569-2", "") in new stack
-- Executing Wait("IAX2/192.168.1.148:4569-2", "1") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "TIMEOUT(digit)=3") in new stack
-- Digit timeout set to 3
-- Executing Set("IAX2/192.168.1.148:4569-2", "TIMEOUT(response)=10") in new stack
-- Response timeout set to 10
-- Executing BackGround("IAX2/192.168.1.148:4569-2", "custom/cn_dial_ext") in new stack
-- Playing 'custom/cn_dial_ext' (language 'en')
== CDR updated on IAX2/192.168.1.148:4569-2
-- Executing Macro("IAX2/192.168.1.148:4569-2", "exten-vm|novm|111") in new stack
-- Executing Macro("IAX2/192.168.1.148:4569-2", "user-callerid") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "0?report") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "0?start") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "REALCALLERIDNUM=112") in new stack
-- Executing NoOp("IAX2/192.168.1.148:4569-2", "REALCALLERIDNUM is 112") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "AMPUSER=112") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "AMPUSERCIDNAME=") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "1?report") in new stack
-- Goto (macro-user-callerid,s,10)
-- Executing NoOp("IAX2/192.168.1.148:4569-2", "Using CallerID "IAX Notebook" <112>") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "FROMCONTEXT=exten-vm") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "VMBOX=novm") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "EXTTOCALL=111") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "CFUEXT=") in new stack
-- Executing Set("IAX2/192.168.1.148:4569-2", "RT=") in new stack
-- Executing Macro("IAX2/192.168.1.148:4569-2", "record-enable|111|IN") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "0 > 0?2:4") in new stack
-- Goto (macro-record-enable,s,4)
-- Executing DeadAGI("IAX2/192.168.1.148:4569-2", "recordingcheck|20061121-231623|1164179772.9") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/recordingcheck
recordingcheck|20061121-231623|1164179772.9: Inbound recording not enabled
-- AGI Script recordingcheck completed, returning 0
-- Executing NoOp("IAX2/192.168.1.148:4569-2", "No recording needed") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "0?dolocaldial|1") in new stack
-- Executing Macro("IAX2/192.168.1.148:4569-2", "dial||tr|111") in new stack
-- Executing DeadAGI("IAX2/192.168.1.148:4569-2", "dialparties.agi") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/dialparties.agi
dialparties.agi: Starting New Dialparties.agi
dialparties.agi: priority is 1
dialparties.agi: Caller ID name is 'IAX Notebook' number is '112'
dialparties.agi: Methodology of ring is 'none'
> dialparties.agi: USE_CONFIRMATION: 'FALSE'
> dialparties.agi: RINGGROUP_INDEX: ''
-- dialparties.agi: Added extension 111 to extension map
-- dialparties.agi: Extension 111 cf is disabled
-- dialparties.agi: Extension 111 do not disturb is disabled
> dialparties.agi: extnum: 111
> dialparties.agi: exthascw: 1
> dialparties.agi: exthascfb: 0
> dialparties.agi: extcfb:
> dialparties.agi: exthascfu: 0
> dialparties.agi: extcfu:
-- dialparties.agi: dbset CALLTRACE/111 to 112
-- AGI Script dialparties.agi completed, returning 0
-- Executing Dial("IAX2/192.168.1.148:4569-2", "SIP/111||tr") in new stack
-- Called 111
-- SIP/111-08558c68 is ringing
-- SIP/111-08558c68 answered IAX2/192.168.1.148:4569-2
== Spawn extension (macro-dial, s, 10) exited non-zero on 'IAX2/192.168.1.148:4569-2' in macro 'dial'
== Spawn extension (macro-dial, s, 10) exited non-zero on 'IAX2/192.168.1.148:4569-2' in macro 'exten-vm'
== Spawn extension (macro-dial, s, 10) exited non-zero on 'IAX2/192.168.1.148:4569-2'
-- Executing Macro("IAX2/192.168.1.148:4569-2", "hangupcall") in new stack
-- Executing ResetCDR("IAX2/192.168.1.148:4569-2", "w") in new stack
-- Executing NoCDR("IAX2/192.168.1.148:4569-2", "") in new stack
-- Executing GotoIf("IAX2/192.168.1.148:4569-2", "1?theend") in new stack
-- Goto (macro-hangupcall,s,6)
-- Executing Wait("IAX2/192.168.1.148:4569-2", "5") in new stack
-- Executing Hangup("IAX2/192.168.1.148:4569-2", "") in new stack
== Spawn extension (macro-hangupcall, s, 7) exited non-zero on 'IAX2/192.168.1.148:4569-2' in macro 'hangupcall'
== Spawn extension (macro-hangupcall, s, 7) exited non-zero on 'IAX2/192.168.1.148:4569-2'
-- Hungup 'IAX2/192.168.1.148:4569-2

现在我们可以从中看到Asterisk的一举一动,如果在这个过程中你遇到了问题,CLI一般会有相应的输出信息。这会对故障排查带来极大便利。当你与别人交流或求助时,如果能附上一个CLI输出信息,那将非常有利于对方对你的问题的迅速和准确的理解。

上面提到CLI除了监控外,还有很多命令。灵活,准确地运用这些命令将大大加快故障排除的速度。

你可能感兴趣的:(浅谈一下如何使用CLI监查Asterisk的运行)