[Switch] Use snmptrap to send SNMP traps

 

Transfer: http://blog.chinaunix.net/uid-20644632-id-4115863.html

Send SNMP trap using snmptrap 2014-02-21 13:55:33

Category: LINUX

 

Send SNMP traps using snmptrap

Leng Shengkui (Seaquester)
[email protected]
2014-01-15

Using snmptrap and other tools provided by net-snmp can realize trap sending and receiving. The following is the specific method.

1. Create the snmptrapd.conf
file The content of the snmptrapd.conf file is as follows:
    authCommunity log,execute,net public
Here, for simplicity, we did not specify the corresponding handler after receiving the trap.

2. Start snmptrapd (specify the location of the config file)
to run in the foreground, and print the log information to stdout:
  1. $ sudo snmptrapd -C -c ./snmptrapd.conf -f -Lo
It can also run in the background and print log information to a file:
  1. $ sudo snmptrapd -C -c ./snmptrapd.conf -Lf /tmp/trapd.log

3. Send a trap through the snmptrap tool (the destination address is "127.0.0.1:162")
The command line format of snmptrap is as follows:
  1.   snmptrap -v [2c|3] [COMMON OPTIONS]        uptime      trap-oid                [OID TYPE VALUE]
  2. $ snmptrap -v 2c     -c public 127.0.0.1:162 ""         .1.3.6.1.4.1.2021.251.1  sysLocation.0 s "test"
  3. $ snmptrap -v 2c     -c public 127.0.0.1:162 "12345678" .1.3.6.1.4.1.2021.251.1  sysLocation.0 s "test"

4. Check the log information of snmptrapd, you can see the trap we sent:
  1. 2014-01-14 17:08:13 localhost [UDP: [127.0.0.1]:59609->[127.0.0.1]]:
  2. DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (3081118) 8:33:31.18 SNMPv2-MIB::snmpTrapOID.0 = OID: UCD-SNMP-MIB::ucdStart SNMPv2-MIB::sysLocation.0 = STRING: test
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326674783&siteId=291194637