Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

Icon

This Specification is still in draft form.

1. Introduction

This Asterisk Manager Interface (AMI) specification describes the relationship between Asterisk and an external entity wishing to communicate with Asterisk over the AMI protocol. It describes:

  • An overview of the AMI protocol
  • The operations AMI provides external entities wishing to control Asterisk
  • Basic formatting of AMI message structures
  • Guaranteed operations, configuration control, and other information provided by Asterisk in AMI 1.4

1.1. Scope

This specification describes AMI version 1.4 for Asterisk 12. This specification provides details on the functional, operational and design requirements for AMI 1.4. Note that this does not include a comprehensive listing of the AMI configuration file parameters or messages that a system interfacing over AMI in Asterisk 12 will send/receive; however, it does provide a baseline of the supported features and messages provided in AMI 1.4. This specification should be used in conjunction with the documented AMI actions and events in Asterisk 12 to encompass the full range of functionality provided by AMI in Asterisk 12.

In addition, this specification provides interface requirements levied on AMI by Stasis Core. It conveys sufficient detail to understand how AMI attaches to Stasis Core and interacts with other entities on the Stasis Core message bus.

This specification is intended for all parties requiring such information, including software developers, system designers and testers responsible for implementing the interface.

2. Terminology

Term

Definition

Action

A command issued to Asterisk from an external entity via AMI

Client

An external entity communicating with Asterisk via AMI over some transport mechanism

Event

A message sent from Asterisk to an external entity via AMI

Field

A key/value pair that exists in either an action or event

Stasis-Core

The internal framework that AMI is built on top of

3. Protocol Overview

Asterisk provides a number of interfaces that serve different purposes. Say, for example, we wanted to manipulate a call between Alice and Bob via some external mechanism. Depending on what we wanted to do with the call, we may use one or more interfaces to manipulate the channels that make up the call between Alice and Bob.

Alice calls Bob and...

Interface

... we want to use a local script to execute some logic on Alice's channel

AGI

... we want to execute a script on a remote machine on Bob's channel

FastAGI

... we want to put Alice into an IVR with fine grained media control, where the IVR is written outside of extensions.conf

ExternalIVR

... we want to control Alice and Bob's underlying channel objects

AMI (with, possibly, AsyncAGI as well)

In general, AMI is used to manage Asterisk and its channels. It does not determine what actions are executed on a particular channel - the dialplan and some AGI interface does that - but it does allow a client to control call generation, aspects of call flow, and other internals of Asterisk.

At its heart, AMI is an asynchronous message bus: it spills events that contain information about the Asterisk system over some transport. In response, clients may request that Asterisk takes some action. These two concepts - actions and events - make up the core of what is AMI. As AMI is asynchronous, as events occur in Asterisk they are immediately sent to the clients. This means that actions issued by entities happen without any synchronization with the events being received, even if those events occur in response to an action. It is the responsibility of entities to associate event responses back to actions.

Clients wishing to use AMI act as clients and connect to Asterisk's AMI server over a supported transport mechanism. Authentication may or may not be enabled, depending on the configuration. Once connected, events can be automatically spilled to the connected clients, or limited in a variety of fashions. A connected client can send an action to the AMI server at any time. Depending on the allowed authorizations, the action may be allowed or disallowed.

More information on the various ways a client can be configured can be seen in [AMI Configuration].

Icon

Sometimes, the term command may be used instead of the term action. With respect to AMI actions, command is synonymous with action, and the two can be treated the same. For the sake of consistency, we've attempted to use the term action where possible.

Historically, AMI has existed in Asterisk as its own core component manager. AMI events were raised throughout Asterisk encoded in an AMI specific format, and AMI actions were processed and passed to the functions that implemented the logic. In Asterisk 12, AMI has been refactored to sit on top of Stasis Core, which is a generic, protocol independent message bus internal to Asterisk. From the perspective of clients wishing to communicate with Asterisk over AMI very little has changed; internally, the Stasis representation affords a much higher degree of flexibility with how messages move through Asterisk.

Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Full Size
Unknown macro: {tr}
Unknown macro: {td}

Asterisk's Stasis-Core provides a generic publish/subscribe message bus inside of Asterisk. While AMI often directly interacts with constructs in Asterisk through actions, it receives its events through messages published over Stasis-Core. It translates the generic Stasis messages into an AMI event, and sends those to the appropriate AMI clients.

4. Semantics and Syntax

4.1. Message Sending and Receiving

