I have a need to collect snmptraps and display them in a web interface. The application already includes *ruby on rails *linux *delayed_job (for queueing) *postgresql *A few cron jobs that do snmp queries
Now I need to run something like snmptrapd to collect alarms. Would it be possible for snmptrapd to write its traps to a queue that I can process with a cron job. Something like the built in mqueue of linux would be great. Or even writing it to a postgresql database (I know it supports mysql but no mention of postgres anywhere)
Does anyone know how I can redirect the output of snmptrapd into something I can process with a cron job.
I did something similar in Perl but you can do that with Ruby as well.
First you need to tell snmptrapd who is the default handler for traps. In the snmptrapdconf you can define it as the following:
traphandle default /yourpluginpath/yourplugin
Now every time a trap occours its data will be sent to yourplugin. It's up to him now to handle it. Once you have the packet you can store it to any DB you want, doesn't matter if it is MySQL or PostgreSQL.
The only problem is the library that parses the data that comes from the trap. In Perl I used SNMP::Trapinfo but since I nevery used Ruby I don't know the equivalent, I am sure someone else can point you to the right library. You can even parse it yourself. Actually you can also use a basic shell script if you wish someone else to store the data to the DB.