asterisk - AMI

最後更新: 2015-08-17

Asterisk 一共有三套 API, 分別是 ARI, AGI, AMI

Asterisk REST Interface (ARI)

https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=29395573

Asterisk Gateway Interface (AGI)

provides an interface between the Asterisk dialplan and an external program that wants to manipulate a channel in the dialplan. In general, the interface is synchronous - actions taken on a channel from an AGI block and do not return until the action is completed.

https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=32375589

Asterisk Manager Interface (AMI)

Info:

- client/server model
- TCP port 5038

AMI receive commands, called "actions".
These generate a "response" from Asterisk.
Asterisk will also send "Events" containing various information messages about changes within Asterisk.

 

AMI 的設定

 

manager.conf

[general]
enabled = yes
port = 5038
bindaddr = 0.0.0.0

; Allows access to the AMI through the built-in HTTP server.
;webenabled = no

; more than one connection at the same time
allowmultiplelogin = yes

; Adds a Unix epoch-based timestamp to every event reported
timestampevents = yes

; AMI user accounts
[amiuser]
secret = mysecret
deny=0.0.0.0/0.0.0.0
permit=192.168.88.0/255.255.255.0
permit=127.0.0.1/255.255.255.0
writetimeout = 600

; all - All event classes below
read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate,message

設定後 reload 即可

boxA*CLI> manager reload

測試

telnet 192.168.88.81 5038

會見到

Asterisk Call Manager/2.6.0

 


CLI

 

To see all of the available manager commands:

"manager show commands"
"manager show command <commandname>"

查看 User

manager show user amiuser

          username: amiuser
            secret: <Set>
               ACL: yes
         read perm: <none>
        write perm: <none>
   displayconnects: yes
allowmultiplelogin: yes
         Variables:

manager show settings

Global Settings:
----------------
  Manager (AMI):             No
  Web Manager (AMI/HTTP):    No
  TCP Bindaddress:           Disabled
  HTTP Timeout (minutes):    60
  TLS Enable:                No
  TLS Bindaddress:           Disabled
  TLS Certfile:              asterisk.pem
  TLS Privatekey:
  TLS Cipher:
  Allow multiple login:      Yes
  Display connects:          Yes
  Timestamp events:          No
  Channel vars:
  Debug:                     No

# 查看支援什麼

manager show commands

# 什麼人可以 login

manager show users

# 有什麼 event 出來

manager show events

# 什麼人連了上 AMI

manager show connected

Debug

boxA*CLI> manager set debug on

 


AMI Command Syntax

"header: value"

每 cmd 之間用 (\r\n) 分隔

i.e. Login

輸入

Action: Login
Username: testuser
Secret: testsecret

會見到

Response: Success
Message: Authentication accepted

Event: FullyBooted
Privilege: system,all
Status: Fully Booted

Event: SuccessfulAuth
Privilege: security,all
Timestamp: 1439278138.309006
EventTV: 2015-08-11T15:28:58.308+0800
Severity: Informational
Service: AMI
EventVersion: 1
AccountID: amiuser
SessionID: 0x7f1d7c001e58
LocalAddress: IPV4/TCP/0.0.0.0/5038
RemoteAddress: IPV4/TCP/192.168.88.150/46063
UsingPassword: 0
SessionTV: 2015-08-11T15:28:58.308+0800

* It is possible to connect to the manager interface before all Asterisk modules are loaded.

所以要在 Event 後才 send CMD

Event: FullyBooted
Privilege: system,all
Status: Fully Booted

Disable Event

Action: Events
ActionID: 0001
EventMask: off

 


Call out

Action: Originate
Channel: PJSIP/????????@mytrunk_endpoint
CallerID: 9025XXXX
Exten: 2771YYYY
Context: MyBridge
Priority: 1

 


Queue
 

Action: QueueSummary
Queue: 500

 

Action: QueueStatus

Event: QueueParams
Queue: queue_test1
Max: 0
Strategy: ringall
Calls: 0
Holdtime: 0
TalkTime: 0
Completed: 0
Abandoned: 2
ServiceLevel: 0
ServicelevelPerf: 0.0
Weight: 0

Action: Queues

 


Channels Usage

Action: CoreShowChannels
ActionID: 0002

 


Control Event Flow

 

Action: Events
ActionID: <value>
EventMask: <value>

ActionID: ActionID for this transaction. Will be returned.
EventMask: on | off | system,call,log,...

Action: Events
ActionID: 0001
EventMask: off

Result

Response: Success
ActionID: 0001
Events: Off

 

 


Frameworks

java
https://blogs.reucon.com/asterisk-java/

php
https://github.com/marcelog/PAMI

py
https://github.com/rdegges/pyst2

 


; get CDR events over the manager API in Asterisk.

cdr_manager

cdr_manager.conf

 

Creative Commons license icon Creative Commons license icon