By default, AMI is an asynchronous protocol that sends events immediately to clients when those events are available. Likewise, clients are free to send actions to AMI at any time, which may or may not trigger additional events. The exception to this is when the connection is over [HTTP/HTTPS]; in that scenario, events are only transmitted as part of the response to an HTTP POST.

Various options for configuration of clients can control which events are sent to a client. Events can be whitelisted/blacklisted explicitly via event filters, or implicitly by [class authorizations].

4.2. Message Layout

AMI is an ASCII protocol that provides bidirectional communication with clients. Each field in an AMI message - action or event - is delineated by the '\r\n' characters. An action or event is terminated by an additional '\r\n' character. Within a message, each field is a key value pair delineated by a ':'. A single space MUST follow the ':' and precede the value.

 
Event: Newchannel
Privilege: call,all
Channel: SIP/misspiggy-00000001
Uniqueid: 1368479157.3
ChannelState: 3
ChannelStateDesc: Up
CallerIDNum: 657-5309
CallerIDName: Miss Piggy
ConnectedLineName:
ConnectedLineNum:
AccountCode: Pork
Priority: 1
Exten: 31337
Context: inbound

This is syntantically equivalent to the following ASCII string:

Event: Newchannel\r\nPrivilege: call,all\r\nChannel: SIP/misspiggy-00000001\r\n
Uniqueid: 1368479157.3\r\nChannelState: 3\r\n
ChannelStateDesc: Up\r\nCallerIDNum: 657-5309\r\n
CallerIDName: Miss Piggy\r\nConnectedLineName:\r\nConnectedLineNum:\r\nAccountCode: Pork\r\n
Priority:\r\nExten: 31337\r\nContext: inbound\r\n\r\n

Actions are specified in a similar manner. Note that depending on the message, some keys can be repeated.

Action: Originate
ActionId: SDY4-12837-123878782
Channel: SIP/kermit
Context: outbound
Exten: s
Priority: 1
CallerID: "Kermit the Frog" <123-4567>
Account: FrogLegs
Variable: MY_VAR=frogs
Variable: HIDE_FROM_CHEF=true

In addition, no ordering is implied on message specific keys. Hence, the following two messages are semantically the same.

Action: Originate
ActionId: SDY4-12837-123878782
Channel: SIP/kermit
Context: outbound
Exten: s
Priority: 1
CallerID: "Kermit the Frog" <123-4567>
Account: FrogLegs
Variable: MY_VAR=frogs
Variable: HIDE_FROM_CHEF=true
ActionId: SDY4-12837-123878782
Action: Originate
Variable: HIDE_FROM_CHEF=true
Variable: MY_VAR=frogs
Channel: SIP/kermit
Account: FrogLegs
Context: outbound
Exten: s
CallerID: "Kermit the Frog" <123-4567>
Priority: 1

This is also true for events, although by convention, the Event key is the first key in the event. If an action or event contains duplicate keys, such as Variable, the order in which Asterisk processes said keys is the order in which they occur within the action or event.

Keys are case insensitive. Hence, the following keys are equivalent:

Action: Originate
ACTION: Originate
action: Originate

The case sensitivity for values is left up to the context in which they are interpreted.

4.2.1. Common Fields

4.2.1.1. Actions

4.2.1.1.1. General Fields

This section lists fields that apply generally to all actions.

4.2.1.1.1.1. Action

Action specifies the action to execute within Asterisk. Each value corresponds to a unique action to execute within Asterisk. The value of the Action field determines the allowed fields within the rest of the message. By convention, the first field in any action is the Action field.

4.2.1.1.1.2. ActionId

ActionId is a universal unique identifier that can optionally be provided with an action. If provided in an action, events that are related to that action will contain the same ActionId value, allowing a client to associate actions with events that were caused by that action.

It is recommended that clients always provide an ActionId for each action they submit.

4.2.1.1.2. Channels

This section lists fields that apply generally to all actions that interact upon an Asterisk channel. Note that an Action that interacts with a channel must supply either the Channel field or the Uniqueid field.

Icon

In the past, only the Channel field could be used. As Asterisk can change the name of a channel, the Uniqueid is now the preferred way of initiating an action on a channel.

4.2.1.1.2.1. Channel

The Asterisk channel name. A channel name is provided by AMI to clients during a Newchannel event. A channel name can be used as a handle to a channel, although the Uniqueid field is generally preferred.

Why Uniqueid over Channel name?

Icon

