In SNMP, we usually use SNMP trap-related definitions. Many of my friends do not know how to apply it. Today, let's analyze the relevant content. So, first, let's take a look at what Trap means. Traps can be translated into traps or traps in SNMP. The agent in the managed device can report errors to the network management workstation at any time, such as pre-defined threshold out-of-bounds. The agent does not need to wait until the management workstation polls the agent to receive these errors. These errors are well known SNMP traps ).
In this method, you can use a network management workstation to query a device if it is still reachable ), for more information.
Using snmptrapd to receive SNMP trap information and write it into a specific document recently, we are studying snmp trap and snmptrapd information. So far, we have not found out how to Enable snmp trap to automatically send information. However, you can use snmptrapd to receive SNMP trap information and write it into a specific document.
I. Management end
Create/usr/share/snmp/snmptrapd. conf is used on my machine. Different machines may be stored in/etc/snmp,/usr/local/share/snmp/, and experiment with each other based on different situations)
Add the following line:
Set access permissions for all users: executable, record, and pass:
- authcommunity execute,log,net public
Set traphandle (that is, when you receive the OID information of. 1.3.6.1.4.1.2021.251.1, run test. pl)
- traphandle .1.3.6.1.4.1.2021.251.1 /home/long/test.pl
Here. 1.3.6.1.4.1.2021.251.1 is an Enterprise-OID
/Home/long/test. pl is a processing perl file:
- #!/usr/bin/perluse strict;my $file="file.trap";open(HANDOUT,">>./$file");
- while(<STDIN>){print HANDOUT "$_";}
This is the packet sent by snmp trap into file. in the trap file, start/etc/init. d/snmpd start, which must be started first, and then use "snmptrapd-c/etc/snmp/snmptrapd. conf"
Ii. Proxy
Enter the following command on another machine:
- Snmptrap-v 2c-c public 192.168.126.99 "". 1.3.6.1.4.1.2021.251.1 sysLocation.0 s "longtengfei"
- 192.168.126.99 is the management end address. 1.3.6.1.4.1.2021.251.1 corresponds to the Enterprise-OID in snmptrapd. conf of the management end.
After the execution is completed, the file content in file. trap (in the/root/file. trap directory) becomes:
- <UNKNOWN>UDP:[192.168.126.200]:35327DISMAN-EVENT-MIB::sysUpTimeInstance 3:1:37:20:21
- SNMPv2-MIB::snmpTrapOID.0 UCD-SNMP-MIB::ucdStartSNMPv2-MIB::sysLocation.0 longtengfei