<%
/********************************************************************************
FileName	:egAppDashboardJSON.jsp
Purpose		:This is created for Application tab in Monitor Dashboard
Created by	:ANTHONI LAWRANCE A
Created on	:21/09/2013 dd/MM/yyyy
**********************************************************************************/
%>
<%@ include file = "EgMonitorTracker.jsp"%>
<%//@ page errorPage = "EgProbsM.jsp"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.eg.EgInstallInfo" %>
<%@ page import = "com.eg.EgMemCheck"%>
<%@ page import="egurkha.*"	%>
<%@ page import="egurkha.reporter.ErInfo"%>
<%@ page import="egurkha.reporter.ErTimePlotsBean"%>
<%@ page import = "egurkha.reporter.ErUtils"%>
<%@ page import="com.eg.IniFile"%>
<%@ page import="com.eg.EgExternalInfo"%> 
<%@ page import = "com.eg.EgURLEncoder"%>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import = "com.eg.EgSpecsInfo"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import="com.eg.EgMemInfo"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import = "com.egurkha.util.DateUtil"%>
<%@ page import="com.egurkha.util.DateTimeTokenizer"%>
<%@ page import="com.egurkha.Health"%>
<%@ page import="com.egurkha.State"%>
<%@ page import = "com.egurkha.EgMeasureGraphExt" %>
<%@ page import="com.egurkha.monitor.*"%>
<%@ page import = "com.eg.EgDbAdapterTypeUI" %>
<%@ page import = "egurkha.EgDbAdapterUI" %>
<%@page import="egurkha.reporter.ErUtils"%>
<%@ page import="com.objectplanet.chart.*"%>
<%@ page import="com.eg.*"%>
<%@ page import="net.sf.json.*"%>
<%@ page language="java" contentType="application/json;charset=UTF-8" pageEncoding="UTF-8" %>
<%
		response.setHeader("Cache-Control","no-store");
		response.setHeader("Pragma","no-cache");
		response.setDateHeader("Expires", -1);
