我的snmp字符串是
snmptrap -Ci -Ls 7 -r1 -t10 -v 2c -c 100.100.100.104 00000 NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification UCD-DEMO-MIB::ucdDemoPublicString s {"m":"17","time":"1388559297","date":"1388559297"}
如何发送这个字符串uning SNMP4j库请帮我在java中调用它
我有这个代码需要做什么改变才能发送上面的字符串
try {
// Create Transport Mapping
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
// Create Target
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(community));
comtarget.setVersion(SnmpConstants.version2c);
comtarget.setAddress(new UdpAddress("100.100.100.104" + "/" + 162));
comtarget.setRetries(2);
comtarget.setTimeout(5000);
// Create PDU for V2
PDU pdu = new PDU();
// need to specify the system up time
long sysUpTime = 111111;
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(sysUpTime)));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(trapOid)));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(ipAddress)));
// variable binding for Enterprise Specific objects, Severity (should be defined in MIB file)
//pdu.add(new VariableBinding(new OID(trapOid), new OctetString("NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification")));
//pdu.add(new VariableBinding(new OID(trapOid), new OctetString("UCD-DEMO-MIB::ucdDemoPublicString")));
pdu.setType(PDU.NOTIFICATION);
Snmp snmp = new Snmp(transport);
System.out.println("Sending V2 Trap to " + ipAddress + " on Port " + port);
snmp.send(pdu, comtarget);
snmp.close();
} catch (Exception e) {
System.err.println("Error in Sending V2 Trap to " + ipAddress + " on Port " + port);
System.err.println("Exception Message = " + e.getMessage());
}