In the past, channel masquerades would rename channels and AMI clients would have to track the name changes via a sequence of Rename events. While this no longer occurs, it is possible for certain channel drivers and other third party modules to rename a channel. As such, the safest way to handle a channel is to use the Uniqueid, which cannot be changed.

4.2.1.1.2.2. Uniqueid

A universal unique identifier that acts as a handle to the channel. Once a communication path between an endpoint and Asterisk is established, a Uniqueid is created as a handle to that communication path.

4.2.1.2. Events

4.2.1.2.1. General Fields

This section lists fields that apply generally to all events.

4.2.1.2.1.1. Event

The unique name of the event being raised. The value of the Event field determines the rest of the contents of the message. By convention, the Event field is the first field in an AMI message.

4.2.1.2.1.2. ActionId

If present, the Action's corresponding [ActionId] that caused this event to be created. If an Action contained an ActionId, any event relating the success or failure of that action MUST contain an ActionId field with the same value.

4.2.1.2.1.3. Privilege

The class authorizations associated with this particular event. The class authorizations for a particular event are in a comma-delineated list. For more information, see [class authorizations].

4.2.1.2.2. Channels

This section lists fields that apply generally to all events that occur due to interactions upon an Asterisk channel.

Events that relate multiple channels will prefix these fields with an event specific role specifier. For example, a DialBegin or a DialEnd event will prefix the outbound channel's fields with Dest. So, the Channel field is the DestChannel field; the Uniqueid field is the DestUniqueid field, etc.

4.2.1.2.2.1. Channel

The current Asterisk channel name. This corresponds to the [Channel] field in actions.

4.2.1.2.2.2. Uniqueid

A universal unique identifier that acts as a handle to the channel. This corresponds to the [Uniqueid] field in actions.

4.2.1.2.2.3. ChanVariable

Channel variables specific to a channel can be conveyed in each AMI event related to that channel. When this occurs, each variable is referenced in a ChanVariable field. The value of a ChanVariable field will always be of the form key=value, where key is the name of the channel variable and value is its value.

4.2.1.2.3. Bridges
4.2.1.2.3.1. BridgeUniqueid

A unique identifier for the bridge, which provides a handle to actions that manipulate bridges.

4.2.1.2.3.2. Bridgetype

The type of the bridge. Bridge types can vary based on the registered bridge technologies; in general, however, this will indicate whether the bridge is a holding bridge, a simple two-party bridge, or a multi-party bridge. The type of a bridge can change during the lifetime of the bridge as channels enter and leave a bridge.

4.2.1.2.4. Action Responses

When an Action is submitted to AMI, the success or failure of the action is communicated in subsequent events.

4.2.1.2.4.1. Response

Contains whether or not the action succeeded or failed. Valid values are "Success" or "Error". Events that are in response to an action MUST include this field.

4.2.1.2.4.2. EventList

Some actions will cause a chain of events to be created. Events that are a response to an action that causes such a sequence will contain the EventList field with a value of "start". When all generated events have been sent, a final event will be sent containing the EventList field with the value "complete".

If, for some reason, an error occurs and the events cannot be sent, an event will be sent with an EventList field that contains the value "cancelled".

Note that the events that mark the completion or cancellation of an event list are not technically action responses, and have their own specific event types.

4.2.1.2.4.3. Message

An optional text message that provides additional contextual information regarding the success or failure of the action.

4.3. Actions

The supported actions for Asterisk 12 are listed here:

Asterisk 12 AMI Actions

4.4. Events

The supported events for Asterisk 12 are listed here:

Asterisk 12 AMI Events

4.5. Channel Interaction/Lifetime

While channels are independent of AMI, they have a large implication on the events sent out over AMI. Many of the events in AMI correspond to changes in channel state. While AMI is an asynchronous protocol, there is some ordering with respect to the events that are relayed for a particular channel. This section provides the basic event relationships that are guaranteed through AMI.

4.5.1. Basic Channel Lifetime

All channels begin with a Newchannel event. A Newchannel will always contain the following fields:

  • The current [Channel] name
  • The [Uniqueid] that acts as a handle to the channel for that channel's lifetime

Changes in the state of the channel, i.e., the [ChannelState] field, are conveyed via Newstate events.
Notification of a Channel being disposed of occurs via a Hangup event. A Hangup signals the termination of the channel associated with the Uniqueid. After the Hangup event, no further events will be raised in relation to the channel with that Uniqueid, and the communication between the endpoint and Asterisk via that channel is terminated.

4.5.2. Channel Variables

