phpubuntudaemonsnmpd

Pass SNMP trap packet to a php daemon on Ubuntu


I have a Ubuntu server which is collecting incoming SNMP traps. Currently these traps are handled and logged using a PHP script.

file /etc/snmp/snmptrapd.conf

traphandle default /home/svr/00-VHOSTS/nagios/scripts/snmpTrap.php

This script is quite long and it contains many database operations. Usually the server receives thousands of traps per day and therefore this script is taking too much CPU time. My understand is this is due to high start-up cost of the php script every-time when a trap received.

I got a request to re-write this and I was thinking of running this script as a daemon. I can create an Ubuntu daemon. My question is how can I pass trap-handler to this daemon using snmptrapd.conf file?

Thank you in advance.


Solution

  • One suggestion is to use mysql support thats built into 5.5 of snmptrapd. That way you can use mysql as a queue and process the traps in bulk.

    details of this are on the snmptrapd page: http://www.net-snmp.org/wiki/index.php/Snmptrapd

    If not using mysql another option is to use a named pipe.

    Do mkfifo snmptrapd.log Now change snmptrapd to write to this log. Its not a file but it looks like one. You then write another daemon to watch the named pipe for new data.