use of org.snmp4j.event.ResponseEvent in project opennms by OpenNMS.
the class BrocadeMibIT method sendRequestV3.
private PDU sendRequestV3(PDU pdu) throws IOException {
PDU response;
OctetString userId = new OctetString("opennmsUser");
OctetString pw = new OctetString("0p3nNMSv3");
UserTarget target = new UserTarget();
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(userId);
target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
target.setVersion(SnmpConstants.version3);
target.setTimeout(5000);
TransportMapping<UdpAddress> transport = null;
try {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
snmp.getUSM().addUser(userId, user);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} finally {
if (transport != null) {
transport.close();
}
}
return response;
}
use of org.snmp4j.event.ResponseEvent in project opennms by OpenNMS.
the class LLDPMibIT method sendRequestV3.
private PDU sendRequestV3(PDU pdu) throws IOException {
PDU response;
OctetString userId = new OctetString("opennmsUser");
OctetString pw = new OctetString("0p3nNMSv3");
UserTarget target = new UserTarget();
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(userId);
target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
target.setVersion(SnmpConstants.version3);
if (m_timeout > 0) {
target.setTimeout(m_timeout);
} else {
target.setTimeout(5000);
}
TransportMapping<UdpAddress> transport = null;
try {
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
snmp.getUSM().addUser(userId, user);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} finally {
if (transport != null) {
transport.close();
}
}
return response;
}
use of org.snmp4j.event.ResponseEvent in project opennms by OpenNMS.
the class LLDPMibIT 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);
if (m_timeout > 0) {
target.setTimeout(m_timeout);
}
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.event.ResponseEvent in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getMultiDiskData.
public Map<String, List<SNMPTriple>> getMultiDiskData() throws IOException {
Map<String, List<SNMPTriple>> resMap = new HashMap<String, List<SNMPTriple>>();
Map<Integer, String> indexes = this.getDiskIndexes();
if (indexes == null || indexes.size() == 0)
return resMap;
logger.fine("Query disk stats");
PDU pdu = createPDU();
int reqSize = 0;
for (Map.Entry<Integer, String> entry : indexes.entrySet()) {
for (int i = 1; i < DISK_TABLE_ENTRIES.length; i++) {
if (DISK_TABLE_ENTRIES[i].length() == 0)
continue;
reqSize++;
pdu.add(new VariableBinding(new OID("." + DISK_TABLE_OID + "." + i + "." + entry.getKey())));
}
}
pdu.setType(PDU.GET);
Map<String, String> res = new HashMap<String, String>(13);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
PDU resp = event.getResponse();
if (resp == null) {
logger.info("Unexpected snmp response: " + event + ", request size " + reqSize);
return resMap;
}
VariableBinding[] binds = resp.toArray();
for (VariableBinding b : binds) res.put(b.getOid().toString(), b.getVariable().toString());
//logger.info(res.toString());
}
for (Map.Entry<Integer, String> entry : indexes.entrySet()) {
List<SNMPTriple> resList = new ArrayList<SNMPTriple>(res.size());
for (int i = 1; i < DISK_TABLE_ENTRIES.length; i++) {
if (DISK_TABLE_ENTRIES[i].length() == 0)
continue;
resList.add(new SNMPTriple("." + DISK_TABLE_OID + "." + i + "." + entry.getKey(), DISK_TABLE_ENTRIES[i], res.get(DISK_TABLE_OID + "." + i + "." + entry.getKey())));
}
resMap.put(entry.getValue(), resList);
}
return resMap;
}
use of org.snmp4j.event.ResponseEvent in project mysql_perf_analyzer by yahoo.
the class SNMPClient method get.
/**
* This method is capable of handling multiple OIDs
* @param oids
* @return
* @throws IOException
*/
public Map<OID, String> get(OID[] oids) throws IOException {
PDU pdu = createPDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
PDU pdu2 = event.getResponse();
VariableBinding[] binds = pdu2 != null ? event.getResponse().toArray() : null;
if (binds != null) {
Map<OID, String> res = new LinkedHashMap<OID, String>(binds.length);
for (VariableBinding b : binds) res.put(b.getOid(), b.getVariable().toString());
return res;
} else
return null;
}
throw new RuntimeException("GET timed out");
}
Aggregations