Problem in Auto discovery feature in our NMS Web application
Hi All,
I need a help on this .
Problem: In our application there is auto discovery feature, in that we can discover the SNMP agent in three ways
a) Local Network--It will constructs PDU and broadcast packets into Broadcast IP. (192.168.6.255 in our case)
b) Entire Network--It will check nodes in entire network
c) Select Range--We need to specify the IP range to detect nodes
We have device i.e media converter which has IP:192.168.6.166. This device detected in b) & c) approach ... but could not able to locate in a) approach .
I have attached the core code here ... Please help me to overcome this problem.
public class AutoDiscovery implements SnmpClient {
public synchronized void getNetworkElements(String action) {
System.out.println("inside getNetworkElements");
try {
try {
String deleDiscovery = "DELETE FROM TblAutoDiscovery";
dbCon.executeSql(deleDiscovery);
}catch(Exception e4) {
appLogger.logError("Exception in Deleting from TblAutoDiscovery"+e4);
}
try {
String deleDiscoveryDetails = "DELETE FROM TblAutoDiscoveryDetails";
dbCon.executeSql(deleDiscoveryDetails);
}catch(Exception e8){
appLogger.logError("Exception in Deleting from TblAutoDiscoveryDetails"+e8);
}
String values[] = {
"None", null, null, "161", null, null, "None",
null, null, null, null, null, null, null,
null, null, null, null
};
AutoDiscoveryGenerics ADG = new AutoDiscoveryGenerics();
String serverip = ADG.NMSServerIp();
System.out.println("SERVER IP---->"+serverip);
System.out.println("----------------");
String strIpWildcard = serverip.substring( 0,serverip.lastIndexOf(".") );
String IP4 = "255";
String broadcastIP = strIpWildcard + "." + IP4 ; //Broadcast ip calculation Algorithm has not been done worked out with serverip(99.9% perfect)
System.out.println("bROADCAST IP---->"+broadcastIP);
System.out.println("-------------");
AutoDiscovery snmpobj = new AutoDiscovery ();
//Start SNMP API
snmpobj.api = new SnmpAPI();
if (values[0].equals("Set")) {
System.out.println("inside set");
System.out.println("-------------");
snmpobj.api.setDebug( true );
}
// Open session
snmpobj.session = new SnmpSession(snmpobj.api);
int PORT = 3;
SnmpPDU pdu = new SnmpPDU();
UDPProtocolOptions ses_opt = new UDPProtocolOptions();
pdu.setVersion(SnmpAPI.SNMP_VERSION_2C);
ses_opt.setRemoteHost(broadcastIP);
if(values[PORT] != null) {
System.out.println("inside if");
System.out.println("--------------");
try {
ses_opt.setRemotePort(Integer.parseInt(values[PORT]));
}catch(Exception exp) {
System.exit(1); //Has to be Tested
}
}
pdu.setProtocolOptions(ses_opt);
snmpobj.session.addSnmpClient(snmpobj);
// Build Get request PDU
pdu.setCommand( snmpobj.api.GET_REQ_MSG );
// add OIDs (Multiple OIDs)
Vector remaining = new Vector();
remaining.addElement(Constants.OID_SYSTEM_DESC);
remaining.addElement(Constants.OID_IPFORWARD);
remArgs = new String[remaining.size()];
for (i=0;i < remaining.size();i++) {
System.out.println("inside first for loop");
remArgs[i] = (String) remaining.elementAt(i);
System.out.println("remaining arguments------>"+remArgs[i]);
System.out.println("--------------");
}
for (int i=0;i < remArgs.length;i++) {
System.out.println("inside second for loop");
SnmpOID oid = new SnmpOID(remArgs[i]);
if (oid.toValue() == null) {
System.out.println("if oid is null");
appLogger.logSNMPError("Invalid OID argument: " + remArgs[i]);
} else {
System.out.println("if oid is not null");
pdu.addNull(oid);
}
}
System.out.println("after for loop");
pdu.setTimeout(10000);
try {
//Open session
System.out.println("sesion is opened");
snmpobj.session.open();
}catch (SnmpException e) {
appLogger.logSNMPError("Error opening session:"+e.getMessage());
}
try {
//snmpobj.session.send(pdu);
snmpobj.session.send(pdu);
}catch (SnmpException e) {
//e.printStackTrace();
appLogger.logSNMPError("Error sending pdu:"+e);
}
String[] ip_ListOfSwitches = new String[1] ;
int j = 0;
while(true) {
System.out.println("inside while true");
try {
Thread.sleep(1000); //old value 100
}catch(Exception e) { }
if (snmpobj.getFinished && action.equals("ViewAutoDiscoveryLocal")) {
break;
}
if(snmpobj.getFinished && !action.equals("ViewAutoDiscoveryLocal")) {
if(snmpobj.check2){
String[] ip_ipForwardNextHop = new String[10] ;
int j1 = 0;
Vector finalhopList = getNextHops(strIpWildcard + "." + "1");
Iterator it1 = finalhopList.iterator();
while(it1.hasNext()) {
ip_ipForwardNextHop[j1] = it1.next().toString();
checkipForwardAndAddToDb(ip_ipForwardNextHop[j1]);
j1++;
}
}
Vector v = getListOfSwitches();
ip_ListOfSwitches = new String[v.size()];
Iterator it = v.iterator();
while(it.hasNext()) {
String walkedData1[] = new String[1];
ip_ListOfSwitches[j] = it.next().toString();
SNMPRequest snmpw = new SNMPRequest();
String oidwalk[] = new String[1];
oidwalk[0] = Constants.OID_IPADENTADDR;
String oidwalk1[] = new String[1];
oidwalk1[0] = Constants.OID_IPNETTOMEDIANETADDRESS;
try {
for( int k = 0; k < ip_ListOfSwitches.length; k++ ) { //get the ipNetTo Madia for the subnets in the switches
walkedData1 = snmpw.snmpWalk(oidwalk1, ip_ListOfSwitches[k]);
}
}catch (Exception EX) { }
try {
for( int k1 = 0; k1 < walkedData1.length; k1++ ) {
String strIpWildcard1 = walkedData1[k1].substring( 0,walkedData1[k1].lastIndexOf(".") );
for( int k22 = 0; k22 < ip_ListOfSwitches.length; k22++ ) {
String strIpWildcard12 = ip_ListOfSwitches[k22].substring( 0,ip_ListOfSwitches[k22].lastIndexOf(".") );
if(strIpWildcard1.equals(strIpWildcard12)) {
pollAndUpdate(walkedData1[k1]);
}
}
}
}catch (Exception e) { }
j++;
}
break;
}
} //End of Outer while
}catch(Exception e) {
appLogger.logError("Exception in AutoDiscovery.java - getNetworkElements(): "+ e);
}
}
public boolean authenticate(SnmpPDU pdu, String community) {
System.out.println("inside authethentication>>>>>>>>>>>>>>"+pdu.getVersion());
if(pdu.getVersion() == 3) {
return !((Snmp3Message)pdu.getMsg()).isAuthenticationFailed();
} else {
return (pdu.getCommunity().equals(community));
}
}
private int totalResponses = 1;
/*
* Callback method that is invoked on receiving an SNMP Inform request message
*/
public boolean callback(SnmpSession session,SnmpPDU pdu, int requestID) {
System.out.println("inside callback");
// Check if valid PDU
if (pdu == null) {
System.out.println("inside if condition where pdu is null");
//System.out.println("Null PDU received:Timeout\n");
getFinished = true;
check2 = true;
} else {
System.out.println("inside else part where pdu is not null");
String res = pdu.getProtocolOptions().getSessionId() + ".";
UDPProtocolOptions opt = (UDPProtocolOptions)pdu.getProtocolOptions();
String remoteHost = opt.getRemoteHost();
if(pdu.getVersion() == 3) {
System.out.println("inside get version if loop");
res = res + " Community: " + pdu.getCommunity();
}
// print varbinds
Enumeration e = pdu.getVariableBindings().elements();
boolean check = true;
boolean check1 = true;
while(e.hasMoreElements()) {
String theReqObject = ((SnmpVarBind) e.nextElement()).toTagString();
String ip = pdu.getVariable(1).toString();
System.out.println("before try block");
try {
System.out.println("inside try block");
if(check1) {
check1 = false;
if(ip.equals("1")) {
String insQry1 = "INSERT INTO TblAutoDiscoveryDetails (IPAddress,IpForward) Values ( '"+remoteHost+"','"+ip+"' );";
dbCon.executeSql(insQry1);
}
}
}catch(Exception e7){ //e7.printStackTrace();
}
try {
String sysDes = pdu.getVariable(0).toString();
System.out.println("--0---"+pdu.getVariable(0).toString());
System.out.println("---1--"+pdu.getVariable(1).toString());
System.out.println("SYSdES===>"+sysDes);
SystemDescription SysDescr = new SystemDescription(sysDes);
String sysD = SysDescr.getSystemDescription();
System.out.println("getSystemDescription from SystemDescription===>"+sysD);
int iNodeID=0, iNoOfFxPorts=0, iNoOfUtpPorts=0, iFxDistance=0;
String strProductName="", strFamilyName = "", strFxSignal = "", strFxConnectorType = "", strFxModeType = "";
String strWavelengthType = "", strUtpSignal = "", strBoardType = "", strPowerSupply = "", strOthers = "";
String strSysDescr = "";
if(check) {
check = false;
if( sysDes.equals(sysD) ) {
System.out.println("System Descriptions are euual");
String productFamilyName = SysDescr.getProductFamilyName();
int productType = SysDescr.getProductType();
int noOfFxPorts = SysDescr.getNoOfFxPorts();
int noOfUtpPorts = SysDescr.getNoOfUtpPorts();
strProductName = SysDescr.getProductName();
System.out.println("Product name from System Description");
if( strProductName.equals( Constants.PRODUCT_NAME[ Constants.PRODUCT_TYPE_IVY2424 ] ) ){
iProductType = Constants.PRODUCT_TYPE_IVY2424;
} else if(strProductName.equals(Constants.PRODUCT_NAME[Constants.PRODUCT_TYPE_FCAT100M])){
iProductType = Constants.PRODUCT_TYPE_FCAT100M;
}
GetDetails liteviewDetails = new GetDetails();
String[] productStatus = liteviewDetails.getProductDetails( iProductType );
if( productStatus != null && !productStatus[0].equals( Constants.NO_DATA )
&& Integer.parseInt( productStatus[2] ) == Constants.PRODUCT_ACTIVATED ) {
strSysDescr = SysDescr.getSystemDescription();
strFamilyName = SysDescr.getProductFamilyName();
iNoOfFxPorts = SysDescr.getNoOfFxPorts();
strFxSignal = SysDescr.getFxSignal();
strFxConnectorType = SysDescr.getFxConnectorType();
strFxModeType = SysDescr.getFxModeType();
strWavelengthType = SysDescr.getFxWavelengthType();
iFxDistance = SysDescr.getFxDistance();
iNoOfUtpPorts = SysDescr.getNoOfUtpPorts();
strUtpSignal = SysDescr.getUtpSignal();
strBoardType = SysDescr.getBoardType();
strPowerSupply = SysDescr.getPowerSupply();
strOthers = SysDescr.getOthers();
System.out.println("BEFORE INSERTING INTO TblAutoDiscovery");
strSql = strSql.delete(0, strSql.length());
strSql = strSql.append("INSERT INTO TblAutoDiscovery ( IPAddress, SystemDescription, ProductFamilyName, ");
strSql = strSql.append(" ProductType, NoOfFXPorts, FxSignal, FXConnectorType, NoOfUTPPorts, UTPSignal, ");
strSql = strSql.append(" Others, NodeID, FxModeType, FxWavelength, FxDistance, BoardType, PowerSupply ) ");
strSql = strSql.append(" VALUES( '").append( remoteHost ).append("', '").append( sysD ).append("', '");
strSql = strSql.append( strFamilyName ).append( "', '" ).append( iProductType ).append( "', " );
strSql = strSql.append( iNoOfFxPorts ).append( ", '" ).append( strFxSignal ).append( "', '");
strSql = strSql.append( strFxConnectorType ).append( "', ").append( iNoOfUtpPorts ).append( ", '");
strSql = strSql.append( strUtpSignal ).append( "', '").append( strOthers ).append( "', ").append( iNodeID );
strSql = strSql.append(" , '" ).append( strFxModeType ).append("', '").append( strWavelengthType );
strSql = strSql.append("' , " ).append( iFxDistance ).append(" , '").append( strBoardType );
strSql = strSql.append("' , '" ).append( strPowerSupply );
strSql = strSql.append("' )" );
System.out.println("-sql--->"+strSql.toString());
dbCon.executeSql( strSql.toString() );
}
}
}
} catch(Exception e3) {//e3.printStackTrace();
}
} //End Of While
if(pdu.isBroadCastEnabled()) {
/* System.out.println("This is the response for" +
" a broadCast request.");
System.out.println("Total Responses received = " +
(totalResponses++) + ".");*/
} else {
getFinished = true;
}
}
return true;
}
public void debugPrint(String debugOutput) {
return;
}
}
New to ADSelfService Plus?