Logging Events to a Database with Adhearsion

One of the new features of Adhearsion is the events subsystem, a completely new way to handle events from Asterisk. First, the Theatre library embedded in Adhearsion follows the Actor Model for handling the TCP sockets with the Asterisk AMI. This allows for a fully multi-threaded implementation of the AMI synchronous protocol that ensures thread safety. Second, Adhearsion now uses Ragel to parse the AMI protocol. This implementation allows for the efficient parsing of the AMI, which tends to be inconsistent. These capabilities are part of what puts Adhearsion in a class of its own for open source voice development for Asterisk.
Media_httpjsgoeckefil_ajxtq
I have recently create an example Adhearsion component, event_logger, that shows how to use the event sub-system to log events to a database. The event_logger component allows for logging events via either ActiveRecord or to CouchDB. Currently the ActiveRecord implementation supports a subset of the total events available in Asterisk. Given that CouchDB is a Documented Oriented Database, its schema-less nature means that all events are currently supported. One thing to keep in mind when using events with Asterisk, is that when you set your own custom channel variables, these are not delivered with every event. Instead, they must be queried. For tracking and logging custom channel variables with Asterisk, I recommend using the UserEvent application that allows you to send your own events over the AMI. For example, you may add this to your extensions.conf to log a custom event via the event_logger: [sourcecode language='html'] exten => _X.,n,UserEvent(LOGVARIABLES|invoice:${INVOICE}) [/sourcecode] Which results in this event being logged to the database:
Media_httpjsgoeckefil_misbh
This will allow you to decide, either in extensions.conf or dialplan.rb, when to log specific channel variables to the database for later reporting. To get started have a look at the event_logger component.
Posted