Asterisk AMI – get detailed extension status

asterisk

I am using AMI from Python. I guess the same can be achieved from the Asterisk CLI. I want to be able to get details about every extension in the PBX. More specifically, for every extension I want to know:

  • If the extension is in a call, what is the unique ID of that call, what is the caller id, what phone number was called (incoming line)
  • If the extension is ringing, what incoming line is ringing right now.

The system currently has a number of custom contexts that will first hunt and then ring all available extensions and I want to know who and where is ringing and talking. I looked through almost all calls of AMI I could find, but couldn't figure out where to get that information.

Best Answer

Digium has somewhat complete documentation for all AMI Actions and AMI Events on their wiki. I say "somewhat" because it lists all available actions and events, and how to use them, but some of it is a little sparse when it comes to the output you should expect to see.

Actions you might find useful:

  • Command - lets you run an arbitrary CLI command from the AMI, useful if there isn't a dedicated AMI action to get information available on the CLI
  • CoreShowChannels - equivalent of CLI core show channels, which shows channel names and associated caller-id info
  • ExtensionState - get the current state of an extension, probably most useful if you have extension hints defined
  • Getvar - get the value of a channel variable
  • Status - shows current status info for a channel, including channel variables (which you can then interrogate with Getvar)

Events you might find useful:

  • ExtensionStatus - raised when the status of an extension changes
  • Newchannel - raised when a new channel is created (e.g. new incoming call)
  • Newstate - raised when a channel's state changes (e.g. existing call transferred and now ringing)

Of the actions, I'd think Status will be most useful, and the Newchannel and Newstate events will tell you when channels are ringing or get answered.