[SNMP4J] Not able to send SNMP Trap Using DefaultTcpTransportMapping

vikas br vikas.br2 at gmail.com
Thu Mar 31 09:21:15 CEST 2016


Dear Frank,

Thanks for your quick reply.

I am using snmp4j version 1.9.1f using maven
          <dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>1.9.1f</version>
<scope>compile</scope>
          </dependency>


I need to send some snmptrap over tcp for NMS Server IP

I can send trap using
snmptrap -v2c -cPu8pnHLi0peyA tcp:localhost:1622 "" <var-binds>

These traps are received properly. but when I will send traps as previously
described code then it will not received on NMS Server(Trap Receiver).

Yes I called transport.close(); snmp.close(); in my code. Is there anything
missing, please let me know.



On Wed, Mar 30, 2016 at 10:29 PM, Frank Fock <fock at agentpp.com> wrote:

> Hi,
>
> What means "unable to send"? Do you get an error message?
> What type of trap receiver are you using?
> What versions on both sides?
>
> Have you realized that you are closing the TCP connection right after you
> have successfully send
> the message? Sending the message does not mean that the receiver has
> already processed it!
> When you close the connection, the receiver will by interrupted and
> probably (most likely)
> drop the unprocessed message before processing it.
>
> Best regards,
> Frank
>
>
> Am 30.03.2016 um 16:25 schrieb vikas br:
>
>> I have to some traps on TCP 162  of Trap Receiver. But I am not able to
>> send snmp trap on that server using snmp4j jar.
>>
>> I can send traps using DefaultUdpTransportMapping but not with
>> DefaultTcpTransportMapping.
>>
>>
>> Our Trap Receiver is listen on both tcp:1622 and udp:1622 port.
>>
>> Please let me know how can I achieve that.
>>
>> Code is below
>> -------------------
>>
>>
>> TransportMapping transport = null;
>> TransportIpAddress address=null;
>> try {
>> address=new TcpAddress("<ip-address>"+"/"+1622);
>> transport=new DefaultTcpTransportMapping();
>> // address=new UdpAddress("ip-address"+"/"+1622);
>> // transport=new DefaultUdpTransportMapping();
>> transport.listen();
>> Snmp snmp = new Snmp(transport);
>> CommunityTarget target = new CommunityTarget();
>> target.setCommunity(new OctetString("secure"));
>> target.setVersion(SnmpConstants.version2c);
>> target.setAddress(address);
>> target.setRetries(1);
>> target.setTimeout(2000);
>> VariableBinding[] appSpecVbs = getTestVarBinds();
>> PDU pdu = new PDU();
>> pdu.addAll(appSpecVbs);
>> pdu.setType(PDU.TRAP);
>> snmp.send(pdu, target);
>> transport.close();
>> snmp.close();
>>
>> } catch (IOException e) {
>> e.printStackTrace();
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> https://oosnmp.net/mailman/listinfo/snmp4j
>>
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j
>



-- 
Thanks & Regards,
Vikas



More information about the SNMP4J mailing list