Sending SNMP2 trap message from Linux command lne

落爺英雄遲暮 提交于 2019-12-08 02:58:12

问题


Folks,

I need to use this command (snmptrap) from Linux command line to send my custom message to a trap listener. I need to send the same message in both v1 and v2c depending on user settings.

Here is what I found.

For v1:

snmptrap -v 1 -c Tas hostname 1.3.6.1.4.1.2.3 "" 6 3 1234 s s "This is a test"

The above command works, I see the following message in my listener.

Display of SNMPv1 trap:
community:       Tas
enterprise oid:  1.3.6.1.4.1.2.3
        .....    ibmAgents
agentAddress:    hostname
generic-trap:    enterpriseSpecific ('00000006'h)
specific-trap:   3 ('00000003'h)
time-stamp:      1234 - 12.34 seconds
varBind oid:     OBJECT_IDENTIFIER 1.3.6.1.6
        name:    snmpV2
        value:   OCTET_STRING This is a test <- Here is my message. 

My listener is a basically an AIX system, running the following command.

clsnmp -c public TRAP

For v2c: I am issuing this command.

snmptrap -v 2c -c "Tas" hostname '1234' 1.3.6.1.4.1.2.3 s s "This is a Test"

The command does not give me any error. But on the listener I see this.

Display of SNMPv2 trap with SNMPV2C security
community:       Tas

The message "This is a Test" is not shown.

I am not familiar with snmptrap command - know very little about the protocol also. I have googled the command. My questions...

  1. Is there anything wrong with the v2c command?

  2. Is there anything wrong with my listener command? Let me know if I should something else. I can set up a Linux listener too.

Any suggestion is most welcome. I want to keep it simple - sending a custom message over snmp to a host, v1 and v2c and set up a listener to verify that my commands are working.

Thanks a lot

Tas


回答1:


The command should look like this:

snmptrap -v 2c -c "Tas" 127.0.0.1 0 1.3.6.1.4.1.2.3 1.3.6.1.6.1.4.1.2.3.1.1.1.1.1 s "This is a Test"

Please note that varbind (OCTET STRING in this case) which is part of your SNMP trap PDU should also have an OID assigned. I've just used random OID for this varbind: 1.3.6.1.6.1.4.1.2.3.1.1.1.1.1

Please also note that you should use proper OIDs based on trap definitions from MIB file(s).

I'd suggest using enterprise class SNMP tools to send out SNMP traps like NetDecision Trap Simulator. This tool sends out traps in full accordance with SNMP standards and based on MIB file definitions:



来源:https://stackoverflow.com/questions/37280356/sending-snmp2-trap-message-from-linux-command-lne

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!