use of org.snmp4j.util.DefaultPDUFactory in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getNetIfData.
public Map<String, List<SNMPTriple>> getNetIfData(String device) throws IOException {
Map<Integer, String> ifMaps = new HashMap<Integer, String>();
Map<String, List<SNMPTriple>> resMap = new HashMap<String, List<SNMPTriple>>();
Map<String, String> res = new HashMap<String, String>();
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query " + this.address + " for network interface, excluding lo");
@SuppressWarnings("unchecked") List<TableEvent> events = tUtils.getTable(getTarget(), new OID[] { new OID("." + IF_TABLE_OID) }, null, null);
for (TableEvent event : events) {
if (event.isError()) {
logger.warning("SNMP event error: " + event.getErrorMessage() + ", already returned: " + ifMaps);
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for (VariableBinding vb : event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
res.put(key, value);
if (key.startsWith(IF_TABLE_DEVICE_OID + ".")) {
if (device != null && !device.isEmpty() && !value.equalsIgnoreCase(device))
continue;
if (value != null && !value.equalsIgnoreCase("lo")) {
logger.fine("Find device OID entry: " + key);
int index = -1;
String[] strs = key.split("\\.");
try {
index = Integer.parseInt(strs[strs.length - 1]);
ifMaps.put(index, value);
} catch (Exception ex) {
}
}
}
}
//for var
}
for (Map.Entry<Integer, String> entry : ifMaps.entrySet()) {
int index = entry.getKey();
String ifName = entry.getValue();
//ignore the case with no incoming and no outgoing traffic
if ("0".equals(res.get(IF_TABLE_OID + ".6." + index)) && "0".equals(res.get(IF_TABLE_OID + ".10." + index)))
continue;
resMap.put(ifName, new ArrayList<SNMPTriple>(IF_TABLE_ENTRIES.length));
for (int i = 1; i < IF_TABLE_ENTRIES.length; i++) {
if (IF_TABLE_ENTRIES[i].length() == 0)
continue;
resMap.get(ifName).add(new SNMPTriple("." + IF_TABLE_OID + "." + i + "." + index, IF_TABLE_ENTRIES[i], res.get(IF_TABLE_OID + "." + i + "." + index)));
}
}
return resMap;
}
use of org.snmp4j.util.DefaultPDUFactory in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getDiskIndex.
private int getDiskIndex(String device) throws IOException {
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query " + this.address + " for disk data: " + device);
@SuppressWarnings("unchecked") List<TableEvent> events = tUtils.getTable(getTarget(), new OID[] { new OID("." + DISK_TABLE_DEVICE_OID) }, null, null);
for (TableEvent event : events) {
if (event.isError()) {
logger.warning("SNMP event error: " + event.getErrorMessage());
continue;
//throw new RuntimeException(event.getErrorMessage());
}
for (VariableBinding vb : event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
if (value != null && value.equals(device)) {
logger.fine("Find device OID entry: " + key);
int index = -1;
String[] strs = key.split("\\.");
try {
index = Integer.parseInt(strs[strs.length - 1]);
} catch (Exception ex) {
}
return index;
}
}
}
return -1;
}
Aggregations