Vajira Lasantha
Vajira Lasantha

Reputation: 2513

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.

Upvotes: 2

Views: 1143

Answers (2)

Tommie Jones
Tommie Jones

Reputation: 1011

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.

Upvotes: 1

Kalle Volkov
Kalle Volkov

Reputation: 458

You can probably use php-fpm / php-fcgi to minimize PHP script start-up cost.

Although, you probably need to write some wrapper shell script to forward request from snmptrapd to fcgi protocol.

But at first I'd recommend checking the PHP script. PHP start-up cost is not that high that few requests per minute should rise CPU usage notably.

Upvotes: 1

Related Questions