Simple SNMP Trap Testing

Start a non forking snmptrapd daemon accepting all incoming traps and logging them to standard output:
snmptrapd -CdfLo --disableAuthorization=yes
Send a testing trap to the host running snmptrapd daemon (in this example
snmptrap -v 1 -c public . "" 0 0 coldStart.0
Also make sure the host firewall is not blocking incoming UDP/162 traffic.


  1. Exactly what I was looking for. Thank you

  2. Thank you! This did just what I needed

  3. :) Many time talk is cheap ,but little talk worth

  4. Thanks for this. This was the first SNMP trap I successfully sent. As partial payback, here's a script for others who are facing the same problem. it works on RHEL 7.2, I haven't tested anywhere else, but it should work anywhere with net-SNMP mibs installed.

    Dan Baker

    # this script just sends a test snmp trap. it uses a real trap,
    # so don't use it with automated systems unless you can handle
    # the alarm when it comes in

    # User details
    # I enclose the community string in single quotes because they
    # often contain characters the shell considers special.

    HELP_MSG="This script sends a simple snmp trap.
    you MUST edit it to set the correct destination
    and Community string. It's too tricky handling
    possible special characters to attempt that here.
    By default it goes to localhost with the default
    "public" string. This will work if you first run
    a local trap collector like this:

    snmptrapd -CdfLo --disableAuthorization="yes"

    USAGE: $0 [linkUp|linkDown|coldStart|warmStart]"

    # parse the parameters to get a TYPE
    # default TYPE to linkup
    case $1 in
    up|linkup|linkUp|ifup ) MIB="IF-MIB" ; TYPE="linkUp";;
    down|linkdown|linkDown|ifdown ) MIB="IF-MIB" ; TYPE="linkDown" ;;
    cold|coldstart|coldStart ) MIB=SNMPv2-MIB ; TYPE="coldStart" ;;
    warm|warmstart|warmStart ) MIB=SNMPv2-MIB ; TYPE="warmStart";;
    help ) echo $HELP_MSG ; exit 0;;
    * ) echo "No valid type given, sending linkUp trap"
    echo "For usage, try $0 help"

    # Now that we have a MIB and a Trap, we can construct an OID

    # Values: type meaning:
    # ifIndex i interface number starting from 1, not zero. 2=eth1
    # ifAdminStatus i 1=up 2=down
    # ifOperStatus i 1=up 2=down

    #syntax snmptrap <-c Community string> ...

    # Drop a log entry just to be nice
    logger -p user.notice "sending snmp trap"

    # send a trap
    case $TYPE in
    linkUp ) snmptrap -v2c -c $COMMUNITY $COLLECTOR_IP '' ${OID} ifIndex i 1 ifAdminStatus i 1 ifOperStatus i 1 ;;
    linkDown) snmptrap -v2c -c $COMMUNITY $COLLECTOR_IP '' ${OID} ifIndex i 1 ifAdminStatus i 2 ifOperStatus i 2;;
    coldStart|warmStart ) snmptrap -v2c -c $COMMUNITY $COLLECTOR_IP '' ${OID} ;;
    * ) echo "Unpossible error did not occur.";;

    # drop another log to say it's been sent
    logger -p user.notice "${OID} trap sent"

    # pull the log messages to get a time stamp, if needed
    tail /var/log/messages |grep ${OID} |tail -2