For each channel variable that is changed, a VarSet event is sent to the client. The VarSet event contains the new value of the appropriate channel variable. Note that channel variables can also be conveyed in [ChanVariable] fields.

4.5.3. DTMF

DTMF is indicated via a DTMFBegin/DTMFEnd events. A DTMFEnd event MUST convey the duration of the DTMF tone in milliseconds.

Unknown macro: {warn}

The combination of DTMFBegin/DTMFEnd events replaces the DTMF event.

4.5.4. Dialplan Execution

As a channel executes operations in the dialplan, those operations are conveyed via a NewExten event. Each transition to a new combination of context, extension, and priority will trigger a NewExten event.

Example
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: Newexten
Privilege: dialplan,all
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Context: default
Extension: h
Priority: 1
Application: NoOp
AppData: Ah Snap
Unknown macro: {td}

Kermit the Frog's SIP channel has been hung up, and he's been tossed rudely into the h extension. This event informs the clients that Kermit's channel is in context default, extension h, priority 1, and is about to execute the NoOp application with application data "Ah Snap".

4.5.5. Dialing and Channel Origination

Dial operations always result in two events: a DialBegin event that signals the beginning of the dial to a particular destination, and a DialEnd event that signals the end of the dialing. In parallel dialing situations, DialBegin/DialEnd events MUST be sent for each channel dialed. For each DialBegin event sent, there MUST be a corresponding DialEnd event.

 
A DialEnd occurs whenever Asterisk knows the final state of the channel that it was attempting to establish. This is communicated in the DialStatus field.

Unknown macro: {warn}

The pair of DialBegin/DialEnd events replaces the deprecated Dial event. Note that the Dial event signalling the end of dialing would not normally be sent until after bridging was complete; this operation should now occur when the dial operation has determined the status of a particular called channel.

When Asterisk originates an outbound channel, there is no calling party. DialBegin and DialEnd events are still sent for the originated channel, where the originated channel is the destination of the dialing attempt.

Simple Successful Dial
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/animal-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Event: DialBegin
Channel: SIP/kermit-00000000
Uniqueid: 550e8400-e29b-41d4-a716-446655430000
DestChannel: SIP/animal-00000001
DestUniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Event: DialEnd
Channel: SIP/kermit-00000000
Uniqueid: 550e8400-e29b-41d4-a716-446655430000
DestChannel: SIP/animal-00000001
DestUniqueid: 550e8400-e29b-41d4-a716-446655440000
DialStatus: ANSWER
...
Unknown macro: {td}

In this example, Kermit decides to dial Animal. We create a new channel to between Asterisk and Animal's SIP device, and begin a dial operation. When Animal eats his handset (causing the device to think he merely took it off the hook), the SIP device answers and the dial operation completes. This indicated by a DialEnd event. At this point, the channel is ready for something - it can execute in the dialplan, or be immediately bridged with another channel (which, in this case, would be Kermit.)
 
Note that in the DialBegin and DialEnd events, Animal's channel is prefixed with the role "Dest", indicating that Animal is the destination of the dial attempt.

Simple Failed Dial
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialBegin
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialEnd
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
DialStatus: TIMEDOUT
...
Event: Hangup
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Unknown macro: {td}

In this example, we decide to dial Animal again. Unfortunately, Animal ate his handset, so we inevitably time out. When we do, a DialEnd event is received indicating the failure.

Parallel Dial
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/animal-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: Newchannel
Channel: SIP/drteeth-00000004
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: DialBegin
Channel: SIP/animal-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: DialBegin
Channel: SIP/drteeth-00000004
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: DialEnd
Channel: SIP/drteeth-00000004
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
DialStatus: ANSWER
...
Event: DialEnd
Channel: SIP/animal-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
DialStatus: CANCEL
...
Unknown macro: {td}

In this example, we decide to dial Animal and Dr. Teeth. Dr. Teeth immediately answers, and so we cancel the dial to Animal. We can now do something with Dr. Teeth's channel (such as bridge him with his dentist) - however, Animal's channel is implicitly destroyed, as his device never answered.

4.5.6. Bridging

A bridge contains 0 or more channels. When a channel is in a bridge, it has the potential to communicate with other channels within the bridge. Before channels enter a bridge, a BridgeCreate event is sent, indicating that a bridge has been created. When a bridge is destroyed, a BridgeDestroy event is sent. All channels within a bridge must leave a bridge prior to the BridgeDestroy event being sent.

