Not able to send trap by using org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification API

Hi Frank,

I am not able to send traps using org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification. I am getting following error stacktrace

org.snmp4j.MessageException: Invalid argument (sendto failed)
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:545)
        at org.snmp4j.Snmp.sendMessage(Snmp.java:1087)
        at org.snmp4j.Snmp.send(Snmp.java:968)
        at org.snmp4j.Snmp.send(Snmp.java:961)
        at org.snmp4j.Snmp.send(Snmp.java:926)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification(NotificationOriginatorImpl.java:272)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:378)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:140)
        at com.ericsson.vil.pms.snmp.NodeAgent.sendTrap(NodeAgent.java:463)
        at com.ericsson.vil.pms.watcher.filesystem.LogWatcher.detectTrap(LogWatcher.java:87)
        at com.ericsson.vil.pms.watcher.filesystem.FileMonitor$1.onFileChange(FileMonitor.java:72)
        at org.apache.commons.io.monitor.FileAlterationObserver.doMatch(FileAlterationObserver.java:410)
        at org.apache.commons.io.monitor.FileAlterationObserver.checkAndNotify(FileAlterationObserver.java:333)
        at org.apache.commons.io.monitor.FileAlterationObserver.checkAndNotify(FileAlterationObserver.java:303)
        at org.apache.commons.io.monitor.FileAlterationMonitor.run(FileAlterationMonitor.java:182)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Invalid argument (sendto failed)
        at java.net.PlainDatagramSocketImpl.send(Native Method)
        at java.net.DatagramSocket.send(DatagramSocket.java:693)
        at org.snmp4j.transport.DefaultUdpTransportMapping.sendMessage(DefaultUdpTransportMapping.java:117)
        at org.snmp4j.transport.DefaultUdpTransportMapping.sendMessage(DefaultUdpTransportMapping.java:42)
        at org.snmp4j.MessageDispatcherImpl.sendMessage(MessageDispatcherImpl.java:203)
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:522)

I am Using following dependencies:

org.snmp4j snmp4j 2.8.2 org.snmp4j snmp4j-agent 2.7.9

Can you please help here? What could be the possible reasons?

–Anirban

I have no idea. Maybe wrong target address or port?

Even you dont have an idea. It means a bad news for me.

The exception is thrown by native method java.net.PlainDatagramSocketImpl.send(), so it is not something that SNMP4J is complaining about itself. The main clue is “Invalid argument”… Start there. Some parameter sent to the native method (but originating in your code) is not good. Verify each of the parameters you are sending in your call, starting with the address and port, as suggested.

1 Like

This is call is made from org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification where is only send the array of Variable Bindings.