BLOG     |     FORUM

Send emails on receiving SNMP Traps

This article explains how you can send an email  when SNMP traps are received by Unbrowse SNMP. We use Unbrowse Scripting and the Ruby programming language for this purpose.

Here's what we are going to do:

  1. Open the server and listen for traps (SNMP v1, v2, v3 supported as well as IPv4, IPv6 and all security models)
  2. Every 30 seconds get a list of traps received, format them into an email message
  3. Send the email message to an address (also supports cc)
  4. Remove processed traps so the server memory is freed up

 

About the high performance trap server

A common misconception about the Unbrowse Scripting interface is that it is slow. Lets clear that up. The trap receiver is a really fast C++ server capable of processing bursts of thousands of traps per second without dropping anything. The server keeps the traps and the script is only used to drain the server. This combination provides the optimum mix of performance and flexibility.

For example : You can write a Ruby or VBScript program to do whatever custom housekeeping work you want without the fear of losing traps due to the script execution speed. If tasks like sending emails or inserting into a database were baked into the C++ server - it would be severely restrictive.


Running the server

Step 1 : Download the latest version of Unbrowse SNMP and install it

Step 2 : Get the script and save it in a directory of your choice

 t2mail.rbThe ruby script that sends emails when SNMP Traps are received 

Step 3 : Download and install the Ruby one click installer

Get it  from  http://rubyforge.org/projects/rubyinstaller/ (Get the latest version)

Step 4 : After the ruby installer is done. Type the following command

gem install tmail

This will install the TMail library which we use to send out SMTP emails.

Step 5 : Edit the email settings

Enter your password details, to and from addresses, etc

Open the script you downloaded in Step 2 and locate the following section

# Change this to your environment
server_settings = {
 :server => "mail.xyz.com",
 :port => 25,
 :username => " This e-mail address is being protected from spambots. You need JavaScript enabled to view it ",
 :domain => 'localhost',
 :password => 'PekingDucky0011'}
# Add from,to,and cc
mail_settings = {
 :from => "unbrowse_snmp_traps",
 :to => " This e-mail address is being protected from spambots. You need JavaScript enabled to view it ",
 :cc => ""
 }
# Max Mail frequency seconds
mail_frequency_seconds  = 30

All parameters are self explanatory. The mail_frequency_settings is the minimum amount of time between emails. The default is 30, which means the script will not send emails faster than this rate. If there are many SNMP Traps in this interval, the script will combine them into a single email.

 

Step 6 : Run the script

Open a command prompt and type the following

ruby t2email.rb

 

Thats it ! Now you have a high performance SNMP server that sends emails. You can adapt the script to perform more involved work like translating the trap OIDs to SNMP OID Names using the scripting interface

If you have any trouble getting this to work please post a message in our forum or send an email across to info at