if (address == null || !PortScan.isOpen(address, Settings.getInt("snmp.port", 161))) {
return null;
}
String ipAddress = address.toString();
HashMap<String, String> oid = new HashMap<String, String>();
ResponseEvent response = null;
TransportMapping transport = null;
String oidValue = "0";
//int count = 0;
Properties p = new Properties();
final File f = new File(IO.userDir, "MIB");
String descr;
// read from File MIB the oids to request over SNMP
Logger.debug("Loading MIB");
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
p.load(fis);
} catch (IOException e) {
Logger.error("Failed to open MIB.", e);
} finally {
try {
fis.close();
} catch (Exception e) {
}
}// end reading
try {
transport = new DefaultUdpTransportMapping();
transport.listen();
} catch (IOException e) {
}
// Create Target Address object
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(Settings.get("snmp.community", "public")));
comtarget.setVersion(SnmpConstants.version1);
comtarget.setAddress(new UdpAddress(ipAddress + "/" + Settings.getInt("snmp.port", 161)));
comtarget.setRetries(2);
comtarget.setTimeout(1000);
// Create the PDU object
// Create Snmp object
Snmp snmp = new Snmp(transport);
// Iterating over map
for (Entry<Object, Object> entry : p.entrySet()) {
oidValue = entry.getValue().toString();
descr = entry.getKey().toString();
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(oidValue)));
pdu.setRequestID(new Integer32(1));
pdu.setType(PDU.GET);
try {
response = snmp.get(pdu, comtarget);
} catch (IOException e) {
}
// Process Agent Response
if (response != null) {
PDU responsePDU = response.getResponse();
if (responsePDU != null) {
int errorStatus = responsePDU.getErrorStatus();
int errorIndex = responsePDU.getErrorIndex();
String errorStatusText = responsePDU.getErrorStatusText();