When a channel enters a bridge, a BridgeEnter event is raised. When a channel is put into a bridge, it is implied that the channel can pass media between other channels in the bridge. This is not guaranteed, as other properties on the channel or bridge may restrict media flow. When a channel leaves a bridge, a corresponding BridgeLeave event is raised. A BridgeLeave event MUST mean that the channel that left the bridge can no longer pass media to other channels still in the bridge. This does not necessarily mean that the channel is being hung up; rather, that it is no longer in a communication path with some other set of channels. In some scenarios, a channel may enter a bridge that has no other channels; this could occur when the channel has been put in some hold state (such as in a parking lot).

In all cases, if a channel has a BridgeEnter event, it MUST have a corresponding BridgeLeave event. If a channel is hung up and it is in a bridge, a BridgeLeave event MUST precede the Hangup event.

If a transfer operation begins, a Transfer event MUST be raised for the channels involved in the transfer prior to those channels leaving the bridge or entering another bridge. Similarly, if a channel enters a parking lot, a ParkedCall event MUST be raised for the channel prior to it entering the bridge that represents the parking lot.

If a property of a bridge is changed, such as the type going from a "native" bridge to a "core" bridge, then the BridgeUpdate event is sent with the updated parameters.

4.5.6.1. Two Party Bridging

Parties are bridged by virtue of them entering a bridge, as indicated by a BridgeEnter. When parties are no longer talking, a BridgeLeave event is sent for each channel that leaves the bridge.

Example - Two Party Bridge
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Unknown macro: {td}

Kermit the Frog's SIP channel enters into Bridge 1234. As a result, the bridge is first created (denoted by the BridgeCreate event), and then Kermit's channel enters the bridge (the BridgeEnter event)

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/gonzo-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Unknown macro: {td}

Gonzo the Great enters the bridge and talks with Kermit. Note that the bridge Gonzo entered is Bridge 1234; by virtue of this being the same bridge Kermit entered, we know that the two can talk.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...

Event: Hangup
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Unknown macro: {td}

Kermit decided he was tired of Gonzo's pontificating, and hung up on Gonzo. We are first alerted that Kermit has left the bridge; quickly thereafter, we receive the Hangup event indicating that Kermit's channel is dead.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/gonzo-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...

Event: Hangup
Channel: SIP/gonzo-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...

Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 1234
...
Unknown macro: {td}

Asterisk is configured to not let Gonzo continue on in the dialplan once his bridge is broken. As such, Gonzo is forcibly ejected from the bridge, and is hung up on after. Because no channels are left in the bridge, the bridge is destroyed.

Icon

In this scenario, it was perfectly acceptable for either Kermit or Gonzo's channels to continue after the bridge was broken. Since this represents the most basic two-party call scenario, once one party decided to hang up, the other party was also hung up on.

4.5.6.2. Transfers

Transfers begin with a Transfer event, which indicates information about the transfer that is about to take place. Subsequently, BridgeLeave/BridgeEnter events are used to indicate which channels are talking at different stages during the transfer.

Example - Blind Transfer
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Unknown macro: {td}

Kermit the Frog's SIP channel enters into Bridge 1234

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/fozzie-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Unknown macro: {td}

Fozzie Bear's SIP channel enters into Bridge 1234. At this point, Fozzie and Kermit can talk to each other.

Unknown macro: {tr}
Unknown macro: {td}
Event: Transfer
Privilege: call,all
TransferMethod: Core
TransferType: Blind
Channel: SIP/fozzie-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
TargetChannel: SIP/kermit-00000001
TargetUniqueid: 550e8400-e29b-41d4-a716-446655440000
TransferExten: call_miss_piggy
TransferContext: default
Unknown macro: {td}

Fozzie decides he's tired of telling Kermit jokes and blind transfers him off to Miss Piggy via the dialplan extension call_miss_piggy. The fact that a transfer is occurring starts off with the Transfer event. This tells the user who initiates the transfer, who is being transferred, and where the transfer target is going.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
...
Unknown macro: {td}

Kermit leaves the bridge with Fozzie.

Unknown macro: {tr}
Unknown macro: {td}
Icon

At this point, the order of the events that affect Fozzie versus Kermit are not defined. Fozzie and Kermit are no longer bridged together, and their respective events may arrive in any order.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/fozzie-00000002
...

Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 1234
...
Unknown macro: {td}

Because Fozzie isn't talking to anyone anymore, he leaves the bridge as well. At this point Asterisk could hang up Fozzie's channel, or, if configured, he could continue on in the dialplan (say, perhaps, to talk to his rubber chicken).

Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialBegin
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialEnd
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
DialStatus: ANSWER
...
Unknown macro: {td}

