<%@ include file="../../EgTrackerAJSON.jsp" %>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import = "java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.eg.EgInstallInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>
<%@ page import="com.eg.IniFile" %>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import = "com.eg.EgConfigFilesSync"%>
<%@ page import = "com.egurkha.admin.AuditLogThread"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import ="egurkha.EgDbAdapterUI"%>
<%@ page import ="com.eg.EgDbAdapterTypeUI"%>
<%@ page import="com.eg.UpdateAndTransmitTrendInfo" %>
<%@ page import="com.eg.EgTesterInfo" %>
<%@ page import="com.eg.EgThresholdInfo" %>
<%@ page import="com.eg.EgSpecsInfo" %>
<%@ page import="com.eg.EgConfigInfo" %>
<%@ page import="com.eg.EgDiscInfo" %>
<%@ page import="com.eg.EgDiscInfo2" %>
<%@ page import="com.eg.EgServerGroupBean" %>
<%@ page import="net.sf.json.*"%>

<jsp:useBean id="prgBean" class="egurkha.EgTestParamBean" scope="page" />
<jsp:useBean id="threshBean" class="egurkha.EgThresholdBean" scope="page" />

<%
	JSONObject rootJson = new JSONObject();
	IniUI iniUI = IniUI.getInstance();
	//user language
	String userLanguage = iniUI.getDefaultLanguage();
	if (_user != null)
	{
		userLanguage = _user.getLanguage();
	}

	EgDbAdapterUI egDb;
	EgTesterInfo testerInfo =new EgTesterInfo("manager");
	EgSpecsInfo egSpecs = new EgSpecsInfo("manager");
	EgDiscInfo egDiscs = new EgDiscInfo("manager");
	EgDiscInfo2 discInfo2 = new EgDiscInfo2("manager");
	EgServerGroupBean serverGrpBean = new EgServerGroupBean();
	EgMappingInfo mappingInfo = new EgMappingInfo(userLanguage);

	ResultSet rs = null;
	ArrayList threshGrpTestList = new ArrayList();
	ArrayList userThreshList = new ArrayList();
	ArrayList descThreshList = new ArrayList();
	ArrayList infoBasedGroupList = new ArrayList();
	ArrayList groupTestsList = new ArrayList();
	ArrayList tmpManagedInfos = new ArrayList();

	Hashtable ht = new Hashtable();
	String subjectVal = "Newtarget_Update_EgThresholdManager";
	String user_thresh = "USER_THRESHOLDS";
	String descr_thresh = "DESCRIPTOR_THRESHOLDS";
	String status ="";
	String query = "";

	String operation = request.getParameter("operation");
	String testName = request.getParameter("testName");
	String strDescName = request.getParameter("descName");

	TreeSet threshGrpTreeSet = serverGrpBean.getTestColnComponentsForServerType();
	threshGrpTestList.addAll(threshGrpTreeSet);
	UpdateAndTransmitTrendInfo updateHelper = new UpdateAndTransmitTrendInfo();
	ArrayList globalThresholds=testerInfo.getGlobalThresholds();
	if (globalThresholds == null || globalThresholds.isEmpty())
	{
		globalThresholds = new ArrayList();
	}

	String[] hostTests = egSpecs.getDefaultTestsForServer("Host_system");
	ArrayList hostLevelTests = new ArrayList(Arrays.asList(hostTests));
	ArrayList getAllCompsForServer = getAllManagedComps();
	IniFile servicesIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_services.ini");
	prgBean.createFile("eg_thresholds.ini");
	TreeSet managedInfos = serverGrpBean.getAllManagedInfosForTest(testName);
	tmpManagedInfos.addAll(managedInfos);


	if(!StringUtils.isNull(strDescName))
	{
		strDescName = StringUtils.decodeSecurityChar(strDescName);

		String strInfo = "+"+strDescName;
		query = "SELECT TRGT_HOST,PORT_NO,SITE_NAME,INFO,MSMT_HOST FROM MEASURE_LAST WHERE TEST_NAME='"+testName+"' AND INFO LIKE '%"+strInfo+"'";
	}
	
	String[] userThreshVal = prgBean.getVariables(user_thresh);
	if(userThreshVal.length > 0)
	{
		for(int r=0; r<userThreshVal.length; r++)
		{
			if(userThreshVal[r].startsWith(testName))
			{
				userThreshList.add(userThreshVal[r]);
			}
		}
	}
	String []descThreshVal = prgBean.getVariables(descr_thresh);
	if(descThreshVal.length > 0)
	{
		for(int r=0; r<descThreshVal.length; r++)
		{
			if(descThreshVal[r].startsWith(testName))
			{
				descThreshList.add(descThreshVal[r]);
			}
		}
	}

	//new ini entry code starts here
	for(int g=0;g<getAllCompsForServer.size(); g++)
	{
		String component = (String) getAllCompsForServer.get(g);
		String tmpComp = "";
		if(hostLevelTests.contains(testName))
		{
			tmpComp = component.substring(0,component.indexOf(":"));
			tmpComp +=":NULL";
		}
		else
		{
			tmpComp = component;
		}

		if(!serverGrpBean.isServerAssociatedToTest(component,testName) && serverGrpBean.isServerAssociatedToTestUI(component,testName))
		{
			if(tmpManagedInfos != null && tmpManagedInfos.size() > 0)
			{
				for(int v=0;v<tmpManagedInfos.size();v++)
				{
					String vecInfo = (String) tmpManagedInfos.get(v);
					infoBasedGroupList.add(testName+":"+tmpComp+"#"+vecInfo);
				}
			}
		}

		if(serverGrpBean.isServerAssociatedToTest(component,testName))
		{
			groupTestsList.add(testName+":"+tmpComp);
			continue;
		}
	}

	if(!StringUtils.isNull(testName) && !StringUtils.isNull(strDescName))
	{
		egDb=EgDbAdapterTypeUI.getObject();
		try
		{
			boolean isConnected = false;
			status = egDb.setConnection();
			if(status.equals("CONNECTED"))
			{
				isConnected = true;
			}
			if(isConnected)
			{
				rs = egDb.SelectExec(query);
				while(rs.next())
				{
					String hostVal = rs.getString(1);
					String portVal = rs.getString(2);
					String siteVal = rs.getString(3);
					String infoVal = rs.getString(4);
					String msmthostVal = rs.getString(5);

					String updateDbData = hostVal+"#&#"+portVal+"#&#"+siteVal+"#&#"+StringUtils.encodeSecurityChar(infoVal)+"#&#"+msmthostVal+"#&#"+testName;
					int r = infoVal.indexOf(EgConfigInfo.infoFieldSeparator);
					String tmpStr_info="";
					String tmpSidVal="";
					if(r != -1)
					{
						tmpStr_info = infoVal.substring(r+1).trim();
						tmpSidVal = infoVal.substring(0,r);
					}
					if(StringUtils.isNull(tmpSidVal))
					{
						ht.put(hostVal+":"+portVal+"#"+infoVal+"#"+msmthostVal,updateDbData);
					}
					else
					{
						ht.put(hostVal+":"+portVal+":"+tmpSidVal+"#"+infoVal+"#"+msmthostVal,updateDbData);
					}
				}
			}
			rs.close();
			egDb.releaseConnection(false);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		catch(Exception e)
		{
			if(rs != null)
			{
				rs.close();
			}
			egDb.releaseConnection(true);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
	}
	ArrayList htKeyValues = new ArrayList();
	if(ht != null && ht.size() > 0)
	{
		Iterator iterAll = ht.keySet().iterator();
		while(iterAll.hasNext())
		{
			String tempKeys = (String) iterAll.next();
			htKeyValues.add(tempKeys);
		}
	}
	if(operation.equals("updateThresholds"))
	{
		String threshold = request.getParameter("threshold");
		String measure = threshold.substring(0,threshold.indexOf(":"));
		measure+=":";
		String strApplyAllMeasure = request.getParameter("allMeasure");
		String newDefaultThreshold = "";
		StringBuffer strbuffer = new StringBuffer();
		IniFile defaultIni = new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini");
		String defaultThreshold = null;
		String strVariable = testName+":"+StringUtils.encodeSecurityChar(strDescName);
		defaultThreshold = defaultIni.getValue("DESCRIPTOR_DEFAULT_THRESHOLDS",strVariable);
		if(StringUtils.isNull(defaultThreshold))
		{
			strVariable = testName+":"+strDescName;
			defaultThreshold = defaultIni.getValue("DESCRIPTOR_DEFAULT_THRESHOLDS",strVariable);
		}

		if(StringUtils.isNull(defaultThreshold))
		{
			defaultThreshold = defaultIni.getValue("DEFAULT_THRESHOLDS",testName);
		}
		ArrayList previousValues = new ArrayList();
		ArrayList currentValues = new ArrayList();
		StringTokenizer st = new StringTokenizer(defaultThreshold,",");
		if(!StringUtils.isNull(strApplyAllMeasure))
		{
			String tmpThreshold = threshold.substring(threshold.indexOf(":")+1,threshold.lastIndexOf(":"));
			String commonThreshVal = tmpThreshold.substring(0,tmpThreshold.lastIndexOf(":"));
			while (st.hasMoreTokens())
			{
				String strTok = st.nextToken();
				previousValues.add(strTok);
				if (strTok.startsWith(measure+":"))
				{
					strbuffer.append(threshold).append(",");
					currentValues.add(threshold);
				}
				else
				{
					String tmpMeasureToken = strTok.substring(0,strTok.indexOf(":"));
					String tmpHmlToken = strTok.substring(strTok.lastIndexOf(":")+1);
					String tmpToken = strTok.substring(strTok.indexOf(":")+1,strTok.lastIndexOf(":"));
					String tmpAlarmToken = tmpToken.substring(tmpToken.lastIndexOf(":")+1);
					StringBuffer strBuffThresh = new StringBuffer();
					strBuffThresh.append(tmpMeasureToken);
					strBuffThresh.append(":");
					strBuffThresh.append(commonThreshVal);
					strBuffThresh.append(":");
					strBuffThresh.append(tmpAlarmToken);
					strBuffThresh.append(":");
					strBuffThresh.append(tmpHmlToken);
					strTok = strBuffThresh.toString();
					strbuffer.append(strTok).append(",");
					currentValues.add(strTok);
				}
			}
		}
		else
		{
			while (st.hasMoreTokens())
			{
				String strTok = st.nextToken();
				previousValues.add(strTok);
				if (strTok.startsWith(measure))
				{
					strbuffer.append(threshold).append(",");
				}
				else
				{
					strbuffer.append(strTok).append(",");
				}
			}
		}

		/* code for auditlog starts */
		AuditLogThread auditLogThread = new AuditLogThread();	
		auditLogThread.setValue("Category","Admin");
		auditLogThread.setValue("User_id",_user.getLoginID());
		auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
		auditLogThread.setValue("Session_id",session.getId());
		auditLogThread.setValue("Module","Thresholds");

		if(!StringUtils.isNull(strApplyAllMeasure))
		{
			for(int i=0;i<previousValues.size();i++)
			{
				String preData = (String) previousValues.get(i);
				String currData = (String) currentValues.get(i);
				ArrayList tempPrevious = StringUtils.egTokenizer(preData,":");
				ArrayList tempCurrent = StringUtils.egTokenizer(currData,":");

				String auditMeasure = "$measure$:"+testName+":"+tempPrevious.get(0).toString().trim();
				//auditMeasure = mappingInfo.getMeasureDescription(testName,auditMeasure);
				String previousMin = tempPrevious.get(2).toString().trim();
				String previousMax = tempPrevious.get(3).toString().trim();
				String alarmPolicyPrevious = tempPrevious.get(4).toString().trim();

				String currentMin = tempCurrent.get(2).toString().trim();
				String currentMax = tempCurrent.get(3).toString().trim();
				String alarmPolicyCurrent = tempCurrent.get(4).toString().trim();

				if(!previousMin.equals(currentMin))
				{
					if(previousMin.equals("-1"))
					{
						previousMin = "none";
					}
					if(currentMin.equals("-1"))
					{
						currentMin = "none";
					}
					auditLogThread.setPreviousValue(auditMeasure,"Minimum-Threshold " + previousMin);
					auditLogThread.setCurrentValue(auditMeasure,"Minimum-Threshold " + currentMin);
				}

				if(!previousMax.equals(currentMax))
				{
					if(previousMax.equals("-1"))
					{
						previousMax = "none";
					}
					if(currentMax.equals("-1"))
					{
						currentMax = "none";
					}
					auditLogThread.setPreviousValue(auditMeasure,"Maximum-Threshold " + previousMax);
					auditLogThread.setCurrentValue(auditMeasure,"Maximum-Threshold " + currentMax);
				}

				if(!alarmPolicyPrevious.equals(alarmPolicyCurrent))
				{
					auditLogThread.setPreviousValue(auditMeasure,"Alarms " + alarmPolicyPrevious);
					auditLogThread.setCurrentValue(auditMeasure,"Alarms " + alarmPolicyCurrent);
				}
			}
		}
		else
		{
			for(int i=0;i<previousValues.size();i++)
			{
				String preData = (String) previousValues.get(i);
				if(preData.startsWith(measure))
				{
					ArrayList tempPrevious = StringUtils.egTokenizer(preData,":");
					ArrayList tempCurrent = StringUtils.egTokenizer(threshold,":");

					String auditMeasure = "$measure$:"+testName+":"+tempPrevious.get(0).toString().trim();
					//auditMeasure = mappingInfo.getMeasureDescription(testName,auditMeasure);
					String previousMin = tempPrevious.get(2).toString().trim();
					String previousMax = tempPrevious.get(3).toString().trim();
					String alarmPolicyPrevious = tempPrevious.get(4).toString().trim();

					String currentMin = tempCurrent.get(2).toString().trim();
					String currentMax = tempCurrent.get(3).toString().trim();
					String alarmPolicyCurrent = tempCurrent.get(4).toString().trim();

					if(!previousMin.equals(currentMin))
					{
						if(previousMin.equals("-1"))
						{
							previousMin = "none";
						}
						if(currentMin.equals("-1"))
						{
							currentMin = "none";
						}
						auditLogThread.setPreviousValue(auditMeasure,"Minimum-Threshold " + previousMin);
						auditLogThread.setCurrentValue(auditMeasure,"Minimum-Threshold " + currentMin);
					}

					if(!previousMax.equals(currentMax))
					{
						if(previousMax.equals("-1"))
						{
							previousMax = "none";
						}
						if(currentMax.equals("-1"))
						{
							currentMax = "none";
						}
						auditLogThread.setPreviousValue(auditMeasure,"Maximum-Threshold " + previousMax);
						auditLogThread.setCurrentValue(auditMeasure,"Maximum-Threshold " + currentMax);
					}

					if(!alarmPolicyPrevious.equals(alarmPolicyCurrent))
					{
						auditLogThread.setPreviousValue(auditMeasure,"Alarms " + alarmPolicyPrevious);
						auditLogThread.setCurrentValue(auditMeasure,"Alarms " + alarmPolicyCurrent);
					}
				}
			}
		}
		auditLogThread.setValue("Activity","Configure Thresholds");
		if (!StringUtils.isNull(testName))
		{
			auditLogThread.setValue("Description","The default thresholds for " + mappingInfo.getTestDescription(strDescName) + " descriptor of " + mappingInfo.getTestDescription(testName) + " test have been modified");
		}
		auditLogThread.sendItToDB();
		/* code for auditlog ends */

		// DB updation code starts
		if(!StringUtils.isNull(testName) && !globalThresholds.contains(testName))
		{
			boolean isSaveIni = false;
			IniFile serIniWr = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_threshupdate.ini");
			for(int ct = 0;ct<getAllCompsForServer.size();ct++)
			{
				String tempComp = (String)getAllCompsForServer.get(ct);
				String tmpTrgtHost = tempComp.substring(0,tempComp.indexOf(":"));
				if(hostLevelTests.contains(testName))
				{
					if(!tempComp.endsWith(":NULL"))
					{
						tempComp = tempComp.substring(0,tempComp.indexOf(":"));
						tempComp+=":NULL";
					}
				}
				if(ht != null && ht.size() > 0)
				{
					for(int h=0;h<htKeyValues.size();h++)
					{
						String htKey = (String) htKeyValues.get(h);
						String infoData = htKey.substring(htKey.indexOf("#")+1);
						infoData = infoData.substring(0,infoData.indexOf("#"));
						int r = infoData.indexOf(EgConfigInfo.infoFieldSeparator);
						String str_info="";
						String sidVal="";
						if(r != -1)
						{
							str_info = infoData.substring(r+1).trim();
							sidVal = infoData.substring(0,r);
						}

						if(htKey.startsWith(tempComp))
						{
							if(hostLevelTests.contains(testName))
							{
								String strUserVal = testName+":"+tmpTrgtHost;
								String strGrpVal = testName+":"+tempComp;
								String nickWithNullPort = tmpTrgtHost+":NULL";
								String strDescVal = testName+":"+nickWithNullPort+"#"+StringUtils.encodeSecurityChar(str_info);
								String strGrpDescVal = testName+":"+nickWithNullPort+"#"+str_info;
								if(userThreshList != null && userThreshList.contains(strUserVal))
								{
									continue;
								}
								else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
								{
									continue;
								}
								else if(groupTestsList != null && groupTestsList.contains(strGrpVal))
								{
									continue;
								}
								else
								{
									String htValues = (String) ht.get(htKey);
									isSaveIni = true;
									serIniWr.setValue(subjectVal,htValues,testName);
								}
							}
							else
							{
								String strUserVal = testName+":"+tempComp;
								String strDescVal = testName+":"+tempComp+"#"+StringUtils.encodeSecurityChar(str_info);
								String strGrpDescVal = testName+":"+tempComp+"#"+str_info;

								if(userThreshList != null && userThreshList.contains(strUserVal))
								{
									continue;
								}
								else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
								{
									continue;
								}
								else if(groupTestsList != null && groupTestsList.contains(strUserVal))
								{
									continue;
								}
								else
								{
									String htValues = (String) ht.get(htKey);
									isSaveIni = true;
									serIniWr.setValue(subjectVal,htValues,testName);
								}
							}
						}
					}
				}
			}
			if(isSaveIni)
			{
				serIniWr.saveFile();
			}
			EgConfigFilesSync.releaseInstance(serIniWr);
		}
		rootJson.put("successUpdate",true);

		//DB updation code ends
		newDefaultThreshold = strbuffer.toString();
		int len = newDefaultThreshold.length()-1;
		newDefaultThreshold = newDefaultThreshold.substring(0,len);

		String strThresholdIni = EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini";
		IniFile ThresholdIniWrite = EgConfigFilesSync.getInstance(strThresholdIni);
		String defaultDescIniVal = ThresholdIniWrite.getValue("DESCRIPTOR_DEFAULT_THRESHOLDS",StringUtils.decodeSecurityChar(strVariable));
		if(!StringUtils.isNull(defaultDescIniVal))
		{
			ThresholdIniWrite.deleteValue("DESCRIPTOR_DEFAULT_THRESHOLDS",StringUtils.decodeSecurityChar(strVariable));
		}
		ThresholdIniWrite.setValue("DESCRIPTOR_DEFAULT_THRESHOLDS",testName+":"+StringUtils.encodeSecurityChar(strDescName),newDefaultThreshold);
		ThresholdIniWrite.saveFile();
		EgConfigFilesSync.releaseInstance(ThresholdIniWrite);
	}
	else if(operation.equals("deleteThresholds"))
	{
		String iniSubject = "";
		String iniVariable = "";

		/* code for auditlog starts */
		AuditLogThread auditLogThread = new AuditLogThread();	
		auditLogThread.setValue("Category","Admin");
		auditLogThread.setValue("User_id",_user.getLoginID());
		auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
		auditLogThread.setValue("Session_id",session.getId());
		auditLogThread.setValue("Module","Thresholds");
		auditLogThread.setValue("Activity","Delete Thresholds");
		if(!StringUtils.isNull(strDescName))
		{
			auditLogThread.setValue("Description","The default thresholds for descriptor "+strDescName+" of "+ mappingInfo.getTestDescription(testName) + " test have been deleted");
		}
		auditLogThread.sendItToDB();
		/* code for auditlog ends */

		if(!StringUtils.isNull(testName) && !globalThresholds.contains(testName))
		{
			boolean isSaveIni = false;
			IniFile serIniWr = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_threshupdate.ini");
			for(int ct = 0;ct<getAllCompsForServer.size();ct++)
			{
				String tempComp = (String)getAllCompsForServer.get(ct);
				String tmpTrgtHost = tempComp.substring(0,tempComp.indexOf(":"));
				if(hostLevelTests.contains(testName))
				{
					if(!tempComp.endsWith(":NULL"))
					{
						tempComp = tempComp.substring(0,tempComp.indexOf(":"));
						tempComp+=":NULL";
					}
				}
				if(ht != null && ht.size() > 0)
				{
					for(int h=0;h<htKeyValues.size();h++)
					{
						String htKey = (String) htKeyValues.get(h);
						String infoData = htKey.substring(htKey.indexOf("#")+1);
						infoData = infoData.substring(0,infoData.indexOf("#"));
						int r = infoData.indexOf(EgConfigInfo.infoFieldSeparator);
						String str_info="";
						String sidVal="";
						if(r != -1)
						{
							str_info = infoData.substring(r+1).trim();
							sidVal = infoData.substring(0,r);
						}

						if(htKey.startsWith(tempComp))
						{
							if(hostLevelTests.contains(testName))
							{
								String strUserVal = testName+":"+tmpTrgtHost;
								String strGrpVal = testName+":"+tempComp;
								String nickWithNullPort = tmpTrgtHost+":NULL";
								String strDescVal = testName+":"+nickWithNullPort+"#"+StringUtils.encodeSecurityChar(str_info);
								String strGrpDescVal = testName+":"+nickWithNullPort+"#"+str_info;
								if(userThreshList != null && userThreshList.contains(strUserVal))
								{
									continue;
								}
								else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
								{
									continue;
								}
								else if(groupTestsList != null && groupTestsList.contains(strGrpVal))
								{
									continue;
								}
								else
								{
									String htValues = (String) ht.get(htKey);
									isSaveIni = true;
									serIniWr.setValue(subjectVal,htValues,testName);
								}
							}
							else
							{
								String strUserVal = testName+":"+tempComp;
								String strDescVal = testName+":"+tempComp+"#"+StringUtils.encodeSecurityChar(str_info);
								String strGrpDescVal = testName+":"+tempComp+"#"+str_info;

								if(userThreshList != null && userThreshList.contains(strUserVal))
								{
									continue;
								}
								else if((descThreshList != null && (descThreshList.contains(strDescVal) || descThreshList.contains(strGrpDescVal))) || (infoBasedGroupList != null && infoBasedGroupList.contains(strGrpDescVal)))
								{
									continue;
								}
								else if(groupTestsList != null && groupTestsList.contains(strUserVal))
								{
									continue;
								}
								else
								{
									String htValues = (String) ht.get(htKey);
									isSaveIni = true;
									serIniWr.setValue(subjectVal,htValues,testName);
								}
							}
						}
					}
				}
			}
			if(isSaveIni)
			{
				serIniWr.saveFile();
			}
			EgConfigFilesSync.releaseInstance(serIniWr);
		}

		String strThresholdIni = EgInstallInfo.getInstallDir()+"/manager/config/eg_thresholds.ini";
		IniFile ThresholdIniWrite = EgConfigFilesSync.getInstance(strThresholdIni);
		iniSubject = "DESCRIPTOR_DEFAULT_THRESHOLDS";
		iniVariable = testName+":"+StringUtils.encodeSecurityChar(strDescName);
		String defaultDescIniVal = ThresholdIniWrite.getValue("DESCRIPTOR_DEFAULT_THRESHOLDS",testName+":"+strDescName);
		if(!StringUtils.isNull(defaultDescIniVal))
		{
			ThresholdIniWrite.deleteValue("DESCRIPTOR_DEFAULT_THRESHOLDS",testName+":"+strDescName);
		}
		ThresholdIniWrite.deleteValue(iniSubject,iniVariable);
		ThresholdIniWrite.saveFile();
		EgConfigFilesSync.releaseInstance(ThresholdIniWrite);
		EgThresholdInfo.setUpdated();
	}
	out.println(rootJson.toString());
%>

<%!

	public ArrayList getAllManagedComps()
	{
		ArrayList aListPorts = new ArrayList();
		EgDiscInfo2 discInfo2 = new EgDiscInfo2("manager");
		List allHosts = discInfo2.getAllManagedComponents();
		for (int i=0;i<allHosts.size();i++)
		{
			String strTemp = "";
			String allData = (String)allHosts.get(i);
			StringTokenizer st = new StringTokenizer(allData,",");
			String serType = st.nextToken();
			String ipVal = st.nextToken();
			String nick = "";
			String port = "";
			String sid = "";
			if(serType.equals("Oracle_server"))
			{
				nick = st.nextToken();
				port = st.nextToken();
				String isPassive = st.nextToken();
				if (!st.hasMoreTokens())
					continue;
				sid = st.nextToken();
				strTemp = nick+":"+port+":"+sid;
			}
			else
			{
				nick = st.nextToken();
				port = st.nextToken();
				strTemp = nick+":"+port;
			}
			aListPorts.add(strTemp);
		}
		return aListPorts;
	}
%>