text
stringlengths
0
152
If you are running tests from a telnet client, what this means is that after the last line
of instructions, you’ll need to press the Enter key twice.
Events
Manager events always have an Event header and a Privilege header. The Event
header gives the name of the event, while the Privilege header lists the permission
levels associated with the event. Any other headers included with the event are spe‐
cific to the event type. Here’s an example:
Event: Hangup
Privilege: call,all
Channel: SIP/0004F2060EB4-00000000
Uniqueid: 1283174108.0
CallerIDNum: 2565551212
CallerIDName: Russell Bryant
Cause: 16
Cause-txt: Normal Clearing
The Asterisk CLI includes the commands manager show events and manager show
event <event>. Run these commands at the Asterisk CLI to get a list of events or to
find out the details of a specific event.
Don’t forget that an excellent reference for all things Asterisk, including the AMI, is
the official Asterisk wiki.
Actions
When executing a manager action, you must include the Action header. The Action
header identifies which manager action is being executed. The rest of the headers are
arguments to the manager action, and may or may not be required depending on the
action.
To get a list of the headers associated with a particular manager action, type manager
show command <Action> at the Asterisk CLI. To get a full list of manager actions sup‐
ported by the version of Asterisk you are running, enter manager show commands at
the Asterisk CLI.
The final response to a manager action is typically a message that includes the
Response header. The value of the Response header will be Success if the manager
action was successfully executed. If the manager action was not successfully executed,
the value of the Response header will be Error. For example:
Action: Login
Username: hello
Secret: world
Protocol Overview
|
307
Response: Success
Message: Authentication accepted
AMI over HTTP
In addition to the native TCP interface, it is also possible to access the Asterisk Man‐
ager Interface over HTTP. Programmers with previous experience writing applica‐
tions that use web APIs will likely prefer this over the native TCP connectivity. While
the TCP interface only offers a single type of message structure, AMI over HTTP
offers a few encoding options. You can receive responses in the same format as the
TCP interface, in XML, or as a basic HTML page. The encoding type is chosen based
on a field in the request URL. The encoding options are discussed in more detail later
in this section.
Authentication and session handling
There are two methods of performing authentication against the AMI over HTTP.
The first is to use the Login action, similar to authentication with the native TCP
interface. This is the method that was used in the quick-start example, as seen in
“AMI over HTTP” on page 303.
Once successfully authenticated, Asterisk will provide a cookie that identifies the
authenticated session. Here is an example response to the Login action that includes a
session cookie from Asterisk:
$ curl -v "http://localhost:8088/rawman?action=login&username=hello&secret=world"
The second authentication option is HTTP digest authentication. In this example, the
requested encoding type based on the request URL is rawman. To indicate that HTTP
digest authentication should be used, prefix the encoding type in the request URL
with an a:
$ curl -v --digest -u hello:world http://127.0.0.1:8088/arawman?action=ping
/rawman (/arawman) encoding
The rawman encoding type is what has been used in all the AMI over HTTP examples
in this chapter so far. The responses received from requests using rawman are format‐
ted in the exact same way that they would be if the requests were sent over a direct
TCP connection to the AMI.
curl -v "http://localhost:8088/rawman?action=login&username=hello&secret=world"
curl -v --digest -u hello:world http://127.0.0.1:8088/arawman?action=ping
308