Asterisk的AMI中常用的重要的AMI操作

1.  AbsoluteTimeout 

AbsoluteTimeout :这个命令将要求 Asterisk 在指定秒数后挂断特定的通道,从而有效地结束通话。

 

参数:

 

Channel : 哪些渠道挂断,如 SIP/123-1c20

 

Timeout : 到通道应挂断的秒数

 

例子:

 

请求信息

 

Action: AbsoluteTimeout

 

Channel: SIP/123-1c20

 

Timeout: 20

 

 

返回成功信息

 

Response: Success

 

Message: Timeout Set

 

 

返回失败信息

 

Response: Error

 

Message: No such channel

 

 

ChangeMonitor :更改记录某通道信息文件名。

 

参数:

 

Channel :通道名称

 

File :文件名

 

 

例子:

 

发送请求

 

ACTION: ChangeMonitor

 

Channel: SIP/x7065558529-1c20

 

File: 20050103-140105_cc51

 

 

返回失败信息

 

Response: Error

 

Message: No such channel

 

 

返回成功信息

 

Response: Success

 

Message: Stopped monitoring channel

 

2. Command

 

Command :发送 Asterisk CLI 命令。

 

参数:

 

Command Asterisk CLI 命令。

 

 

例子:

 

发送请求

 

ACTION: COMMAND

 

command: Show Channels

 

 

返回信息

 

Response: Follows

 

Channel (Context Extension Pri ) State Appl. Data

 

0 active channel(s)

 

--END COMMAND-

 

 

 

3 Events

 

Events :事件控制流,用于启用 / 禁用发送给管理客户端的事件。

 

参数:

 

EventMask: 'on' 表示所有事件均会被发送到管理客户端。

 

'off' 表示所有时间都不会被发送。

 

'system,call,log' 用于选择被发送的事件。

 

提示:有些事件是启用或禁已经在 .conf 文件中配置了, They might be disabled by default. 他们可能是默认为禁用。

 

 

例子:

 

注意在此例子中 EventMask 事件没有立即返回的响应信息,只有在设备注销时才返回相关信息。

 

发送请求:

 

ACTION: EVENTS

EVENTMASK: ON

返回信息:

Event: PeerStatus

Peer: SIP/ChannelName

PeerStatus: Unregistered

Cause: Expired

 

 

EventMask 参数为 'off' 时会立即返回响应信息,如下:

 

发送:

 

ACTION: EVENTS

EVENTMASK: OFF

返回:

Response: Events Off

 

 

4. GetVar

 

 

GetVar :获取一个通道变量。

 

参数: Channel Variable actionID

 

ActionID 是一个可选的参数匹配信息。

 

 

例子:

 

发送:

 

ACTION: GetVar

 

Channel: SIP/5060-44d225d0

 

Variable: extension

 

成功返回:

 

Response: Success

 

Value: 17065551419

 

失败返回:

 

Response: Error

 

Message: No such channel

 

 

Response: Success

 

varname: (null)

 

 

5. Hangup

 

 

Hangup :挂断指定通道。

 

参数: Channel

 

 

例子:

 

 

发送:

 

ACTION: Hangup

 

Channel: SIP/x7065558529-99a0

 

 

接收:

 

Event: Unlink

 

Channel1: SIP/127.180.254.109-44df88e8

 

Channel2: SIP/x7065558529-99a0

 

Uniqueid1: 1124989110.20473

 

Uniqueid2: 1124989110.20474

 

 

Event: Hangup

 

Channel: SIP/x7065558529-99a0

 

Uniqueid: 1124989110.20474

 

Cause: 16

 

 

Event: Hangup

 

Channel: SIP/127.180.254.109-44df88e8

 

Uniqueid: 1124989110.20473

 

Cause: 16

 

 

Response: Success

 

Message: Channel Hungup

 

 

6 UpdateConfig

 

 

UpdateConfig :更新配置文件。

 

参数:

 

SrcFilename: 要读取的配置文件 (.conf)

 

DstFilename: 要更新的配置文件 (.conf)

 

Reload: 是否重新加载( asterisk 或者模块名称)

 

Action-XXXXXX: 采取的动作 NewCat RenameCat DelCat Update Delete Append

 

Cat-XXXXXX: 操作对象

 

Var-XXXXXX: 采用的变量

 

Value-XXXXXX: 变量的值

 

Match-XXXXXX: 其他匹配信息

 

 

1 :(更新 manager.conf

 

action: updateconfig

 

reload: yes

 

srcfilename: manager.conf

 

dstfilename: manager.conf

 

action-000000: append

 

cat-000000: newuser

 

var-000000: secret

 

value-000000: nottelling

 

2:( 更新 extension.conf ,通过 '>' 增加前缀 )

 

action:updateconfig

reload:yes

srcfilename: extensions.conf

dstfilename: extensions.conf

Action-000000:append

Cat-000000: ami-test

Var-000000: exten

Value-000000: >999,1,Dial(SIP/Bob)

 

 

3 :(删除 manager.conf 中的配置信息)

 

action: updateconfig

 

srcfilename: manager.conf

 

dstfilename: manager.conf

 

action-000000: delete

 

cat-000000: newuser

 

var-000000: secret

 

value-000000: nottelling

 

match-000000: nottelling

 

 

删除时必须设置 'value' 'match' ,不设置 'match' 将会删除变量为 'var' 所有条目

 

 

GetConfig :显示配置文件内容,主要给 AJAM asterisk 图形界面使用。

 

变量: FileName :显示的文件名( .conf )。

 

 

 

 

 

 

猜你喜欢

转载自hwzyyx.iteye.com/blog/840552