New Logging Profile in FreeSWITCH mod_amqp

Background

For a basic background on RabbitMQ and mod_amqp in FreeSWITCH, check out our previous RabbitMQ post.

New Functionality

mod_amqp now has the ability to handle events when log lines are printed. You can configure the rabbitmq server connection details and set which loglevels to track by updating the newly added logging profile in autoload_configs/amqp.conf.xml

The default logging profile looks like this:

 <logging>
   <profile name="default">
     <connections>
       <connection name="primary">
         <param name="hostname" value="localhost"/>
         <param name="virtualhost" value="/"/>
         <param name="username" value="guest"/>
         <param name="password" value="guest"/>
         <param name="port" value="5672"/>
         <param name="heartbeat" value="0"/>
       </connection>
     </connections>
     <params>
       <param name="exchange-name" value="TAP.Logging"/>
       <param name="send_queue_size" value="5000"/>
       <param name="reconnect_interval_ms" value="1000"/>
       <param name="log-levels" value="debug,info,notice,warning,err,crit,alert"/>
     </params>
   </profile>
 </logging>

After making your updates, apply them in fs_cli with

 reloadxml
 reload mod_amqp

FreeSWITCH will now send the events to your rabbitmq server. NOTE: If you leave debug enabled, prepare yourself for a LOT of messages.

Grabbing the Events

The example perl script below shows how to bind to a queue and consume the logging events.

amqp_logging.pl

You can process the message however you would prefer. The example script above produces the following output for a session destroy notice:

 Routing Key: QuentusAmqp77.26a41148-6457-43e6-9db7-d3ced7eacb0d.NOTICE.switch_core_session_c
 $VAR1 = {
   'timestamp_epoch' => '1452807000',
   'level' => 'NOTICE',
   'function' => 'switch_core_session_thread',
   'timestamp' => '2016-01-14 13:34:00.218992',
   'file' => 'switch_core_session.c',
   'content' => ' Close Channel sofia/external/kaytortuga@172.18.101.166 [CS_DESTROY]
 ',
   'line' => 1668
 };

Note that the routing key holds the server name, call uuid, log level, and the FreeSWITCH file that generated the line.

Output from a log line in the dialplan produces something akin to the following:

 Routing Key: QuentusAmqp77.63689b85-889a-4fbd-aeee-4f2e2f7c4359.WARNING.mod_dptools_c
 $VAR1 = {
   'timestamp_epoch' => '1452810000',
   'level' => 'WARNING',
   'function' => 'log_function',
   'timestamp' => '2016-01-14 14:26:08.517320',
   'file' => 'mod_dptools.c'',
   'content' => ' This is a sample warning message
 ',
   'line' => 1692
 };

Test it out!

Make a call or perform any action that would print FreeSWITCH log lines.

To see it all, add the following extension to your public dialplan:

 <extension name="log_all_the_things">
   <condition field="destination_number" expression="^log_all_the_things$">
     <action application="answer"/>
     <action application="log" data="ALERT This is a sample alert message"/>
     <action application="log" data="CRIT This is a sample critical message"/>
     <action application="log" data="ERR This is a sample error message"/>
     <action application="log" data="WARNING This is a sample warning message"/>
     <action application="log" data="NOTICE This is a sample notice message"/>
     <action application="log" data="INFO This is a sample information message"/>
     <action application="log" data="DEBUG This is a sample debug message"/>
     <action application="hangup"/>
   </condition>
 </extension>

Apply the change in fs_cli

 reloadxml

And dial your new extension from a SIP client.

Conclusion

Check out the latest release of FreeSWITCH to get access to the expanded mod_amqp functionality. If you have any questions or comments, feel free to submit a comment below.

Category
Tagcloud
rabbitmq amqp reviews limits hiredis freeswitch sip smpp sms yealink flowroute redis
Powered by Pelican
which takes great advantage of Python