The act of Kermit entering into extension call_miss_piggy causes a new channel to be created between Asterisk and Miss Piggy. Asterisk immediately dials Miss Piggy, who answers.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1235
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1235
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Unknown macro: {td}

Kermit enters into a bridge. Note that the BridgeUniqueid is different than the previous bridge's BridgeUniqueid.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1235
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Unknown macro: {td}

Miss Piggy enters the bridge. At this point, Kermit and Miss Piggy can converse, and the blind transfer is complete.

4.5.7. Local Channels

Local channels are different than 'normal' channels in Asterisk, in that they have several properties that make them unique:

  • A Local channel never has a physical device that it directly communicates with - it exists as a virtual channel within Asterisk.
  • A Local channel can communicate with one or more channels, or directly with an Asterisk application.
  • Local channels can be optimized out of a communication path, causing the state of bridges and channels to change.
  • A Local channel is actually always two separate channels with a special bridge between them.
Full Size

While the Local channel exists as a single concept from the perspective of the dialplan, from the perspective of an AMI client, it is always two channels that are tied together by a special bridge. When the bridge between the Local channel halves is formed, a LocalBridge event is raised denoting that the two are connected.

4.5.7.1. Local Channel Creation

When a Local channel is created, a Newchannel event is created for each half of the Local channel being created. Each Local channel half has its own Channel field name and its own Uniqueid - for the purposes of an AMI client, they are two separate channels that can be manipulated separately but whose lifetime is tied together. When either Local channel half is hungup, denoted by a Hangup event, the other Local channel half will also be hungup automatically.

4.5.7.2. Local Channel Bridging

Local channels receive bridge events in the same fashion as other channels. Thus, when they join a bridge, they receive a BridgeEnter event and when they leave a bridge, a corresponding BridgeLeave event. The exception to this is a Local channel bridge, denoted by a LocalBridge event. Once a LocalBridge event occurs, the two Local channel halves can pass frames back and forth between each other. Because the lifetime of the Local channel halves is the same, there is no event representing a Local channel bridge being broken.

Example - Local Channel between two SIP Channels
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Unknown macro: {td}

Miss Piggy decides to call Kermit the Frog, and a channel is created between Asterisk and Miss Piggy's SIP device.

Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: Newchannel
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: LocalBridge
Channel1: Local/kermit@default-00000001;1
Channel2: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440003
Uniqueid2: 550e8400-e29b-41d4-a716-446655440004
LocalOptimization: No
...Event: DialBegin
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Unknown macro: {td}

Instead of dialing Kermit the Frog directly, a Local channel is created inside Asterisk and Asterisk dials one half of the Local channel. Note that both halves of the Local channel are created first; the Local channel bridges its two halves together; then a DialBegin event indicates that Asterisk is attempting to connect to one half of the Local channel, Local/kermit@default-00000001;1.

Unknown macro: {tr}
Unknown macro: {td}
Event: DialEnd
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Unknown macro: {td}

The dial operation succeeds and Miss Piggy is bridged with one half of the Local channel that will eventually connect her to Kermit. Note that Miss Piggy doesn't realize that any changes have occurred - from her perspective, nothing has really happened, as the Local channel is a virtual channel and we haven't yet dialed Kermit.

Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Event: DialBegin
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Event: DialEnd
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 5678
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Unknown macro: {td}

We dial Kermit, and he foolishly answers. He is now bridged with the second half of the Local channel, Local/kermit@default-00000001;2, as both that channel and the SIP channel communicating with his SIP device have corresponding BridgeEnter events.

Icon

In those situations where both a Local channel half and a SIP channel are bridged, there is no ordering guaranteed on which channel enters the bridge first - however, both a Local channel half and the SIP channel will be bridged in the same bridge.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: Hangup
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: Hangup
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: Hangup
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Event: Hangup
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...

Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 5678
Unknown macro: {td}

Miss Piggy, in a fit of frustrated porkine anger, karate chops her SIP phone, causing it to hangup. She leaves the bridge with the Local channel half, Local/kermit@default-00000001;1. This causes it to be hungup, as no one else is in the bridge. Because Local/kermit@default-00000001;1 is hungup, its corresponding other Local channel half, Local/kermit@default-00000001;2, leaves the bridge with Kermit's SIP phone and is also hung up. Kermit's SIP channel realizes it's all by itself (it's not easy being green), leaves the bridge it had with its Local channel half, and hangs up as well.

4.5.7.3. Local Channel Optimization