%>
<%
try
{
	if(EgInstallInfo.isSuperManager)
	{
		String currentSession = session.getId();
		String hostname = request.getParameter("hostName");
		//System.out.println("egAppDashboardJson.jsp hostname " + hostname);
		if(hostname != null && !hostname.trim().equalsIgnoreCase("null"))
		{
			if(hostname.indexOf(":")>-1)
			{
				hostname = hostname.substring(0,hostname.indexOf(":"));
			}
			//System.out.println("egAppDashboardJson.jsp host " + hostname);
			ArrayList managerIds = EgElementInfo.getInstance().getManagerIDs("component",hostname);
			//System.out.println("egAppDashboardJson.jsp managerIds " + managerIds);
			if(managerIds != null && !managerIds.isEmpty())
			{
				SmSessionData smsData = new SmSessionData(currentSession,managerIds);
				EgThreadLocal egtl = new EgThreadLocal();
				egtl.set(smsData);
			}
		}
	}
//	System.out.println("The app dashboard json request is "+ErUtils.prepareQueryString(request.getParameterMap()));
	JSONObject rootJson = new JSONObject();
	JSONObject screenLabels = new JSONObject();
	JSONObject selectedValues = new JSONObject();
	JSONObject hiddens = new JSONObject();
	UserRegistry registry = UserRegistry.getInstance();
	User user = registry.getUser(session.getId());
	String s_iniFile_dir=EgInstallInfo.getInstallDir()+"/manager/config/";
	IniFile iniObj=new IniFile(s_iniFile_dir+"eg_serverdashboard.ini");

	String uiFile = "eg_ui.ini";
	IniFile iniUI = new IniFile(s_iniFile_dir + uiFile);

	EgTablesInfo tablesInfo=new EgTablesInfo("manager");
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
//	EgMappingInfo mappingInfo=new EgMappingInfo(trackerLanguage);
	EgMeasureGraphExt measureGraphInfo = new EgMeasureGraphExt();
	DateTimeTokenizer dtd = new DateTimeTokenizer();
	EgServerDashboardModel  egDashboard=new  EgServerDashboardModel();
	egDashboard.setUser(user);
	EgFusionChartUtil fusionChart=new EgFusionChartUtil(trackerLanguage);
	String subject="";

	boolean hasConfig=false;
	boolean ddEnabled = EgMemInfo.ddEnabled;
	boolean noGraphsFound=true;

	String compName=request.getParameter("hostName");
	String compType=request.getParameter("compType");
	String siteName=request.getParameter("site");	
	String componentState=egDashboard.getServerState(compName,compType,siteName);
	
	String jvmAppTabForCompType = iniObj.getValue("JVM_Enabled_AppServers", compType);
	if(jvmAppTabForCompType != null && jvmAppTabForCompType.equalsIgnoreCase("Yes")) {
		subject = "Java_virtual_machine";
	} else {
		subject = compType;
	}
	egDashboard.setSubject(subject);

	String tab=request.getParameter("tab");
	String subsystem=request.getParameter("subsystem");
	String graphType=request.getParameter("graphType");
	String info=request.getParameter("selectedInfo");
	String appHealthStartDate=request.getParameter("starttime");
	String appHealthEndDate=request.getParameter("endtime");
	String appHealthStartHr=request.getParameter("starthr");
	String appHealthEndHr=request.getParameter("endhr");
	String high=mappingInfo.getTextDescription("monitor.dashboard.Critical");
	String inter=mappingInfo.getTextDescription("monitor.dashboard.Major");
	String low=mappingInfo.getTextDescription("monitor.dashboard.Minor");

	Vector priorities = new Vector();

	priorities.add("HIGH");
	priorities.add("INTERMEDIATE");
	priorities.add("LOW");
	priorities.add("GOOD");
	priorities.add("UNKNOWN");

	

	SimpleDateFormat sf=new SimpleDateFormat("MM/dd/yyyy");
	SimpleDateFormat sf1=new SimpleDateFormat("dd/MM/yyyy");
	SimpleDateFormat  dateFormatWithTime=new SimpleDateFormat("dd/MM/yyyy HH:mm");
	java.util.Date endDate=new java.util.Date();
	java.util.Date startDate=new java.util.Date(endDate.getTime()-(60*60*1000));
	EgExternalInfo egExternalInfo=new EgExternalInfo("manager");
	EgDbInfo dbInfo=new EgDbInfo("manager");
	EgServerDashboardMGraphModel measureGraph=new EgServerDashboardMGraphModel();

	String hostName="";
	String portNo="";
	String startTime="";
	String endTime="";
	String startHour="";
	String endHour="";
	String startDateTime="";
	String endDateTime="";

	String startTime1="";
	String endTime1="";
	String test="";
	String measure="";
	String status="";
	String sid="";
	String msmtHost="";
	String duration=request.getParameter("duration");
	String trendType=request.getParameter("trendType");
	String threadType=request.getParameter("threadType");
	startTime=request.getParameter("starttime");
	endTime=request.getParameter("endtime");
	startHour=request.getParameter("starthr");
	endHour=request.getParameter("endhr");
	String timelineFormat=request.getParameter("format");

	String eventCriticalPageUrl ="";
	String eventMajorPageUrl ="";
	String eventMinorPageUrl ="";
	boolean isfromSuper = session.getAttribute("fromSuper") != null && session.getAttribute("fromSuper").toString().equalsIgnoreCase("yes");
	if(compName!=null && !compName.equals(""))
	{
		StringTokenizer st=new StringTokenizer(compName,":");
		if(st.hasMoreTokens())
			hostName=st.nextToken();

		if(st.hasMoreTokens())
			portNo=st.nextToken();

		if(st.hasMoreTokens())
			sid=st.nextToken();
	}
	try
	{
		if ( !StringUtils.isNull( startTime ) && startTime.equals("")) {
			java.util.Date startDateFormat = sf.parse(startTime);
			startTime=sf.format(startDateFormat);	
		}
		else
		{
			startTime=sf.format(startDate);
		}
		if ( !StringUtils.isNull( endTime ) && endTime.equals("")) {
			java.util.Date endDateFormat = sf.parse(endTime);
			endTime=sf.format(endDateFormat);
		}
		else
		{
			endTime=sf.format(endDate);
		}
		startDateTime=dateFormatWithTime.format(startDate);
		endDateTime=dateFormatWithTime.format(endDate);
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
	}



	boolean isSubjectFound=false;
	List subjects=Arrays.asList(iniObj.getSubjects());
	
	if(subjects.contains(subject))
		isSubjectFound=true;

	String applicationSubsystems=iniObj.getValue(subject,"Application_subsystems");

	if(isSubjectFound && applicationSubsystems!=null && !applicationSubsystems.trim().equals(""))
	{
		rootJson.put("METRICS","TRUE");
		String healthFlag="No";
		String EventAnalysistimeline=iniObj.getValue("Default_HistoricalEvents_Duration","duration");
		String actualTimeline=EventAnalysistimeline;
		if(EventAnalysistimeline!=null && EventAnalysistimeline.indexOf(" ")!=-1)
		{
			String eventTimeDuration=EventAnalysistimeline.substring(0,EventAnalysistimeline.indexOf(" "));
			String eventTimePeriod=EventAnalysistimeline.substring(EventAnalysistimeline.indexOf(" ")+1,EventAnalysistimeline.length());			eventTimePeriod=eventTimePeriod.substring(0,1).toUpperCase()+eventTimePeriod.substring(1,eventTimePeriod.length());
			EventAnalysistimeline=eventTimeDuration+" "+eventTimePeriod;
		}
		MonitorDAOFactory	monitorDaoFactory = MonitorDAOFactory.getInstance();
		ErUtils erutils=new ErUtils();
		
		EgServerDashBoardDAO dashboardDAO=monitorDaoFactory.getServerDashBoardDAO();
		dashboardDAO.setDashboardType("Application");
		ErInfo erInfo=new ErInfo();
		EgDateInfo egDate=new EgDateInfo();
		Hashtable performanceIndicators=egDashboard.getPerformanceIndicators(compName,compType,"Application");
		Hashtable alarmCount=egDashboard.getAlarmCount(compName,compType,"Application");
		egDashboard.setAllAlarmDetails();
		session.setAttribute("DashboardModelObject",egDashboard);
		Hashtable alarmDetails=egDashboard.getAlarmDetails();
		Hashtable currentStatus=egDashboard.getCurrentStatusForServer(compName,compType,"Application");
		Hashtable events=egDashboard.getEventsForServer(compName,compType,"Application");
		Hashtable eventDetails=egDashboard.getEventDetails();

		String  ddMeasures=egDashboard.getDDMeasures(compType,"Application");

		String ddtimeline=iniObj.getValue("Default_DD_Duration","duration");
		String startenddates=egDashboard.getStartEndDatesForTimelines(ddtimeline,"");

		EgDDOverview  ddoverview=new  EgDDOverview();
		String ddtest="";
		String ddmeasure="";
		String  ddformat="";
		String dataTitle="";
		String graphTitle="";

		int eventsCount=0;
		if(events!=null)
		{
			Integer countObj=(Integer)events.get("Count");
			if(countObj!=null)
				eventsCount=countObj.intValue();
		}

		String unit="";

		Hashtable analysisData=ddoverview.getDDAnalysisData(compName,compType,ddtest,ddmeasure,ddformat,"Application","","","","","","","","");

		String appIniVal="";
		appIniVal=iniObj.getValue(subject,"Application_"+subsystem);

		Vector configuredTests=new Vector();
		Vector configuredMeasures=new Vector();

		if(appIniVal!=null && !appIniVal.equals(""))
		{
			StringTokenizer testDetails=new StringTokenizer(appIniVal,",");
			while(testDetails.hasMoreTokens())
			{
				String token=testDetails.nextToken();
				if(token!=null && token.indexOf(":")!=-1)
				{
					configuredTests.add(token.substring(0,token.indexOf(":")));
					configuredMeasures.add(token.substring(token.indexOf(":")+1));
				}
			}
		}
		String graphTimeline=request.getParameter("time_line");

		String ua = request.getHeader( "User-Agent" );
		boolean isFirefox2 = ( ua != null && ua.indexOf( "Firefox/2" ) != -1 );
		boolean isFirefox3 = ( ua != null && ua.indexOf( "Firefox/3" ) != -1 );
		boolean isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );
		boolean isChrome = ( ua != null && ua.indexOf( "Chrome/" ) != -1 );


		boolean isOverview=subsystem!=null  && subsystem.equalsIgnoreCase("overview");
		boolean isGraphTimelineAvailable=timelineFormat!=null && !timelineFormat.equals("") && !timelineFormat.equals("null");
		boolean isGraphTimelineAny=graphTimeline!=null && graphTimeline.equals("Any");
		boolean loadDefaultGraphTimeline=!isGraphTimelineAvailable && !isGraphTimelineAny;
		boolean isSubsystemHasComparisonGraphs=false;
		boolean isComponentHasComparisonGraphs=false;

		String componentWithComparisonGraph = iniObj.getValue("Application_Comparison_View", subject);

		isComponentHasComparisonGraphs=(componentWithComparisonGraph!=null && componentWithComparisonGraph.equalsIgnoreCase("Yes"));

		session.setAttribute("Page_IdentifierM","/final/monitor/egAppDashboard.jsp");
		session.setAttribute("Source",compType);

		if(isComponentHasComparisonGraphs)
		{
			String subsystemsWithComparisonGraphs=iniObj.getValue(subject,"Application_subsystems_Comparison");
			StringTokenizer stksubSystems=new StringTokenizer(subsystemsWithComparisonGraphs,",");
			while(stksubSystems.hasMoreTokens())
			{
				if(subsystem!=null && subsystem.equals(stksubSystems.nextToken()))
				{
					isSubsystemHasComparisonGraphs=true;
					break;
				}
			}
		}
		String dashboardHistoryGraphType="SummaryAtGlance";
		if(isOverview && (graphType==null) || (graphType!=null && (graphType.equals("null") || graphType.equals(""))))
		{
			dashboardHistoryGraphType="SummaryAtGlance";
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("CitrixApplications")) && (graphType==null) || (graphType!=null && (graphType.equals("null") || graphType.equals(""))))
		{
			dashboardHistoryGraphType="citrixapps";
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("CitrixUsers")) && (graphType==null) || (graphType!=null && (graphType.equals("null") || graphType.equals(""))))
		{
			dashboardHistoryGraphType="citrixuser";
		}
		else if(!isOverview && (graphType==null) || (graphType!=null && (graphType.equals("null") || graphType.equals(""))))
		{
			if(subsystem!=null && subsystem.equalsIgnoreCase("SQLDatabases"))
			{
				dashboardHistoryGraphType="sqldatabases";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("SQLApplications"))
			{
				dashboardHistoryGraphType="top queries";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("SQLProcesses"))
			{
				dashboardHistoryGraphType="sqlprocess";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("TableSpaces"))
			{
				dashboardHistoryGraphType="oracletablespaces";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("DataFiles"))
			{
				dashboardHistoryGraphType="DDgraph";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("Memory Structures"))
			{
				dashboardHistoryGraphType="DDgraph";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("Database access"))
			{
				dashboardHistoryGraphType="oracleconnection";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("Weblogic service"))
			{
				dashboardHistoryGraphType="weblogic service";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("weblogic databases"))
			{
				dashboardHistoryGraphType="weblogic databases";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("JVM"))
			{
				dashboardHistoryGraphType="JVM";
			}
			else if(subsystem!=null && subsystem.equalsIgnoreCase("weblogic threads"))
			{
				dashboardHistoryGraphType="weblogic threads";
			}
			else if(isSubsystemHasComparisonGraphs)
			{
				dashboardHistoryGraphType="DDgraph";
			}
			else
			{
				dashboardHistoryGraphType="measureGraph";
			}
		}
		else
		{
			dashboardHistoryGraphType=graphType;
			if((graphTimeline==null) || (graphTimeline!=null && graphTimeline.equalsIgnoreCase("null") || graphTimeline.equals("")))
			{
				graphTimeline=iniObj.getValue("Default_MeasureGraph_Duration","duration");
			}
		}
	
		String SummaryDivWidth="740px";
		String graphDivDisplay="";
		String graphDivWidth="961px";
		String tabDivWidth="961px";

		//out.print(isFirefox3);

		if (isMSIE)
		{
			SummaryDivWidth="740px";
			graphDivDisplay="block";
			graphDivWidth="958px";
			tabDivWidth="958px";
		}
		else if(isFirefox3)
		{
			SummaryDivWidth="738px";
			graphDivDisplay="block";
			graphDivWidth="956px";
			tabDivWidth="958px";
		}
		else if(isFirefox2)
		{
			SummaryDivWidth="738px";
			graphDivDisplay="table-row";
			graphDivWidth="956px";
			tabDivWidth="956px";
		}
		else if(isChrome)
		{
			SummaryDivWidth="740px";
			graphDivDisplay="block";
			graphDivWidth="958px";
			tabDivWidth="960px";
		}
		String imageNameForSubSystem=subsystem;
		if(subsystem!=null && subsystem.indexOf(" ")!=-1)
			imageNameForSubSystem=com.egurkha.util.StringUtils.replace(subsystem," ","_");

		
		
		screenLabels.put("subsystemTitle", mappingInfo.getTextDescription("monitor.dashboard.Subsystem"));
		JSONArray subsystemArr = new JSONArray();
		if(tab!=null && tab.equalsIgnoreCase("application"))
		{
			StringTokenizer subsystemTokens=new StringTokenizer(applicationSubsystems,":");
			while(subsystemTokens.hasMoreTokens())
			{
				JSONObject subsystemObj = new JSONObject();
				String token=subsystemTokens.nextToken();
				if(compType.equalsIgnoreCase("Citrix_server") || compType.equalsIgnoreCase("Citrix_XcXenApp_server"))
				{
					if(token!=null && token.indexOf("_")>0)
					{
						String value  = com.egurkha.util.StringUtils.replace(token,"_","");
						String disp  = com.egurkha.util.StringUtils.replace(token,"_"," ");
						subsystemObj.put("valueField", value);
						subsystemObj.put("displayField", mappingInfo.getTextDescription("monitor.dashboard."+disp));
					}
				}
				else
				{
					subsystemObj.put("valueField", token);
					subsystemObj.put("displayField", mappingInfo.getTextDescription("monitor.dashboard."+token));
				}
				subsystemArr.add(subsystemObj);
				if(subsystem!=null && token!=null && subsystem.equalsIgnoreCase(token))
				{
					selectedValues.put("subsystemSelected", token);
				}
			}
			rootJson.put("subsystemCombo", subsystemArr);
		}
		if(isOverview)
		{
			rootJson.put("SUBSYSTEM", "Overview");
			JSONObject overviewObj = new JSONObject();
			overviewObj.put("alertTitle", mappingInfo.getTextDescription("monitor.dashboard.Current Application Alerts"));
			int openproblems=0;
			Integer   critical=(Integer)alarmCount.get("HIGH");
			Integer   major=(Integer)alarmCount.get("INTERMEDIATE");
			Integer   minor=(Integer)alarmCount.get("LOW");
			if(alarmCount!=null && alarmCount.size()>0 && (critical.intValue()+major.intValue()+minor.intValue())>0)
			{
				JSONObject alertObj = new JSONObject();
				String criticalDesc=(String)alarmDetails.get("HIGH");
				String majorDesc=(String)alarmDetails.get("INTERMEDIATE");
				String minorDesc=(String)alarmDetails.get("LOW"); openproblems=critical.intValue()+major.intValue()+minor.intValue();
				alertObj.put("OPEN_ALERT_TITLE", mappingInfo.getTextDescription("monitor.dashboard.Open Alerts"));
				alertObj.put("DISTRIBUTION_TITLE", mappingInfo.getTextDescription("monitor.dashboard.Distribution"));
				alertObj.put("OPEN_ALERTS", openproblems);
				if(critical!=null && critical.intValue()>0)
				{
					alertObj.put("DISTRIBUTION_CRITICAL_VALUE", String.valueOf(critical.intValue()));
					alertObj.put("DISTRIBUTION_CRITICAL_DESC", criticalDesc);
					JSONObject linkObj = new JSONObject();
					linkObj.put("METHOD_NAME", "showAlert");
					linkObj.put("PARAMS", "event|"+criticalDesc+"|"+critical.intValue()+"HIGH");
					alertObj.put("DISTRIBUTION_CRITICAL_LINK", linkObj);
				}
				else
				{
					alertObj.put("DISTRIBUTION_CRITICAL_VALUE", String.valueOf(critical.intValue()));
				}

				if(major!=null && major.intValue()>0)
				{
					alertObj.put("DISTRIBUTION_MAJOR_VALUE", String.valueOf(major.intValue()));
					alertObj.put("DISTRIBUTION_MAJOR_DESC", majorDesc);
					JSONObject linkObj = new JSONObject();
					linkObj.put("METHOD_NAME", "showAlert");
					linkObj.put("PARAMS", "event|"+majorDesc+"|"+major.intValue()+"INTERMEDIATE");
					alertObj.put("DISTRIBUTION_MAJOR_LINK", linkObj);
				}
				else
				{
					alertObj.put("DISTRIBUTION_MAJOR_VALUE", String.valueOf(major.intValue()));
				}

				if(minor!=null && minor.intValue()>0)
				{
					alertObj.put("DISTRIBUTION_MINOR_VALUE", String.valueOf(minor.intValue()));
					alertObj.put("DISTRIBUTION_MINOR_DESC", minorDesc);
					JSONObject linkObj = new JSONObject();
					linkObj.put("METHOD_NAME", "showAlert");
					linkObj.put("PARAMS", "event|"+minorDesc+"|"+minor.intValue()+"LOW");
					alertObj.put("DISTRIBUTION_MINOR_LINK", linkObj);
				}
				else
				{
					alertObj.put("DISTRIBUTION_MINOR_VALUE", String.valueOf(minor.intValue()));
				}
				overviewObj.put("ALERTS", alertObj);
			}
			else
			{
				overviewObj.put("ALERTS", "-");
				overviewObj.put("NO_ALERTS", mappingInfo.getTextDescription("monitor.dashboard.No alarms found")+"!");
			}

			JSONObject eventsObj = new JSONObject();	
			eventsObj.put("eventsTitle", mappingInfo.getTextDescription("monitor.dashboard.History of Events During the Last")+" "+mappingInfo.getTextDescription("monitor.common."+EventAnalysistimeline));
			if(eventsCount!=0)
			{
				ErUtils erUtils=new ErUtils();
				double criticalEvtCount=0.0;
				double majorEvtCount=0.0;
				double minorEvtCount=0.0;
				Integer   criticalEvents=null;
				Integer majorEvents=null;
				Integer  minorEvents=null;
				ArrayList al=new ArrayList();
				criticalEvents=(Integer)events.get("HIGH");
				majorEvents=(Integer)events.get("INTERMEDIATE");
				minorEvents=(Integer)events.get("LOW");
				al.add(criticalEvents.toString());
				al.add(majorEvents.toString());
				al.add(minorEvents.toString());
				criticalEvtCount=criticalEvents.doubleValue();
				majorEvtCount=majorEvents.doubleValue();
				minorEvtCount=minorEvents.doubleValue();
				String max=erUtils.getMaximum(al);
				double[] Hsevalues=new double[]{criticalEvtCount,majorEvtCount,minorEvtCount};

				eventsObj.put("criticalEvtCount",criticalEvtCount);
				eventsObj.put("majorEvtCount",majorEvtCount);
				eventsObj.put("minorEvtCount",minorEvtCount);

				String HistoricalEventsGraphURL="/final/servlet/com.egurkha.monitor.EgEventChart?hostName="+compName+"&compType="+compType+"&module=Application&width=220&height=88&imgdate="+new java.util.Date();

				eventCriticalPageUrl = response.encodeURL("/final/monitor/EgAlarmHistoryView.jsp?")+"newAlarms=true&compTypeList="+compType+"&compNameList="+EgURLEncoder.encode(compName,"UTF-8")+"&glduration=0&duration=0&timeselect=seconds&eg_timeline="+actualTimeline+"&eventsPerPage=All&arrangeAlarms=-1&fromDashBoard=true&selectedLayer="+"Application"+"&tab="+tab+"&dashboardcomptype="+compType+"&dashboardcompname="+EgURLEncoder.encode(compName,"UTF-8")+"&state=HIGH";
				eventMajorPageUrl = response.encodeURL("/final/monitor/EgAlarmHistoryView.jsp?")+"newAlarms=true&compTypeList="+compType+"&compNameList="+EgURLEncoder.encode(compName,"UTF-8")+"&glduration=0&duration=0&timeselect=seconds&eg_timeline="+actualTimeline+"&eventsPerPage=All&arrangeAlarms=-1&fromDashBoard=true&selectedLayer="+"Application"+"&tab="+tab+"&dashboardcomptype="+compType+"&dashboardcompname="+EgURLEncoder.encode(compName,"UTF-8")+"&state=INTERMEDIATE";
				eventMinorPageUrl = response.encodeURL("/final/monitor/EgAlarmHistoryView.jsp?")+"newAlarms=true&compTypeList="+compType+"&compNameList="+EgURLEncoder.encode(compName,"UTF-8")+"&glduration=0&duration=0&timeselect=seconds&eg_timeline="+actualTimeline+"&eventsPerPage=All&arrangeAlarms=-1&fromDashBoard=true&selectedLayer="+"Application"+"&tab="+tab+"&dashboardcomptype="+compType+"&dashboardcompname="+EgURLEncoder.encode(compName,"UTF-8")+"&state=LOW";
				Vector eventChartAttribute=new Vector();

				
				eventChartAttribute.add("majorTMNumber='6'");
				eventChartAttribute.add("majorTMHeight='10'");
				eventChartAttribute.add("majorTMColor='d5d5d5'");
				eventChartAttribute.add("minorTMColor='D5D5D5'");
				eventChartAttribute.add("minorTMHeight='5'");
				eventChartAttribute.add("minorTMNumber='5'");
				eventChartAttribute.add("majorTMThickness='2'");
				eventChartAttribute.add("palette='2'");
				eventChartAttribute.add("showValues='1'");
				eventChartAttribute.add("showYAxisValues='0'");
				eventChartAttribute.add("decimals='0'");
				eventChartAttribute.add("formatNumberScale='0'");
				eventChartAttribute.add("useRoundEdges='1'");
				eventChartAttribute.add("exportEnabled='0'");
				eventChartAttribute.add("showExportDialog='1'");
				eventChartAttribute.add("exportAction='save'");
				eventChartAttribute.add("exportTargetWindow='1'");
				eventChartAttribute.add("showShadow='1'");
				eventChartAttribute.add("showToolTipShadow='1'");
				eventChartAttribute.add("chartLeftMargin='8'");
				eventChartAttribute.add("chartRightMargin='20'");
				eventChartAttribute.add("chartTopMargin='3'");
				eventChartAttribute.add("chartBottomMargin='8'");
				eventChartAttribute.add("bgColor='99CCFF,FFFFFF'");
				eventChartAttribute.add("bgAlpha='0,0'");
				eventChartAttribute.add("outCnvBaseFontColor='ffffff'");
				eventChartAttribute.add("canvasLeftMargin='17'");
				eventChartAttribute.add("canvasRightMargin='7'");
				eventChartAttribute.add("canvasTopMargin='5'");
				eventChartAttribute.add("canvasBottomMargin='7'");
				eventChartAttribute.add("showBorder='0'");
				String smUrl = null;
				if(isfromSuper)
				{
					smUrl = (String)session.getAttribute("Super_Manager_Url");
				}
				String timeline=iniObj.getValue("Default_HistoricalEvents_Duration","duration");
				if(timeline==null || timeline.trim().equals(""))
					timeline="24 hours";
				String historyXMLData=fusionChart.getXMLforEventHistory(compName,compType,tab,timeline,"",eventChartAttribute,isfromSuper,smUrl,"eventUrl1","eventUrl2","eventUrl3");
				eventsObj.put("SWF_PATH", "/final/FusionCharts/swf/Bar2D.swf");
				eventsObj.put("XML_DATA", historyXMLData);
				eventsObj.put("monitor.dashboard.Total Events", mappingInfo.getTextDescription("monitor.dashboard.Total Events"));
				eventsObj.put("TOTAL_EVENTS", ((Integer)events.get("Count")).toString());

				eventsObj.put("monitor.dashboard.Avg Duration", mappingInfo.getTextDescription("monitor.dashboard.Avg Duration"));
				eventsObj.put("AVG_DURATION", (String)events.get("AvgDuration"));

				eventsObj.put("monitor.dashboard.Avg Duration", mappingInfo.getTextDescription("monitor.dashboard.Avg Duration"));
				eventsObj.put("AVG_DURATION", (String)events.get("AvgDuration"));

				eventsObj.put("monitor.dashboard.Max Duration", mappingInfo.getTextDescription("monitor.dashboard.Max Duration"));
				eventsObj.put("MAX_DURATION", (String)events.get("MaxDuration"));
				overviewObj.put("EVENTS",eventsObj);
			}
			else
			{
				overviewObj.put("eventsTitle", mappingInfo.getTextDescription("monitor.dashboard.History of Events During the Last")+" "+mappingInfo.getTextDescription("monitor.common."+EventAnalysistimeline));
				overviewObj.put("EVENTS","-");
				overviewObj.put("NO_EVENTS",mappingInfo.getTextDescription("monitor.dashboard.No events found")+"!");
			}
			overviewObj.put("eventUrl1", eventCriticalPageUrl);
			overviewObj.put("eventUrl2", eventMajorPageUrl);
			overviewObj.put("eventUrl3", eventMinorPageUrl);
			rootJson.put("OVERVIEW", overviewObj);
		}
		else
		{
			String url="egSummary.jsp?hostName="+compName+"&compType="+compType+"&subsystem="+subsystem+"&subject="+subject;
		}
		String urlString="/final/monitor/egDashboardGraphTimeline.jsp?showGraph="+dashboardHistoryGraphType+"&compType="+compType+"&subsystem="+subsystem+"&tab=Application&graphTimeline="+graphTimeline+"&starttime="+startTime+"&endtime="+endTime+"&starthr="+startHour+"&endhr="+endHour+"&format="+timelineFormat+"&subject="+subject+"&graphType="+graphType;
		rootJson.put("TAB_URL", urlString);
		String className="";						
		String divScroll="";
		if((subsystem!=null && subsystem.equalsIgnoreCase("SQLDatabases")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("sqldatabases")))
		{
			className="innerTabBorder";
		}
		else
		{
			className="innerTabBorder";
		}
		if((subsystem!=null && subsystem.equalsIgnoreCase("Tablespaces")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("oracletablespaces")) ||((subsystem!=null && subsystem.equalsIgnoreCase("weblogic databases")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("weblogic databases"))))
		{
			divScroll="";
		}
		else if(isOverview && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("SummaryAtGlance")))
		{
			divScroll="overflow-y:scroll";
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("Database access")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("oracleconnection")))
		{
			divScroll="overflow-y:hidden";
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("SQLProcesses")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("sqlprocess")))
		{
			divScroll="overflow-y:scroll;overflow-x:scroll";
		}
		else
		{
			divScroll="overflow-y:scroll";
		}
		if(isOverview && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("SummaryAtGlance")))
		{
			String url="/final/monitor/egDashboardOverviewJSON.jsp?hostName="+compName+"&compType="+compType+"&subject="+subject+"&tab=Application";
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("SQLDatabases")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("sqldatabases")))
		{
			rootJson.put("SUBSYSTEM", "SQLDatabases");
			String selectedInfo=request.getParameter("selectedInfo");
			String url="/final/monitor/egSQLDatabasesJSON.jsp?hostName="+compName+"&compType="+compType+"&tab="+tab+"&selectedInfo="+selectedInfo+"&selectedTabName="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("SQLApplications")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("top queries")))
		{
			rootJson.put("SUBSYSTEM", "SQLApplications");
			String url="/final/monitor/egSQLDatabasesJSON.jsp?hostName="+compName+"&compType="+compType+"&tab="+tab+"&selectedTabName=sqlapps";
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("SQLProcesses")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("sqlprocess")))
		{
			rootJson.put("SUBSYSTEM", "SQLProcesses");
			String url="/final/monitor/egSQLDatabasesJSON.jsp?hostName="+compName+"&compType="+compType+"&tab="+tab+"&selectedTabName="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("CitrixApplications")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("citrixapps")))
		{
			rootJson.put("SUBSYSTEM", "CitrixApplications");
			String url="/final/monitor/egCitrixUsersJSON.jsp?hostName="+compName+"&compType="+compType+"&subsystem="+subsystem+"&tab="+tab+"&subject="+subject+"&fromCitrixApplication=true";
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("CitrixUsers")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("citrixuser")))
		{
			rootJson.put("SUBSYSTEM", "CitrixUsers");
			String url="/final/monitor/egCitrixUsersJSON.jsp?hostName="+compName+"&compType="+compType+"&subsystem="+subsystem+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("TableSpaces")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("oracletablespaces")))

		{
			rootJson.put("SUBSYSTEM", "TableSpaces");
			String url="/final/monitor/egOracleDashboardJSON.jsp?hostName="+compName+"&subsystem="+subsystem+"&compType="+compType+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info+"&graphType="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("Database access")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("oracleconnection") || (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("OracleHighUtilQueries"))))
		{
			rootJson.put("SUBSYSTEM", "Database access");
			String url="/final/monitor/egOracleDashboardJSON.jsp?hostName="+compName+"&subsystem="+subsystem+"&compType="+compType+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info+"&graphType="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("weblogic service")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("weblogic service")))
		{
			rootJson.put("SUBSYSTEM", "Weblogic service");
			String url="/final/monitor/egWeblogicDashboardJSON.jsp?hostName="+compName+"&compType="+compType+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info+"&subsystem="+subsystem+"&selectedTabName="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("weblogic databases")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("weblogic databases")))
		{
			rootJson.put("SUBSYSTEM", "Weblogic databases");
			String url="/final/monitor/egWeblogicDashboardJSON.jsp?hostName="+compName+"&subsystem="+subsystem+"&compType="+compType+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info+"&selectedTabName="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("JVM")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("JVM") || dashboardHistoryGraphType.equalsIgnoreCase("jvmthreadstacktrace")))
		{
			rootJson.put("SUBSYSTEM", "JVM");
			String url="/final/monitor/egWeblogicDashboardJSON.jsp?hostName="+compName+"&subsystem="+subsystem+"&compType="+compType+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info+"&graphType="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else if((subsystem!=null && subsystem.equalsIgnoreCase("weblogic threads")) && (dashboardHistoryGraphType!=null && dashboardHistoryGraphType.equalsIgnoreCase("weblogic threads")))
		{
			rootJson.put("SUBSYSTEM", "Weblogic Threads");
			String url="/final/monitor/egWeblogicDashboardJSON.jsp?hostName="+compName+"&subsystem="+subsystem+"&compType="+compType+"&tab="+tab+"&subject="+subject+"&selectedInfo="+info+"&selectedTabName="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		else
		{
			rootJson.put("SUBSYSTEM", subsystem);
			String url="/final/monitor/egDashboardHistoryJSON.jsp?tab=Application&subsystem="+subsystem+"&hostName="+compName+"&compType="+compType+"&graphType="+dashboardHistoryGraphType+"&subject="+subject+"&starttime="+appHealthStartDate+"&time_line="+graphTimeline+"&endtime="+endTime+"&starthr="+startHour+"&endhr="+endHour+"&format="+timelineFormat+"&showGraph="+dashboardHistoryGraphType;
			rootJson.put("INNER_TAB_URL", url);
		}
		rootJson.put("selectedGraphType","Application_"+dashboardHistoryGraphType);
	}
	else
	{
		rootJson.put("METRICS","FALSE");
	}
	
	rootJson.put("selectedValues", selectedValues);
	rootJson.put("screenLabels", screenLabels);
	rootJson.put("hiddens", hiddens);
//	System.out.println("The app dashboard json is "+rootJson.toString());
	out.println(rootJson.toString());
}
catch(Throwable ex)
{
	System.out.println("Exception in egAppDashboardJSON "+ex);
	ex.printStackTrace();
}
%>