This is my first time working with SNMP, but after reading the SNMP pages I'm 
still having trouble getting a simple shell script to run when receiving a trap.

My /etc/snmp/snmptrapd.conf file looks like this:

# Example configuration file for snmptrapd
# No traps are handled by default, you must edit this file!
disableAuthorization yes
authCommunity log,execute,net public
# the generic traps
traphandle default /usr/local/bin/

The script just says "hello".


echo "hello"

The script is executable and runs when executed independently:

> /usr/local/bin/

The snmptrapd is running as a background process:

> ps -ef | grep snmp
root     29477     1  0 14:49 ?        00:00:00 /usr/sbin/snmptrapd -Lsd -p 
/var/run/ -Cc /etc/snmp/snmptrapd.conf

And yet when I send a trap locally using snmptrap nothing happens:

> snmptrap -v 2c -c public localhost "" 
> NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification 
> netSnmpExampleHeartbeatRate i 123456

Now it seems that the trap does get logged, because the system log file 
(/var/log/messages) has the following entry:

Aug  8 15:46:10 <server_name> snmptrapd[29477]: 2017-08-08 15:46:10 localhost
[UDP: []:44928->[]]:#012DISMAN-EVENT-MIB::sysUpTimeInstance =
Timeticks: (1338382434) 154 days, 21:43:44.34#011SNMPv2-MIB::snmpTrapOID.0 =
= INTEGER: 123456

When I added the -Ci option to the snmptrapd command line options I got the 
following error:

No log handling enabled - turning on stderr logging
: Unknown Object Identifier (Sub-id not found: (top) -> )

As far as I can see everything is set up correctly. If so, why is the trap 
handle not working and how can one check why the trap doesn't trigger the 

Thanks in advance.

Check out the vibrant tech community on one of the world's most
engaging tech sites,!
Net-snmp-coders mailing list

Reply via email to