Local channels have an option wherein they can be optimized away if there are two other channels in the Answered state on either end of the Local channel half. This option is performed on Local channel creation, and is communicated back to the AMI clients in the LocalBridge event in the LocalOptimization field. When a Local channel optimization occurs, a LocalOptimization event is sent that indicates the channels involved in the optimization and any bridges they happen to be in. If, after the Local channel optimization, either bridges contains only a single channel, then a single channel in that bridge is moved to the bridge that had the other channel half.

Icon

It is not defined which channel is moved first - in this situation, that is an implementation detail left up to Asterisk. Suffice to say, if a Local channel is optimized away, Asterisk attempts to rebridge the channels left over.

Example - Optimizing Local Channel between two SIP Channels
Unknown macro: {table}
Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: SIP/gonzo-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Unknown macro: {td}

Gonzo decides to call Kermit the Frog, and a channel is created between Asterisk and Gonzo's SIP device.

Unknown macro: {tr}
Unknown macro: {td}
Event: Newchannel
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Event: Newchannel
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialBegin
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Unknown macro: {td}

Instead of dialing Kermit the Frog directly, a Local channel is created inside Asterisk and Asterisk dials it.

Unknown macro: {tr}
Unknown macro: {td}
Event: DialEnd
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/gonzo-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Event: LocalBridge
Channel1: Local/kermit@default-00000001;1
Channel2: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
Uniqueid2: 550e8400-e29b-41d4-a716-446655440002
LocalOptimization: Yes
...
Unknown macro: {td}

The dial operation succeeds and Gonzo is bridged with one half of the Local channel that will eventually connect him (it?) to Kermit. The Local channel itself has also decided to go ahead and bridge the two local halves together, since we have one half of the full chain of channels established. Note that we are told at this point that the Local channel will attempt to optimize itself away, if Kermit answers.

Unknown macro: {tr}
Unknown macro: {td}
Event: DialBegin
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: DialEnd
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 5678
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Unknown macro: {td}

We dial Kermit and he answers. He is now bridged with the second half of the Local channel, Local/kermit@default-00000001;2.

Icon

Note that even in the optimizing case, both the Local channel halves and the other channels involved first enter their respective bridges.

Unknown macro: {tr}
Unknown macro: {td}
Event: LocalOptimization
Channel1: Local/kermit@default-00000001;1
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
BridgeUniqueid1: 1234
Channel2: Local/kermit@default-00000001;2
Uniqueid2: 550e8400-e29b-41d4-a716-446655440002
BridgeUniqueid2: 5678
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Unknown macro: {td}

Asterisk determines that it can optimize away the Local channel. It notifies the AMI client that this is about to occur, which Local channels are involved, and what bridges they are currently in. It starts first by moving Kermit into Gonzo's bridge. From their perspective, nothing has happened - they just now happen to be in the same bridge, instead of having a Local channel pass frames for them.

Note that before this happens, a LocalOptimization event is sent indicating that some shenanigans are about to ensue with the Local channels and by extension, the bridges they are in.

Unknown macro: {tr}
Unknown macro: {td}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel1: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel1: Local/kermit@default-00000001;1
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
...
Event: Hangup
Channel1: Local/kermit@default-00000001;1
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
...
Event: Hangup
Channel1: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440002
...Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 5678
...
Unknown macro: {td}

The Local channels now leave their bridges and are hung up. As a result, the bridge with no channels left in it - Bridge 5678 - is destroyed.

4.5.8. Masquerades

Masquerades have changed

Icon

In the past, masquerades occurred rather frequently - most often in any scenario where a transfer occurred or where a pbx_thread needed to be associated with a channel. This has now changed. Masquerades now rarely occur, and are never communicated to AMI clients. From the perspective of AMI clients, nothing changes - you still use your handle to a channel to communicate with it, regardless of the presence (or lack thereof) of a masquerade operation.

This note only exists to explicitly call out that fact.

4.6. Transports

AMI supports the following transport mechanisms:

  • TCP/TLS
  • HTTP/HTTPS

When clients connect over HTTP/HTTPS, AMI events are queued up for retrieval. Events queued up for a client are automatically retrieved and sent in the response to any POST operation. The WaitEvent action can be used to wait for and retrieve AMI events.

5. Security Considerations

AMI supports security at the transport level via TLS using OpenSSL.

5.1. Class Authorizations

Icon

