Search code examples
snmpsnmp4j

How do I send a SNMP trap to multiple managers using snmp4j?


Need to forward the snmp trap to multiple managers. Below is the snippet used to send trap to single target address and it is working as expected.

Address targetaddress = new UdpAddress(ConnectionPropertyUtil
    .getProperty("snmpAddress").toString()+ "/"+ConnectionPropertyUtil.getProperty("snmpPort").toString());

CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(targetaddress);
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.send(trap, target, null, null);

Is there any way where I can set multiple targetAdresses and send trap at a single shot.


Solution

  • You need to define one CommunityTarget for each manager. If there is more than one, it probably should go in a for loop, fetching their addresses from a file or other source.