public class Snmp4jTest {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Test
public void test() throws Exception {
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
transport.listen();
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(new UdpAddress("192.168.0.59" + "/" + "162"));
target.setRetries(1);
target.setTimeout(3000);
target.setVersion(SnmpConstants.version2c);
PDU pdu = new PDU();
pdu.setType(PDU.TRAP);
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(".1.3.6.1.4.1.89691.100.2.1")));
pdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.89691.100.1.1"), new OctetString("API_CATEGORY")));
pdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.89691.100.1.2"), new Integer32(1)));
pdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.89691.100.1.3"), new OctetString("Alarm")));
log.debug("pdu: " + pdu.toString());
log.debug("target: " + target.toString());
ResponseEvent event = snmp.send(pdu, target);
log.debug("event: " + event);
}
}