Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending SNMP2 trap message from Linux command lne

Tags:

linux

snmp

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

like image 521
Tas Avatar asked Jun 05 '26 06:06

Tas


1 Answers

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: enter image description here

like image 187
Andrew Komiagin Avatar answered Jun 08 '26 00:06

Andrew Komiagin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!