May 15, 2007

snmptrap command

snmptrap -v 1 -c public 192.168.100.40 1.2.3.4 192.168.254.60 3 0 ''

syntax:

-v 1: version 1
-c public: use community string "public"
192.168.100.40: trap manager's IP address (trap destination)
1.2.3.4: enterprise (i.e. type of device/object generating trap, default to system ID in mib II, can be empty)
192.168.254.50: trap source IP address (device's IP address)
3: generic trap ID, they are:
  • coldStart(0),
  • warmStart(1),
  • linkDown(2),
  • linkUp(3),
  • authenticationFailure(4),
  • egpNeighborLoss(5),
  • enterpriseSpecific(6)

0: specific trap ID, 0 when generic trap ID is not 6
'': system up time (timestamp)

You can also add "mib type value" to the end of the command to send them along with the trap

v2 trap:
snmptrap -v 2c -c public 192.168.100.40 "" 1.2.3.4.0

"": system Uptime (when given as empty "", the system finds itself)
1.2.3.4.0: trap OID

again, add "mib type value" to the end if you want.


v3 trap:

snmptrap -v 3 -a SHA -A 1234567890 -x DES -X 1234567890 -l authPriv -u myuser -e "123abc" 192.168.100.1 "" linkUp.0

---
Update (09/10/2013)

When running snmptrap command, and seeing warning message like:

    read_config_store open failure on /var/lib/net-snmp/snmpapp.conf

is okay. The trap is still being sent.

To run a debug catch-all snmptrapd:

     snmptrapd -Le -On -f -n

with the following just-one-line in /etc/snmp/snmptrapd.conf
    disableAuthorization yes

-n: no DNS lookup
-f:  no fork
-On: print numeric OID
-Le: log to standard error