To Connect to the Remote Server for Server and Services Health Check
import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Properties; import java.util.StringTokenizer; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; public class ServerHealthCheck { public HashMap<String,ArrayList<String>> connect() { ArrayList<String> result=null; HashMap result1=new HashMap(); String server_list=null; Session session = null; ReadProp mdis_prop; try { mdis_prop = new ReadProp(ConstantValue.mdis_properties); ReadProp rp=new ReadProp(ConstantValue.serv); server_list=mdis_prop.getvalue(ConstantValue.server_list); String serverstat="null"; if(server_list!=null) { server_list=server_list.trim(); StringTokenizer st = new StringTokenizer(server_list,ConstantValue.comma); while(st.hasMoreTokens()) { AXconn aix=new AXconn(); HashMap<String, ArrayList<String>> resul=new HashMap<String, ArrayList<String>>(); String execServer=st.nextToken(); execServer=execServer.trim(); serverstat=rp.getvalue(execServer+ConstantValue.dot+ConstantValue.stat); if(execServer !=null && serverstat.equals(ConstantValue.active)) { try { session=aix.getSession(execServer); serverstat=rp.getvalue(execServer+ConstantValue.dot+ConstantValue.stat); } catch (Exception e) { String excep = "there is an JSCh exception: Like Password is expired change for the server:" + execServer; ArrayList list = new ArrayList(); list.add(excep); resul.put("ExceptioninCredentilas", list); //System.out.print(excep); Properties pro = null; try { pro = rp.alterProperties(execServer + ConstantValue.dot + ConstantValue.stat, ConstantValue.Ntactive); } catch (Exception e1) { String Exc = "While opening the MDIS properties file"; list.add(Exc); resul.put("Exceptioninupdating the serverStatusfile",list); //System.out.print(Exc); } rp.saveProperties(pro); } } else { //System.out.print("server name is null"); ArrayList list = new ArrayList(); String Exc = "While opening the MDIS properties file"; list.add(Exc); resul.put("Exceptioninupdating the serverStatusfile",list); } ReadProp rp1=new ReadProp(ConstantValue.serv); serverstat=rp1.getvalue(execServer+ConstantValue.dot+ConstantValue.stat); try{ if(session!=null && serverstat.equals(ConstantValue.active)) { ReadProp ser_com = null; String cmd_list = null; String Excmd = ConstantValue.prop + execServer + ConstantValue.underscore + ConstantValue.exce; ser_com = new ReadProp(Excmd); cmd_list = ser_com.getvalue(ConstantValue.command_list); if (cmd_list != null) { cmd_list = cmd_list.trim(); StringTokenizer st1 = new StringTokenizer(cmd_list, ConstantValue.comma); //System.out.print("entering here"); while (st1.hasMoreTokens()) { String ExecCmd = st1.nextToken(); //System.out.print(ExecCmd); ExecCmd = ExecCmd.trim(); if (ExecCmd != null && session != null) { String execCmd = ser_com.getvalue(ExecCmd); execCmd = execCmd.trim(); try { result = aix.getExecutedResult(session,execCmd); } catch (Exception e) { ArrayList list = new ArrayList(); String Exc = "Exception in Excecuting the Commands"; list.add(Exc); resul.put("Exceptioninupdating the Excecuting the Commands",list); //System.out.print(Exc); } //System.out.print("n"); //System.out.print("entering here"); resul.put(ExecCmd, result); //System.out.print("n"); } } } } } catch(Exception e) { } finally{ try { if (session != null) session.disconnect(); System.out.println("Connection closed:->" + execServer); System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); } catch (Exception e) { e.printStackTrace(); } } result1.put(execServer,resul); } } } catch(FileNotFoundException e) { result1.put("Exception","While opening the MDIS properties file"); return result1; } catch (IOException e) { result1.put("Exception","While Reading the MDIS properties file"); return result1; }catch (Exception e) { result1.put("Exception","Exception"); return result1; } // System.out.print(result1); return result1; } }