Do not rely on class authorizations for security. While they provide a means to restrict a client's access to sets of functionality, there are often ways of achieving similar functionality through multiple mechanisms. Do NOT assume that because a class authorization has not been granted to a client, that they can't find a way around it. In general, view class authorizations as a coarse grained way of providing sets of filters.

Events and actions are automatically classified with particular class authorizations. Clients can be configured to support some set of class authorizations, filtering the actions that they can perform and events that they receive. The supported class authorizations are listed below.

Class Type

Description

system

The item is associated with something that reports on the status of the system or manipulates the system in some fashion

call

The item is associated with calls, i.e., state changes in a call, etc.

log

The item is associated with the logging subsystem

verbose

The item is associated with verbose messages

command

The item is associated with execution of CLI commands through AMI

agent

The item is associated with Queue Agent manipulation

user

The item is associated with user defined events

config

The item is associated with manipulating the configuration of Asterisk

dtmf

The item is associated with DTMF manipulation

reporting

The item is associated with querying information about the state of the Asterisk system

cdr

The item is associated with CDR manipulation

dialplan

The item is associated with dialplan execution

originate

The item is associated with originating a channel

agi

The item is associated with AGI execution

cc

The item is associated with call completion

aoc

The item is associated with Advice of Charge

test

The item is associated with some test action

message

The item is associated with out of call messaging

all

The item has all class authorizations associated with it

none

The item has no class authorization associated with it

5.2. Access Control Lists

Access Control Lists can be used to filter connections based on address. If an attempt to connect from an unauthorized address is detected, the connection attempt will be rejected.

5.3. Authorization

Authorization can be provided via the Login action. If a client fails to provide a valid username/password, the connection attempt and any subsequent actions will be rejected. Events will not be sent until the client provides authorized credentials.

The actions that are excluded from successful login are:

  • Login
  • Logout
  • Challenge
Icon

The action Logoff has been replaced by a corresponding action Logout. Logoff has been deprecated in favor of Logout.

6. AMI Configuration

AMI supports the following configuration options. Note that additional configurations MAY be specified; however, these configuration options are valid for Asterisk 12.

6.1. General Settings

Option

Type

Description

Default

enabled

Boolean

Enable AMI

no

webenabled

Boolean

Enable AMI over HTTP/HTTPS

no

port

Integer

The port AMI's TCP server will bind to

5038

bindaddr

IP Address

The address AMI's TCP server will bind to

0.0.0.0

tlsenable

Boolean

Enable TLS over TCP

no

tlsbindaddr

IP Address

The address AMI's TCP/TLS server will bind to

0.0.0.0:5039

tlscertfile

String

The full path to the TLS certificate to use

/tmp/asterisk.pem

tlsprivatekey

String

The full path to the private key. If no path is specified, tlscertfile will be used for the private key.

/tmp/private.pem

tlscipher

String

The string specifying which SSL ciphers to use. Valid SSL ciphers can be found at http://www.openssl.org/docs/apps/ciphers.html#CIPHER_STRINGS

 

allowmultiplelogin

Boolean

Allow multiple logins for the same user. If set to no, multiple logins from the same user will be rejected.

Yes

timestampevents

Boolean

Add a Unix epoch Timestamp field to all AMI events

No

authlimit

Integer

The number of unauthenticated clients that can be connected at any time

 

6.2. Client Settings

Note that the name of the client settings context is the username for the client connection.

Option

Type

Description

Default

secret

String

The password that must be provided by the client via the Login action

 

deny

ACL

An address/mask to deny in an ACL. This option may be present multiple times.

 

permit

ACL

An address/mask to allow in an ACL. This option may be present multiple times.

 

acl

String

A Named ACL to apply to the client.

 

setvar

String

A channel variable key/value pair (using the nomenclature VARIABLE=value) that will be set on all channels originated from this client

 

eventfilter

Regular Expression

This option may be present multiple times. This options allows clients to whitelist or blacklist events. A filter is assumed to be a whitelist unless preceeded by a '!'. Evaluation of the filters is as follows:

  • If no filters are configured all events are reported as normal.
  • If there are white filters only: implied black all filter processed first, then white filters.
  • If there are black filters only: implied white all filter processed first, then black filters.
  • If there are both white and black filters: implied black all filter processed first, then white filters, and lastly black filters.

 

read

String

A comma delineated list of the allowed class authorizations applied to events

all

write

String

A comma delineated list of the allowed class authorizations applied to actions

all

tag

String

If present, the client will only receive events that are related to channels created in relation to endpoints that are configured with the same tag. See [Publish/Subscribe] for more information.

 

  • No labels