Asynchronous Javascript Asterisk Manager (AJAM)

AJAM is a new technology available in Asterisk 1.4 which allows web browsers or other HTTP enabled applications and web pages to directly access the Asterisk Manager Interface (AMI) via HTTP. Setting up your server to process AJAM involves a few steps:

Setup the Asterisk HTTP server


1) Uncomment the line "enabled=yes" in /etc/asterisk/http.conf to enable Asterisk's builtin micro HTTP server.

2) If you want Asterisk to actually deliver simple HTML pages, CSS, JavaScript, etc. you should uncomment "enablestatic=yes"

3) Adjust your "bindaddr" and "bindport" settings as appropriate for your desired accessibility

4) Adjust your "prefix" if appropriate, which must be the beginning of any URI on the server to match. The default is "asterisk" and the rest of these instructions assume that value.

Allow Manager Access via HTTP


1) Make sure you have both "enabled = yes" and "webenabled = yes" setup in /etc/asterisk/manager.conf

2) You may also use "httptimeout" to set a default timeout for HTTP connections (in seconds).

3) Make sure you have a manager username/secret

Once these configuration changes are complete you can reload or restart Asterisk and you should be able to point your web browser to specific URI's which will allow you to access various web functions. A complete list can be found by typing "show http" at the Asterisk CLI. For 1.4 versions this command changed to 'http show status'.

Examples:

http://localhost:8088/asterisk/manager?action=login&username=foo&secret=bar

This logs you into the manager interface's "HTML" view. Once you're logged in, Asterisk stores a cookie on your browser (valid for the length of httptimeout) which is used to connect to the same session.

http://localhost:8088/asterisk/rawman?action=status

Assuming you've already logged into manager, this URI will give you a "raw" manager output for the "status" command.

http://localhost:8088/asterisk/mxml?action=status

This will give you the same status view but represented as AJAX data, theoretically compatible with RICO (http://www.openrico.org).

http://localhost:8088/asterisk/static/ajamdemo.html

If you have enabled static content support and have done a make install, Asterisk will serve up a demo page which presents a live, but very basic, "astman" like interface. You can login with your username/secret for manager and have a basic view of channels as well as transfer and hangup calls. It's only tested in Firefox, but could probably be made to run in other browsers as well.

A sample library (astman.js) is included to help ease the creation of manager HTML interfaces.

Note that for the demo, there is no need for *any* external web server.

You need to be aware that as soon as you have logged in with a user name that has event reporting rights then
Asterisk saves *all* the events for you, waiting for you to issue the WaitEvent command which will then return
everything that has happened since the last call as a single XML document. If you log out (or time out) then
these events will be discarded, but if you continue in a loop calling Status or equivalent without calling WaitEvent
then you will eat memory and greatly increase Asterisk's CPU usage.

A good approach to monitoring Asterisk is to call WaitEvent and then process the XML message returned, finding any useful responses and processing them, then call Status and process the result, then call QueueStatus and process those results, then loop back to call WaitEvent.

Integration with other web servers


Asterisk's micro HTTP server is *not* designed to replace a general purpose web server and it is intentionally created to provide only the minimal interfaces required. Even without the addition of an external web server, one can use Asterisk's interfaces to implement screen pops and similar tools pulling data from other web servers using iframes, div's etc. If you want to integrate CGI's, databases, PHP, etc. you will likely need to use a more traditional web server like Apache and link in your Asterisk micro HTTP server with something like this:

ProxyPass /asterisk http://localhost:8088/asterisk

See also

  • AstManProxy: Allows for SSL/HTTPS secured AMI communication

  • AsterClick: open source allows for a true event driven (NO POLLING) HTML5 based interface to Asterisk AMI. Ask about the open source WBEA tool and make those HTML5 applications stand alone desktop executables on both windows and Linux, no browser nor web server required!


AJAM is a new technology available in Asterisk 1.4 which allows web browsers or other HTTP enabled applications and web pages to directly access the Asterisk Manager Interface (AMI) via HTTP. Setting up your server to process AJAM involves a few steps:

Setup the Asterisk HTTP server


1) Uncomment the line "enabled=yes" in /etc/asterisk/http.conf to enable Asterisk's builtin micro HTTP server.

2) If you want Asterisk to actually deliver simple HTML pages, CSS, JavaScript, etc. you should uncomment "enablestatic=yes"

3) Adjust your "bindaddr" and "bindport" settings as appropriate for your desired accessibility

4) Adjust your "prefix" if appropriate, which must be the beginning of any URI on the server to match. The default is "asterisk" and the rest of these instructions assume that value.

Allow Manager Access via HTTP


1) Make sure you have both "enabled = yes" and "webenabled = yes" setup in /etc/asterisk/manager.conf

2) You may also use "httptimeout" to set a default timeout for HTTP connections (in seconds).

3) Make sure you have a manager username/secret

Once these configuration changes are complete you can reload or restart Asterisk and you should be able to point your web browser to specific URI's which will allow you to access various web functions. A complete list can be found by typing "show http" at the Asterisk CLI. For 1.4 versions this command changed to 'http show status'.

Examples:

http://localhost:8088/asterisk/manager?action=login&username=foo&secret=bar

This logs you into the manager interface's "HTML" view. Once you're logged in, Asterisk stores a cookie on your browser (valid for the length of httptimeout) which is used to connect to the same session.

http://localhost:8088/asterisk/rawman?action=status

Assuming you've already logged into manager, this URI will give you a "raw" manager output for the "status" command.

http://localhost:8088/asterisk/mxml?action=status

This will give you the same status view but represented as AJAX data, theoretically compatible with RICO (http://www.openrico.org).

http://localhost:8088/asterisk/static/ajamdemo.html

If you have enabled static content support and have done a make install, Asterisk will serve up a demo page which presents a live, but very basic, "astman" like interface. You can login with your username/secret for manager and have a basic view of channels as well as transfer and hangup calls. It's only tested in Firefox, but could probably be made to run in other browsers as well.

A sample library (astman.js) is included to help ease the creation of manager HTML interfaces.

Note that for the demo, there is no need for *any* external web server.

You need to be aware that as soon as you have logged in with a user name that has event reporting rights then
Asterisk saves *all* the events for you, waiting for you to issue the WaitEvent command which will then return
everything that has happened since the last call as a single XML document. If you log out (or time out) then
these events will be discarded, but if you continue in a loop calling Status or equivalent without calling WaitEvent
then you will eat memory and greatly increase Asterisk's CPU usage.

A good approach to monitoring Asterisk is to call WaitEvent and then process the XML message returned, finding any useful responses and processing them, then call Status and process the result, then call QueueStatus and process those results, then loop back to call WaitEvent.

Integration with other web servers


Asterisk's micro HTTP server is *not* designed to replace a general purpose web server and it is intentionally created to provide only the minimal interfaces required. Even without the addition of an external web server, one can use Asterisk's interfaces to implement screen pops and similar tools pulling data from other web servers using iframes, div's etc. If you want to integrate CGI's, databases, PHP, etc. you will likely need to use a more traditional web server like Apache and link in your Asterisk micro HTTP server with something like this:

ProxyPass /asterisk http://localhost:8088/asterisk

See also

  • AstManProxy: Allows for SSL/HTTPS secured AMI communication

  • AsterClick: open source allows for a true event driven (NO POLLING) HTML5 based interface to Asterisk AMI. Ask about the open source WBEA tool and make those HTML5 applications stand alone desktop executables on both windows and Linux, no browser nor web server required!


Created by: muppetmaster, Last modification: Sat 19 of May, 2012 (00:51 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+