use of org.snmp4j.transport.DefaultUdpTransportMapping in project mysql_perf_analyzer by yahoo.
the class SNMPClient method start.
/**
* Start the Snmp session. If you forget the listen() method you will not
* get any answers because the communication is asynchronous
* and the listen() method listens for answers.
* @throws IOException
*/
public void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
if (//add v3 support
"3".equals(this.version)) {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
}
// Do not forget this line!
transport.listen();
}
use of org.snmp4j.transport.DefaultUdpTransportMapping in project opennms by OpenNMS.
the class Snmp4JAgentConfig method createSnmpSession.
public Snmp createSnmpSession() throws IOException {
final TransportMapping<?> transport = new DefaultUdpTransportMapping();
final MessageDispatcher disp = new MessageDispatcherImpl();
final Snmp session;
// models we need for the specific agent
if (!isSnmpV3()) {
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
session = new Snmp(disp, transport);
} else {
// Make a new USM
final USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
// Add the specified user to the USM
usm.addUser(getSecurityName(), new UsmUser(getSecurityName(), getAuthProtocol(), getAuthPassPhrase(), getPrivProtocol(), getPrivPassPhrase()));
disp.addMessageProcessingModel(new MPv3(usm));
session = new Snmp(disp, transport);
}
return session;
}
use of org.snmp4j.transport.DefaultUdpTransportMapping in project opennms by OpenNMS.
the class MockSnmpAgentIT method sendRequestV1V2.
private PDU sendRequestV1V2(PDU pdu, int version) {
PDU response = null;
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(new UdpAddress(InetAddressUtils.addr("127.0.0.1"), m_agent.getPort()));
target.setVersion(version);
TransportMapping<UdpAddress> transport = null;
Snmp snmp = null;
try {
transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (snmp != null) {
try {
snmp.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
if (transport != null) {
try {
transport.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}
return response;
}
use of org.snmp4j.transport.DefaultUdpTransportMapping in project opennms by OpenNMS.
the class BrocadeMibIT method sendRequestV1V2.
private PDU sendRequestV1V2(PDU pdu, int version) throws Exception {
PDU response;
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
target.setVersion(version);
TransportMapping<UdpAddress> transport = null;
try {
transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} finally {
if (transport != null) {
transport.close();
}
}
return response;
}
use of org.snmp4j.transport.DefaultUdpTransportMapping in project opennms by OpenNMS.
the class MockAgentTest method testWalkSystem.
public void testWalkSystem() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
TableUtils walker = new TableUtils(snmp, new DefaultPDUFactory());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
// Implements snmp4j API
@SuppressWarnings("rawtypes") List results = walker.getTable(target, new OID[] { new OID("1.3.6.1.2.1.1") }, null, null);
assertNotNull(results);
assertFalse(results.isEmpty());
assertTrue(results.get(results.size() - 1) instanceof TableEvent);
TableEvent lastEvent = (TableEvent) results.get(results.size() - 1);
MockUtil.println("Status of lastEvent is " + lastEvent.getStatus());
assertEquals(TableEvent.STATUS_OK, lastEvent.getStatus());
}
Aggregations