public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0) { return(true); } try { loggerConsole.Info("Prepare Snapshots Method Calls Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER Snapshots Method Call Lines Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Snapshots Method Call Lines Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivot // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_METHOD_CALL_LINES); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Type"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.Cells[3, 1].Value = "See Location"; sheet.Cells[3, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT); sheet.Cells[3, 2].StyleName = "HyperLinkStyle"; sheet.Cells[4, 1].Value = "See Timeline"; sheet.Cells[4, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT); sheet.Cells[4, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METHOD_CALL_LINES); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 5, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METHOD_CALL_LINES); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METHOD_CALL_LINES); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 9, 1); #endregion #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion loggerConsole.Info("Fill Snapshots Method Call Lines Report File"); #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications loggerConsole.Info("List of Applications"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ApplicationSnapshotsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Method Call Lines loggerConsole.Info("List of Method Call Lines"); sheet = excelReport.Workbook.Worksheets[SHEET_METHOD_CALL_LINES]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.SnapshotsMethodCallLinesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT + 1, 1); #endregion loggerConsole.Info("Finalize Snapshots Method Call Lines Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; adjustColumnsOfEntityRowTableInMetricReport(APMApplication.ENTITY_TYPE, sheet, table); ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshots"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshots"].Position + 1); var cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsNormal"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsNormal"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsVerySlow"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsVerySlow"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsStall"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsStall"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsSlow"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsSlow"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSnapshotsError"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSnapshotsError"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); } #endregion #region Method Call Lines // Make table sheet = excelReport.Workbook.Worksheets[SHEET_METHOD_CALL_LINES]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT + 1) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT + 1, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_METHOD_CALL_LINES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; try { sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["TierName"].Position + 1).Width = 20; sheet.Column(table.Columns["NodeName"].Position + 1).Width = 20; sheet.Column(table.Columns["BTName"].Position + 1).Width = 20; sheet.Column(table.Columns["SegmentUserExperience"].Position + 1).Width = 10; sheet.Column(table.Columns["SnapshotUserExperience"].Position + 1).Width = 10; sheet.Column(table.Columns["RequestID"].Position + 1).Width = 20; sheet.Column(table.Columns["SegmentID"].Position + 1).Width = 10; sheet.Column(table.Columns["Type"].Position + 1).Width = 10; sheet.Column(table.Columns["Framework"].Position + 1).Width = 15; sheet.Column(table.Columns["FullNameIndent"].Position + 1).Width = 45; sheet.Column(table.Columns["ExitCalls"].Position + 1).Width = 15; sheet.Column(table.Columns["Occurred"].Position + 1).Width = 20; sheet.Column(table.Columns["OccurredUtc"].Position + 1).Width = 20; } catch (OutOfMemoryException ex) { // Do nothing, we must have a lot of cells logger.Warn("Ran out of memory due to too many rows/cells"); logger.Warn(ex); } ExcelAddress cfAddressUserExperience = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["SegmentUserExperience"].Position + 1, sheet.Dimension.Rows, table.Columns["SegmentUserExperience"].Position + 1); addUserExperienceConditionalFormatting(sheet, cfAddressUserExperience); cfAddressUserExperience = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["SnapshotUserExperience"].Position + 1, sheet.Dimension.Rows, table.Columns["SnapshotUserExperience"].Position + 1); addUserExperienceConditionalFormatting(sheet, cfAddressUserExperience); sheet = excelReport.Workbook.Worksheets[SHEET_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, PIVOT_METHOD_CALL_LINES_TYPE_EXEC_AVERAGE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "ElementType"); addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending); addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending); addFilterFieldToPivot(pivot, "Depth", eSortType.Ascending); addFilterFieldToPivot(pivot, "ExecRange", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "TierName"); addRowFieldToPivot(pivot, "BTName"); addRowFieldToPivot(pivot, "FullName"); addColumnFieldToPivot(pivot, "Type", eSortType.Ascending); addColumnFieldToPivot(pivot, "Framework", eSortType.Ascending); addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Average); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_METHOD_CALL_LINESTYPE_EXEC_AVERAGE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; sheet = excelReport.Workbook.Worksheets[SHEET_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE_PIVOT]; pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_METHOD_CALL_LINES_LOCATION_EXEC_AVERAGE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "ElementType"); addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending); addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending); addFilterFieldToPivot(pivot, "Depth", eSortType.Ascending); addRowFieldToPivot(pivot, "Type"); addRowFieldToPivot(pivot, "Framework"); addRowFieldToPivot(pivot, "FullName"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "TierName"); addRowFieldToPivot(pivot, "BTName"); addColumnFieldToPivot(pivot, "ExecRange", eSortType.Ascending); addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Count); chart = sheet.Drawings.AddChart(GRAPH_METHOD_CALL_LINESLOCATION_EXEC_AVERAGE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; sheet.Column(6).Width = 20; sheet.Column(7).Width = 20; sheet = excelReport.Workbook.Worksheets[SHEET_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE_PIVOT]; pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 6, 1], range, PIVOT_METHOD_CALL_LINES_TIMELINE_EXEC_AVERAGE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "ElementType"); addFilterFieldToPivot(pivot, "NumChildren", eSortType.Ascending); addFilterFieldToPivot(pivot, "NumExits", eSortType.Ascending); addFilterFieldToPivot(pivot, "Depth", eSortType.Ascending); addFilterFieldToPivot(pivot, "Class", eSortType.Ascending); addFilterFieldToPivot(pivot, "Method", eSortType.Ascending); addFilterFieldToPivot(pivot, "FullName", eSortType.Ascending); addFilterFieldToPivot(pivot, "BTName", eSortType.Ascending); addFilterFieldToPivot(pivot, "ExecRange", eSortType.Ascending); ExcelPivotTableField fieldR = pivot.RowFields.Add(pivot.Fields["Occurred"]); fieldR.AddDateGrouping(eDateGroupBy.Days | eDateGroupBy.Hours | eDateGroupBy.Minutes); fieldR.Compact = false; fieldR.Outline = false; addColumnFieldToPivot(pivot, "Type", eSortType.Ascending); addColumnFieldToPivot(pivot, "Framework", eSortType.Ascending); addDataFieldToPivot(pivot, "Exec", DataFieldFunctions.Average); chart = sheet.Drawings.AddChart(GRAPH_METHOD_CALL_LINESTIMELINE_EXEC_AVERAGE, eChartType.Line, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.SnapshotMethodCallsExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_BIQ) == 0) { logger.Warn("No {0} targets to process", APPLICATION_TYPE_BIQ); loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_BIQ); return(true); } try { loggerConsole.Info("Prepare Detected BIQ Entities Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER Detected BIQ Entities Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Detected BIQ Entities Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_BIQ_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_SEARCHES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SEARCHES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_SEARCHES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SEARCHES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_WIDGETS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WIDGETS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_WIDGETS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WIDGETS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_SAVED_METRICS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SAVED_METRICS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_SAVED_METRICS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_SAVED_METRICS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_BUSINESS_JOURNEYS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_BUSINESS_JOURNEYS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_BUSINESS_JOURNEYS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_BUSINESS_JOURNEYS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_EXPERIENCE_LEVELS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EXPERIENCE_LEVELS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_EXPERIENCE_LEVELS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_EXPERIENCE_LEVELS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_SCHEMAS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_FIELDS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_FIELDS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_FIELDS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_FIELDS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1); #endregion loggerConsole.Info("Fill Detected BIQ Entities Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications - All loggerConsole.Info("List of Applications - All"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, typeof(ControllerApplication), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications loggerConsole.Info("List of Applications"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_BIQ_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQApplicationsReportFilePath(), 0, typeof(BIQApplication), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Searches loggerConsole.Info("List of Searches"); sheet = excelReport.Workbook.Worksheets[SHEET_SEARCHES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQSearchesReportFilePath(), 0, typeof(BIQSearch), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Widgets loggerConsole.Info("List of Widgets"); sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQWidgetsReportFilePath(), 0, typeof(BIQWidget), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Saved Metrics loggerConsole.Info("List of Saved Metrics"); sheet = excelReport.Workbook.Worksheets[SHEET_SAVED_METRICS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQMetricsReportFilePath(), 0, typeof(BIQMetric), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Business Journeys loggerConsole.Info("List of Business Journeys"); sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_JOURNEYS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQBusinessJourneysReportFilePath(), 0, typeof(BIQBusinessJourney), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Experience Levels loggerConsole.Info("List of Experience Levels"); sheet = excelReport.Workbook.Worksheets[SHEET_EXPERIENCE_LEVELS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQExperienceLevelsReportFilePath(), 0, typeof(BIQExperienceLevel), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Schemas loggerConsole.Info("List of Schemas"); sheet = excelReport.Workbook.Worksheets[SHEET_SCHEMAS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQSchemasReportFilePath(), 0, typeof(BIQSchema), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Schema Fields loggerConsole.Info("List of Schema Fields"); sheet = excelReport.Workbook.Worksheets[SHEET_FIELDS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BIQSchemaFieldsReportFilePath(), 0, typeof(BIQSchema), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion loggerConsole.Info("Finalize Detected BIQ Entities Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications - All // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; } #endregion #region Applications // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_BIQ_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_BIQ); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSearches"].Position + 1); var cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumMultiSearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumMultiSearches"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSingleSearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSingleSearches"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumLegacySearches"].Position + 1, sheet.Dimension.Rows, table.Columns["NumLegacySearches"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSavedMetrics"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSavedMetrics"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumBusinessJourneys"].Position + 1, sheet.Dimension.Rows, table.Columns["NumBusinessJourneys"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumExperienceLevels"].Position + 1, sheet.Dimension.Rows, table.Columns["NumExperienceLevels"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumSchemas"].Position + 1, sheet.Dimension.Rows, table.Columns["NumSchemas"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumFields"].Position + 1, sheet.Dimension.Rows, table.Columns["NumFields"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); } #endregion #region Searches // Make table sheet = excelReport.Workbook.Worksheets[SHEET_SEARCHES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_SEARCHES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["SearchName"].Position + 1).Width = 20; sheet.Column(table.Columns["SearchType"].Position + 1).Width = 10; sheet.Column(table.Columns["SearchMode"].Position + 1).Width = 10; sheet.Column(table.Columns["Visualization"].Position + 1).Width = 10; sheet.Column(table.Columns["ViewMode"].Position + 1).Width = 10; sheet.Column(table.Columns["DataSource"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_SEARCHES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_SEARCHES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "ViewMode"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "DataSource"); addRowFieldToPivot(pivot, "SearchName"); addColumnFieldToPivot(pivot, "SearchMode"); addColumnFieldToPivot(pivot, "SearchType"); addDataFieldToPivot(pivot, "NumWidgets", DataFieldFunctions.Sum, "NumWidgets"); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_SEARCHES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; } #endregion #region Widgets // Make table sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_WIDGETS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["SearchName"].Position + 1).Width = 20; sheet.Column(table.Columns["SearchType"].Position + 1).Width = 10; sheet.Column(table.Columns["WidgetName"].Position + 1).Width = 15; sheet.Column(table.Columns["WidgetType"].Position + 1).Width = 10; sheet.Column(table.Columns["DataSource"].Position + 1).Width = 15; sheet.Column(table.Columns["StartTime"].Position + 1).Width = 20; sheet.Column(table.Columns["EndTime"].Position + 1).Width = 20; sheet.Column(table.Columns["StartTimeUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["EndTime"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_WIDGETS_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "Resolution", eSortType.Ascending); addFilterFieldToPivot(pivot, "IsStacking"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "DataSource"); addRowFieldToPivot(pivot, "SearchName"); addRowFieldToPivot(pivot, "WidgetName"); addColumnFieldToPivot(pivot, "WidgetType"); addDataFieldToPivot(pivot, "WidgetID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_WIDGETS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; } #endregion #region Saved Metrics // Make table sheet = excelReport.Workbook.Worksheets[SHEET_SAVED_METRICS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_SAVED_METRICS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["MetricName"].Position + 1).Width = 20; sheet.Column(table.Columns["DataSource"].Position + 1).Width = 15; sheet.Column(table.Columns["EventType"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_SAVED_METRICS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_SAVED_METRICS_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "IsEnabled"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "DataSource"); addRowFieldToPivot(pivot, "MetricName"); addColumnFieldToPivot(pivot, "LastExecStatus"); addDataFieldToPivot(pivot, "MetricName", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_SAVED_METRICS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; } #endregion #region Business Journeys // Make table sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_JOURNEYS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_BUSINESS_JOURNEYS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["JourneyName"].Position + 1).Width = 20; sheet.Column(table.Columns["Stages"].Position + 1).Width = 30; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_JOURNEYS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_BUSINESS_JOURNEY_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "NumStages", eSortType.Ascending); addFilterFieldToPivot(pivot, "IsEnabled"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "KeyField"); addRowFieldToPivot(pivot, "JourneyName"); addDataFieldToPivot(pivot, "JourneyID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_BUSINESS_JOURNEY_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; } #endregion #region Experience Levels // Make table sheet = excelReport.Workbook.Worksheets[SHEET_EXPERIENCE_LEVELS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_EXPERIENCE_LEVELS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["ExperienceLevelName"].Position + 1).Width = 20; sheet.Column(table.Columns["DataSource"].Position + 1).Width = 15; sheet.Column(table.Columns["EventField"].Position + 1).Width = 15; sheet.Column(table.Columns["StartOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["StartOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_EXPERIENCE_LEVELS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, PIVOT_EXPERIENCE_LEVELS_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "IsActive"); addFilterFieldToPivot(pivot, "EventField", eSortType.Ascending); addFilterFieldToPivot(pivot, "ThresholdOperator", eSortType.Ascending); addFilterFieldToPivot(pivot, "ThresholdValue", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "DataSource"); addRowFieldToPivot(pivot, "Criteria"); addRowFieldToPivot(pivot, "ExperienceLevelName"); addColumnFieldToPivot(pivot, "Period"); addDataFieldToPivot(pivot, "ExperienceLevelName", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_EXPERIENCE_LEVELS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; } #endregion #region Schemas // Make table sheet = excelReport.Workbook.Worksheets[SHEET_SCHEMAS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_SCHEMAS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["SchemaName"].Position + 1).Width = 20; } #endregion #region Schema Fields // Make table sheet = excelReport.Workbook.Worksheets[SHEET_FIELDS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_FIELDS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["SchemaName"].Position + 1).Width = 20; sheet.Column(table.Columns["FieldName"].Position + 1).Width = 20; sheet.Column(table.Columns["FieldType"].Position + 1).Width = 15; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_FIELDS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, PIVOT_FIELD_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "Category", eSortType.Ascending); addFilterFieldToPivot(pivot, "NumParents", eSortType.Ascending); addFilterFieldToPivot(pivot, "IsHidden"); addFilterFieldToPivot(pivot, "IsDeleted"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "SchemaName"); addRowFieldToPivot(pivot, "FieldName"); addColumnFieldToPivot(pivot, "FieldType"); addDataFieldToPivot(pivot, "FieldName", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_FIELD_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.BIQEntitiesExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_MOBILE) == 0) { logger.Warn("No {0} targets to process", APPLICATION_TYPE_MOBILE); loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_MOBILE); return(true); } #region Template comparisons if (jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller == BLANK_APPLICATION_CONTROLLER && jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application == BLANK_APPLICATION_MOBILE) { jobConfiguration.Target.Add(jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE); } else { // Check if there is a valid reference application JobTarget jobTargetReferenceApp = jobConfiguration.Target.Where(t => t.Type == APPLICATION_TYPE_MOBILE && String.Compare(t.Controller, jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller, StringComparison.InvariantCultureIgnoreCase) == 0 && String.Compare(t.Application, jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application, StringComparison.InvariantCultureIgnoreCase) == 0).FirstOrDefault(); if (jobTargetReferenceApp == null) { // No valid reference, fall back to comparing against template logger.Warn("Unable to find reference target {0}, will index default template", jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE); loggerConsole.Warn("Unable to find reference target {0}, will index default template", jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE); jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller = BLANK_APPLICATION_CONTROLLER; jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application = BLANK_APPLICATION_MOBILE; jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Type = APPLICATION_TYPE_MOBILE; jobConfiguration.Target.Add(jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE); } } #endregion bool reportFolderCleaned = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_MOBILE) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Preload list of detected entities // For later cross-reference List <ControllerApplication> controllerApplicationList = FileIOHelper.ReadListFromCSVFile <ControllerApplication>(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget), new ControllerApplicationReportMap()); #endregion #region Application Summary MOBILEApplicationConfiguration applicationConfiguration = new MOBILEApplicationConfiguration(); loggerConsole.Info("Application Summary"); applicationConfiguration.Controller = jobTarget.Controller; applicationConfiguration.ControllerLink = String.Format(DEEPLINK_CONTROLLER, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); applicationConfiguration.ApplicationName = jobTarget.Application; applicationConfiguration.ApplicationID = jobTarget.ApplicationID; applicationConfiguration.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, applicationConfiguration.Controller, applicationConfiguration.ApplicationID, DEEPLINK_TIMERANGE_LAST_15_MINUTES); if (controllerApplicationList != null) { ControllerApplication controllerApplication = controllerApplicationList.Where(a => a.Type == APPLICATION_TYPE_MOBILE && a.ApplicationID == jobTarget.ApplicationID).FirstOrDefault(); if (controllerApplication != null) { applicationConfiguration.ApplicationDescription = controllerApplication.Description; } } // Application Key JObject appKeyObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILEApplicationKeyDataFilePath(jobTarget)); if (appKeyObject != null) { applicationConfiguration.ApplicationKey = getStringValueFromJToken(appKeyObject, "appKey"); } // Monitoring State string monitoringState = FileIOHelper.ReadFileFromPath(FilePathMap.MOBILEApplicationMonitoringStateDataFilePath(jobTarget)); if (monitoringState != String.Empty) { bool parsedBool = false; Boolean.TryParse(monitoringState, out parsedBool); applicationConfiguration.IsEnabled = parsedBool; } // Configuration Settings JObject configurationSettingsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILEAgentPageSettingsRulesDataFilePath(jobTarget)); if (configurationSettingsObject != null) { if (isTokenPropertyNull(configurationSettingsObject, "thresholds") == false) { applicationConfiguration.SlowThresholdType = getStringValueFromJToken(configurationSettingsObject["thresholds"]["slowThreshold"], "type"); applicationConfiguration.SlowThreshold = getIntValueFromJToken(configurationSettingsObject["thresholds"]["slowThreshold"], "value"); applicationConfiguration.VerySlowThresholdType = getStringValueFromJToken(configurationSettingsObject["thresholds"]["verySlowThreshold"], "type"); applicationConfiguration.VerySlowThreshold = getIntValueFromJToken(configurationSettingsObject["thresholds"]["verySlowThreshold"], "value"); applicationConfiguration.StallThresholdType = getStringValueFromJToken(configurationSettingsObject["thresholds"]["stallThreshold"], "type"); applicationConfiguration.StallThreshold = getIntValueFromJToken(configurationSettingsObject["thresholds"]["stallThreshold"], "value"); } applicationConfiguration.Percentiles = getStringValueOfObjectFromJToken(configurationSettingsObject, "percentileMetrics", true); applicationConfiguration.SessionTimeout = getIntValueFromJToken(configurationSettingsObject["sessionsMonitor"], "sessionTimeoutMins"); applicationConfiguration.CrashThreshold = getIntValueFromJToken(configurationSettingsObject["crashAlerts"], "threshold"); applicationConfiguration.IsIPDisplayed = getBoolValueFromJToken(configurationSettingsObject, "ipAddressDisplayed"); applicationConfiguration.EnableScreenshot = getBoolValueFromJToken(configurationSettingsObject["agentConfigData"], "enableScreenshot"); applicationConfiguration.AutoScreenshot = getBoolValueFromJToken(configurationSettingsObject["agentConfigData"], "autoScreenshot"); applicationConfiguration.UseCellular = getBoolValueFromJToken(configurationSettingsObject["agentConfigData"], "screenshotUseCellular"); } #endregion #region Network Requests List <MOBILENetworkRequestRule> networkRequestRulesList = new List <MOBILENetworkRequestRule>(128); JObject networkRequestRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILEAgentNetworkRequestsRulesDataFilePath(jobTarget)); if (networkRequestRulesObject != null) { if (isTokenPropertyNull(networkRequestRulesObject, "customNamingIncludeRules") == false) { JArray includeRulesArray = (JArray)networkRequestRulesObject["customNamingIncludeRules"]; foreach (JObject includeRuleObject in includeRulesArray) { MOBILENetworkRequestRule networkRequestRule = fillNetworkRequestRule(includeRuleObject, jobTarget); if (networkRequestRule != null) { networkRequestRule.DetectionType = "INCLUDE"; networkRequestRulesList.Add(networkRequestRule); } } } if (isTokenPropertyNull(networkRequestRulesObject, "customNamingExcludeRules") == false) { JArray excludeRulesArray = (JArray)networkRequestRulesObject["customNamingExcludeRules"]; foreach (JObject excludeRuleObject in excludeRulesArray) { MOBILENetworkRequestRule networkRequestRule = fillNetworkRequestRule(excludeRuleObject, jobTarget); if (networkRequestRule != null) { networkRequestRule.DetectionType = "EXCLUDE"; networkRequestRulesList.Add(networkRequestRule); } } } } // Sort them networkRequestRulesList = networkRequestRulesList.OrderBy(o => o.DetectionType).ThenBy(o => o.Priority).ToList(); FileIOHelper.WriteListToCSVFile(networkRequestRulesList, new MOBILENetworkRequestRuleReportMap(), FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget)); loggerConsole.Info("Completed {0} Rules", networkRequestRulesList.Count); #endregion #region Application Settings if (networkRequestRulesList != null) { applicationConfiguration.NumNetworkRulesInclude = networkRequestRulesList.Count(r => r.DetectionType == "INCLUDE"); applicationConfiguration.NumNetworkRulesExclude = networkRequestRulesList.Count(r => r.DetectionType == "EXCLUDE"); } List <MOBILEApplicationConfiguration> applicationConfigurationsList = new List <MOBILEApplicationConfiguration>(1); applicationConfigurationsList.Add(applicationConfiguration); FileIOHelper.WriteListToCSVFile(applicationConfigurationsList, new MOBILEApplicationConfigurationReportMap(), FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + applicationConfigurationsList.Count; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.MOBILEConfigurationReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.WEBConfigurationReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILEApplicationConfigurationReportFilePath(), FilePathMap.MOBILEApplicationConfigurationIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILENetworkRequestRulesReportFilePath(), FilePathMap.MOBILENetworkRequestRulesIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } // Remove all templates from the list jobConfiguration.Target.RemoveAll(t => t.Controller == BLANK_APPLICATION_CONTROLLER); return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } List <JobTarget> listOfTargetsAlreadyProcessed = new List <JobTarget>(jobConfiguration.Target.Count); bool reportFolderCleaned = false; bool haveProcessedAtLeastOneDBCollector = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); if (listOfTargetsAlreadyProcessed.Count(j => (j.Controller == jobTarget.Controller) && (j.ApplicationID == jobTarget.ApplicationID)) > 0) { // Already saw this target, like an APM and WEB pairs together continue; } // For databases, we only process this once for the first collector we've seen if (jobTarget.Type == APPLICATION_TYPE_DB) { if (haveProcessedAtLeastOneDBCollector == false) { haveProcessedAtLeastOneDBCollector = true; } else { continue; } } listOfTargetsAlreadyProcessed.Add(jobTarget); #region Prepare time variables long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From); long toTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To); long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000); string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes); #endregion #region Health Rule violations List <HealthRuleViolationEvent> healthRuleViolationList = new List <HealthRuleViolationEvent>(); loggerConsole.Info("Index Health Rule Violations"); JArray healthRuleViolationsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationHealthRuleViolationsDataFilePath(jobTarget)); if (healthRuleViolationsArray != null) { foreach (JObject interestingEventObject in healthRuleViolationsArray) { HealthRuleViolationEvent healthRuleViolationEvent = new HealthRuleViolationEvent(); healthRuleViolationEvent.Controller = jobTarget.Controller; healthRuleViolationEvent.ApplicationName = jobTarget.Application; healthRuleViolationEvent.ApplicationID = jobTarget.ApplicationID; healthRuleViolationEvent.EventID = getLongValueFromJToken(interestingEventObject, "id"); healthRuleViolationEvent.FromUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "startTimeInMillis")); healthRuleViolationEvent.From = healthRuleViolationEvent.FromUtc.ToLocalTime(); if (getLongValueFromJToken(interestingEventObject, "endTimeInMillis") > 0) { healthRuleViolationEvent.ToUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "endTimeInMillis")); healthRuleViolationEvent.To = healthRuleViolationEvent.FromUtc.ToLocalTime(); } healthRuleViolationEvent.Status = getStringValueFromJToken(interestingEventObject, "incidentStatus"); healthRuleViolationEvent.Severity = getStringValueFromJToken(interestingEventObject, "severity"); healthRuleViolationEvent.EventLink = String.Format(DEEPLINK_INCIDENT, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EventID, getStringValueFromJToken(interestingEventObject, "startTimeInMillis"), DEEPLINK_THIS_TIMERANGE);; healthRuleViolationEvent.Description = getStringValueFromJToken(interestingEventObject, "description"); if (isTokenPropertyNull(interestingEventObject, "triggeredEntityDefinition") == false) { healthRuleViolationEvent.HealthRuleID = getLongValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "entityId"); healthRuleViolationEvent.HealthRuleName = getStringValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "name"); // TODO the health rule can't be hotlinked to until platform rewrites the screen that opens from Flash healthRuleViolationEvent.HealthRuleLink = String.Format(DEEPLINK_HEALTH_RULE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.HealthRuleID, DEEPLINK_THIS_TIMERANGE); } if (isTokenPropertyNull(interestingEventObject, "affectedEntityDefinition") == false) { healthRuleViolationEvent.EntityID = getIntValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityId"); healthRuleViolationEvent.EntityName = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "name"); string entityType = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityType"); if (entityTypeStringMapping.ContainsKey(entityType) == true) { healthRuleViolationEvent.EntityType = entityTypeStringMapping[entityType]; } else { healthRuleViolationEvent.EntityType = entityType; } // Come up with links switch (entityType) { case ENTITY_TYPE_FLOWMAP_APPLICATION: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_APPLICATION_MOBILE: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APPLICATION_MOBILE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_TIER: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_TIER, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_NODE: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_NODE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_BACKEND: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BACKEND, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; default: logger.Warn("Unknown entity type {0} in affectedEntityDefinition in health rule violations", entityType); break; } } healthRuleViolationEvent.ControllerLink = String.Format(DEEPLINK_CONTROLLER, healthRuleViolationEvent.Controller, DEEPLINK_THIS_TIMERANGE); healthRuleViolationEvent.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE); healthRuleViolationList.Add(healthRuleViolationEvent); } } loggerConsole.Info("{0} Health Rule Violations", healthRuleViolationList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + healthRuleViolationList.Count; // Sort them healthRuleViolationList = healthRuleViolationList.OrderBy(o => o.HealthRuleName).ThenBy(o => o.From).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <HealthRuleViolationEvent>(healthRuleViolationList, new HealthRuleViolationEventReportMap(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)); #endregion #region Events List <Event> eventsList = new List <Event>(); List <EventDetail> eventDetailsList = new List <EventDetail>(); loggerConsole.Info("Index Events"); foreach (string eventType in EVENT_TYPES) { JArray eventsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationEventsWithDetailsDataFilePath(jobTarget, eventType)); if (eventsArray == null) { eventsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationEventsDataFilePath(jobTarget, eventType)); } if (eventsArray != null) { loggerConsole.Info("{0} Events", eventType); foreach (JObject interestingEventObject in eventsArray) { Event @event = new Event(); @event.Controller = jobTarget.Controller; @event.ApplicationName = jobTarget.Application; @event.ApplicationID = jobTarget.ApplicationID; @event.EventID = getLongValueFromJToken(interestingEventObject, "id"); @event.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "eventTime")); @event.Occurred = @event.OccurredUtc.ToLocalTime(); @event.Type = getStringValueFromJToken(interestingEventObject, "type"); @event.SubType = getStringValueFromJToken(interestingEventObject, "subType"); @event.Severity = getStringValueFromJToken(interestingEventObject, "severity"); @event.EventLink = getStringValueFromJToken(interestingEventObject, "deepLinkUrl"); @event.Summary = getStringValueFromJToken(interestingEventObject, "summary"); if (isTokenPropertyNull(interestingEventObject, "triggeredEntity") == false) { @event.TriggeredEntityID = getLongValueFromJToken(interestingEventObject["triggeredEntity"], "entityId"); @event.TriggeredEntityName = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "name"); string entityType = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "entityType"); if (entityTypeStringMapping.ContainsKey(entityType) == true) { @event.TriggeredEntityType = entityTypeStringMapping[entityType]; } else { @event.TriggeredEntityType = entityType; } } foreach (JObject affectedEntity in interestingEventObject["affectedEntities"]) { string entityType = getStringValueFromJToken(affectedEntity, "entityType"); switch (entityType) { case ENTITY_TYPE_FLOWMAP_APPLICATION: // already have this data break; case ENTITY_TYPE_FLOWMAP_TIER: @event.TierID = getIntValueFromJToken(affectedEntity, "entityId"); @event.TierName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_NODE: @event.NodeID = getIntValueFromJToken(affectedEntity, "entityId"); @event.NodeName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_MACHINE: @event.MachineID = getIntValueFromJToken(affectedEntity, "entityId"); @event.MachineName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION: @event.BTID = getIntValueFromJToken(affectedEntity, "entityId"); @event.BTName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_HEALTH_RULE: @event.TriggeredEntityID = getLongValueFromJToken(affectedEntity, "entityId"); @event.TriggeredEntityType = entityTypeStringMapping[getStringValueFromJToken(affectedEntity, "entityType")]; @event.TriggeredEntityName = getStringValueFromJToken(affectedEntity, "name"); break; default: logger.Warn("Unknown entity type {0} in affectedEntities in events", entityType); break; } } @event.ControllerLink = String.Format(DEEPLINK_CONTROLLER, @event.Controller, DEEPLINK_THIS_TIMERANGE); @event.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, @event.Controller, @event.ApplicationID, DEEPLINK_THIS_TIMERANGE); if (@event.TierID != 0) { @event.TierLink = String.Format(DEEPLINK_TIER, @event.Controller, @event.ApplicationID, @event.TierID, DEEPLINK_THIS_TIMERANGE); } if (@event.NodeID != 0) { @event.NodeLink = String.Format(DEEPLINK_NODE, @event.Controller, @event.ApplicationID, @event.NodeID, DEEPLINK_THIS_TIMERANGE); } if (@event.BTID != 0) { @event.BTLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, @event.Controller, @event.ApplicationID, @event.BTID, DEEPLINK_THIS_TIMERANGE); } if (isTokenPropertyNull(interestingEventObject, "details") == false && isTokenPropertyNull(interestingEventObject["details"], "eventDetails") == false) { JArray eventDetailsArray = (JArray)interestingEventObject["details"]["eventDetails"]; if (eventDetailsArray != null) { List <EventDetail> eventDetailsForThisEventList = new List <EventDetail>(eventDetailsArray.Count); foreach (JObject eventDetailObject in eventDetailsArray) { EventDetail eventDetail = new EventDetail(); eventDetail.Controller = @event.Controller; eventDetail.ApplicationName = @event.ApplicationName; eventDetail.ApplicationID = @event.ApplicationID; eventDetail.TierName = @event.TierName; eventDetail.TierID = @event.TierID; eventDetail.NodeName = @event.NodeName; eventDetail.NodeID = @event.NodeID; eventDetail.MachineName = @event.MachineName; eventDetail.MachineID = @event.MachineID; eventDetail.BTName = @event.BTName; eventDetail.BTID = @event.BTID; eventDetail.EventID = @event.EventID; eventDetail.OccurredUtc = @event.OccurredUtc; eventDetail.Occurred = @event.Occurred; eventDetail.Type = @event.Type; eventDetail.SubType = @event.SubType; eventDetail.Severity = @event.Severity; eventDetail.Summary = @event.Summary; eventDetail.DetailName = getStringValueFromJToken(eventDetailObject, "name"); eventDetail.DetailValue = getStringValueFromJToken(eventDetailObject, "value"); // Parse the special types of the event types, such as options and envinronment variable changes bool shouldContinue = true; switch (@event.Type) { #region APPLICATION_CONFIG_CHANGE case "APPLICATION_CONFIG_CHANGE": if (shouldContinue == true) { // Added Option 1 // Removed Option 1 Regex regex = new Regex(@"(.*\sOption)\s\d+", RegexOptions.IgnoreCase); Match match = regex.Match(eventDetail.DetailName); if (match != null && match.Groups.Count == 2) { eventDetail.DetailAction = match.Groups[1].Value; //-Dgw.cc.full.upgrade.intended.date=20191112 //-XX:+UseGCLogFileRotation //-XX:NumberOfGCLogFiles=< number of log files > //-XX:GCLogFileSize=< file size >[ unit ] //-Xloggc:/path/to/gc.log parseJavaStartupOptionIntoEventDetail(eventDetail); shouldContinue = false; } } if (shouldContinue == true) { // Added Variable 1: // Removed Variable 1: Regex regex = new Regex(@"((Added|Removed) Variable)\s\d+", RegexOptions.IgnoreCase); Match match = regex.Match(eventDetail.DetailName); if (match != null && match.Groups.Count == 3) { eventDetail.DetailAction = match.Groups[1].Value; // SSH_TTY=/dev/pts/0 // HOSTNAME=felvqcap1174.farmersinsurance.com parseEnvironmentVariableIntoEventDetail(eventDetail); shouldContinue = false; } } if (shouldContinue == true) { // Modified Variable 1: Regex regex = new Regex(@"(Modified Variable)\s\d+", RegexOptions.IgnoreCase); Match match = regex.Match(eventDetail.DetailName); if (match != null && match.Groups.Count == 2) { eventDetail.DetailAction = match.Groups[1].Value; // MAIL=/var/mail/jbossapp (changed to) MAIL=/var/spool/mail/jbossapp // SHLVL=5 (changed to) SHLVL=3 parseModifiedEnvironmentVariableIntoEventDetail(eventDetail); shouldContinue = false; } } if (shouldContinue == true) { // Modified Property 2: Regex regex = new Regex(@"(Modified Property)\s\d+", RegexOptions.IgnoreCase); Match match = regex.Match(eventDetail.DetailName); if (match != null && match.Groups.Count == 2) { eventDetail.DetailAction = match.Groups[1].Value; // gw.cc.full.upgrade.intended.date=20191112 (changed to) gw.cc.full.upgrade.intended.date=20191113 // user.dir=/jboss/scripts/jenkins/28/slave/workspace/ClaimsCenter/GWCC_GW_DB_APP_DP/perfcc06post (changed to) user.dir=/jboss/scripts/ccperf06 parseModifiedPropertyIntoEventDetail(eventDetail); shouldContinue = false; } } break; #endregion #region POLICY_*** case "POLICY_OPEN_WARNING": case "POLICY_OPEN_CRITICAL": case "POLICY_CLOSE_WARNING": case "POLICY_CLOSE_CRITICAL": case "POLICY_UPGRADED": case "POLICY_DOWNGRADED": case "POLICY_CANCELED_WARNING": case "POLICY_CANCELED_CRITICAL": case "POLICY_CONTINUES_CRITICAL": case "POLICY_CONTINUES_WARNING": if (eventDetail.DetailName == "Evaluation End Time" || eventDetail.DetailName == "Evaluation Start Time") { // These are a unix datetime value DateTime dateTimeVal1 = UnixTimeHelper.ConvertFromUnixTimestamp(Convert.ToInt64(eventDetail.DetailValue)); eventDetail.DataType = "DateTime"; eventDetail.DetailValue = dateTimeVal1.ToLocalTime().ToString("G"); } break; #endregion default: break; } if (eventDetail.DataType == null || eventDetail.DataType.Length == 0) { // Get datatype of value long longVal = 0; double doubleVal = 0; DateTime dateTimeVal = DateTime.MinValue; if (Int64.TryParse(eventDetail.DetailValue, out longVal) == true) { eventDetail.DataType = "Integer"; } else if (Double.TryParse(eventDetail.DetailValue, out doubleVal) == true) { eventDetail.DataType = "Double"; } else if (DateTime.TryParse(eventDetail.DetailValue, out dateTimeVal) == true) { eventDetail.DataType = "DateTime"; } else { eventDetail.DataType = "String"; } } eventDetailsForThisEventList.Add(eventDetail); } @event.NumDetails = eventDetailsForThisEventList.Count; // Sort them eventDetailsForThisEventList = eventDetailsForThisEventList.OrderBy(o => o.DetailName).ToList(); eventDetailsList.AddRange(eventDetailsForThisEventList); } } eventsList.Add(@event); } } } loggerConsole.Info("{0} Events", eventsList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + eventsList.Count; // Sort them eventsList = eventsList.OrderBy(o => o.Type).ThenBy(o => o.Occurred).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <Event>(eventsList, new EventReportMap(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget)); FileIOHelper.WriteListToCSVFile <EventDetail>(eventDetailsList, new EventDetailReportMap(), FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget)); #endregion #region Application ApplicationEventSummary application = new ApplicationEventSummary(); application.Controller = jobTarget.Controller; application.ApplicationName = jobTarget.Application; application.ApplicationID = jobTarget.ApplicationID; application.Type = jobTarget.Type; application.NumEvents = eventsList.Count; application.NumEventsError = eventsList.Count(e => e.Severity == "ERROR"); application.NumEventsWarning = eventsList.Count(e => e.Severity == "WARN"); application.NumEventsInfo = eventsList.Count(e => e.Severity == "INFO"); application.NumHRViolations = healthRuleViolationList.Count; application.NumHRViolationsCritical = healthRuleViolationList.Count(e => e.Severity == "CRITICAL"); application.NumHRViolationsWarning = healthRuleViolationList.Count(e => e.Severity == "WARNING"); application.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; application.From = jobConfiguration.Input.TimeRange.From.ToLocalTime(); application.To = jobConfiguration.Input.TimeRange.To.ToLocalTime(); application.FromUtc = jobConfiguration.Input.TimeRange.From; application.ToUtc = jobConfiguration.Input.TimeRange.To; // Determine what kind of entity we are dealing with and adjust accordingly application.ControllerLink = String.Format(DEEPLINK_CONTROLLER, application.Controller, DEEPLINK_THIS_TIMERANGE); application.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, application.Controller, application.ApplicationID, DEEPLINK_THIS_TIMERANGE); if (application.NumEvents > 0 || application.NumHRViolations > 0) { application.HasActivity = true; } List <ApplicationEventSummary> applicationList = new List <ApplicationEventSummary>(1); applicationList.Add(application); FileIOHelper.WriteListToCSVFile(applicationList, new ApplicationEventSummaryReportMap(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)); #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ApplicationEventsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ApplicationEventsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationHealthRuleViolationsReportFilePath(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsReportFilePath(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventDetailsReportFilePath(), FilePathMap.ApplicationEventDetailsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsSummaryReportFilePath(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.ReportJobFilePath; stepTimingFunction.StepName = programOptions.ReportJob.Status.ToString(); stepTimingFunction.StepID = (int)programOptions.ReportJob.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = 0; this.DisplayJobStepStartingStatus(programOptions); this.FilePathMap = new FilePathMap(programOptions); try { FileIOHelper.CreateFolder(this.FilePathMap.Report_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_User_FolderPath()); List <User> usersList = FileIOHelper.ReadListFromCSVFile <User>(FilePathMap.Data_ShowUsers_FilePath(), new UserShowUsersMap()); if (usersList != null) { loggerConsole.Info("Parsing user details for {0} users", usersList.Count); int j = 0; foreach (User user in usersList) { logger.Trace("Parsing details for user {0}", user.LOGIN_NAME); List <UserProperty> userPropertiesList = FileIOHelper.ReadListFromCSVFile <UserProperty>(FilePathMap.Data_DescribeUser_FilePath(user.NAME), new UserPropertyMap()); if (userPropertiesList != null) { foreach (UserProperty userProperty in userPropertiesList) { if (userProperty.PropValue == "null") { userProperty.PropValue = String.Empty; } switch (userProperty.PropName) { case "COMMENT": user.COMMENT = userProperty.PropValue; break; case "DAYS_TO_EXPIRY": if (userProperty.PropValue != null && userProperty.PropValue.Length > 0) { try { user.DAYS_TO_EXPIRY = Convert.ToInt32(userProperty.PropValue); } catch {} } break; case "DEFAULT_NAMESPACE": user.DEFAULT_NAMESPACE = userProperty.PropValue; break; case "DEFAULT_ROLE": user.DEFAULT_ROLE = userProperty.PropValue; break; case "DEFAULT_WAREHOUSE": user.DEFAULT_WAREHOUSE = userProperty.PropValue; break; case "DISABLED": user.DISABLED = Convert.ToBoolean(userProperty.PropValue); break; case "DISPLAY_NAME": user.DISPLAY_NAME = userProperty.PropValue; break; case "EMAIL": user.EMAIL = userProperty.PropValue; break; case "EXT_AUTHN_DUO": user.EXT_AUTHN_DUO = Convert.ToBoolean(userProperty.PropValue); break; case "EXT_AUTHN_UID": user.EXT_AUTHN_UID = userProperty.PropValue; break; case "FIRST_NAME": user.FIRST_NAME = userProperty.PropValue; break; case "LAST_NAME": user.LAST_NAME = userProperty.PropValue; break; case "LOGIN_NAME": // Already parsed break; case "MIDDLE_NAME": user.MIDDLE_NAME = userProperty.PropValue; break; case "MINS_TO_BYPASS_MFA": if (userProperty.PropValue != null && userProperty.PropValue.Length > 0) { try { user.MINS_TO_BYPASS_MFA = Convert.ToInt32(userProperty.PropValue); } catch {} } break; case "MINS_TO_BYPASS_NETWORK_POLICY": if (userProperty.PropValue != null && userProperty.PropValue.Length > 0) { try { user.MINS_TO_BYPASS_NETWORK_POLICY = Convert.ToInt32(userProperty.PropValue); } catch {} } break; case "MINS_TO_UNLOCK": if (userProperty.PropValue != null && userProperty.PropValue.Length > 0) { try { user.MINS_TO_UNLOCK = Convert.ToInt32(userProperty.PropValue); } catch {} } break; case "MUST_CHANGE_PASSWORD": user.MUST_CHANGE_PASSWORD = Convert.ToBoolean(userProperty.PropValue); break; case "NAME": // Already parsed, but check for special characters if (String.Compare(userProperty.PropValue, quoteObjectIdentifier(userProperty.PropValue), true, CultureInfo.InvariantCulture) == 0) { user.IsObjectIdentifierSpecialCharacters = false; } else { user.IsObjectIdentifierSpecialCharacters = true; } break; case "PASSWORD": // Not parsing break; case "PASSWORD_LAST_SET_TIME": if (userProperty.PropValue != null && userProperty.PropValue.Length > 0) { try { // https://community.snowflake.com/s/article/4-26-Release-Notes-July-28-30-2020 // The timestamp on which the last non-null password was set for the user. // Default to null if no password has been set yet. // Values of 292278994-08-17 07:12:55.807 or 1969-12-31 23:59:59.999 indicate the password was set before the inclusion of this row. A value of 1969-12-31 23:59:59.999 can also indicate an expired password and the user needs to change their password. if (userProperty.PropValue == "292278994-08-17 07:12:55.807") { // This date 300 million year in the future is not parseable // Set it back to good old 1969 userProperty.PropValue = "1969-12-31 23:59:59.999"; } user.PASSWORD_LAST_SET_TIME = Convert.ToDateTime(userProperty.PropValue); } catch {} } break; case "RSA_PUBLIC_KEY_2_FP": user.RSA_PUBLIC_KEY_2_FP = userProperty.PropValue; break; case "RSA_PUBLIC_KEY_FP": user.RSA_PUBLIC_KEY_FP = userProperty.PropValue; break; case "SNOWFLAKE_LOCK": user.SNOWFLAKE_LOCK = Convert.ToBoolean(userProperty.PropValue); break; case "SNOWFLAKE_SUPPORT": user.SNOWFLAKE_SUPPORT = Convert.ToBoolean(userProperty.PropValue); break; default: logger.Warn("Unknown user property {0} for user {1}", userProperty, user); break; } } } j++; if (j % 10 == 0) { Console.Write("{0}.", j); } } loggerConsole.Info("Done {0} items", usersList.Count); FileIOHelper.WriteListToCSVFile <User>(usersList, new UserDetailsMap(), FilePathMap.Report_UserDetail_FilePath()); } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(programOptions, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; stepTimingTarget.NumEntities = 0; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Controller Version loggerConsole.Info("Controller Version"); // Create this row ControllerSummary controllerSummary = new ControllerSummary(); controllerSummary.Controller = jobTarget.Controller; controllerSummary.ControllerLink = String.Format(DEEPLINK_CONTROLLER, controllerSummary.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); // Lookup version // Load the configuration.xml from the child to parse the version XmlDocument configXml = FileIOHelper.LoadXmlDocumentFromFile(FilePathMap.ControllerVersionDataFilePath(jobTarget)); if (configXml != null) { //<serverstatus version="1" vendorid=""> // <available>true</available> // <serverid/> // <serverinfo> // <vendorname>AppDynamics</vendorname> // <productname>AppDynamics Application Performance Management</productname> // <serverversion>004-004-001-000</serverversion> // <implementationVersion>Controller v4.4.1.0 Build 164 Commit 6e1fd94d18dc87c1ecab2da573f98cea49d31c3a</implementationVersion> // </serverinfo> // <startupTimeInSeconds>19</startupTimeInSeconds> //</serverstatus> string controllerVersion = configXml.SelectSingleNode("serverstatus/serverinfo/serverversion").InnerText; string[] controllerVersionArray = controllerVersion.Split('-'); int[] controllerVersionArrayNum = new int[controllerVersionArray.Length]; for (int j = 0; j < controllerVersionArray.Length; j++) { controllerVersionArrayNum[j] = Convert.ToInt32(controllerVersionArray[j]); } controllerVersion = String.Join(".", controllerVersionArrayNum); controllerSummary.Version = controllerVersion; controllerSummary.VersionDetail = configXml.SelectSingleNode("serverstatus/serverinfo/implementationVersion").InnerText; controllerSummary.StartupTime = Convert.ToInt32(configXml.SelectSingleNode("serverstatus/startupTimeInSeconds").InnerText); } else { controllerSummary.Version = "No config data"; } #endregion #region All Applications JObject allApplicationsContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.AllApplicationsDataFilePath(jobTarget)); JArray mobileApplicationsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.MOBILEApplicationsDataFilePath(jobTarget)); List <ControllerApplication> controllerApplicationsList = new List <ControllerApplication>(100); if (isTokenPropertyNull(allApplicationsContainerObject, "apmApplications") == false) { loggerConsole.Info("Index List of APM Applications"); foreach (JObject applicationObject in allApplicationsContainerObject["apmApplications"]) { ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_APM; controllerApplicationsList.Add(controllerApplication); } } if (isTokenPropertyNull(allApplicationsContainerObject, "eumWebApplications") == false) { loggerConsole.Info("Index List of WEB Applications"); foreach (JObject applicationObject in allApplicationsContainerObject["eumWebApplications"]) { ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_WEB; controllerApplicationsList.Add(controllerApplication); } } if (isTokenPropertyNull(allApplicationsContainerObject, "iotApplications") == false) { loggerConsole.Info("Index List of IOT Applications"); foreach (JObject applicationObject in allApplicationsContainerObject["iotApplications"]) { ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_IOT; controllerApplicationsList.Add(controllerApplication); } } if (isTokenPropertyNull(allApplicationsContainerObject, "mobileAppContainers") == false) { loggerConsole.Info("Index List of MOBILE Applications"); foreach (JObject applicationObject in allApplicationsContainerObject["mobileAppContainers"]) { ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_MOBILE; if (controllerApplicationsList.Where(a => a.ApplicationID == controllerApplication.ApplicationID).Count() == 0) { controllerApplicationsList.Add(controllerApplication); } // Now go through children if (mobileApplicationsArray != null) { JToken mobileApplicationContainerObject = mobileApplicationsArray.Where(a => getLongValueFromJToken(a, "applicationId") == controllerApplication.ApplicationID).FirstOrDefault(); if (mobileApplicationContainerObject != null) { foreach (JObject mobileApplicationChildJSON in mobileApplicationContainerObject["children"]) { ControllerApplication controllerApplicationChild = controllerApplication.Clone(); controllerApplicationChild.ParentApplicationID = controllerApplicationChild.ApplicationID; controllerApplicationChild.ApplicationName = getStringValueFromJToken(mobileApplicationChildJSON, "name"); controllerApplicationChild.ApplicationID = getLongValueFromJToken(mobileApplicationChildJSON, "mobileAppId"); controllerApplicationsList.Add(controllerApplicationChild); } } } } } if (isTokenPropertyNull(allApplicationsContainerObject, "dbMonApplication") == false) { loggerConsole.Info("Index DB Application"); JObject applicationObject = (JObject)allApplicationsContainerObject["dbMonApplication"]; ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_DB; controllerApplicationsList.Add(controllerApplication); } if (isTokenPropertyNull(allApplicationsContainerObject, "simApplication") == false) { loggerConsole.Info("Index SIM Application"); JObject applicationObject = (JObject)allApplicationsContainerObject["simApplication"]; ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_SIM; controllerApplicationsList.Add(controllerApplication); } if (isTokenPropertyNull(allApplicationsContainerObject, "analyticsApplication") == false) { loggerConsole.Info("Index BIQ Application"); JObject applicationObject = (JObject)allApplicationsContainerObject["analyticsApplication"]; ControllerApplication controllerApplication = new ControllerApplication(); controllerApplication.Controller = jobTarget.Controller; populateApplicationInfo(applicationObject, controllerApplication); controllerApplication.Type = APPLICATION_TYPE_BIQ; controllerApplicationsList.Add(controllerApplication); } // Sort them controllerApplicationsList = controllerApplicationsList.OrderBy(o => o.Type).ThenBy(o => o.ApplicationName).ToList(); FileIOHelper.WriteListToCSVFile(controllerApplicationsList, new ControllerApplicationReportMap(), FilePathMap.ControllerApplicationsIndexFilePath(jobTarget)); controllerSummary.NumApps = controllerApplicationsList.Count; controllerSummary.NumAPMApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_APM).Count(); controllerSummary.NumWEBApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_WEB).Count(); controllerSummary.NumMOBILEApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_MOBILE).Count(); controllerSummary.NumSIMApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_SIM).Count(); controllerSummary.NumDBApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_DB).Count(); controllerSummary.NumBIQApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_BIQ).Count(); controllerSummary.NumIOTApps = controllerApplicationsList.Where(a => a.Type == APPLICATION_TYPE_IOT).Count(); List <ControllerSummary> controllerList = new List <ControllerSummary>(1); controllerList.Add(controllerSummary); FileIOHelper.WriteListToCSVFile(controllerList, new ControllerSummaryReportMap(), FilePathMap.ControllerSummaryIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + controllerApplicationsList.Count; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ControllerEntitiesReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ControllerEntitiesReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.ControllerSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerSummaryIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerSummaryReportFilePath(), FilePathMap.ControllerSummaryIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerApplicationsReportFilePath(), FilePathMap.ControllerApplicationsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; stepTimingTarget.NumEntities = 0; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Dashboards List and Widgets List loggerConsole.Info("Dashboards and their widgets"); List <Dashboard> dashboardsList = new List <Dashboard>(1024); List <DashboardWidget> dashboardWidgetsAllList = new List <DashboardWidget>(10240); List <DashboardMetricSeries> dashboardMetricSeriesAllList = new List <DashboardMetricSeries>(10240); JArray dashboardsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ControllerDashboards(jobTarget)); if (dashboardsArray != null) { int j = 0; foreach (JObject dashboardObject in dashboardsArray) { Dashboard dashboard = new Dashboard(); dashboard.Controller = jobTarget.Controller; dashboard.DashboardName = getStringValueFromJToken(dashboardObject, "name"); dashboard.Description = getStringValueFromJToken(dashboardObject, "description"); dashboard.CanvasType = getStringValueFromJToken(dashboardObject, "canvasType").Replace("CANVAS_TYPE_", ""); dashboard.TemplateEntityType = getStringValueFromJToken(dashboardObject, "templateEntityType"); dashboard.SecurityToken = getStringValueFromJToken(dashboardObject, "securityToken"); if (dashboard.SecurityToken.Length > 0) { dashboard.IsShared = true; } dashboard.IsSharingRevoked = getBoolValueFromJToken(dashboardObject, "sharingRevoked"); dashboard.IsTemplate = getBoolValueFromJToken(dashboardObject, "template"); dashboard.Height = getIntValueFromJToken(dashboardObject, "height"); dashboard.Width = getIntValueFromJToken(dashboardObject, "width"); dashboard.BackgroundColor = getIntValueFromJToken(dashboardObject, "backgroundColor").ToString("X6"); dashboard.MinutesBefore = getIntValueFromJToken(dashboardObject, "minutesBeforeAnchorTime"); dashboard.RefreshInterval = getIntValueFromJToken(dashboardObject, "refreshInterval") / 1000; dashboard.StartTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "startTime")); try { dashboard.StartTime = dashboard.StartTimeUtc.ToLocalTime(); } catch { } dashboard.EndTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "endTime")); try { dashboard.EndTime = dashboard.EndTimeUtc.ToLocalTime(); } catch { } dashboard.CreatedBy = getStringValueFromJToken(dashboardObject, "createdBy"); dashboard.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "createdOn")); try { dashboard.CreatedOn = dashboard.CreatedOnUtc.ToLocalTime(); } catch { } dashboard.UpdatedBy = getStringValueFromJToken(dashboardObject, "modifiedBy"); dashboard.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dashboardObject, "modifiedOn")); try { dashboard.UpdatedOn = dashboard.UpdatedOnUtc.ToLocalTime(); } catch { } dashboard.DashboardID = getLongValueFromJToken(dashboardObject, "id"); dashboard.DashboardLink = String.Format(DEEPLINK_DASHBOARD, dashboard.Controller, dashboard.DashboardID, DEEPLINK_TIMERANGE_LAST_15_MINUTES); // Now parse the Widgets JObject dashboardDetailObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.ControllerDashboard(jobTarget, dashboard.DashboardName, dashboard.DashboardID)); if (dashboardDetailObject != null && isTokenPropertyNull(dashboardDetailObject, "widgetTemplates") == false) { List <DashboardWidget> dashboardWidgetsList = new List <DashboardWidget>(dashboardDetailObject["widgetTemplates"].Count()); int dashboardWidgetIndex = 0; foreach (JObject dashboardWidgetObject in dashboardDetailObject["widgetTemplates"]) { DashboardWidget dashboardWidget = new DashboardWidget(); dashboardWidget.Controller = dashboard.Controller; dashboardWidget.DashboardName = dashboard.DashboardName; dashboardWidget.DashboardID = dashboard.DashboardID; dashboardWidget.CanvasType = dashboard.CanvasType; dashboardWidget.WidgetType = getStringValueFromJToken(dashboardWidgetObject, "widgetType"); dashboardWidget.Index = dashboardWidgetIndex; dashboardWidget.ApplicationName = getStringValueFromJToken(dashboardWidgetObject["applicationReference"], "applicationName"); dashboardWidget.EntityType = getStringValueFromJToken(dashboardWidgetObject, "entityType"); dashboardWidget.EntitySelectionType = getStringValueFromJToken(dashboardWidgetObject, "entitySelectionType"); try { if (isTokenPropertyNull(dashboardWidgetObject, "entityReferences") == false) { string[] entities = new string[dashboardWidgetObject["entityReferences"].Count()]; int entitiesIndex = 0; foreach (JToken entityReferenceToken in dashboardWidgetObject["entityReferences"]) { string scopingEntityName = getStringValueFromJToken(entityReferenceToken, "scopingEntityName"); string entityName = getStringValueFromJToken(entityReferenceToken, "entityName"); string subType = getStringValueFromJToken(entityReferenceToken, "subtype"); StringBuilder sb = new StringBuilder(100); sb.Append(scopingEntityName); if (scopingEntityName.Length > 0) { sb.Append("/"); } sb.Append(entityName); if (subType.Length > 0) { sb.AppendFormat(" [{0}]", subType); } entities[entitiesIndex] = sb.ToString(); entitiesIndex++;; } dashboardWidget.SelectedEntities = String.Join(";", entities); dashboardWidget.NumSelectedEntities = entities.Length; } } catch { } dashboardWidget.Title = getStringValueFromJToken(dashboardWidgetObject, "title"); dashboardWidget.Description = getStringValueFromJToken(dashboardWidgetObject, "description"); dashboardWidget.Label = getStringValueFromJToken(dashboardWidgetObject, "label"); dashboardWidget.Text = getStringValueFromJToken(dashboardWidgetObject, "text"); dashboardWidget.TextAlign = getStringValueFromJToken(dashboardWidgetObject, "textAlign"); dashboardWidget.Width = getIntValueFromJToken(dashboardWidgetObject, "width"); dashboardWidget.Height = getIntValueFromJToken(dashboardWidgetObject, "height"); dashboardWidget.MinWidth = getIntValueFromJToken(dashboardWidgetObject, "minHeight"); dashboardWidget.MinHeight = getIntValueFromJToken(dashboardWidgetObject, "minWidth"); dashboardWidget.X = getIntValueFromJToken(dashboardWidgetObject, "x"); dashboardWidget.Y = getIntValueFromJToken(dashboardWidgetObject, "y"); dashboardWidget.ForegroundColor = getIntValueFromJToken(dashboardWidgetObject, "color").ToString("X6"); dashboardWidget.BackgroundColor = getIntValueFromJToken(dashboardWidgetObject, "backgroundColor").ToString("X6"); dashboardWidget.BackgroundAlpha = getDoubleValueFromJToken(dashboardWidgetObject, "backgroundAlpha"); dashboardWidget.BorderColor = getIntValueFromJToken(dashboardWidgetObject, "borderColor").ToString("X6"); dashboardWidget.BorderSize = getIntValueFromJToken(dashboardWidgetObject, "borderThickness"); dashboardWidget.IsBorderEnabled = getBoolValueFromJToken(dashboardWidgetObject, "borderEnabled"); dashboardWidget.Margin = getIntValueFromJToken(dashboardWidgetObject, "margin"); try { dashboardWidget.NumDataSeries = dashboardWidgetObject["dataSeriesTemplates"].Count(); } catch { } dashboardWidget.FontSize = getIntValueFromJToken(dashboardWidgetObject, "fontSize"); dashboardWidget.MinutesBeforeAnchor = getIntValueFromJToken(dashboardWidgetObject, "minutesBeforeAnchorTime"); dashboardWidget.VerticalAxisLabel = getStringValueFromJToken(dashboardWidgetObject, "verticalAxisLabel"); dashboardWidget.HorizontalAxisLabel = getStringValueFromJToken(dashboardWidgetObject, "horizontalAxisLabel"); dashboardWidget.AxisType = getStringValueFromJToken(dashboardWidgetObject, "axisType"); dashboardWidget.IsMultipleYAxis = getBoolValueFromJToken(dashboardWidgetObject, "multipleYAxis"); dashboardWidget.StackMode = getStringValueFromJToken(dashboardWidgetObject, "stackMode"); dashboardWidget.AggregationType = getStringValueFromJToken(dashboardWidgetObject, "aggregationType"); dashboardWidget.DrillDownURL = getStringValueFromJToken(dashboardWidgetObject, "drillDownUrl"); dashboardWidget.IsDrillDownMetricBrowser = getBoolValueFromJToken(dashboardWidgetObject, "useMetricBrowserAsDrillDown"); dashboardWidget.IsShowEvents = getBoolValueFromJToken(dashboardWidgetObject, "showEvents"); dashboardWidget.EventFilter = getStringValueOfObjectFromJToken(dashboardWidgetObject, "eventFilterTemplate", false); dashboardWidget.ImageURL = getStringValueFromJToken(dashboardWidgetObject, "imageURL"); if (dashboardWidget.ImageURL.Length > 0) { if (dashboardWidget.ImageURL.StartsWith("data:") == true) { dashboardWidget.EmbeddedImageSize = dashboardWidget.ImageURL.Length; dashboardWidget.ImageURL = "Embedded base64 image"; } } dashboardWidget.SourceURL = getStringValueFromJToken(dashboardWidgetObject, "sourceURL"); dashboardWidget.IsSandbox = getBoolValueFromJToken(dashboardWidgetObject, "sandbox"); if (dashboardWidget.WidgetType == "AnalyticsWidget") { try { if (dashboardWidgetObject["adqlQueryList"].Count() == 0) { dashboardWidget.AnalyticsQueries = String.Empty; } else if (dashboardWidgetObject["adqlQueryList"].Count() == 1) { dashboardWidget.AnalyticsQueries = dashboardWidgetObject["adqlQueryList"][0].ToString(); } else { dashboardWidget.AnalyticsQueries = getStringValueOfObjectFromJToken(dashboardWidgetObject, "adqlQueryList", false); } } catch { } dashboardWidget.AnalyticsWidgetType = getStringValueFromJToken(dashboardWidgetObject, "analyticsWidgetType"); dashboardWidget.AnalyticsSearchMode = getStringValueFromJToken(dashboardWidgetObject, "searchMode"); } #region Maybe discern between Widget Types? //switch (dashboardWidget.WidgetType) //{ // case "HealthListWidget": // break; // case "ImageWidget": // break; // case "TextWidget": // break; // case "GraphWidget": // break; // case "MetricLabelWidget": // break; // case "EventListWidget": // break; // case "AnalyticsWidget": // break; // case "PieWidget": // break; // case "GaugeWidget": // break; // case "IFrameWidget": // break; // default: // logger.Warn("Unknown Widget Type {0} in {1}, Widget {2}", dashboardWidget.WidgetType, dashboard, dashboardWidget.Index); // loggerConsole.Warn("Unknown Widget Type {0} in {1}, Widget {2}", dashboardWidget.WidgetType, dashboard, dashboardWidget.Index); // break; //} #endregion dashboardWidgetsList.Add(dashboardWidget); // Now process metric data series for widgets that support them if (dashboardWidget.NumDataSeries > 0) { List <DashboardMetricSeries> dashboardMetricSeriesList = new List <DashboardMetricSeries>(dashboardWidget.NumDataSeries); foreach (JObject dashboardMetricSeriesObject in dashboardWidgetObject["dataSeriesTemplates"]) { DashboardMetricSeries dashboardMetricSeries = new DashboardMetricSeries(); dashboardMetricSeries.Controller = dashboard.Controller; dashboardMetricSeries.DashboardName = dashboard.DashboardName; dashboardMetricSeries.DashboardID = dashboard.DashboardID; dashboardMetricSeries.CanvasType = dashboard.CanvasType; dashboardMetricSeries.WidgetType = dashboardWidget.WidgetType; dashboardMetricSeries.Index = dashboardWidget.Index; dashboardMetricSeries.SeriesName = getStringValueFromJToken(dashboardMetricSeriesObject, "name"); dashboardMetricSeries.SeriesType = getStringValueFromJToken(dashboardMetricSeriesObject, "seriesType"); dashboardMetricSeries.MetricType = getStringValueFromJToken(dashboardMetricSeriesObject, "metricType"); if (isTokenPropertyNull(dashboardMetricSeriesObject, "colorPalette") == false) { if (isTokenPropertyNull(dashboardMetricSeriesObject["colorPalette"], "colors") == false) { string[] entities = new string[dashboardMetricSeriesObject["colorPalette"]["colors"].Count()]; int entitiesIndex = 0; foreach (JToken entityReferenceToken in dashboardMetricSeriesObject["colorPalette"]["colors"]) { int color = (int)entityReferenceToken; entities[entitiesIndex] = color.ToString("X6"); entitiesIndex++;; } dashboardMetricSeries.Colors = String.Join(";", entities); dashboardMetricSeries.NumColors = entities.Length; } } dashboardMetricSeries.Axis = getStringValueFromJToken(dashboardMetricSeriesObject, "axisPosition"); if (isTokenPropertyNull(dashboardMetricSeriesObject, "metricMatchCriteriaTemplate") == false) { JObject dashboardMetricSeriesMetricMatchCriteriaTemplateObject = (JObject)dashboardMetricSeriesObject["metricMatchCriteriaTemplate"]; dashboardMetricSeries.MaxResults = getIntValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "maxResults"); dashboardMetricSeries.ApplicationName = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "applicationName"); dashboardMetricSeries.Expression = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "expressionString"); dashboardMetricSeries.EvalScopeType = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "evaluationScopeType"); dashboardMetricSeries.Baseline = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "baselineName"); dashboardMetricSeries.DisplayStyle = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "metricDisplayNameStyle"); dashboardMetricSeries.DisplayFormat = getStringValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "metricDisplayNameCustomFormat"); dashboardMetricSeries.IsRollup = getBoolValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "rollupMetricData"); dashboardMetricSeries.UseActiveBaseline = getBoolValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "useActiveBaseline"); if (getBoolValueFromJToken(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "sortResultsAscending") == true) { dashboardMetricSeries.SortDirection = "Ascending"; } else { dashboardMetricSeries.SortDirection = "Descending"; } if (isTokenPropertyNull(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "entityMatchCriteria") == false) { JObject dashboardMetricSeriesEntityMatchCriteriaObject = (JObject)dashboardMetricSeriesMetricMatchCriteriaTemplateObject["entityMatchCriteria"]; dashboardMetricSeries.IsSummary = getBoolValueFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "summary"); dashboardMetricSeries.EntityType = getStringValueFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "entityType"); dashboardMetricSeries.EntitySelectionType = getStringValueFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "matchCriteriaType"); dashboardMetricSeries.AgentType = getStringValueOfObjectFromJToken(dashboardMetricSeriesEntityMatchCriteriaObject, "agentTypes", true); if (isTokenPropertyNull(dashboardMetricSeriesEntityMatchCriteriaObject, "entityNames") == false) { string[] entities = new string[dashboardMetricSeriesEntityMatchCriteriaObject["entityNames"].Count()]; int entitiesIndex = 0; foreach (JToken entityReferenceToken in dashboardMetricSeriesEntityMatchCriteriaObject["entityNames"]) { string scopingEntityName = getStringValueFromJToken(entityReferenceToken, "scopingEntityName"); string entityName = getStringValueFromJToken(entityReferenceToken, "entityName"); string subType = getStringValueFromJToken(entityReferenceToken, "subtype"); StringBuilder sb = new StringBuilder(100); sb.Append(scopingEntityName); if (scopingEntityName.Length > 0) { sb.Append("/"); } sb.Append(entityName); if (subType.Length > 0) { sb.AppendFormat(" [{0}]", subType); } entities[entitiesIndex] = sb.ToString(); entitiesIndex++;; } dashboardMetricSeries.SelectedEntities = String.Join(";", entities); dashboardMetricSeries.NumSelectedEntities = entities.Length; } } if (isTokenPropertyNull(dashboardMetricSeriesMetricMatchCriteriaTemplateObject, "metricExpressionTemplate") == false) { JObject dashboardMetricSeriesMetricExpressionTemplateObject = (JObject)dashboardMetricSeriesMetricMatchCriteriaTemplateObject["metricExpressionTemplate"]; dashboardMetricSeries.MetricExpressionType = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "metricExpressionType"); dashboardMetricSeries.MetricDisplayName = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "displayName"); if (dashboardMetricSeries.MetricDisplayName == "null") { // yes, sometimes that value is saved as string "null" dashboardMetricSeries.MetricDisplayName = String.Empty; } dashboardMetricSeries.FunctionType = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "functionType"); dashboardMetricSeries.MetricPath = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "relativeMetricPath"); if (dashboardMetricSeries.MetricPath.Length == 0) { // Must be dashboardMetricSeries.MetricExpressionType = Absolute dashboardMetricSeries.MetricPath = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "metricPath"); } if (dashboardMetricSeries.NumSelectedEntities == 0) { // Must be dashboardMetricSeries.MetricExpressionType = Absolute if (isTokenPropertyNull(dashboardMetricSeriesMetricExpressionTemplateObject, "scopeEntity") == false) { JObject dashboardMetricSeriesScopeEntityObject = (JObject)dashboardMetricSeriesMetricExpressionTemplateObject["scopeEntity"]; string scopingEntityName = getStringValueFromJToken(dashboardMetricSeriesScopeEntityObject, "scopingEntityName"); string entityName = getStringValueFromJToken(dashboardMetricSeriesScopeEntityObject, "entityName"); string subType = getStringValueFromJToken(dashboardMetricSeriesScopeEntityObject, "subtype"); StringBuilder sb = new StringBuilder(100); sb.Append(scopingEntityName); if (scopingEntityName.Length > 0) { sb.Append("/"); } sb.Append(entityName); if (subType.Length > 0) { sb.AppendFormat(" [{0}]", subType); } dashboardMetricSeries.SelectedEntities = sb.ToString(); dashboardMetricSeries.NumSelectedEntities = 1; } } if (dashboardMetricSeries.MetricExpressionType == "Boolean") { dashboardMetricSeries.ExpressionOperator = getStringValueFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject["operator"], "type"); dashboardMetricSeries.Expression1 = getStringValueOfObjectFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "expression1", false); dashboardMetricSeries.Expression2 = getStringValueOfObjectFromJToken(dashboardMetricSeriesMetricExpressionTemplateObject, "expression2", false); } } } dashboardMetricSeriesList.Add(dashboardMetricSeries); } dashboardMetricSeriesAllList.AddRange(dashboardMetricSeriesList); } dashboardWidgetIndex++; } dashboardWidgetsAllList.AddRange(dashboardWidgetsList); dashboard.NumWidgets = dashboardWidgetsList.Count; dashboard.NumAnalyticsWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "AnalyticsWidget"); dashboard.NumEventListWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "EventListWidget"); dashboard.NumGaugeWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "GaugeWidget"); dashboard.NumGraphWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "GraphWidget"); dashboard.NumHealthListWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "HealthListWidget"); dashboard.NumIFrameWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "IFrameWidget"); dashboard.NumImageWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "ImageWidget"); dashboard.NumMetricLabelWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "MetricLabelWidget"); dashboard.NumPieWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "PieWidget"); dashboard.NumTextWidgets = dashboardWidgetsList.Count(d => d.WidgetType == "TextWidget"); } dashboardsList.Add(dashboard); j++; if (j % 100 == 0) { Console.Write("[{0}].", j); } } } loggerConsole.Info("{0} Dashboards", dashboardsList.Count); loggerConsole.Info("{0} Dashboard Widgets", dashboardWidgetsAllList.Count); loggerConsole.Info("{0} Dashboard Widget Time Series", dashboardMetricSeriesAllList.Count); dashboardsList = dashboardsList.OrderBy(d => d.DashboardName).ToList(); FileIOHelper.WriteListToCSVFile(dashboardsList, new DashboardReportMap(), FilePathMap.DashboardsIndexFilePath(jobTarget)); dashboardWidgetsAllList = dashboardWidgetsAllList.OrderBy(d => d.DashboardName).ThenBy(d => d.Index).ToList(); FileIOHelper.WriteListToCSVFile(dashboardWidgetsAllList, new DashboardWidgetReportMap(), FilePathMap.DashboardWidgetsIndexFilePath(jobTarget)); dashboardMetricSeriesAllList = dashboardMetricSeriesAllList.OrderBy(d => d.DashboardName).ThenBy(d => d.Index).ThenBy(d => d.SeriesName).ToList(); FileIOHelper.WriteListToCSVFile(dashboardMetricSeriesAllList, new DashboardMetricSeriesReportMap(), FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + dashboardsList.Count; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ControllerDashboardsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ControllerDashboardsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.DashboardsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DashboardsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.DashboardsReportFilePath(), FilePathMap.DashboardsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.DashboardWidgetsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DashboardWidgetsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.DashboardWidgetsReportFilePath(), FilePathMap.DashboardWidgetsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.DashboardMetricSeriesReportFilePath(), FilePathMap.DashboardMetricSeriesIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(jobConfiguration) == false) { return(true); } try { loggerConsole.Info("Prepare Dashboards Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER Dashboards Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Dashboards Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_DASHBOARDS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_DASHBOARDS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_DASHBOARDS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_DASHBOARDS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_WIDGETS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WIDGETS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_WIDGETS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WIDGETS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_DATA_SERIES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Type"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_DATA_SERIES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.Cells[3, 1].Value = "See Location"; sheet.Cells[3, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_DATA_SERIES_LOCATION_PIVOT); sheet.Cells[3, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_DATA_SERIES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_DATA_SERIES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_DATA_SERIES_LOCATION_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_DATA_SERIES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); #endregion loggerConsole.Info("Fill Dashboards Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications - All loggerConsole.Info("List of Applications - All"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Dashboards loggerConsole.Info("List of Dashboards"); sheet = excelReport.Workbook.Worksheets[SHEET_DASHBOARDS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.DashboardsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Widgets loggerConsole.Info("List of Widgets"); sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.DashboardWidgetsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Widget Data Series loggerConsole.Info("List of Widget Data Series"); sheet = excelReport.Workbook.Worksheets[SHEET_DATA_SERIES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.DashboardMetricSeriesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion loggerConsole.Info("Finalize Dashboards Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications - All // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; } #endregion #region Dashboards // Make table sheet = excelReport.Workbook.Worksheets[SHEET_DASHBOARDS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_DASHBOARDS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumWidgets"].Position + 1, sheet.Dimension.Rows, table.Columns["NumWidgets"].Position + 1); var cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["DashboardName"].Position + 1).Width = 20; sheet.Column(table.Columns["StartTime"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["StartTimeUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_DASHBOARDS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_DASHBOARDS_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "CreatedBy", eSortType.Ascending); addFilterFieldToPivot(pivot, "UpdatedBy", eSortType.Ascending); addFilterFieldToPivot(pivot, "IsShared"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "CanvasType"); addRowFieldToPivot(pivot, "DashboardName"); addDataFieldToPivot(pivot, "DashboardID", DataFieldFunctions.Count, "Dashboards"); addDataFieldToPivot(pivot, "NumWidgets", DataFieldFunctions.Sum, "Widgets"); addDataFieldToPivot(pivot, "NumAnalyticsWidgets", DataFieldFunctions.Sum, "Analytics"); addDataFieldToPivot(pivot, "NumEventListWidgets", DataFieldFunctions.Sum, "Events"); addDataFieldToPivot(pivot, "NumGaugeWidgets", DataFieldFunctions.Sum, "Gauges"); addDataFieldToPivot(pivot, "NumGraphWidgets", DataFieldFunctions.Sum, "Graphs"); addDataFieldToPivot(pivot, "NumIFrameWidgets", DataFieldFunctions.Sum, "IFrames"); addDataFieldToPivot(pivot, "NumImageWidgets", DataFieldFunctions.Sum, "Images"); addDataFieldToPivot(pivot, "NumMetricLabelWidgets", DataFieldFunctions.Sum, "Labels"); addDataFieldToPivot(pivot, "NumPieWidgets", DataFieldFunctions.Sum, "Pies"); addDataFieldToPivot(pivot, "NumTextWidgets", DataFieldFunctions.Sum, "Texts"); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_DASHBOARDS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; } #endregion #region Widgets // Make table sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_WIDGETS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["DashboardName"].Position + 1).Width = 20; sheet.Column(table.Columns["WidgetType"].Position + 1).Width = 15; sheet.Column(table.Columns["Title"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_WIDGETS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1], range, PIVOT_WIDGETS_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "EntityType", eSortType.Ascending); addFilterFieldToPivot(pivot, "EntitySelectionType"); addFilterFieldToPivot(pivot, "NumSelectedEntities", eSortType.Ascending); addFilterFieldToPivot(pivot, "NumDataSeries", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "CanvasType"); addRowFieldToPivot(pivot, "DashboardName"); addColumnFieldToPivot(pivot, "WidgetType"); addDataFieldToPivot(pivot, "DashboardName", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_WIDGETS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; } #endregion #region Data Series // Make table sheet = excelReport.Workbook.Worksheets[SHEET_DATA_SERIES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_DATA_SERIES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["DashboardName"].Position + 1).Width = 20; sheet.Column(table.Columns["WidgetType"].Position + 1).Width = 15; sheet.Column(table.Columns["SeriesName"].Position + 1).Width = 20; sheet.Column(table.Columns["MetricType"].Position + 1).Width = 15; sheet.Column(table.Columns["MetricPath"].Position + 1).Width = 25; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_DATA_SERIES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_DATA_SERIES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "WidgetType"); addFilterFieldToPivot(pivot, "ApplicationName", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "CanvasType"); addRowFieldToPivot(pivot, "DashboardName"); addRowFieldToPivot(pivot, "MetricType"); addRowFieldToPivot(pivot, "MetricPath"); addColumnFieldToPivot(pivot, "SeriesType"); addDataFieldToPivot(pivot, "DashboardName", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_DATA_SERIES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; sheet = excelReport.Workbook.Worksheets[SHEET_DATA_SERIES_LOCATION_PIVOT]; pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_DATA_SERIES_LOCATION); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "ApplicationName", eSortType.Ascending); addFilterFieldToPivot(pivot, "EntityType", eSortType.Ascending); addRowFieldToPivot(pivot, "WidgetType"); addRowFieldToPivot(pivot, "MetricType"); addRowFieldToPivot(pivot, "MetricPath"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "CanvasType"); addRowFieldToPivot(pivot, "DashboardName"); addColumnFieldToPivot(pivot, "SeriesType"); addDataFieldToPivot(pivot, "DashboardName", DataFieldFunctions.Count); chart = sheet.Drawings.AddChart(GRAPH_DATA_SERIES_LOCATION, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; sheet.Column(6).Width = 20; } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.DashboardsExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0) { return(true); } List <string> listOfControllersAlreadyProcessed = new List <string>(jobConfiguration.Target.Count); bool reportFolderCleaned = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_APM) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Health Rule violations loggerConsole.Info("Index Health Rule Violations"); List <HealthRuleViolationEvent> healthRuleViolationList = new List <HealthRuleViolationEvent>(); long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From); long toTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To); long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000); string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes); if (File.Exists(FilePathMap.HealthRuleViolationsDataFilePath(jobTarget))) { JArray healthRuleViolationEvents = FileIOHelper.LoadJArrayFromFile(FilePathMap.HealthRuleViolationsDataFilePath(jobTarget)); if (healthRuleViolationEvents != null) { foreach (JObject interestingEvent in healthRuleViolationEvents) { HealthRuleViolationEvent eventRow = new HealthRuleViolationEvent(); eventRow.Controller = jobTarget.Controller; eventRow.ApplicationName = jobTarget.Application; eventRow.ApplicationID = jobTarget.ApplicationID; eventRow.EventID = (long)interestingEvent["id"]; eventRow.FromUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["startTimeInMillis"]); eventRow.From = eventRow.FromUtc.ToLocalTime(); if ((long)interestingEvent["endTimeInMillis"] > 0) { eventRow.ToUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["endTimeInMillis"]); eventRow.To = eventRow.FromUtc.ToLocalTime(); } eventRow.Status = interestingEvent["incidentStatus"].ToString(); eventRow.Severity = interestingEvent["severity"].ToString(); eventRow.EventLink = String.Format(DEEPLINK_INCIDENT, eventRow.Controller, eventRow.ApplicationID, eventRow.EventID, interestingEvent["startTimeInMillis"], DEEPLINK_THIS_TIMERANGE);; eventRow.Description = interestingEvent["description"].ToString(); if (interestingEvent["triggeredEntityDefinition"].HasValues == true) { eventRow.HealthRuleID = (int)interestingEvent["triggeredEntityDefinition"]["entityId"]; eventRow.HealthRuleName = interestingEvent["triggeredEntityDefinition"]["name"].ToString(); // TODO the health rule can't be hotlinked to until platform rewrites the screen that opens from Flash eventRow.HealthRuleLink = String.Format(DEEPLINK_HEALTH_RULE, eventRow.Controller, eventRow.ApplicationID, eventRow.HealthRuleID, DEEPLINK_THIS_TIMERANGE); } if (interestingEvent["affectedEntityDefinition"].HasValues == true) { eventRow.EntityID = (int)interestingEvent["affectedEntityDefinition"]["entityId"]; eventRow.EntityName = interestingEvent["affectedEntityDefinition"]["name"].ToString(); string entityType = interestingEvent["affectedEntityDefinition"]["entityType"].ToString(); if (entityTypeStringMapping.ContainsKey(entityType) == true) { eventRow.EntityType = entityTypeStringMapping[entityType]; } else { eventRow.EntityType = entityType; } // Come up with links switch (entityType) { case ENTITY_TYPE_FLOWMAP_APPLICATION: eventRow.EntityLink = String.Format(DEEPLINK_APPLICATION, eventRow.Controller, eventRow.ApplicationID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_APPLICATION_MOBILE: eventRow.EntityLink = String.Format(DEEPLINK_APPLICATION_MOBILE, eventRow.Controller, eventRow.ApplicationID, eventRow.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_TIER: eventRow.EntityLink = String.Format(DEEPLINK_TIER, eventRow.Controller, eventRow.ApplicationID, eventRow.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_NODE: eventRow.EntityLink = String.Format(DEEPLINK_NODE, eventRow.Controller, eventRow.ApplicationID, eventRow.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION: eventRow.EntityLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, eventRow.Controller, eventRow.ApplicationID, eventRow.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_BACKEND: eventRow.EntityLink = String.Format(DEEPLINK_BACKEND, eventRow.Controller, eventRow.ApplicationID, eventRow.EntityID, DEEPLINK_THIS_TIMERANGE); break; default: logger.Warn("Unknown entity type {0} in affectedEntityDefinition in health rule violations", entityType); break; } } eventRow.ControllerLink = String.Format(DEEPLINK_CONTROLLER, eventRow.Controller, DEEPLINK_THIS_TIMERANGE); eventRow.ApplicationLink = String.Format(DEEPLINK_APPLICATION, eventRow.Controller, eventRow.ApplicationID, DEEPLINK_THIS_TIMERANGE); healthRuleViolationList.Add(eventRow); } } } loggerConsole.Info("{0} Health Rule Violation events", healthRuleViolationList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + healthRuleViolationList.Count; // Sort them healthRuleViolationList = healthRuleViolationList.OrderBy(o => o.HealthRuleName).ThenBy(o => o.From).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <HealthRuleViolationEvent>(healthRuleViolationList, new HealthRuleViolationEventReportMap(), FilePathMap.HealthRuleViolationsIndexFilePath(jobTarget)); #endregion #region Events loggerConsole.Info("Index Events"); List <Event> eventsList = new List <Event>(); foreach (string eventType in EVENT_TYPES) { loggerConsole.Info("Type {0} Events", eventType); if (File.Exists(FilePathMap.EventsDataFilePath(jobTarget, eventType))) { JArray events = FileIOHelper.LoadJArrayFromFile(FilePathMap.EventsDataFilePath(jobTarget, eventType)); if (events != null) { foreach (JObject interestingEvent in events) { Event eventRow = new Event(); eventRow.Controller = jobTarget.Controller; eventRow.ApplicationName = jobTarget.Application; eventRow.ApplicationID = jobTarget.ApplicationID; eventRow.EventID = (long)interestingEvent["id"]; eventRow.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["eventTime"]); eventRow.Occurred = eventRow.OccurredUtc.ToLocalTime(); eventRow.Type = interestingEvent["type"].ToString(); eventRow.SubType = interestingEvent["subType"].ToString(); eventRow.Severity = interestingEvent["severity"].ToString(); eventRow.EventLink = interestingEvent["deepLinkUrl"].ToString(); eventRow.Summary = interestingEvent["summary"].ToString(); if (interestingEvent["triggeredEntity"].HasValues == true) { eventRow.TriggeredEntityID = (long)interestingEvent["triggeredEntity"]["entityId"]; eventRow.TriggeredEntityName = interestingEvent["triggeredEntity"]["name"].ToString(); string entityType = interestingEvent["triggeredEntity"]["entityType"].ToString(); if (entityTypeStringMapping.ContainsKey(entityType) == true) { eventRow.TriggeredEntityType = entityTypeStringMapping[entityType]; } else { eventRow.TriggeredEntityType = entityType; } } foreach (JObject affectedEntity in interestingEvent["affectedEntities"]) { string entityType = affectedEntity["entityType"].ToString(); switch (entityType) { case ENTITY_TYPE_FLOWMAP_APPLICATION: // already have this data break; case ENTITY_TYPE_FLOWMAP_TIER: eventRow.TierID = (int)affectedEntity["entityId"]; eventRow.TierName = affectedEntity["name"].ToString(); break; case ENTITY_TYPE_FLOWMAP_NODE: eventRow.NodeID = (int)affectedEntity["entityId"]; eventRow.NodeName = affectedEntity["name"].ToString(); break; case ENTITY_TYPE_FLOWMAP_MACHINE: eventRow.MachineID = (int)affectedEntity["entityId"]; eventRow.MachineName = affectedEntity["name"].ToString(); break; case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION: eventRow.BTID = (int)affectedEntity["entityId"]; eventRow.BTName = affectedEntity["name"].ToString(); break; case ENTITY_TYPE_FLOWMAP_HEALTH_RULE: eventRow.TriggeredEntityID = (int)affectedEntity["entityId"]; eventRow.TriggeredEntityType = entityTypeStringMapping[affectedEntity["entityType"].ToString()]; eventRow.TriggeredEntityName = affectedEntity["name"].ToString(); break; default: logger.Warn("Unknown entity type {0} in affectedEntities in events", entityType); break; } } eventRow.ControllerLink = String.Format(DEEPLINK_CONTROLLER, eventRow.Controller, DEEPLINK_THIS_TIMERANGE); eventRow.ApplicationLink = String.Format(DEEPLINK_APPLICATION, eventRow.Controller, eventRow.ApplicationID, DEEPLINK_THIS_TIMERANGE); if (eventRow.TierID != 0) { eventRow.TierLink = String.Format(DEEPLINK_TIER, eventRow.Controller, eventRow.ApplicationID, eventRow.TierID, DEEPLINK_THIS_TIMERANGE); } if (eventRow.NodeID != 0) { eventRow.NodeLink = String.Format(DEEPLINK_NODE, eventRow.Controller, eventRow.ApplicationID, eventRow.NodeID, DEEPLINK_THIS_TIMERANGE); } if (eventRow.BTID != 0) { eventRow.BTLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, eventRow.Controller, eventRow.ApplicationID, eventRow.BTID, DEEPLINK_THIS_TIMERANGE); } eventsList.Add(eventRow); } } } } // Only output this once per controller if (listOfControllersAlreadyProcessed.Contains(jobTarget.Controller) == false) { listOfControllersAlreadyProcessed.Add(jobTarget.Controller); loggerConsole.Info("Index Notification Events"); JObject notificationsContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.NotificationsDataFilePath(jobTarget)); if (notificationsContainer != null) { foreach (JObject interestingEvent in notificationsContainer["notifications"]) { if ((long)interestingEvent["notificationData"]["applicationId"] < 0) { foreach (JObject affectedEntity in interestingEvent["notificationData"]["affectedEntities"]) { Event eventRow = new Event(); eventRow.Controller = jobTarget.Controller; eventRow.EventID = (long)interestingEvent["id"]; try { eventRow.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["notificationData"]["time"]); eventRow.Occurred = eventRow.OccurredUtc.ToLocalTime(); } catch { } try { eventRow.Type = interestingEvent["notificationData"]["eventType"].ToString(); } catch { } try { eventRow.Severity = interestingEvent["notificationData"]["severity"].ToString(); } catch { } try { eventRow.Summary = interestingEvent["notificationData"]["summary"].ToString(); } catch { } try { eventRow.TriggeredEntityID = (long)affectedEntity["entityId"]; } catch { } try { eventRow.TriggeredEntityType = affectedEntity["entityType"].ToString(); } catch { } eventRow.ControllerLink = String.Format(DEEPLINK_CONTROLLER, eventRow.Controller, DEEPLINK_THIS_TIMERANGE); eventsList.Add(eventRow); } } } } } loggerConsole.Info("{0} events", eventsList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + eventsList.Count; // Sort them eventsList = eventsList.OrderBy(o => o.Type).ThenBy(o => o.Occurred).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <Event>(eventsList, new EventReportMap(), FilePathMap.EventsIndexFilePath(jobTarget)); #endregion #region Audit Events if (File.Exists(FilePathMap.AuditEventsIndexFilePath(jobTarget)) == false) { List <AuditEvent> auditEventsList = new List <AuditEvent>(); loggerConsole.Info("Index Audit Log events"); JArray auditEvents = FileIOHelper.LoadJArrayFromFile(FilePathMap.AuditEventsDataFilePath(jobTarget)); if (auditEvents != null) { foreach (JObject interestingEvent in auditEvents) { AuditEvent eventRow = new AuditEvent(); eventRow.Controller = jobTarget.Controller; //eventRow.ApplicationName = jobTarget.Application; //eventRow.ApplicationID = jobTarget.ApplicationID; try { eventRow.EntityID = (long)interestingEvent["objectId"]; } catch { } try { eventRow.EntityType = interestingEvent["objectType"].ToString(); } catch { } try { eventRow.EntityName = interestingEvent["objectName"].ToString(); } catch { } try { eventRow.UserName = interestingEvent["userName"].ToString(); } catch { } try { eventRow.AccountName = interestingEvent["accountName"].ToString(); } catch { } try { eventRow.LoginType = interestingEvent["securityProviderType"].ToString(); } catch { } try { eventRow.Action = interestingEvent["action"].ToString(); } catch { } try { eventRow.EntityID = (long)interestingEvent["objectId"]; } catch { } try { eventRow.EntityType = interestingEvent["objectType"].ToString(); } catch { } try { eventRow.EntityName = interestingEvent["objectName"].ToString(); } catch { } try { eventRow.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp((long)interestingEvent["timeStamp"]); } catch { } try { eventRow.Occurred = eventRow.OccurredUtc.ToLocalTime(); } catch { } auditEventsList.Add(eventRow); } } auditEventsList = auditEventsList.OrderBy(o => o.Occurred).ToList(); loggerConsole.Info("{0} Audit events", auditEventsList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + auditEventsList.Count; FileIOHelper.WriteListToCSVFile <AuditEvent>(auditEventsList, new AuditEventReportMap(), FilePathMap.AuditEventsIndexFilePath(jobTarget)); } #endregion #region Application List <APMApplication> applicationList = FileIOHelper.ReadListFromCSVFile <APMApplication>(FilePathMap.ApplicationIndexFilePath(jobTarget), new APMApplicationReportMap()); if (applicationList != null && applicationList.Count > 0) { APMApplication applicationsRow = applicationList[0]; applicationsRow.NumEvents = eventsList.Count; applicationsRow.NumEventsError = eventsList.Count(e => e.Severity == "ERROR"); applicationsRow.NumEventsWarning = eventsList.Count(e => e.Severity == "WARN"); applicationsRow.NumEventsInfo = eventsList.Count(e => e.Severity == "INFO"); applicationsRow.NumHRViolations = healthRuleViolationList.Count; applicationsRow.NumHRViolationsCritical = healthRuleViolationList.Count(e => e.Severity == "CRITICAL"); applicationsRow.NumHRViolationsWarning = healthRuleViolationList.Count(e => e.Severity == "WARNING"); applicationsRow.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; applicationsRow.From = jobConfiguration.Input.TimeRange.From.ToLocalTime(); applicationsRow.To = jobConfiguration.Input.TimeRange.To.ToLocalTime(); applicationsRow.FromUtc = jobConfiguration.Input.TimeRange.From; applicationsRow.ToUtc = jobConfiguration.Input.TimeRange.To; if (applicationsRow.NumEvents > 0 || applicationsRow.NumHRViolations > 0) { applicationsRow.HasActivity = true; } FileIOHelper.WriteListToCSVFile(applicationList, new ApplicationEventReportMap(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget)); } #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.EventsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.EventsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual application files into one if (File.Exists(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsReportFilePath(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.HealthRuleViolationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.HealthRuleViolationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.HealthRuleViolationsReportFilePath(), FilePathMap.HealthRuleViolationsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.EventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.EventsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.EventsReportFilePath(), FilePathMap.EventsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.AuditEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.AuditEventsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.AuditEventsReportFilePath(), FilePathMap.AuditEventsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_WEB) == 0) { return(true); } bool reportFolderCleaned = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_WEB) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Preload list of detected entities // For later cross-reference List <ControllerApplication> controllerApplicationList = FileIOHelper.ReadListFromCSVFile <ControllerApplication>(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget), new ControllerApplicationReportMap()); #endregion #region Application Summary WEBApplicationConfiguration applicationConfiguration = new WEBApplicationConfiguration(); loggerConsole.Info("Application Summary"); applicationConfiguration.Controller = jobTarget.Controller; applicationConfiguration.ControllerLink = String.Format(DEEPLINK_CONTROLLER, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); applicationConfiguration.ApplicationName = jobTarget.Application; applicationConfiguration.ApplicationID = jobTarget.ApplicationID; applicationConfiguration.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, applicationConfiguration.Controller, applicationConfiguration.ApplicationID, DEEPLINK_TIMERANGE_LAST_15_MINUTES); if (controllerApplicationList != null) { ControllerApplication controllerApplication = controllerApplicationList.Where(a => a.Type == APPLICATION_TYPE_WEB && a.ApplicationID == applicationConfiguration.ApplicationID).FirstOrDefault(); if (controllerApplication != null) { applicationConfiguration.ApplicationDescription = controllerApplication.Description; } } // Application Key JObject appKeyObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBApplicationKeyDataFilePath(jobTarget)); if (appKeyObject != null) { applicationConfiguration.ApplicationKey = getStringValueFromJToken(appKeyObject, "appKey"); } // Instrumentation Options JObject instrumentationObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentConfigDataFilePath(jobTarget)); if (instrumentationObject != null) { applicationConfiguration.IsXsccEnabled = getBoolValueFromJToken(instrumentationObject, "enableXssc"); applicationConfiguration.HostOption = getIntValueFromJToken(instrumentationObject, "hostOption"); applicationConfiguration.AgentHTTP = getStringValueFromJToken(instrumentationObject, "jsAgentUrlHttp"); applicationConfiguration.AgentHTTPS = getStringValueFromJToken(instrumentationObject, "jsAgentUrlHttps"); applicationConfiguration.GeoHTTP = getStringValueFromJToken(instrumentationObject, "geoUrlHttp"); applicationConfiguration.GeoHTTPS = getStringValueFromJToken(instrumentationObject, "geoUrlHttps"); applicationConfiguration.BeaconHTTP = getStringValueFromJToken(instrumentationObject, "beaconUrlHttp"); applicationConfiguration.BeaconHTTPS = getStringValueFromJToken(instrumentationObject, "beaconUrlHttps"); applicationConfiguration.AgentCode = getStringValueFromJToken(instrumentationObject, "codeSnippet"); } // Monitoring State string monitoringState = FileIOHelper.ReadFileFromPath(FilePathMap.WEBApplicationMonitoringStateDataFilePath(jobTarget)); if (monitoringState != String.Empty) { bool parsedBool = false; Boolean.TryParse(monitoringState, out parsedBool); applicationConfiguration.IsEnabled = parsedBool; } // Error Detection JObject errorDetectionRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentErrorRulesDataFilePath(jobTarget)); if (errorDetectionRulesObject != null) { applicationConfiguration.IsJSErrorEnabled = getBoolValueFromJToken(errorDetectionRulesObject, "javaScriptErrorCaptureEnabled"); applicationConfiguration.IsAJAXErrorEnabled = getBoolValueFromJToken(errorDetectionRulesObject, "ajaxRequestErrorCaptureEnabled"); applicationConfiguration.IgnoreJSErrors = getStringValueOfObjectFromJToken(errorDetectionRulesObject, "ignoreJavaScriptErrorConfigRules", true); applicationConfiguration.IgnorePageNames = getStringValueOfObjectFromJToken(errorDetectionRulesObject, "ignorePageNames", true); applicationConfiguration.IgnoreURLs = getStringValueOfObjectFromJToken(errorDetectionRulesObject, "ignoreUrls", true); } // Page Settings JObject pageSettingsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentPageSettingsRulesDataFilePath(jobTarget)); if (pageSettingsObject != null) { if (isTokenPropertyNull(pageSettingsObject, "thresholds") == false) { applicationConfiguration.SlowThresholdType = getStringValueFromJToken(pageSettingsObject["thresholds"]["slowThreshold"], "type"); applicationConfiguration.SlowThreshold = getIntValueFromJToken(pageSettingsObject["thresholds"]["slowThreshold"], "value"); applicationConfiguration.VerySlowThresholdType = getStringValueFromJToken(pageSettingsObject["thresholds"]["verySlowThreshold"], "type"); applicationConfiguration.VerySlowThreshold = getIntValueFromJToken(pageSettingsObject["thresholds"]["verySlowThreshold"], "value"); applicationConfiguration.StallThresholdType = getStringValueFromJToken(pageSettingsObject["thresholds"]["stallThreshold"], "type"); applicationConfiguration.StallThreshold = getIntValueFromJToken(pageSettingsObject["thresholds"]["stallThreshold"], "value"); } applicationConfiguration.Percentiles = getStringValueOfObjectFromJToken(pageSettingsObject, "percentileMetrics", true); applicationConfiguration.SessionTimeout = getIntValueFromJToken(pageSettingsObject["sessionsMonitor"], "sessionTimeoutMins"); applicationConfiguration.IsIPDisplayed = getBoolValueFromJToken(pageSettingsObject, "ipAddressDisplayed"); applicationConfiguration.EnableSlowSnapshots = getBoolValueFromJToken(pageSettingsObject["eventPolicy"], "enableSlowSnapshotCollection"); applicationConfiguration.EnablePeriodicSnapshots = getBoolValueFromJToken(pageSettingsObject["eventPolicy"], "enablePeriodicSnapshotCollection"); applicationConfiguration.EnableErrorSnapshots = getBoolValueFromJToken(pageSettingsObject["eventPolicy"], "enableErrorSnapshotCollection"); } #endregion #region Rules of all kinds loggerConsole.Info("Rules"); #region Page Rules List <WEBPageDetectionRule> pageDetectionRulesList = new List <WEBPageDetectionRule>(1024); JObject pageRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentPageRulesDataFilePath(jobTarget)); if (pageRulesObject != null) { if (isTokenPropertyNull(pageRulesObject, "customNamingIncludeRules") == false) { JArray includeRulesArray = (JArray)pageRulesObject["customNamingIncludeRules"]; foreach (JObject includeRuleObject in includeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "INCLUDE"; webPageDetectionRule.EntityCategory = "Pages&IFrames"; pageDetectionRulesList.Add(webPageDetectionRule); } } } if (isTokenPropertyNull(pageRulesObject, "customNamingExcludeRules") == false) { JArray excludeRulesArray = (JArray)pageRulesObject["customNamingExcludeRules"]; foreach (JObject excludeRuleObject in excludeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "EXCLUDE"; webPageDetectionRule.EntityCategory = "Pages&IFrames"; pageDetectionRulesList.Add(webPageDetectionRule); } } } } #endregion #region AJAX Rules JObject ajaxRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentAjaxRulesDataFilePath(jobTarget)); if (ajaxRulesObject != null) { if (isTokenPropertyNull(ajaxRulesObject, "customNamingIncludeRules") == false) { JArray includeRulesArray = (JArray)ajaxRulesObject["customNamingIncludeRules"]; foreach (JObject includeRuleObject in includeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "INCLUDE"; webPageDetectionRule.EntityCategory = "Ajax"; pageDetectionRulesList.Add(webPageDetectionRule); } } } if (isTokenPropertyNull(ajaxRulesObject, "customNamingExcludeRules") == false) { JArray excludeRulesArray = (JArray)ajaxRulesObject["customNamingExcludeRules"]; foreach (JObject excludeRuleObject in excludeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "EXCLUDE"; webPageDetectionRule.EntityCategory = "Ajax"; pageDetectionRulesList.Add(webPageDetectionRule); } } } if (isTokenPropertyNull(ajaxRulesObject, "eventServiceIncludeRules") == false) { JArray includeRulesArray = (JArray)ajaxRulesObject["eventServiceIncludeRules"]; foreach (JObject includeRuleObject in includeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "INCLUDE"; webPageDetectionRule.EntityCategory = "AjaxEventsSvc"; pageDetectionRulesList.Add(webPageDetectionRule); } } } if (isTokenPropertyNull(ajaxRulesObject, "eventServiceExcludeRules") == false) { JArray excludeRulesArray = (JArray)ajaxRulesObject["eventServiceExcludeRules"]; foreach (JObject excludeRuleObject in excludeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "EXCLUDE"; webPageDetectionRule.EntityCategory = "AjaxEventsSvc"; pageDetectionRulesList.Add(webPageDetectionRule); } } } } #endregion #region Virtual Page Rules JObject virtualPageRulesObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBAgentVirtualPageRulesDataFilePath(jobTarget)); if (virtualPageRulesObject != null) { if (isTokenPropertyNull(virtualPageRulesObject, "customNamingIncludeRules") == false) { JArray includeRulesArray = (JArray)virtualPageRulesObject["customNamingIncludeRules"]; foreach (JObject includeRuleObject in includeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(includeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "INCLUDE"; webPageDetectionRule.EntityCategory = "VirtualPage"; pageDetectionRulesList.Add(webPageDetectionRule); } } } if (isTokenPropertyNull(virtualPageRulesObject, "customNamingExcludeRules") == false) { JArray excludeRulesArray = (JArray)virtualPageRulesObject["customNamingExcludeRules"]; foreach (JObject excludeRuleObject in excludeRulesArray) { WEBPageDetectionRule webPageDetectionRule = fillWebPageDetectionRule(excludeRuleObject, jobTarget); if (webPageDetectionRule != null) { webPageDetectionRule.DetectionType = "EXCLUDE"; webPageDetectionRule.EntityCategory = "VirtualPage"; pageDetectionRulesList.Add(webPageDetectionRule); } } } } #endregion // Sort them pageDetectionRulesList = pageDetectionRulesList.OrderBy(o => o.EntityCategory).ThenBy(o => o.DetectionType).ThenBy(o => o.Priority).ToList(); FileIOHelper.WriteListToCSVFile(pageDetectionRulesList, new WEBPageDetectionRuleReportMap(), FilePathMap.WEBAgentPageAjaxVirtualPageRulesIndexFilePath(jobTarget)); loggerConsole.Info("Completed {0} Rules", pageDetectionRulesList.Count); #endregion #region Synthetic Jobs loggerConsole.Info("Synthetic Jobs"); List <WEBSyntheticJobDefinition> syntheticJobDefinitionsList = null; JObject syntheticJobsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.WEBSyntheticJobsDataFilePath(jobTarget)); if (syntheticJobsObject != null) { if (isTokenPropertyNull(syntheticJobsObject, "jobListDatas") == false) { JArray syntheticJobsArray = (JArray)syntheticJobsObject["jobListDatas"]; syntheticJobDefinitionsList = new List <WEBSyntheticJobDefinition>(syntheticJobsArray.Count); foreach (JObject syntheticJobObject in syntheticJobsArray) { if (isTokenPropertyNull(syntheticJobObject, "config") == false) { JObject syntheticJobConfigObject = (JObject)syntheticJobObject["config"]; WEBSyntheticJobDefinition syntheticJobDefinition = new WEBSyntheticJobDefinition(); syntheticJobDefinition.Controller = jobTarget.Controller; syntheticJobDefinition.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); syntheticJobDefinition.ApplicationName = jobTarget.Application; syntheticJobDefinition.ApplicationID = jobTarget.ApplicationID; syntheticJobDefinition.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, jobTarget.Controller, jobTarget.ApplicationID, DEEPLINK_TIMERANGE_LAST_15_MINUTES); syntheticJobDefinition.JobName = getStringValueFromJToken(syntheticJobConfigObject, "description"); syntheticJobDefinition.JobID = getStringValueFromJToken(syntheticJobConfigObject, "id"); syntheticJobDefinition.IsUserEnabled = getBoolValueFromJToken(syntheticJobConfigObject, "userEnabled"); syntheticJobDefinition.IsSystemEnabled = getBoolValueFromJToken(syntheticJobConfigObject, "systemEnabled"); syntheticJobDefinition.FailOnError = getBoolValueFromJToken(syntheticJobConfigObject, "failOnPageError"); syntheticJobDefinition.IsPrivateAgent = getBoolValueFromJToken(syntheticJobObject, "hasPrivateAgent"); syntheticJobDefinition.RateUnit = getStringValueFromJToken(syntheticJobConfigObject["rate"], "unit"); syntheticJobDefinition.Rate = getIntValueFromJToken(syntheticJobConfigObject["rate"], "value"); syntheticJobDefinition.Timeout = getIntValueFromJToken(syntheticJobConfigObject, "timeoutSeconds"); syntheticJobDefinition.Days = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "daysOfWeek", true); syntheticJobDefinition.Browsers = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "browserCodes", true); syntheticJobDefinition.Locations = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "locationCodes", true); if (syntheticJobDefinition.Locations.Length > 0) { syntheticJobDefinition.NumLocations = ((JArray)syntheticJobConfigObject["locationCodes"]).Count(); } syntheticJobDefinition.ScheduleMode = getStringValueFromJToken(syntheticJobConfigObject, "scheduleMode"); syntheticJobDefinition.URL = getStringValueFromJToken(syntheticJobConfigObject, "url"); syntheticJobDefinition.Script = getStringValueFromJToken(syntheticJobConfigObject["script"], "script"); if (syntheticJobDefinition.URL.Length > 0) { syntheticJobDefinition.JobType = "URL"; } else { syntheticJobDefinition.JobType = "SCRIPT"; } syntheticJobDefinition.Network = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "networkProfile", false); syntheticJobDefinition.Config = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "composableConfig", false); syntheticJobDefinition.PerfCriteria = getStringValueOfObjectFromJToken(syntheticJobConfigObject, "performanceCriteria", false); syntheticJobDefinition.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(syntheticJobConfigObject, "created")); try { syntheticJobDefinition.CreatedOn = syntheticJobDefinition.CreatedOnUtc.ToLocalTime(); } catch { } syntheticJobDefinition.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(syntheticJobConfigObject, "updated")); try { syntheticJobDefinition.UpdatedOn = syntheticJobDefinition.UpdatedOnUtc.ToLocalTime(); } catch { } syntheticJobDefinitionsList.Add(syntheticJobDefinition); } } // Sort them syntheticJobDefinitionsList = syntheticJobDefinitionsList.OrderBy(o => o.JobName).ToList(); FileIOHelper.WriteListToCSVFile(syntheticJobDefinitionsList, new WEBSyntheticJobDefinitionReportMap(), FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget)); loggerConsole.Info("Completed {0} Synthetic Jobs", syntheticJobDefinitionsList.Count); } } #endregion #region Application Settings if (pageDetectionRulesList != null) { applicationConfiguration.NumPageRulesInclude = pageDetectionRulesList.Count(r => r.EntityCategory == "Pages&IFrames" && r.DetectionType == "INCLUDE"); applicationConfiguration.NumPageRulesExclude = pageDetectionRulesList.Count(r => r.EntityCategory == "Pages&IFrames" && r.DetectionType == "EXCLUDE"); applicationConfiguration.NumAJAXRulesInclude = pageDetectionRulesList.Count(r => r.EntityCategory == "Ajax" && r.DetectionType == "INCLUDE"); applicationConfiguration.NumAJAXRulesExclude = pageDetectionRulesList.Count(r => r.EntityCategory == "Ajax" && r.DetectionType == "EXCLUDE"); applicationConfiguration.NumVirtPageRulesInclude = pageDetectionRulesList.Count(r => r.EntityCategory == "VirtualPage" && r.DetectionType == "INCLUDE"); applicationConfiguration.NumVirtPageRulesExclude = pageDetectionRulesList.Count(r => r.EntityCategory == "VirtualPage" && r.DetectionType == "EXCLUDE"); } if (syntheticJobDefinitionsList != null) { applicationConfiguration.NumSyntheticJobs = syntheticJobDefinitionsList.Count; } List <WEBApplicationConfiguration> applicationConfigurationsList = new List <WEBApplicationConfiguration>(1); applicationConfigurationsList.Add(applicationConfiguration); FileIOHelper.WriteListToCSVFile(applicationConfigurationsList, new WEBApplicationConfigurationReportMap(), FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + applicationConfigurationsList.Count; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.WEBConfigurationReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.WEBConfigurationReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.WEBApplicationConfigurationReportFilePath(), FilePathMap.WEBApplicationConfigurationIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.WEBAgentPageAjaxVirtualPageRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.WEBAgentPageAjaxVirtualPageRulesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.WEBAgentPageAjaxVirtualPageRulesReportFilePath(), FilePathMap.WEBAgentPageAjaxVirtualPageRulesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.WEBSyntheticJobsReportFilePath(), FilePathMap.WEBSyntheticJobsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(jobConfiguration) == false) { return(true); } try { loggerConsole.Info("Prepare Users, Groups, Roles and Permissions Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER RBAC Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER RBAC Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_USERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "Types of Users"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_USERS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_USERS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_USERS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_GROUPS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "Types of Groups"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_GROUPS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_GROUPS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_GROUPS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_ROLES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "Types of Roles"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_ROLES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_ROLES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_ROLES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_PERMISSIONS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "Types of Permissions"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_PERMISSIONS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_PERMISSIONS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_PERMISSIONS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_USER_PERMISSIONS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "Types of User Permissions"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_USER_PERMISSIONS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_USER_PERMISSIONS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", REPORT_RBAC_SHEET_USER_PERMISSIONS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_GROUP_MEMBERSHIPS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(REPORT_RBAC_SHEET_ROLE_MEMBERSHIPS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(REPORT_RBAC_LIST_SHEET_START_TABLE_AT + 1, 1); #endregion loggerConsole.Info("Fill Users, Groups, Roles and Permissions Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.RBACControllerSummaryReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region Users loggerConsole.Info("List of Users"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_USERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.UsersReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region Groups loggerConsole.Info("List of Groups"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_GROUPS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.GroupsReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region Roles loggerConsole.Info("List of Roles"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_ROLES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.RolesReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region Permissions loggerConsole.Info("List of Permissions"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_PERMISSIONS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.PermissionsReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region User Permissions loggerConsole.Info("List of User Permissions"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_USER_PERMISSIONS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.UserPermissionsReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region Group Memberships loggerConsole.Info("List of Group Memberships"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_GROUP_MEMBERSHIPS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.GroupMembershipsReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion #region Role Memberships loggerConsole.Info("List of Role Memberships"); sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_ROLE_MEMBERSHIPS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.RoleMembershipsReportFilePath(), 0, sheet, REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1); #endregion loggerConsole.Info("Finalize Users, Groups, Roles and Permissions Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["SecurityProvider"].Position + 1).Width = 20; } #endregion #region Users // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_USERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_USERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["UserName"].Position + 1).Width = 20; sheet.Column(table.Columns["DisplayName"].Position + 1).Width = 20; sheet.Column(table.Columns["SecurityProvider"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_USERS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT, 1], range, REPORT_RBAC_PIVOT_USERS); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "CreatedBy"); addFilterFieldToPivot(pivot, "UpdatedBy"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "UserName"); addColumnFieldToPivot(pivot, "SecurityProvider", eSortType.Ascending); addDataFieldToPivot(pivot, "UserID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(REPORT_RBAC_PIVOT_USERS_GRAPH, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; } #endregion #region Groups // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_GROUPS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_GROUPS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["GroupName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 20; sheet.Column(table.Columns["SecurityProvider"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_GROUPS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT, 1], range, REPORT_RBAC_PIVOT_GROUPS); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "CreatedBy"); addFilterFieldToPivot(pivot, "UpdatedBy"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "GroupName"); addColumnFieldToPivot(pivot, "SecurityProvider", eSortType.Ascending); addDataFieldToPivot(pivot, "GroupID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(REPORT_RBAC_PIVOT_GROUPS_GRAPH, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; } #endregion #region Roles // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_ROLES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_ROLES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["RoleName"].Position + 1).Width = 30; sheet.Column(table.Columns["Description"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_ROLES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT, 1], range, REPORT_RBAC_PIVOT_ROLES); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "CreatedBy"); addFilterFieldToPivot(pivot, "UpdatedBy"); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "RoleName"); addDataFieldToPivot(pivot, "RoleID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(REPORT_RBAC_PIVOT_ROLES_GRAPH, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; } #endregion #region Permissions // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_PERMISSIONS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_PERMISSIONS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["RoleName"].Position + 1).Width = 20; sheet.Column(table.Columns["PermissionName"].Position + 1).Width = 20; sheet.Column(table.Columns["EntityName"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_PERMISSIONS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT, 1], range, REPORT_RBAC_PIVOT_PERMISSIONS); setDefaultPivotTableSettings(pivot); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "RoleName"); addRowFieldToPivot(pivot, "EntityName"); addRowFieldToPivot(pivot, "PermissionName"); addColumnFieldToPivot(pivot, "Allowed"); addDataFieldToPivot(pivot, "PermissionID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(REPORT_RBAC_PIVOT_PERMISSIONS_GRAPH, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; } #endregion #region User Permissions // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_USER_PERMISSIONS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_USER_PERMISSIONS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["UserName"].Position + 1).Width = 20; sheet.Column(table.Columns["UserSecurityProvider"].Position + 1).Width = 15; sheet.Column(table.Columns["GroupName"].Position + 1).Width = 20; sheet.Column(table.Columns["GroupSecurityProvider"].Position + 1).Width = 15; sheet.Column(table.Columns["RoleName"].Position + 1).Width = 30; sheet.Column(table.Columns["PermissionName"].Position + 1).Width = 20; sheet.Column(table.Columns["EntityName"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_USER_PERMISSIONS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[REPORT_RBAC_PIVOT_SHEET_START_PIVOT_AT + REPORT_RBAC_PIVOT_SHEET_CHART_HEIGHT, 1], range, REPORT_RBAC_PIVOT_USER_PERMISSIONS); setDefaultPivotTableSettings(pivot); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "UserName"); addRowFieldToPivot(pivot, "GroupName"); addRowFieldToPivot(pivot, "RoleName"); addRowFieldToPivot(pivot, "EntityName"); addRowFieldToPivot(pivot, "PermissionName"); addColumnFieldToPivot(pivot, "Allowed"); addDataFieldToPivot(pivot, "PermissionID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(REPORT_RBAC_PIVOT_USER_PERMISSIONS_GRAPH, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; sheet.Column(6).Width = 20; } #endregion #region Group Memberships // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_GROUP_MEMBERSHIPS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_GROUP_MEMBERSHIPS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["GroupName"].Position + 1).Width = 20; sheet.Column(table.Columns["UserName"].Position + 1).Width = 20; } #endregion #region Role Memberships // Make table sheet = excelReport.Workbook.Worksheets[REPORT_RBAC_SHEET_ROLE_MEMBERSHIPS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > REPORT_RBAC_LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[REPORT_RBAC_LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, REPORT_RBAC_TABLE_ROLE_MEMBERSHIPS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["RoleName"].Position + 1).Width = 30; sheet.Column(table.Columns["EntityName"].Position + 1).Width = 20; } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.RBACExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.ReportJobFilePath; stepTimingFunction.StepName = programOptions.ReportJob.Status.ToString(); stepTimingFunction.StepID = (int)programOptions.ReportJob.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = 0; this.DisplayJobStepStartingStatus(programOptions); this.FilePathMap = new FilePathMap(programOptions); try { FileIOHelper.CreateFolder(this.FilePathMap.Report_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_GraphViz_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_Diagram_SVG_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_Diagram_PNG_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_Diagram_PDF_FolderPath()); #region Construct object hierarchy with grants Account account = buildObjectHierarchyWithGrants(); #endregion List <Role> rolesList = FileIOHelper.ReadListFromCSVFile <Role>(FilePathMap.Report_RoleDetail_FilePath(), new RoleMap()); if (rolesList != null) { #region Make GraphViz charts loggerConsole.Info("Creating visualizations for {0} roles", rolesList.Count); Role syntheticRoleAll = new Role(); syntheticRoleAll.Name = "ALL_ROLES_TOGETHER_SYNTHETIC"; rolesList.Insert(0, syntheticRoleAll); ParallelOptions parallelOptions = new ParallelOptions(); if (programOptions.ProcessSequentially == true) { parallelOptions.MaxDegreeOfParallelism = 1; } int j = 0; Parallel.ForEach <Role, int>( rolesList, parallelOptions, () => 0, (role, loop, subtotal) => { logger.Info("Processing visualization for {0}", role); List <RoleHierarchy> thisRoleAndItsRelationsHierarchiesList = FileIOHelper.ReadListFromCSVFile <RoleHierarchy>(FilePathMap.Report_RoleHierarchy_RoleAndItsRelations_FilePath(role.Name), new RoleHierarchyMap());; List <Role> thisRoleAndItsRelationsList = FileIOHelper.ReadListFromCSVFile <Role>(FilePathMap.Report_RoleDetail_RoleAndItsRelations_FilePath(role.Name), new RoleMap()); if (role == syntheticRoleAll) { thisRoleAndItsRelationsHierarchiesList = FileIOHelper.ReadListFromCSVFile <RoleHierarchy>(FilePathMap.Report_RoleHierarchy_FilePath(), new RoleHierarchyMap());; thisRoleAndItsRelationsList = FileIOHelper.ReadListFromCSVFile <Role>(FilePathMap.Report_RoleDetail_FilePath(), new RoleMap()); } if (thisRoleAndItsRelationsList != null && thisRoleAndItsRelationsHierarchiesList != null) { Dictionary <string, Role> rolesDict = thisRoleAndItsRelationsList.ToDictionary(k => k.Name, r => r); Dictionary <string, Role> roleNamesOutput = new Dictionary <string, Role>(thisRoleAndItsRelationsList.Count); Role roleBeingOutput = null; StringBuilder sbGraphViz = new StringBuilder(64 * thisRoleAndItsRelationsHierarchiesList.Count + 128); // Start the graph and set its default settings sbGraphViz.AppendLine("digraph {"); sbGraphViz.AppendLine(" layout=\"dot\";"); sbGraphViz.AppendLine(" rankdir=\"TB\";"); sbGraphViz.AppendLine(" center=true;"); sbGraphViz.AppendLine(" splines=\"ortho\";"); sbGraphViz.AppendLine(" overlap=false;"); //sbGraphViz.AppendLine(" colorscheme=\"SVG\";"); sbGraphViz.AppendLine(" node [shape=\"rect\" style=\"filled,rounded\" fontname=\"Courier New\"];"); sbGraphViz.AppendLine(" edge [fontname=\"Courier New\"];"); sbGraphViz.AppendFormat(" // Graph for the Role {0}", role); sbGraphViz.AppendLine(); #region Role boxes // Role boxes sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" // Roles"); sbGraphViz.AppendLine(" subgraph cluster_roles {"); sbGraphViz.AppendFormat(" label = \"roles related to: {0}\";", role); sbGraphViz.AppendLine(); foreach (RoleHierarchy roleHierarchy in thisRoleAndItsRelationsHierarchiesList) { if (roleHierarchy.GrantedTo != "<NOTHING>" && roleNamesOutput.ContainsKey(roleHierarchy.GrantedTo) == false) { // Name of the role with color rolesDict.TryGetValue(roleHierarchy.GrantedTo, out roleBeingOutput); sbGraphViz.AppendFormat(" \"{0}\"{1};", roleHierarchy.GrantedTo.Replace("\"", "\\\""), getRoleStyleAttribute(roleBeingOutput)); sbGraphViz.AppendLine(); roleNamesOutput.Add(roleHierarchy.GrantedTo, roleBeingOutput); } if (roleNamesOutput.ContainsKey(roleHierarchy.Name) == false) { // Name of the role with color rolesDict.TryGetValue(roleHierarchy.Name, out roleBeingOutput); sbGraphViz.AppendFormat(" \"{0}\"{1};", roleHierarchy.Name.Replace("\"", "\\\""), getRoleStyleAttribute(roleBeingOutput)); sbGraphViz.AppendLine(); roleNamesOutput.Add(roleHierarchy.Name, roleBeingOutput); } } sbGraphViz.AppendLine(" }// /Roles"); #endregion #region Role hierachy // Role connections sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" // Role hierarchy"); foreach (RoleHierarchy roleHierarchy in thisRoleAndItsRelationsHierarchiesList) { if (roleHierarchy.GrantedTo == "<NOTHING>") { continue; } // Role to role connector sbGraphViz.AppendFormat(" \"{0}\"->\"{1}\";", roleHierarchy.GrantedTo.Replace("\"", "\\\""), roleHierarchy.Name.Replace("\"", "\\\"")); sbGraphViz.AppendLine(); } sbGraphViz.AppendLine(" // /Role hierarchy"); #endregion if (role != syntheticRoleAll) { #region Databases, Schemas, Tables and Views sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" // Databases"); sbGraphViz.AppendLine(" subgraph cluster_db_wrapper {"); sbGraphViz.AppendLine(" label = \"Databases\";"); sbGraphViz.AppendLine(); int databaseIndex = 0; foreach (Database database in account.Databases) { // Should output database bool isDatabaseRelatedToSelectedRole = false; foreach (Grant grant in database.Grants) { if (grant.Privilege == "USAGE" || grant.Privilege == "OWNERSHIP") { if (roleNamesOutput.ContainsKey(grant.GrantedTo) == true) { isDatabaseRelatedToSelectedRole = true; break; } } } if (isDatabaseRelatedToSelectedRole == false) { continue; } // Output database sbGraphViz.AppendFormat(" // Database {0}", database.FullName); sbGraphViz.AppendLine(); sbGraphViz.AppendFormat(" subgraph cluster_db_{0} {{", databaseIndex); sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" style=\"filled\";"); sbGraphViz.AppendLine(" fillcolor=\"snow\";"); sbGraphViz.AppendFormat(" label = \"db: {0}\";", database.ShortName); sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" node [shape=\"cylinder\" fillcolor=\"darkkhaki\"];"); sbGraphViz.AppendLine(); sbGraphViz.AppendFormat(" \"{0}\";", database.FullName); sbGraphViz.AppendLine(); sbGraphViz.AppendLine(); // List of schemas with number of tables and views sbGraphViz.AppendFormat(" \"{0}.schema\" [shape=\"folder\" label=<", database.FullName); sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" <table border=\"0\" cellborder=\"1\" bgcolor=\"white\">"); sbGraphViz.AppendLine(" <tr><td>S</td><td>T</td><td>V</td></tr>"); int schemaLimit = 0; foreach (Schema schema in database.Schemas) { // Only output if (schemaLimit >= 10) { sbGraphViz.AppendFormat(" <tr><td align=\"left\">Up to {0}</td><td align=\"right\">...</td><td align=\"right\">...</td></tr>", database.Schemas.Count); sbGraphViz.AppendLine(); break; } sbGraphViz.AppendFormat(" <tr><td align=\"left\">{0}</td><td align=\"right\">{1}</td><td align=\"right\">{2}</td></tr>", schema.ShortName, schema.Tables.Count, schema.Views.Count); sbGraphViz.AppendLine(); schemaLimit++; } sbGraphViz.AppendLine(" </table>>];"); // Connect database to schemas sbGraphViz.AppendFormat(" \"{0}\"->\"{0}.schema\" [style=\"invis\"];", database.FullName); sbGraphViz.AppendLine(); sbGraphViz.AppendFormat(" }} // /Database {0}", database.FullName); sbGraphViz.AppendLine(); databaseIndex++; } sbGraphViz.AppendLine(" } // /Databases"); #endregion #region Roles using databases sbGraphViz.AppendLine(); sbGraphViz.AppendLine(" // Roles using databases"); // Output connectors from roles USAGE'ing databases foreach (Database database in account.Databases) { foreach (Grant grant in database.Grants) { if (grant.Privilege == "USAGE" || grant.Privilege == "OWNERSHIP") { if (roleNamesOutput.ContainsKey(grant.GrantedTo) == true) { sbGraphViz.AppendFormat(" \"{0}\"->\"{1}\" [color=\"darkkhaki\"];", grant.GrantedTo, grant.ObjectNameUnquoted); sbGraphViz.AppendLine(); } } } } sbGraphViz.AppendLine(" // /Roles using databases"); #endregion } #region Legend // Output Legend sbGraphViz.AppendLine(); string legend = @" // Legend ""legend"" [label=< <table border=""0"" cellborder=""0"" bgcolor=""white""> <tr><td align=""center"">Legend</td></tr> <tr><td align=""left"" bgcolor=""lightgray"">BUILT IN</td></tr> <tr><td align=""left"" bgcolor=""beige"">SCIM</td></tr> <tr><td align=""left"" bgcolor=""wheat"">ROLE MANAGEMENT</td></tr> <tr><td align=""left"" bgcolor=""orchid"">FUNCTIONAL</td></tr> <tr><td align=""left"" bgcolor=""plum"">FUNCTIONAL NOT UNDER SYSADMIN</td></tr> <tr><td align=""left"" bgcolor=""lightblue"">ACCESS</td></tr> <tr><td align=""left"" bgcolor=""azure"">ACCESS NOT UNDER SYSADMIN</td></tr> <tr><td align=""left"" bgcolor=""orange"">NOT UNDER ACCOUNTADMIN</td></tr> </table>>];"; sbGraphViz.AppendLine(legend); #endregion // Close the graph sbGraphViz.AppendLine("}"); FileIOHelper.SaveFileToPath(sbGraphViz.ToString(), FilePathMap.Report_GraphViz_RoleAndItsRelationsGrants_FilePath(role.Name), false); } return(1); }, (finalResult) => { Interlocked.Add(ref j, finalResult); if (j % 50 == 0) { Console.Write("[{0}].", j); } } ); loggerConsole.Info("Completed {0} Roles", rolesList.Count); #endregion #region HTML file with Links to Files loggerConsole.Info("Creating HTML links for {0} roles", rolesList.Count); // Create the HTML page with links for all the images XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.OmitXmlDeclaration = true; xmlWriterSettings.Indent = true; using (XmlWriter xmlWriter = XmlWriter.Create(FilePathMap.UsersRolesAndGrantsWebReportFilePath(), xmlWriterSettings)) { xmlWriter.WriteDocType("html", null, null, null); xmlWriter.WriteStartElement("html"); xmlWriter.WriteStartElement("head"); xmlWriter.WriteStartElement("title"); xmlWriter.WriteString(String.Format("Snowflake Grants Report {0} {1} roles", programOptions.ReportJob.Connection, rolesList.Count)); xmlWriter.WriteEndElement(); // </title> xmlWriter.WriteEndElement(); // </head> xmlWriter.WriteStartElement("body"); xmlWriter.WriteStartElement("table"); xmlWriter.WriteAttributeString("border", "1"); // Header row xmlWriter.WriteStartElement("tr"); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("Role"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("Type"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("# Parents"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("# Children"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("# Ancestry Paths"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("Online"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("SVG"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("PNG"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("th"); xmlWriter.WriteString("PDF"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); // </tr> foreach (Role role in rolesList) { xmlWriter.WriteStartElement("tr"); xmlWriter.WriteStartElement("td"); xmlWriter.WriteString(role.Name); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("td"); xmlWriter.WriteString(role.Type.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("td"); xmlWriter.WriteString(role.NumParentRoles.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("td"); xmlWriter.WriteString(role.NumChildRoles.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("td"); xmlWriter.WriteString(role.NumAncestryPaths.ToString()); xmlWriter.WriteEndElement(); string graphText = FileIOHelper.ReadFileFromPath(FilePathMap.Report_GraphViz_RoleAndItsRelationsGrants_FilePath(role.Name)); xmlWriter.WriteStartElement("td"); // https://edotor.net xmlWriter.WriteStartElement("a"); xmlWriter.WriteAttributeString("href", String.Format("https://edotor.net/?#{0}", Uri.EscapeDataString(graphText))); xmlWriter.WriteString("Online"); xmlWriter.WriteEndElement(); // </a> // // http://magjac.com/graphviz-visual-editor // xmlWriter.WriteStartElement("a"); // xmlWriter.WriteAttributeString("href", String.Format("http://magjac.com/graphviz-visual-editor/?dot={0}", Uri.EscapeDataString(graphText))); // xmlWriter.WriteString("Opt2"); // xmlWriter.WriteEndElement(); // </a> // // https://stamm-wilbrandt.de/GraphvizFiddle/2.1.2/index.html // xmlWriter.WriteStartElement("a"); // xmlWriter.WriteAttributeString("href", String.Format("https://stamm-wilbrandt.de/GraphvizFiddle/2.1.2/index.html?#{0}", Uri.EscapeDataString(graphText))); // xmlWriter.WriteString("Opt3"); // xmlWriter.WriteEndElement(); // </a> // // https://dreampuf.github.io/GraphvizOnline // xmlWriter.WriteStartElement("a"); // xmlWriter.WriteAttributeString("href", String.Format("https://dreampuf.github.io/GraphvizOnline/#{0}", Uri.EscapeDataString(graphText))); // xmlWriter.WriteString("Opt4"); // xmlWriter.WriteEndElement(); // </a> xmlWriter.WriteEndElement(); // </td> xmlWriter.WriteStartElement("td"); xmlWriter.WriteStartElement("a"); xmlWriter.WriteAttributeString("href", FilePathMap.Report_Diagram_SVG_RoleAndItsRelationsGrants_FilePath(role.Name, false)); xmlWriter.WriteString("SVG"); xmlWriter.WriteEndElement(); // </a> xmlWriter.WriteEndElement(); // </td> xmlWriter.WriteStartElement("td"); xmlWriter.WriteStartElement("a"); xmlWriter.WriteAttributeString("href", FilePathMap.Report_Diagram_PNG_RoleAndItsRelationsGrants_FilePath(role.Name, false)); xmlWriter.WriteString("PNG"); xmlWriter.WriteEndElement(); // </a> xmlWriter.WriteEndElement(); // </td> xmlWriter.WriteStartElement("td"); xmlWriter.WriteStartElement("a"); xmlWriter.WriteAttributeString("href", FilePathMap.Report_Diagram_PDF_RoleAndItsRelationsGrants_FilePath(role.Name, false)); xmlWriter.WriteString("PDF"); xmlWriter.WriteEndElement(); // </a> xmlWriter.WriteEndElement(); // </td> xmlWriter.WriteEndElement(); // </tr> } xmlWriter.WriteEndElement(); // </table> xmlWriter.WriteEndElement(); // </body> xmlWriter.WriteEndElement(); // </html> } #endregion #region Make SVG, PNG and PDF Files with GraphViz binaries loggerConsole.Info("Making picture files for {0} roles", rolesList.Count); GraphVizDriver graphVizDriver = new GraphVizDriver(); graphVizDriver.ValidateToolInstalled(programOptions); if (graphVizDriver.ExecutableFilePath.Length > 0) { j = 0; Parallel.ForEach <Role, int>( rolesList, parallelOptions, () => 0, (role, loop, subtotal) => { loggerConsole.Info("Rendering graphs for {0}", role); graphVizDriver.ConvertGraphVizToFile( FilePathMap.Report_GraphViz_RoleAndItsRelationsGrants_FilePath(role.Name), FilePathMap.Report_Diagram_SVG_RoleAndItsRelationsGrants_FilePath(role.Name, true), "svg"); graphVizDriver.ConvertGraphVizToFile( FilePathMap.Report_GraphViz_RoleAndItsRelationsGrants_FilePath(role.Name), FilePathMap.Report_Diagram_PNG_RoleAndItsRelationsGrants_FilePath(role.Name, true), "png"); graphVizDriver.ConvertGraphVizToFile( FilePathMap.Report_GraphViz_RoleAndItsRelationsGrants_FilePath(role.Name), FilePathMap.Report_Diagram_PDF_RoleAndItsRelationsGrants_FilePath(role.Name, true), "pdf"); return(1); }, (finalResult) => { Interlocked.Add(ref j, finalResult); if (j % 10 == 0) { Console.Write("[{0}].", j); } } ); loggerConsole.Info("Completed {0} Roles", rolesList.Count); } #endregion } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(programOptions, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0) { logger.Warn("No {0} targets to process", APPLICATION_TYPE_APM); loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_APM); return(true); } try { loggerConsole.Info("Prepare Entity Flowmaps Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER Entity Flowmaps Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Entity Flowmaps Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT - 13 + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ACTIVITYFLOW); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT - 13 + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_TIERS_ACTIVITYFLOW); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT - 13 + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_NODES_ACTIVITYFLOW); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT - 13 + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_BACKENDS_ACTIVITYFLOW); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT - 13 + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_BUSINESS_TRANSACTIONS_ACTIVITYFLOW); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT - 13 + 1, 1); #endregion loggerConsole.Info("Fill Entity Flowmaps Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT - 13, 1); #endregion #region Applications loggerConsole.Info("Applications Flowmap"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ACTIVITYFLOW]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ApplicationsFlowmapReportFilePath(), 0, typeof(ActivityFlow), sheet, LIST_SHEET_START_TABLE_AT - 13, 1); #endregion #region Tiers loggerConsole.Info("Tiers Flowmap"); sheet = excelReport.Workbook.Worksheets[SHEET_TIERS_ACTIVITYFLOW]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.TiersFlowmapReportFilePath(), 0, typeof(ActivityFlow), sheet, LIST_SHEET_START_TABLE_AT - 13, 1); #endregion #region Nodes loggerConsole.Info("Nodes Flowmap"); sheet = excelReport.Workbook.Worksheets[SHEET_NODES_ACTIVITYFLOW]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.NodesFlowmapReportFilePath(), 0, typeof(ActivityFlow), sheet, LIST_SHEET_START_TABLE_AT - 13, 1); #endregion #region Backends loggerConsole.Info("Backends Flowmap"); sheet = excelReport.Workbook.Worksheets[SHEET_BACKENDS_ACTIVITYFLOW]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BackendsFlowmapReportFilePath(), 0, typeof(ActivityFlow), sheet, LIST_SHEET_START_TABLE_AT - 13, 1); #endregion #region Business Transactions loggerConsole.Info("Business Transactions Flowmap"); sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_TRANSACTIONS_ACTIVITYFLOW]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.BusinessTransactionsFlowmapReportFilePath(), 0, typeof(ActivityFlow), sheet, LIST_SHEET_START_TABLE_AT - 13, 1); #endregion loggerConsole.Info("Finalize Entity Flowmaps Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT - 13) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT - 13, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ACTIVITYFLOW]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT - 13) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT - 13, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ACTIVITYFLOW); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; adjustColumnsOfActivityFlowRowTableInMetricReport(APMApplication.ENTITY_TYPE, sheet, table); } #endregion #region Tiers // Make table sheet = excelReport.Workbook.Worksheets[SHEET_TIERS_ACTIVITYFLOW]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT - 13) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT - 13, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_TIERS_ACTIVITYFLOW); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; adjustColumnsOfActivityFlowRowTableInMetricReport(APMTier.ENTITY_TYPE, sheet, table); } #endregion #region Nodes // Make table sheet = excelReport.Workbook.Worksheets[SHEET_NODES_ACTIVITYFLOW]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT - 13) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT - 13, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_NODES_ACTIVITYFLOW); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; adjustColumnsOfActivityFlowRowTableInMetricReport(APMNode.ENTITY_TYPE, sheet, table); } #endregion #region Backends // Make table sheet = excelReport.Workbook.Worksheets[SHEET_BACKENDS_ACTIVITYFLOW]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT - 13) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT - 13, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_BACKENDS_ACTIVITYFLOW); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; adjustColumnsOfActivityFlowRowTableInMetricReport(APMBackend.ENTITY_TYPE, sheet, table); } #endregion #region Business Transactions // Make table sheet = excelReport.Workbook.Worksheets[SHEET_BUSINESS_TRANSACTIONS_ACTIVITYFLOW]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT - 13) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT - 13, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_BUSINESS_TRANSACTIONS_ACTIVITYFLOW); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; adjustColumnsOfActivityFlowRowTableInMetricReport(APMBusinessTransaction.ENTITY_TYPE, sheet, table); } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.FlowmapsExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_BIQ) == 0) { return(true); } bool reportFolderCleaned = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_BIQ) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Saved Searches loggerConsole.Info("Saved Searches and Their Widgets"); List <BIQSearch> biqSearchesList = null; List <BIQWidget> biqWidgetsList = null; JArray savedSearchesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.BIQSearchesDataFilePath(jobTarget)); if (savedSearchesArray != null) { biqSearchesList = new List <BIQSearch>(savedSearchesArray.Count); biqWidgetsList = new List <BIQWidget>(savedSearchesArray.Count * 8); foreach (JObject savedSearchObject in savedSearchesArray) { BIQSearch search = new BIQSearch(); search.Controller = jobTarget.Controller; search.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); search.ApplicationName = jobTarget.Application; search.ApplicationID = jobTarget.ApplicationID; search.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, search.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); search.SearchName = getStringValueFromJToken(savedSearchObject, "searchName"); search.InternalName = getStringValueFromJToken(savedSearchObject, "name"); search.Description = getStringValueFromJToken(savedSearchObject, "searchDescription"); search.SearchType = getStringValueFromJToken(savedSearchObject, "searchType"); search.SearchMode = getStringValueFromJToken(savedSearchObject, "searchMode"); search.ViewMode = getStringValueFromJToken(savedSearchObject, "viewMode"); search.Visualization = getStringValueFromJToken(savedSearchObject, "visualization"); search.SearchID = getLongValueFromJToken(savedSearchObject, "id"); search.SearchLink = String.Format(DEEPLINK_BIQ_SEARCH, search.Controller, search.SearchID, DEEPLINK_TIMERANGE_LAST_15_MINUTES); search.CreatedBy = getStringValueFromJToken(savedSearchObject, "createdBy"); search.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(savedSearchObject, "createdOn")); try { search.CreatedOn = search.CreatedOnUtc.ToLocalTime(); } catch { } search.UpdatedBy = getStringValueFromJToken(savedSearchObject, "modifiedBy"); search.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(savedSearchObject, "modifiedOn")); try { search.UpdatedOn = search.UpdatedOnUtc.ToLocalTime(); } catch { } if (isTokenPropertyNull(savedSearchObject, "adqlQueries") == false) { try { if (savedSearchObject["adqlQueries"].Count() == 0) { search.Query = String.Empty; } else if (savedSearchObject["adqlQueries"].Count() == 1) { search.Query = savedSearchObject["adqlQueries"][0].ToString(); } else { search.Query = getStringValueOfObjectFromJToken(savedSearchObject, "adqlQueries", false); } } catch { } } if (search.Query.Length > 0) { Regex regexVersion = new Regex(@"(?i).*FROM\s(\S*)\s?.*", RegexOptions.IgnoreCase); Match match = regexVersion.Match(search.Query); if (match != null) { if (match.Groups.Count > 1) { search.DataSource = match.Groups[1].Value; } } } if (isTokenPropertyNull(savedSearchObject, "widgets") == false) { foreach (JObject searchWidget in savedSearchObject["widgets"]) { BIQWidget widget = new BIQWidget(); widget.Controller = search.Controller; widget.ControllerLink = search.ControllerLink; widget.ApplicationName = search.ApplicationName; widget.ApplicationID = search.ApplicationID; widget.ApplicationLink = search.ApplicationLink; widget.SearchName = search.SearchName; widget.SearchType = search.SearchType; widget.SearchMode = search.SearchMode; widget.SearchID = search.SearchID; widget.SearchLink = search.SearchLink; widget.InternalName = getStringValueFromJToken(searchWidget, "name"); widget.WidgetID = getLongValueFromJToken(searchWidget, "id"); if (isTokenPropertyNull(searchWidget, "adqlQueries") == false) { try { if (searchWidget["adqlQueries"].Count() == 0) { widget.Query = String.Empty; } else if (searchWidget["adqlQueries"].Count() == 1) { widget.Query = searchWidget["adqlQueries"][0].ToString(); } else { widget.Query = getStringValueOfObjectFromJToken(searchWidget, "adqlQueries", false); } } catch { } } if (widget.Query.Length > 0) { Regex regexVersion = new Regex(@"(?i).*FROM\s(\S*)\s?.*", RegexOptions.IgnoreCase); Match match = regexVersion.Match(widget.Query); if (match != null) { if (match.Groups.Count > 1) { widget.DataSource = match.Groups[1].Value; } } } if (isTokenPropertyNull(searchWidget, "properties") == false) { JObject searchWidgetPropertiesObject = (JObject)searchWidget["properties"]; widget.WidgetName = getStringValueFromJToken(searchWidgetPropertiesObject, "title"); widget.LegendLayout = getStringValueFromJToken(searchWidgetPropertiesObject, "legendsLayout"); widget.WidgetType = getStringValueFromJToken(searchWidgetPropertiesObject, "type"); widget.Resolution = getStringValueFromJToken(searchWidgetPropertiesObject, "resolution"); widget.Width = getIntValueFromJToken(searchWidgetPropertiesObject, "sizeX"); widget.Height = getIntValueFromJToken(searchWidgetPropertiesObject, "sizeY"); widget.MinWidth = getIntValueFromJToken(searchWidgetPropertiesObject, "minSizeX"); widget.MinHeight = getIntValueFromJToken(searchWidgetPropertiesObject, "minSizeY"); widget.Column = getIntValueFromJToken(searchWidgetPropertiesObject, "col"); widget.Row = getIntValueFromJToken(searchWidgetPropertiesObject, "row"); widget.IsStacking = getBoolValueFromJToken(searchWidgetPropertiesObject, "isStackingEnabled"); widget.IsDrilledDown = getBoolValueFromJToken(searchWidgetPropertiesObject, "isDrilledDown"); widget.FontSize = getIntValueFromJToken(searchWidgetPropertiesObject, "fontSize"); widget.Color = getIntValueFromJToken(searchWidgetPropertiesObject, "color").ToString("X6"); widget.BackgroundColor = getIntValueFromJToken(searchWidgetPropertiesObject, "backgroundColor").ToString("X6"); } if (isTokenPropertyNull(searchWidget, "timeRangeSpecifier") == false) { JObject searchWidgetTimeRangeObject = (JObject)searchWidget["timeRangeSpecifier"]; widget.TimeRangeType = getStringValueFromJToken(searchWidgetTimeRangeObject, "type"); widget.TimeRangeDuration = getIntValueFromJToken(searchWidgetTimeRangeObject, "durationInMinutes"); if (isTokenPropertyNull(searchWidgetTimeRangeObject, "timeRange") == false) { widget.StartTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(searchWidgetTimeRangeObject["timeRange"], "startTime")); try { widget.StartTime = widget.StartTimeUtc.ToLocalTime(); } catch { } widget.EndTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(searchWidgetTimeRangeObject["timeRange"], "endTime")); try { widget.EndTime = widget.EndTimeUtc.ToLocalTime(); } catch { } } } search.NumWidgets++; biqWidgetsList.Add(widget); } } biqSearchesList.Add(search); } // Sort them biqSearchesList = biqSearchesList.OrderBy(o => o.SearchName).ToList(); FileIOHelper.WriteListToCSVFile(biqSearchesList, new BIQSearchReportMap(), FilePathMap.BIQSearchesIndexFilePath(jobTarget)); biqWidgetsList = biqWidgetsList.OrderBy(o => o.SearchName).ThenBy(o => o.WidgetName).ToList(); FileIOHelper.WriteListToCSVFile(biqWidgetsList, new BIQWidgetReportMap(), FilePathMap.BIQWidgetsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + biqSearchesList.Count; } #endregion #region Saved Metrics loggerConsole.Info("Saved Metrics"); List <BIQMetric> biqMetricsList = null; JArray savedMetricsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.BIQMetricsDataFilePath(jobTarget)); if (savedMetricsArray != null) { biqMetricsList = new List <BIQMetric>(savedMetricsArray.Count); foreach (JObject savedMetricObject in savedMetricsArray) { BIQMetric metric = new BIQMetric(); metric.Controller = jobTarget.Controller; metric.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); metric.ApplicationName = jobTarget.Application; metric.ApplicationID = jobTarget.ApplicationID; metric.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, metric.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); metric.MetricName = getStringValueFromJToken(savedMetricObject, "queryName"); metric.MetricDescription = getStringValueFromJToken(savedMetricObject, "queryDescription"); metric.Query = getStringValueFromJToken(savedMetricObject, "adqlQueryString"); if (metric.Query.Length > 0) { Regex regexVersion = new Regex(@"(?i).*FROM\s(\S*)\s?.*", RegexOptions.IgnoreCase); Match match = regexVersion.Match(metric.Query); if (match != null) { if (match.Groups.Count > 1) { metric.DataSource = match.Groups[1].Value; } } } metric.EventType = getStringValueFromJToken(savedMetricObject, "eventType"); metric.IsEnabled = getBoolValueFromJToken(savedMetricObject, "queryExecutionEnabled"); metric.LastExecStatus = getStringValueFromJToken(savedMetricObject, "recentExecutionStatus"); metric.LastExecDuration = getIntValueFromJToken(savedMetricObject, "recentQueryExecutionDuration"); metric.SuccessCount = getIntValueFromJToken(savedMetricObject, "totalSuccessCount"); metric.FailureCount = getIntValueFromJToken(savedMetricObject, "totalFailuresCount"); metric.CreatedBy = getStringValueFromJToken(savedMetricObject, "createdBy"); metric.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(savedMetricObject, "queryCreationTime")); try { metric.CreatedOn = metric.CreatedOnUtc.ToLocalTime(); } catch { } if (isTokenPropertyNull(savedMetricObject, "metricIds") == false) { metric.MetricsIDs = new List <long>(10); foreach (JValue metricIDValue in savedMetricObject["metricIds"]) { long metricID = (long)metricIDValue; metric.MetricsIDs.Add(metricID); } } // Create metric link if (metric.MetricsIDs != null && metric.MetricsIDs.Count > 0) { StringBuilder sb = new StringBuilder(256); foreach (long metricID in metric.MetricsIDs) { if (metricID > 0) { sb.Append(String.Format(DEEPLINK_METRIC_APPLICATION_TARGET_METRIC_ID, metric.ApplicationID, metricID)); sb.Append(","); } } sb.Remove(sb.Length - 1, 1); metric.MetricLink = String.Format(DEEPLINK_METRIC, metric.Controller, metric.ApplicationID, sb.ToString(), DEEPLINK_TIMERANGE_LAST_15_MINUTES); } biqMetricsList.Add(metric); } // Sort them biqMetricsList = biqMetricsList.OrderBy(o => o.MetricName).ToList(); FileIOHelper.WriteListToCSVFile(biqMetricsList, new BIQMetricReportMap(), FilePathMap.BIQMetricsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + biqMetricsList.Count; } #endregion #region Business Journeys loggerConsole.Info("Business Journeys"); List <BIQBusinessJourney> businessJourneysList = null; JArray businessJourneysArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.BIQBusinessJourneysDataFilePath(jobTarget)); if (businessJourneysArray != null) { businessJourneysList = new List <BIQBusinessJourney>(businessJourneysArray.Count); foreach (JObject businessJourneyObject in businessJourneysArray) { BIQBusinessJourney businessJourney = new BIQBusinessJourney(); businessJourney.Controller = jobTarget.Controller; businessJourney.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); businessJourney.ApplicationName = jobTarget.Application; businessJourney.ApplicationID = jobTarget.ApplicationID; businessJourney.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, businessJourney.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); businessJourney.JourneyName = getStringValueFromJToken(businessJourneyObject, "name"); businessJourney.JourneyDescription = getStringValueFromJToken(businessJourneyObject, "description"); businessJourney.JourneyID = getStringValueFromJToken(businessJourneyObject, "id"); businessJourney.State = getStringValueFromJToken(businessJourneyObject, "state"); businessJourney.KeyField = getStringValueFromJToken(businessJourneyObject, "keyFieldName"); businessJourney.IsEnabled = getBoolValueFromJToken(businessJourneyObject, "enabled"); businessJourney.CreatedBy = getStringValueFromJToken(businessJourneyObject, "createdBy"); businessJourney.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(businessJourneyObject, "createdAt")); try { businessJourney.CreatedOn = businessJourney.CreatedOnUtc.ToLocalTime(); } catch { } businessJourney.UpdatedBy = getStringValueFromJToken(businessJourneyObject, "lastModifiedBy"); businessJourney.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(businessJourneyObject, "lastModifiedAt")); try { businessJourney.UpdatedOn = businessJourney.UpdatedOnUtc.ToLocalTime(); } catch { } if (isTokenPropertyNull(businessJourneyObject, "aggregateGraph") == false && isTokenPropertyNull(businessJourneyObject["aggregateGraph"], "root") == false) { StringBuilder sb = new StringBuilder(32 * 10); getStagesRecursive((JObject)businessJourneyObject["aggregateGraph"]["root"], sb); businessJourney.Stages = sb.ToString(); businessJourney.NumStages = businessJourney.Stages.Split('>').Length; } businessJourneysList.Add(businessJourney); } // Sort them businessJourneysList = businessJourneysList.OrderBy(o => o.JourneyName).ToList(); FileIOHelper.WriteListToCSVFile(businessJourneysList, new BIQBusinessJourneyReportMap(), FilePathMap.BIQBusinessJourneysIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + businessJourneysList.Count; } #endregion #region Experience Levels loggerConsole.Info("Experience Levels"); List <BIQExperienceLevel> experienceLevelsList = null; JObject experienceLevelsContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.BIQExperienceLevelsDataFilePath(jobTarget)); if (experienceLevelsContainerObject != null) { if (isTokenPropertyNull(experienceLevelsContainerObject, "items") == false) { JArray experienceLevelsArray = (JArray)experienceLevelsContainerObject["items"]; experienceLevelsList = new List <BIQExperienceLevel>(experienceLevelsArray.Count); foreach (JObject experienceLevelObject in experienceLevelsArray) { BIQExperienceLevel experienceLevel = new BIQExperienceLevel(); experienceLevel.Controller = jobTarget.Controller; experienceLevel.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); experienceLevel.ApplicationName = jobTarget.Application; experienceLevel.ApplicationID = jobTarget.ApplicationID; experienceLevel.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, experienceLevel.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); experienceLevel.ExperienceLevelName = getStringValueFromJToken(experienceLevelObject, "configurationName"); experienceLevel.ExperienceLevelID = getStringValueFromJToken(experienceLevelObject, "id"); experienceLevel.DataSource = getStringValueFromJToken(experienceLevelObject, "eventType"); experienceLevel.EventField = getStringValueFromJToken(experienceLevelObject, "eventField"); experienceLevel.Criteria = getStringValueFromJToken(experienceLevelObject, "criteria"); experienceLevel.ThresholdOperator = getStringValueFromJToken(experienceLevelObject, "thresholdOperator"); experienceLevel.ThresholdValue = getStringValueFromJToken(experienceLevelObject, "thresholdValue"); experienceLevel.Period = getStringValueFromJToken(experienceLevelObject, "compliancePeriod"); experienceLevel.Timezone = getStringValueFromJToken(experienceLevelObject, "timeZone"); experienceLevel.IsActive = getBoolValueFromJToken(experienceLevelObject, "active"); experienceLevel.IsIncludeErrors = getBoolValueFromJToken(experienceLevelObject, "includeErrors"); experienceLevel.NormalThreshold = getIntValueFromJToken(experienceLevelObject, "normalThresholdPercent"); experienceLevel.WarningThreshold = getIntValueFromJToken(experienceLevelObject, "warningThresholdPercent"); //experienceLevel.CriticalThreshold = getIntValueFromJToken(experienceLevelObject, "this needs to be calculated somehow"); experienceLevel.StartOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(experienceLevelObject, "startDate")); try { experienceLevel.StartOn = experienceLevel.StartOnUtc.ToLocalTime(); } catch { } if (isTokenPropertyNull(experienceLevelObject, "metadata") == false) { JObject experienceLevelMetadataObject = (JObject)experienceLevelObject["metadata"]; experienceLevel.CreatedBy = getStringValueFromJToken(experienceLevelMetadataObject, "createdByResolvedName"); experienceLevel.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(experienceLevelMetadataObject, "creationTime")); try { experienceLevel.CreatedOn = experienceLevel.CreatedOnUtc.ToLocalTime(); } catch { } experienceLevel.UpdatedBy = getStringValueFromJToken(experienceLevelMetadataObject, "lastModifiedByResolvedName"); experienceLevel.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(experienceLevelMetadataObject, "lastModifiedTime")); try { experienceLevel.UpdatedOn = experienceLevel.UpdatedOnUtc.ToLocalTime(); } catch { } } if (isTokenPropertyNull(experienceLevelObject, "exclusionPeriodList") == false) { JArray exclusionPeriodsArray = (JArray)experienceLevelObject["exclusionPeriodList"]; experienceLevel.NumExclusionPeriods = exclusionPeriodsArray.Count; experienceLevel.ExclusionPeriodsRaw = getStringValueOfObjectFromJToken(experienceLevelObject, "exclusionPeriodList", false); } experienceLevelsList.Add(experienceLevel); } // Sort them experienceLevelsList = experienceLevelsList.OrderBy(o => o.ExperienceLevelName).ToList(); FileIOHelper.WriteListToCSVFile(experienceLevelsList, new BIQExperienceLevelReportMap(), FilePathMap.BIQExperienceLevelsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + businessJourneysList.Count; } } #endregion #region Schema Fields List <BIQSchema> schemasList = new List <BIQSchema>(16); List <BIQField> schemaFieldsList = new List <BIQField>(16 * 32); List <string> analyticsSchemas = new List <string>(BIQ_SCHEMA_TYPES.Count + 10); analyticsSchemas.AddRange(BIQ_SCHEMA_TYPES); // Add custom schemas if any JObject customSchemasContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.BIQCustomSchemasDataFilePath(jobTarget)); if (customSchemasContainer != null) { JArray customSchemas = JArray.Parse(getStringValueFromJToken(customSchemasContainer, "rawResponse")); foreach (JToken customSchemaToken in customSchemas) { string schemaName = customSchemaToken.ToString(); analyticsSchemas.Add(schemaName); } } // First get known schemas foreach (string schemaName in analyticsSchemas) { loggerConsole.Info("Fields for Schema {0}", schemaName); JArray schemaFieldsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.BIQSchemaFieldsDataFilePath(jobTarget, schemaName)); if (schemaFieldsArray != null) { List <BIQField> schemaFieldsInThisSchemaList = new List <BIQField>(schemaFieldsArray.Count); foreach (JObject schemaFieldObject in schemaFieldsArray) { BIQField field = new BIQField(); field.Controller = jobTarget.Controller; field.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); field.ApplicationName = jobTarget.Application; field.ApplicationID = jobTarget.ApplicationID; field.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, field.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); field.SchemaName = schemaName; field.FieldName = getStringValueFromJToken(schemaFieldObject, "fieldName"); field.FieldType = getStringValueFromJToken(schemaFieldObject, "fieldType"); field.Category = getStringValueFromJToken(schemaFieldObject, "category"); if (isTokenPropertyNull(schemaFieldObject, "parents") == false) { string[] parents = schemaFieldObject["parents"].Select(a => a["fieldName"].ToString()).ToArray(); field.Parents = String.Join(";", parents); field.NumParents = parents.Length; } field.IsSortable = getBoolValueFromJToken(schemaFieldObject, "sortingAllowed"); field.IsAggregatable = getBoolValueFromJToken(schemaFieldObject, "aggregationsAllowed"); field.IsHidden = getBoolValueFromJToken(schemaFieldObject, "hidden"); field.IsDeleted = getBoolValueFromJToken(schemaFieldObject, "softDeleted"); schemaFieldsInThisSchemaList.Add(field); } // Now the schema BIQSchema schema = new BIQSchema(); schema.Controller = jobTarget.Controller; schema.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); schema.ApplicationName = jobTarget.Application; schema.ApplicationID = jobTarget.ApplicationID; schema.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, schema.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); schema.SchemaName = schemaName; schema.IsCustom = (BIQ_SCHEMA_TYPES.Contains(schemaName) == false); schema.NumFields = schemaFieldsInThisSchemaList.Count; schema.NumStringFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "STRING").Count(); schema.NumIntegerFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "INTEGER").Count(); schema.NumLongFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "LONG").Count(); schema.NumFloatFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "FLOAT").Count(); schema.NumDoubleFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "DOUBLE").Count(); schema.NumBooleanFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "BOOLEAN").Count(); schema.NumDateFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "DATE").Count(); schema.NumObjectFields = schemaFieldsInThisSchemaList.Where(s => s.FieldType == "OBJECT").Count(); schemaFieldsList.AddRange(schemaFieldsInThisSchemaList); schemasList.Add(schema); } } // Sort them schemasList = schemasList.OrderBy(o => o.SchemaName).ToList(); FileIOHelper.WriteListToCSVFile(schemasList, new BIQSchemaReportMap(), FilePathMap.BIQSchemasIndexFilePath(jobTarget)); schemaFieldsList = schemaFieldsList.OrderBy(o => o.SchemaName).ThenBy(o => o.FieldName).ToList(); FileIOHelper.WriteListToCSVFile(schemaFieldsList, new BIQFieldReportMap(), FilePathMap.BIQSchemaFieldsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + schemaFieldsList.Count; #endregion #region Application loggerConsole.Info("Index Application"); BIQApplication application = new BIQApplication(); application.Controller = jobTarget.Controller; application.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); application.ApplicationName = jobTarget.Application; application.ApplicationID = jobTarget.ApplicationID; application.ApplicationLink = String.Format(DEEPLINK_BIQ_APPLICATION, application.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); if (biqSearchesList != null) { application.NumSearches = biqSearchesList.Count; application.NumSingleSearches = biqSearchesList.Count(p => p.SearchType == "SINGLE"); application.NumMultiSearches = biqSearchesList.Count(p => p.SearchType == "MULTI"); application.NumLegacySearches = biqSearchesList.Count(p => p.SearchType == "LEGACY42"); } if (biqMetricsList != null) { application.NumSavedMetrics = biqMetricsList.Count; } if (businessJourneysList != null) { application.NumBusinessJourneys = businessJourneysList.Count; } if (experienceLevelsList != null) { application.NumExperienceLevels = experienceLevelsList.Count; } if (schemasList != null) { application.NumSchemas = schemasList.Count; } if (schemaFieldsList != null) { application.NumFields = schemaFieldsList.Count; } List <BIQApplication> applicationsList = new List <BIQApplication>(1); applicationsList.Add(application); FileIOHelper.WriteListToCSVFile(applicationsList, new BIQApplicationReportMap(), FilePathMap.BIQApplicationsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + 1; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.BIQEntitiesReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.BIQEntitiesReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.BIQApplicationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQApplicationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQApplicationsReportFilePath(), FilePathMap.BIQApplicationsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQSearchesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQSearchesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQSearchesReportFilePath(), FilePathMap.BIQSearchesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQWidgetsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQWidgetsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQWidgetsReportFilePath(), FilePathMap.BIQWidgetsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQMetricsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQMetricsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQMetricsReportFilePath(), FilePathMap.BIQMetricsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQBusinessJourneysIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQBusinessJourneysIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQBusinessJourneysReportFilePath(), FilePathMap.BIQBusinessJourneysIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQExperienceLevelsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQExperienceLevelsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQExperienceLevelsReportFilePath(), FilePathMap.BIQExperienceLevelsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQSchemasIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQSchemasIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQSchemasReportFilePath(), FilePathMap.BIQSchemasIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.BIQSchemaFieldsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.BIQSchemaFieldsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.BIQSchemaFieldsReportFilePath(), FilePathMap.BIQSchemaFieldsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } // Let's append all Applications var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; stepTimingTarget.NumEntities = 0; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Users JArray usersArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.UsersDataFilePath(jobTarget)); List <RBACUser> usersList = null; if (usersArray != null && usersArray.Count > 0) { loggerConsole.Info("Index List of Users ({0} entities)", usersArray.Count); usersList = new List <RBACUser>(usersArray.Count); foreach (JToken userToken in usersArray) { RBACUser user = new RBACUser(); user.Controller = jobTarget.Controller; user.UserName = getStringValueFromJToken(userToken, "name"); user.DisplayName = getStringValueFromJToken(userToken, "displayName"); user.Email = getStringValueFromJToken(userToken, "email"); user.SecurityProvider = getStringValueFromJToken(userToken, "securityProviderType"); user.UserID = getLongValueFromJToken(userToken, "id"); user.CreatedBy = getStringValueFromJToken(userToken, "createdBy"); user.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(userToken, "createdOn")); try { user.CreatedOn = user.CreatedOnUtc.ToLocalTime(); } catch { } user.UpdatedBy = getStringValueFromJToken(userToken, "modifiedBy"); user.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(userToken, "modifiedOn")); try { user.UpdatedOn = user.UpdatedOnUtc.ToLocalTime(); } catch { } usersList.Add(user); } // Sort them usersList = usersList.OrderBy(o => o.SecurityProvider).ThenBy(o => o.UserName).ToList(); FileIOHelper.WriteListToCSVFile(usersList, new RBACUserReportMap(), FilePathMap.UsersIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + usersList.Count; } #endregion #region Groups JArray groupsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.GroupsDataFilePath(jobTarget)); List <RBACGroup> groupsList = null; if (groupsArray != null && groupsArray.Count > 0) { loggerConsole.Info("Index List of Groups ({0} entities)", groupsArray.Count); groupsList = new List <RBACGroup>(groupsArray.Count); foreach (JToken groupToken in groupsArray) { RBACGroup group = new RBACGroup(); group.Controller = jobTarget.Controller; group.GroupName = getStringValueFromJToken(groupToken, "name"); group.Description = getStringValueFromJToken(groupToken, "description"); group.SecurityProvider = getStringValueFromJToken(groupToken, "securityProviderType"); group.GroupID = getLongValueFromJToken(groupToken, "id"); group.CreatedBy = getStringValueFromJToken(groupToken, "createdBy"); group.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(groupToken, "createdOn")); try { group.CreatedOn = group.CreatedOnUtc.ToLocalTime(); } catch { } group.UpdatedBy = getStringValueFromJToken(groupToken, "modifiedBy"); group.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(groupToken, "modifiedOn")); try { group.UpdatedOn = group.UpdatedOnUtc.ToLocalTime(); } catch { } groupsList.Add(group); } // Sort them groupsList = groupsList.OrderBy(o => o.SecurityProvider).ThenBy(o => o.GroupName).ToList(); FileIOHelper.WriteListToCSVFile(groupsList, new RBACGroupReportMap(), FilePathMap.GroupsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + groupsList.Count; } #endregion #region Roles JArray rolesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.RolesDataFilePath(jobTarget)); List <RBACRole> rolesList = null; List <RBACPermission> permissionsList = null; List <ControllerApplication> applicationsList = FileIOHelper.ReadListFromCSVFile <ControllerApplication>(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget), new ControllerApplicationReportMap()); if (rolesArray != null && rolesArray.Count > 0) { loggerConsole.Info("Index List of Roles ({0} entities)", rolesArray.Count); rolesList = new List <RBACRole>(rolesArray.Count); permissionsList = new List <RBACPermission>(rolesArray.Count * 32); foreach (JToken roleToken in rolesArray) { RBACRole role = new RBACRole(); role.Controller = jobTarget.Controller; role.RoleName = getStringValueFromJToken(roleToken, "name"); role.Description = getStringValueFromJToken(roleToken, "description"); role.ReadOnly = getBoolValueFromJToken(roleToken, "readonly"); role.RoleID = getLongValueFromJToken(roleToken, "id"); role.CreatedBy = getStringValueFromJToken(roleToken, "createdBy"); role.CreatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(roleToken, "createdOn")); try { role.CreatedOn = role.CreatedOnUtc.ToLocalTime(); } catch { } role.UpdatedBy = getStringValueFromJToken(roleToken, "modifiedBy"); role.UpdatedOnUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(roleToken, "modifiedOn")); try { role.UpdatedOn = role.UpdatedOnUtc.ToLocalTime(); } catch { } // Permissions from role detail JObject roleDetailObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.RoleDataFilePath(jobTarget, role.RoleName, role.RoleID)); if (roleDetailObject != null) { foreach (JToken permissionToken in roleDetailObject["permissions"]) { RBACPermission permission = new RBACPermission(); permission.Controller = role.Controller; permission.RoleName = role.RoleName; permission.RoleID = role.RoleID; permission.PermissionName = getStringValueFromJToken(permissionToken, "action"); permission.Allowed = getBoolValueFromJToken(permissionToken, "allowed"); permission.PermissionID = getLongValueFromJToken(permissionToken, "id"); if (isTokenPropertyNull(permissionToken, "affectedEntity") == false) { permission.EntityType = getStringValueFromJToken(permissionToken["affectedEntity"], "entityType"); permission.EntityID = getLongValueFromJToken(permissionToken["affectedEntity"], "entityId"); } // Lookup the application if (permission.EntityType == "APPLICATION" && permission.EntityID != 0) { if (applicationsList != null) { ControllerApplication application = applicationsList.Where(e => e.ApplicationID == permission.EntityID).FirstOrDefault(); if (application != null) { permission.EntityName = application.ApplicationName; } } } else { permission.EntityType = ""; } role.NumPermissions++; permissionsList.Add(permission); } } rolesList.Add(role); } // Sort them rolesList = rolesList.OrderBy(o => o.RoleName).ToList(); FileIOHelper.WriteListToCSVFile(rolesList, new RBACRoleReportMap(), FilePathMap.RolesIndexFilePath(jobTarget)); permissionsList = permissionsList.OrderBy(o => o.RoleName).ThenBy(o => o.EntityName).ThenBy(o => o.PermissionName).ToList(); FileIOHelper.WriteListToCSVFile(permissionsList, new RBACPermissionReportMap(), FilePathMap.PermissionsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + rolesList.Count; } #endregion #region Groups and Users in Roles List <RBACRoleMembership> roleMembershipsList = new List <RBACRoleMembership>(); // Users in Roles if (usersList != null && rolesList != null) { loggerConsole.Info("Index Users in Roles ({0} entities)", usersList.Count); foreach (RBACUser user in usersList) { JObject userDetailObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.UserDataFilePath(jobTarget, user.UserName, user.UserID)); if (userDetailObject != null) { foreach (JToken roleIDToken in userDetailObject["accountRoleIds"]) { long roleID = (long)roleIDToken; RBACRole role = rolesList.Where(r => r.RoleID == roleID).FirstOrDefault(); if (role != null) { RBACRoleMembership roleMembership = new RBACRoleMembership(); roleMembership.Controller = user.Controller; roleMembership.RoleName = role.RoleName; roleMembership.RoleID = role.RoleID; roleMembership.EntityName = user.UserName; roleMembership.EntityID = user.UserID; roleMembership.EntityType = "User"; roleMembershipsList.Add(roleMembership); } } } } } // Groups in Roles if (groupsList != null && rolesList != null) { loggerConsole.Info("Index Groups in Roles ({0} entities)", groupsList.Count); foreach (RBACGroup group in groupsList) { JObject groupDetailJSON = FileIOHelper.LoadJObjectFromFile(FilePathMap.GroupDataFilePath(jobTarget, group.GroupName, group.GroupID)); if (groupDetailJSON != null) { foreach (JToken roleIDToken in groupDetailJSON["accountRoleIds"]) { long roleID = (long)roleIDToken; RBACRole role = rolesList.Where(r => r.RoleID == roleID).FirstOrDefault(); if (role != null) { RBACRoleMembership roleMembership = new RBACRoleMembership(); roleMembership.Controller = group.Controller; roleMembership.RoleName = role.RoleName; roleMembership.RoleID = role.RoleID; roleMembership.EntityName = group.GroupName; roleMembership.EntityID = group.GroupID; roleMembership.EntityType = "Group"; roleMembershipsList.Add(roleMembership); } } } } } roleMembershipsList = roleMembershipsList.OrderBy(o => o.RoleName).ThenBy(o => o.EntityType).ThenBy(o => o.EntityName).ToList(); FileIOHelper.WriteListToCSVFile(roleMembershipsList, new RBACRoleMembershipReportMap(), FilePathMap.RoleMembershipsIndexFilePath(jobTarget)); #endregion #region Users in Groups List <RBACGroupMembership> groupMembershipsList = new List <RBACGroupMembership>(); if (groupsList != null && usersList != null) { loggerConsole.Info("Index Users in Groups ({0} entities)", groupsList.Count); foreach (RBACGroup group in groupsList) { JArray usersInGroupArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.GroupUsersDataFilePath(jobTarget, group.GroupName, group.GroupID)); if (usersInGroupArray != null) { foreach (JToken userIDToken in usersInGroupArray) { long userID = (long)userIDToken; RBACUser user = usersList.Where(r => r.UserID == userID).FirstOrDefault(); if (user != null) { RBACGroupMembership groupMembership = new RBACGroupMembership(); groupMembership.Controller = group.Controller; groupMembership.GroupName = group.GroupName; groupMembership.GroupID = group.GroupID; groupMembership.UserName = user.UserName; groupMembership.UserID = user.UserID; groupMembershipsList.Add(groupMembership); } } } } } groupMembershipsList = groupMembershipsList.OrderBy(o => o.GroupName).ThenBy(o => o.UserName).ToList(); FileIOHelper.WriteListToCSVFile(groupMembershipsList, new RBACGroupMembershipReportMap(), FilePathMap.GroupMembershipsIndexFilePath(jobTarget)); #endregion #region User Permissions List <RBACUserPermission> userPermissionsList = new List <RBACUserPermission>(); if (roleMembershipsList != null && permissionsList != null) { loggerConsole.Info("Index Users Permissions ({0} entities)", roleMembershipsList.Count); // Scroll through the list of Role memberships foreach (RBACRoleMembership roleMembership in roleMembershipsList) { if (roleMembership.EntityType == "User") { if (usersList != null) { // For User, enumerate permissions associated with this role RBACUser user = usersList.Where(u => u.UserID == roleMembership.EntityID).FirstOrDefault(); if (user != null) { List <RBACPermission> permissionsForRoleList = permissionsList.Where(p => p.RoleID == roleMembership.RoleID).ToList(); if (permissionsForRoleList != null) { foreach (RBACPermission permission in permissionsForRoleList) { RBACUserPermission userPermission = new RBACUserPermission(); userPermission.Controller = user.Controller; userPermission.UserName = user.UserName; userPermission.UserSecurityProvider = user.SecurityProvider; userPermission.UserID = user.UserID; userPermission.RoleName = permission.RoleName; userPermission.RoleID = permission.RoleID; userPermission.PermissionName = permission.PermissionName; userPermission.PermissionID = permission.PermissionID; userPermission.Allowed = permission.Allowed; userPermission.EntityName = permission.EntityName; userPermission.EntityType = permission.EntityType; userPermission.EntityID = permission.EntityID; userPermissionsList.Add(userPermission); } } } } } else if (roleMembership.EntityType == "Group") { RBACGroup groupDetail = null; if (groupsList != null) { groupDetail = groupsList.Where(g => g.GroupID == roleMembership.EntityID).FirstOrDefault(); } if (groupMembershipsList != null) { // For Group, find all users in the group and repeat the permission output List <RBACGroupMembership> usersInGroups = groupMembershipsList.Where(g => g.GroupID == roleMembership.EntityID).ToList(); if (usersInGroups != null) { foreach (RBACGroupMembership user in usersInGroups) { RBACUser userDetail = null; if (usersList != null) { userDetail = usersList.Where(u => u.UserID == user.UserID).FirstOrDefault(); } List <RBACPermission> permissionsForRoleList = permissionsList.Where(p => p.RoleID == roleMembership.RoleID).ToList(); if (permissionsForRoleList != null) { foreach (RBACPermission permission in permissionsForRoleList) { RBACUserPermission userPermission = new RBACUserPermission(); userPermission.Controller = user.Controller; userPermission.UserName = user.UserName; userPermission.UserID = user.UserID; if (userDetail != null) { userPermission.UserSecurityProvider = userDetail.SecurityProvider; } if (groupDetail != null) { userPermission.GroupName = groupDetail.GroupName; userPermission.GroupSecurityProvider = groupDetail.SecurityProvider; userPermission.GroupID = groupDetail.GroupID; } userPermission.RoleName = permission.RoleName; userPermission.RoleID = permission.RoleID; userPermission.PermissionName = permission.PermissionName; userPermission.PermissionID = permission.PermissionID; userPermission.Allowed = permission.Allowed; userPermission.EntityName = permission.EntityName; userPermission.EntityType = permission.EntityType; userPermission.EntityID = permission.EntityID; userPermissionsList.Add(userPermission); } } } } } } } } userPermissionsList = userPermissionsList.OrderBy(o => o.UserName).ThenBy(o => o.GroupName).ThenBy(o => o.PermissionName).ToList(); FileIOHelper.WriteListToCSVFile(userPermissionsList, new RBACUserPermissionReportMap(), FilePathMap.UserPermissionsIndexFilePath(jobTarget)); #endregion #region Controller Summary loggerConsole.Info("Index Controller Summary"); RBACControllerSummary controller = new RBACControllerSummary(); controller.Controller = jobTarget.Controller; string securityProviderType = FileIOHelper.ReadFileFromPath(FilePathMap.SecurityProviderTypeDataFilePath(jobTarget)); if (securityProviderType != String.Empty) { controller.SecurityProvider = securityProviderType.Replace("\"", ""); } string requireStrongPasswords = FileIOHelper.ReadFileFromPath(FilePathMap.StrongPasswordsDataFilePath(jobTarget)); if (requireStrongPasswords != String.Empty) { bool parsedBool = false; Boolean.TryParse(requireStrongPasswords, out parsedBool); controller.IsStrongPasswords = parsedBool; } if (usersList != null) { controller.NumUsers = usersList.Count; } if (groupsList != null) { controller.NumGroups = groupsList.Count; } if (rolesList != null) { controller.NumRoles = rolesList.Count; } List <RBACControllerSummary> controllerList = new List <RBACControllerSummary>(1); controllerList.Add(controller); FileIOHelper.WriteListToCSVFile(controllerList, new RBACControllerSummaryReportMap(), FilePathMap.RBACControllerSummaryIndexFilePath(jobTarget)); #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.UsersGroupsRolesPermissionsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.UsersGroupsRolesPermissionsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.UsersIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.UsersIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.UsersReportFilePath(), FilePathMap.UsersIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.GroupsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.GroupsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.GroupsReportFilePath(), FilePathMap.GroupsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.RolesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.RolesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.RolesReportFilePath(), FilePathMap.RolesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.PermissionsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.PermissionsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.PermissionsReportFilePath(), FilePathMap.PermissionsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.GroupMembershipsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.GroupMembershipsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.GroupMembershipsReportFilePath(), FilePathMap.GroupMembershipsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.RoleMembershipsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.RoleMembershipsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.RoleMembershipsReportFilePath(), FilePathMap.RoleMembershipsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.UserPermissionsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.UserPermissionsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.UserPermissionsReportFilePath(), FilePathMap.UserPermissionsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.RBACControllerSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.RBACControllerSummaryIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.RBACControllerSummaryReportFilePath(), FilePathMap.RBACControllerSummaryIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_APM) == 0) { logger.Warn("No {0} targets to process", APPLICATION_TYPE_APM); loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_APM); return(true); } try { loggerConsole.Info("Prepare Detected APM Metrics Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics Detected APM Metrics Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics Detected APM Metrics Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_METRICS_SUMMARY_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METRICS_SUMMARY_TYPE_PIVOT); sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_METRICS_SUMMARY_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_METRICS_SUMMARY_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); #endregion loggerConsole.Info("Fill Detected APM Metrics Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications - All loggerConsole.Info("List of Applications - All"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, typeof(ControllerApplication), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Metric Summary loggerConsole.Info("Metrics Summary"); sheet = excelReport.Workbook.Worksheets[SHEET_METRICS_SUMMARY_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.MetricPrefixSummaryReportFilePath(), 0, typeof(MetricSummary), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion loggerConsole.Info("Finalize Detected APM Metrics Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications - All // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; } #endregion #region Metrics Summary // Make table sheet = excelReport.Workbook.Worksheets[SHEET_METRICS_SUMMARY_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_METRICS_SUMMARY_LIST); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["MetricPrefix"].Position + 1).Width = 30; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_METRICS_SUMMARY_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_METRICS_SUMMARY_TYPE); setDefaultPivotTableSettings(pivot); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "MetricPrefix"); addDataFieldToPivot(pivot, "NumAll", DataFieldFunctions.Sum, "All"); addDataFieldToPivot(pivot, "NumActivity", DataFieldFunctions.Sum, "Activity"); addDataFieldToPivot(pivot, "NumNoActivity", DataFieldFunctions.Sum, "NoActivity"); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 30; ExcelChart chart = sheet.Drawings.AddChart(GRAPH_METRICS_SUMMARY_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.MetricsListExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion #region Prepare individual application reports ParallelOptions parallelOptions = new ParallelOptions(); if (programOptions.ProcessSequentially == true) { parallelOptions.MaxDegreeOfParallelism = 1; } int j = 0; Parallel.ForEach( jobConfiguration.Target, parallelOptions, () => 0, (jobTarget, loop, subtotal) => { if (jobTarget.Type == APPLICATION_TYPE_APM) { createMetricListApplicationReport(programOptions, jobConfiguration, jobTarget); } return(1); }, (finalResult) => { Interlocked.Add(ref j, finalResult); if (j % 10 == 0) { Console.Write("[{0}].", j); } } ); #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; stepTimingTarget.NumEntities = 0; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Prepare time range long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From); long toTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To); int differenceInMinutes = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes); #endregion #region Account Summary loggerConsole.Info("Account Summary"); LicenseAccountSummary licenseAccountSummary = new LicenseAccountSummary(); JObject accountSummaryContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseAccountDataFilePath(jobTarget)); if (accountSummaryContainerObject != null && isTokenPropertyNull(accountSummaryContainerObject, "account") == false) { JObject accountSummaryLicenseObject = (JObject)accountSummaryContainerObject["account"]; licenseAccountSummary.Controller = jobTarget.Controller; licenseAccountSummary.AccountID = getLongValueFromJToken(accountSummaryLicenseObject, "id"); licenseAccountSummary.AccountName = getStringValueFromJToken(accountSummaryLicenseObject, "name"); licenseAccountSummary.AccountNameGlobal = getStringValueFromJToken(accountSummaryLicenseObject, "globalAccountName"); licenseAccountSummary.AccountNameEUM = getStringValueFromJToken(accountSummaryLicenseObject, "eumAccountName"); licenseAccountSummary.AccessKey1 = getStringValueFromJToken(accountSummaryLicenseObject, "accessKey"); licenseAccountSummary.AccessKey2 = getStringValueFromJToken(accountSummaryLicenseObject, "key"); licenseAccountSummary.LicenseKeyEUM = getStringValueFromJToken(accountSummaryLicenseObject, "eumCloudLicenseKey"); licenseAccountSummary.ServiceKeyES = getStringValueFromJToken(accountSummaryLicenseObject, "eumEventServiceKey"); licenseAccountSummary.ExpirationDate = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(accountSummaryLicenseObject, "expirationDate")); licenseAccountSummary.LicenseLink = String.Format(DEEPLINK_LICENSE, licenseAccountSummary.Controller, DEEPLINK_THIS_TIMERANGE); List <LicenseAccountSummary> licenseAccountSummaryList = new List <LicenseAccountSummary>(1); licenseAccountSummaryList.Add(licenseAccountSummary); FileIOHelper.WriteListToCSVFile(licenseAccountSummaryList, new LicenseAccountSummaryReportMap(), FilePathMap.LicenseAccountIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + licenseAccountSummaryList.Count; } #endregion #region Account Level License Entitlements and Usage loggerConsole.Info("Account License Summary and Usage"); List <License> licensesList = new List <License>(24); // Typically there are 12 values per hour, if we extracted every 5 minute things List <LicenseValue> licenseValuesGlobalList = new List <LicenseValue>(jobConfiguration.Input.HourlyTimeRanges.Count * 12 * licensesList.Count); JObject licenseModulesContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseModulesDataFilePath(jobTarget)); if (licenseModulesContainer != null && isTokenPropertyNull(licenseModulesContainer, "modules") == false) { JArray licenseModulesArray = (JArray)licenseModulesContainer["modules"]; foreach (JObject licenseModuleObject in licenseModulesArray) { string licenseModuleName = getStringValueFromJToken(licenseModuleObject, "name"); License license = new License(); license.Controller = jobTarget.Controller; license.AccountID = licenseAccountSummary.AccountID; license.AccountName = licenseAccountSummary.AccountName; // Duration license.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; license.From = jobConfiguration.Input.TimeRange.From.ToLocalTime(); license.To = jobConfiguration.Input.TimeRange.To.ToLocalTime(); license.FromUtc = jobConfiguration.Input.TimeRange.From; license.ToUtc = jobConfiguration.Input.TimeRange.To; license.AgentType = licenseModuleName; JObject licenseModulePropertiesContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseModulePropertiesDataFilePath(jobTarget, licenseModuleName)); if (licenseModulePropertiesContainer != null && isTokenPropertyNull(licenseModulePropertiesContainer, "properties") == false) { foreach (JObject licensePropertyObject in licenseModulePropertiesContainer["properties"]) { string valueOfProperty = getStringValueFromJToken(licensePropertyObject, "value"); switch (getStringValueFromJToken(licensePropertyObject, "name")) { case "expiry-date": long expiryDateLong = 0; if (long.TryParse(valueOfProperty, out expiryDateLong) == true) { license.ExpirationDate = UnixTimeHelper.ConvertFromUnixTimestamp(expiryDateLong); } break; case "licensing-model": license.Model = valueOfProperty; break; case "edition": license.Edition = valueOfProperty; break; case "number-of-provisioned-licenses": long numberOfLicensesLong = 0; if (long.TryParse(valueOfProperty, out numberOfLicensesLong) == true) { license.Provisioned = numberOfLicensesLong; } break; case "maximum-allowed-licenses": long maximumNumberOfLicensesLong = 0; if (long.TryParse(valueOfProperty, out maximumNumberOfLicensesLong) == true) { license.MaximumAllowed = maximumNumberOfLicensesLong; } break; case "data-retention-period": int dataRetentionPeriodInt = 0; if (int.TryParse(valueOfProperty, out dataRetentionPeriodInt) == true) { license.Retention = dataRetentionPeriodInt; } break; default: break; } } } List <LicenseValue> licenseValuesList = new List <LicenseValue>(jobConfiguration.Input.HourlyTimeRanges.Count * 12); JObject licenseModuleUsagesContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseModuleUsagesDataFilePath(jobTarget, licenseModuleName)); if (licenseModuleUsagesContainer != null && isTokenPropertyNull(licenseModuleUsagesContainer, "usages") == false) { foreach (JObject licenseUsageObject in licenseModuleUsagesContainer["usages"]) { LicenseValue licenseValue = new LicenseValue(); licenseValue.Controller = license.Controller; licenseValue.AccountName = license.AccountName; licenseValue.AccountID = license.AccountID; licenseValue.AgentType = license.AgentType; licenseValue.RuleName = "Account"; licenseValue.LicenseEventTimeUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(licenseUsageObject, "createdOn")); licenseValue.LicenseEventTime = licenseValue.LicenseEventTimeUtc.ToLocalTime(); licenseValue.Min = getLongValueFromJToken(licenseUsageObject, "minUnitsUsed"); licenseValue.Max = getLongValueFromJToken(licenseUsageObject, "maxUnitsUsed"); licenseValue.Average = getLongValueFromJToken(licenseUsageObject, "avgUnitsUsed"); licenseValue.Total = getLongValueFromJToken(licenseUsageObject, "totalUnitsUsed"); licenseValue.Samples = getLongValueFromJToken(licenseUsageObject, "sampleCount"); licenseValuesList.Add(licenseValue); } } // Do the counts and averages from per hour consumption to the total line if (licenseValuesList.Count > 0) { license.Average = (long)Math.Round((double)((double)licenseValuesList.Sum(mv => mv.Average) / (double)licenseValuesList.Count), 0); license.Min = licenseValuesList.Min(l => l.Min); license.Max = licenseValuesList.Max(l => l.Max); } licensesList.Add(license); licenseValuesGlobalList.AddRange(licenseValuesList); } } stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + licensesList.Count; licensesList = licensesList.OrderBy(l => l.AgentType).ToList(); FileIOHelper.WriteListToCSVFile(licensesList, new LicenseReportMap(), FilePathMap.LicensesIndexFilePath(jobTarget)); FileIOHelper.WriteListToCSVFile(licenseValuesGlobalList, new LicenseValueReportMap(), FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget)); #endregion #region License Rules loggerConsole.Info("License Rules"); #region Preload the application and machine mapping Dictionary <string, string> applicationsUsedByRules = null; Dictionary <string, string> simMachinesUsedByRules = null; JArray licenseApplicationsReferenceArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.LicenseApplicationsDataFilePath(jobTarget)); JArray licenseSIMMachinesReferenceArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.LicenseSIMMachinesDataFilePath(jobTarget)); if (licenseApplicationsReferenceArray == null) { applicationsUsedByRules = new Dictionary <string, string>(0); } else { applicationsUsedByRules = new Dictionary <string, string>(licenseApplicationsReferenceArray.Count); foreach (JObject applicationObject in licenseApplicationsReferenceArray) { applicationsUsedByRules.Add(getStringValueFromJToken(applicationObject["objectReference"], "id"), getStringValueFromJToken(applicationObject, "name")); } } if (licenseSIMMachinesReferenceArray == null) { simMachinesUsedByRules = new Dictionary <string, string>(0); } else { simMachinesUsedByRules = new Dictionary <string, string>(licenseSIMMachinesReferenceArray.Count); foreach (JObject machineObject in licenseSIMMachinesReferenceArray) { simMachinesUsedByRules.Add(getStringValueFromJToken(machineObject["objectReference"], "id"), getStringValueFromJToken(machineObject, "name")); } } List <ControllerApplication> controllerApplicationsList = FileIOHelper.ReadListFromCSVFile <ControllerApplication>(FilePathMap.ControllerApplicationsIndexFilePath(jobTarget), new ControllerApplicationReportMap()); #endregion List <LicenseRule> licenseRulesList = new List <LicenseRule>(10); List <LicenseRuleScope> licenseRuleScopesList = new List <LicenseRuleScope>(100); JArray licenseRulesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.LicenseRulesDataFilePath(jobTarget)); if (licenseRulesArray != null) { foreach (JObject licenseRuleObject in licenseRulesArray) { string ruleID = getStringValueFromJToken(licenseRuleObject, "id"); string ruleName = getStringValueFromJToken(licenseRuleObject, "name"); JObject licenseRuleDetailsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseRuleConfigurationDataFilePath(jobTarget, ruleName, ruleID)); if (licenseRuleDetailsObject != null) { LicenseRule licenseRuleTemplate = new LicenseRule(); licenseRuleTemplate.Controller = jobTarget.Controller; licenseRuleTemplate.AccountID = licenseAccountSummary.AccountID; licenseRuleTemplate.AccountName = licenseAccountSummary.AccountName; // Duration licenseRuleTemplate.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; licenseRuleTemplate.From = jobConfiguration.Input.TimeRange.From.ToLocalTime(); licenseRuleTemplate.To = jobConfiguration.Input.TimeRange.To.ToLocalTime(); licenseRuleTemplate.FromUtc = jobConfiguration.Input.TimeRange.From; licenseRuleTemplate.ToUtc = jobConfiguration.Input.TimeRange.To; licenseRuleTemplate.RuleName = getStringValueFromJToken(licenseRuleObject, "name"); licenseRuleTemplate.RuleID = getStringValueFromJToken(licenseRuleObject, "id"); licenseRuleTemplate.AccessKey = getStringValueFromJToken(licenseRuleObject, "access_key"); licenseRuleTemplate.RuleLicenses = getLongValueFromJToken(licenseRuleObject, "total_licenses"); licenseRuleTemplate.RulePeak = getLongValueFromJToken(licenseRuleObject, "peak_usage"); if (isTokenPropertyNull(licenseRuleDetailsObject, "constraints") == false) { JArray licenseRuleConstraintsArray = (JArray)licenseRuleDetailsObject["constraints"]; foreach (JObject licenseConstraintObject in licenseRuleConstraintsArray) { LicenseRuleScope licenseRuleScope = new LicenseRuleScope(); licenseRuleScope.Controller = licenseRuleTemplate.Controller; licenseRuleScope.AccountID = licenseRuleTemplate.AccountID; licenseRuleScope.AccountName = licenseRuleTemplate.AccountName; licenseRuleScope.RuleName = licenseRuleTemplate.RuleName; licenseRuleScope.RuleID = licenseRuleTemplate.RuleID; licenseRuleScope.ScopeSelector = getStringValueFromJToken(licenseConstraintObject, "constraint_type"); string scopeType = getStringValueFromJToken(licenseConstraintObject, "entity_type_id"); if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity") { licenseRuleScope.EntityType = "Application"; } else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity") { licenseRuleScope.EntityType = "Machine"; } if (licenseRuleScope.ScopeSelector == "ALLOW_ALL") { licenseRuleScope.MatchType = "EQUALS"; if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity") { licenseRuleScope.EntityName = "[Any Application]"; licenseRuleTemplate.NumApplications++; } else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity") { licenseRuleScope.EntityName = "[Any Machine]"; licenseRuleTemplate.NumServers++; } licenseRuleScopesList.Add(licenseRuleScope); } else if (isTokenPropertyNull(licenseConstraintObject, "match_conditions") == false) { JArray licenseRuleMatcheConditionsArray = (JArray)licenseConstraintObject["match_conditions"]; foreach (JObject licenseRuleMatchConditionObject in licenseRuleMatcheConditionsArray) { LicenseRuleScope licenseRuleScopeMatchCondition = licenseRuleScope.Clone(); licenseRuleScopeMatchCondition.MatchType = getStringValueFromJToken(licenseRuleMatchConditionObject, "match_type"); if (licenseRuleScopeMatchCondition.MatchType == "EQUALS" && getStringValueFromJToken(licenseRuleMatchConditionObject, "attribute_type") == "ID") { string applicationID = getStringValueFromJToken(licenseRuleMatchConditionObject, "match_string"); if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity") { if (applicationsUsedByRules.ContainsKey(applicationID) == true && controllerApplicationsList != null) { ControllerApplication controllerApplication = controllerApplicationsList.Where(a => a.ApplicationName == applicationsUsedByRules[applicationID]).FirstOrDefault(); if (controllerApplication != null) { licenseRuleScopeMatchCondition.EntityName = controllerApplication.ApplicationName; licenseRuleScopeMatchCondition.EntityType = controllerApplication.Type; licenseRuleScopeMatchCondition.EntityID = controllerApplication.ApplicationID; } } licenseRuleTemplate.NumApplications++; } else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity") { if (simMachinesUsedByRules.ContainsKey(applicationID) == true) { licenseRuleScopeMatchCondition.EntityName = simMachinesUsedByRules[applicationID]; } licenseRuleTemplate.NumServers++; } } else { licenseRuleScopeMatchCondition.EntityName = getStringValueFromJToken(licenseRuleMatchConditionObject, "match_string"); licenseRuleScopeMatchCondition.EntityID = -1; if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.ApplicationEntity") { licenseRuleTemplate.NumApplications++; } else if (scopeType == "com.appdynamics.modules.apm.topology.impl.persistenceapi.model.MachineEntity") { licenseRuleTemplate.NumServers++; } } licenseRuleScopesList.Add(licenseRuleScopeMatchCondition); } } } } if (isTokenPropertyNull(licenseRuleDetailsObject, "entitlements") == false) { JArray licenseRuleEntitlementsArray = (JArray)licenseRuleDetailsObject["entitlements"]; foreach (JObject licenseEntitlementObject in licenseRuleEntitlementsArray) { LicenseRule licenseRule = licenseRuleTemplate.Clone(); licenseRule.Licenses = getLongValueFromJToken(licenseEntitlementObject, "number_of_licenses"); licenseRule.AgentType = getStringValueFromJToken(licenseEntitlementObject, "license_module_type"); licenseRulesList.Add(licenseRule); } } } } licenseRulesList = licenseRulesList.OrderBy(l => l.RuleName).ThenBy(l => l.AgentType).ToList(); FileIOHelper.WriteListToCSVFile(licenseRulesList, new LicenseRuleReportMap(), FilePathMap.LicenseRulesIndexFilePath(jobTarget)); licenseRuleScopesList = licenseRuleScopesList.OrderBy(l => l.RuleName).ThenBy(l => l.ScopeSelector).ThenBy(l => l.EntityType).ThenBy(l => l.EntityName).ToList(); FileIOHelper.WriteListToCSVFile(licenseRuleScopesList, new LicenseRuleScopeReportMap(), FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget)); } #endregion #region License Rule consumption details loggerConsole.Info("Rules License Consumption"); // Typically there are 12 values per hour // Assume there will be 16 different license types List <LicenseValue> licenseValuesRulesList = new List <LicenseValue>(jobConfiguration.Input.HourlyTimeRanges.Count * 12 * 16 * licenseRulesList.Count); foreach (LicenseRule licenseRule in licenseRulesList) { JObject licenseValuesForRuleContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.LicenseRuleUsageDataFilePath(jobTarget, licenseRule.RuleName, licenseRule.RuleID)); if (licenseValuesForRuleContainerObject != null) { if (isTokenPropertyNull(licenseValuesForRuleContainerObject, "apmStackGraphViewData") == false) { // Parse the APM results first JArray licenseValuesForRuleAPMContainerArray = (JArray)licenseValuesForRuleContainerObject["apmStackGraphViewData"]; if (licenseValuesForRuleAPMContainerArray != null) { foreach (JObject licenseValuesContainerObject in licenseValuesForRuleAPMContainerArray) { string licenseType = getStringValueFromJToken(licenseValuesContainerObject, "licenseModuleType"); // If we have the license looked up, look through the values if (licenseType != String.Empty && isTokenPropertyNull(licenseValuesContainerObject, "graphPoints") == false) { // Looks like [[ 1555484400000, 843 ], [ 1555488000000, 843 ]] JArray licenseValuesAPMArray = (JArray)licenseValuesContainerObject["graphPoints"]; List <LicenseValue> licenseValuesList = parseLicenseValuesArray(licenseValuesAPMArray, licenseRule, licenseType); if (licenseValuesList != null) { licenseValuesRulesList.AddRange(licenseValuesList); } } } } } if (isTokenPropertyNull(licenseValuesForRuleContainerObject, "nonApmModuleDetailViewData") == false) { // Parse the non-APM results second JArray licenseValuesForRuleNonAPMContainerArray = (JArray)licenseValuesForRuleContainerObject["nonApmModuleDetailViewData"]; if (licenseValuesForRuleNonAPMContainerArray != null) { foreach (JObject licenseValuesContainerObject in licenseValuesForRuleNonAPMContainerArray) { string licenseType = getStringValueFromJToken(licenseValuesContainerObject, "licenseModuleType"); // If we have the license looked up, look through the values if (licenseType != String.Empty && isTokenPropertyNull(licenseValuesContainerObject, "graphPoints") == false) { // Looks like [[ 1555484400000, 843 ], [ 1555488000000, 843 ]] JArray licenseValuesAPMArray = (JArray)licenseValuesContainerObject["graphPoints"]; List <LicenseValue> licenseValuesList = parseLicenseValuesArray(licenseValuesAPMArray, licenseRule, licenseType); if (licenseValuesList != null) { licenseValuesRulesList.AddRange(licenseValuesList); } } } } } } } FileIOHelper.WriteListToCSVFile(licenseValuesRulesList, new LicenseRuleValueReportMap(), FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget)); #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ControllerLicensesReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ControllerLicensesReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.LicenseAccountIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseAccountIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseAccountReportFilePath(), FilePathMap.LicenseAccountIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.LicensesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicensesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicensesReportFilePath(), FilePathMap.LicensesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.LicenseRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseRulesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseRulesReportFilePath(), FilePathMap.LicenseRulesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseUsageAccountReportFilePath(), FilePathMap.LicenseUsageAccountIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseUsageRulesReportFilePath(), FilePathMap.LicenseUsageRulesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.LicenseRuleScopesReportFilePath(), FilePathMap.LicenseRuleScopesIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(jobConfiguration) == false) { return(true); } try { loggerConsole.Info("Prepare Licenses Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER Licenses Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Licenses Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_ACCOUNTS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSES_USAGE_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSES_USAGE_TIMELINE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSES_USAGE_TIMELINE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSES_USAGE_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 4, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSE_RULES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSE_RULES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSE_RULES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSE_RULES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSE_RULES_USAGE_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSE_RULES_USAGE_TIMELINE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSE_RULES_USAGE_TIMELINE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSE_RULES_USAGE_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 5, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSE_RULE_SCOPES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSE_RULE_SCOPES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_LICENSE_RULE_SCOPES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_LICENSE_RULE_SCOPES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1); #endregion loggerConsole.Info("Fill Licenses Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications - All loggerConsole.Info("List of Applications - All"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Accounts loggerConsole.Info("List of Accounts"); sheet = excelReport.Workbook.Worksheets[SHEET_ACCOUNTS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.LicenseAccountReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Licenses loggerConsole.Info("List of Licenses"); sheet = excelReport.Workbook.Worksheets[SHEET_LICENSES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.LicensesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region License Usage loggerConsole.Info("License Usage"); sheet = excelReport.Workbook.Worksheets[SHEET_LICENSES_USAGE_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.LicenseUsageAccountReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region License Rules loggerConsole.Info("List of License Rules"); sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.LicenseRulesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region License Rules Usage loggerConsole.Info("License Rules Usage"); sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULES_USAGE_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.LicenseUsageRulesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region License Rule Scopes loggerConsole.Info("List of License Rule Scopes"); sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULE_SCOPES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.LicenseRuleScopesReportFilePath(), 0, sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion loggerConsole.Info("Finalize Dashboards Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications - All // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; } #endregion #region Accounts // Make table sheet = excelReport.Workbook.Worksheets[SHEET_ACCOUNTS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_ACCOUNTS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountName"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountNameGlobal"].Position + 1).Width = 20; sheet.Column(table.Columns["AccessKey1"].Position + 1).Width = 15; sheet.Column(table.Columns["AccessKey2"].Position + 1).Width = 35; sheet.Column(table.Columns["ExpirationDate"].Position + 1).Width = 20; } #endregion #region Licenses // Make table sheet = excelReport.Workbook.Worksheets[SHEET_LICENSES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_LICENSES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountName"].Position + 1).Width = 15; sheet.Column(table.Columns["AgentType"].Position + 1).Width = 20; sheet.Column(table.Columns["ExpirationDate"].Position + 1).Width = 20; sheet.Column(table.Columns["From"].Position + 1).Width = 20; sheet.Column(table.Columns["To"].Position + 1).Width = 20; sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["ToUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_LICENSES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_LICENSES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "Edition", eSortType.Ascending); addFilterFieldToPivot(pivot, "Model", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addColumnFieldToPivot(pivot, "AgentType"); addDataFieldToPivot(pivot, "Average", DataFieldFunctions.Sum); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_LICENSES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; } #endregion #region License Usage // Make table sheet = excelReport.Workbook.Worksheets[SHEET_LICENSES_USAGE_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_LICENSES_USAGE); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountName"].Position + 1).Width = 15; sheet.Column(table.Columns["RuleName"].Position + 1).Width = 15; sheet.Column(table.Columns["AgentType"].Position + 1).Width = 20; sheet.Column(table.Columns["LicenseEventTime"].Position + 1).Width = 20; sheet.Column(table.Columns["LicenseEventTimeUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_LICENSES_USAGE_TIMELINE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_LICENSES_USAGE_TIMELINE); setDefaultPivotTableSettings(pivot); ExcelPivotTableField fieldR = pivot.RowFields.Add(pivot.Fields["LicenseEventTime"]); fieldR.AddDateGrouping(eDateGroupBy.Days | eDateGroupBy.Hours); fieldR.Compact = false; fieldR.Outline = false; addColumnFieldToPivot(pivot, "Controller", eSortType.Ascending); addColumnFieldToPivot(pivot, "AgentType", eSortType.Ascending); addDataFieldToPivot(pivot, "Average", DataFieldFunctions.Average); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_LICENSES_USAGE_TIMELINE, eChartType.Line, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; } #endregion #region License Rules // Make table sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_LICENSE_RULES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountName"].Position + 1).Width = 15; sheet.Column(table.Columns["RuleName"].Position + 1).Width = 25; sheet.Column(table.Columns["AgentType"].Position + 1).Width = 20; sheet.Column(table.Columns["From"].Position + 1).Width = 20; sheet.Column(table.Columns["To"].Position + 1).Width = 20; sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["ToUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_LICENSE_RULES_TYPE); setDefaultPivotTableSettings(pivot); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "NumApplications"); addRowFieldToPivot(pivot, "RuleName"); addColumnFieldToPivot(pivot, "AgentType"); addDataFieldToPivot(pivot, "Licenses", DataFieldFunctions.Sum); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_LICENSE_RULES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 10; sheet.Column(3).Width = 20; } #endregion #region License Rules Usage // Make table sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULES_USAGE_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_LICENSE_RULES_USAGE); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountName"].Position + 1).Width = 15; sheet.Column(table.Columns["RuleName"].Position + 1).Width = 25; sheet.Column(table.Columns["AgentType"].Position + 1).Width = 20; sheet.Column(table.Columns["LicenseEventTime"].Position + 1).Width = 20; sheet.Column(table.Columns["LicenseEventTimeUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULES_USAGE_TIMELINE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_LICENSE_RULES_USAGE_TIMELINE); setDefaultPivotTableSettings(pivot); ExcelPivotTableField fieldR = pivot.RowFields.Add(pivot.Fields["LicenseEventTime"]); fieldR.AddDateGrouping(eDateGroupBy.Days | eDateGroupBy.Hours); fieldR.Compact = false; fieldR.Outline = false; addColumnFieldToPivot(pivot, "Controller", eSortType.Ascending); addColumnFieldToPivot(pivot, "RuleName", eSortType.Ascending); addColumnFieldToPivot(pivot, "AgentType", eSortType.Ascending); addDataFieldToPivot(pivot, "Average", DataFieldFunctions.Average); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_LICENSE_RULES_USAGE_TIMELINE, eChartType.Line, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; } #endregion #region License Rule Scopes // Make table sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULE_SCOPES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_LICENSE_RULE_SCOPES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["AccountName"].Position + 1).Width = 15; sheet.Column(table.Columns["RuleName"].Position + 1).Width = 25; sheet.Column(table.Columns["ScopeSelector"].Position + 1).Width = 15; sheet.Column(table.Columns["MatchType"].Position + 1).Width = 10; sheet.Column(table.Columns["EntityName"].Position + 1).Width = 25; sheet.Column(table.Columns["EntityType"].Position + 1).Width = 15; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_LICENSE_RULE_SCOPES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_LICENSE_RULE_SCOPES_TYPE); setDefaultPivotTableSettings(pivot); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "RuleName"); addRowFieldToPivot(pivot, "MatchType"); addRowFieldToPivot(pivot, "EntityName"); addColumnFieldToPivot(pivot, "EntityType"); addDataFieldToPivot(pivot, "RuleID", DataFieldFunctions.Count); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_LICENSE_RULE_SCOPES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.LicensesExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } List <JobTarget> listOfTargetsAlreadyProcessed = new List <JobTarget>(jobConfiguration.Target.Count); bool reportFolderCleaned = false; bool haveProcessedAtLeastOneDBCollector = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); if (listOfTargetsAlreadyProcessed.Count(j => (j.Controller == jobTarget.Controller) && (j.ApplicationID == jobTarget.ApplicationID)) > 0) { // Already saw this target, like an APM and WEB pairs together continue; } // For databases, we only process this once for the first collector we've seen if (jobTarget.Type == APPLICATION_TYPE_DB) { if (haveProcessedAtLeastOneDBCollector == false) { haveProcessedAtLeastOneDBCollector = true; } else { continue; } } listOfTargetsAlreadyProcessed.Add(jobTarget); #region Prepare time variables long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From); long toTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To); long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000); string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes); #endregion #region Health Rule violations List <HealthRuleViolationEvent> healthRuleViolationList = new List <HealthRuleViolationEvent>(); loggerConsole.Info("Index Health Rule Violations"); JArray healthRuleViolationsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationHealthRuleViolationsDataFilePath(jobTarget)); if (healthRuleViolationsArray != null) { foreach (JObject interestingEventObject in healthRuleViolationsArray) { HealthRuleViolationEvent healthRuleViolationEvent = new HealthRuleViolationEvent(); healthRuleViolationEvent.Controller = jobTarget.Controller; healthRuleViolationEvent.ApplicationName = jobTarget.Application; healthRuleViolationEvent.ApplicationID = jobTarget.ApplicationID; healthRuleViolationEvent.EventID = getLongValueFromJToken(interestingEventObject, "id"); healthRuleViolationEvent.FromUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "startTimeInMillis")); healthRuleViolationEvent.From = healthRuleViolationEvent.FromUtc.ToLocalTime(); if (getLongValueFromJToken(interestingEventObject, "endTimeInMillis") > 0) { healthRuleViolationEvent.ToUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "endTimeInMillis")); healthRuleViolationEvent.To = healthRuleViolationEvent.FromUtc.ToLocalTime(); } healthRuleViolationEvent.Status = getStringValueFromJToken(interestingEventObject, "incidentStatus"); healthRuleViolationEvent.Severity = getStringValueFromJToken(interestingEventObject, "severity"); healthRuleViolationEvent.EventLink = String.Format(DEEPLINK_INCIDENT, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EventID, getStringValueFromJToken(interestingEventObject, "startTimeInMillis"), DEEPLINK_THIS_TIMERANGE);; healthRuleViolationEvent.Description = getStringValueFromJToken(interestingEventObject, "description"); if (isTokenPropertyNull(interestingEventObject, "triggeredEntityDefinition") == false) { healthRuleViolationEvent.HealthRuleID = getLongValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "entityId"); healthRuleViolationEvent.HealthRuleName = getStringValueFromJToken(interestingEventObject["triggeredEntityDefinition"], "name"); // TODO the health rule can't be hotlinked to until platform rewrites the screen that opens from Flash healthRuleViolationEvent.HealthRuleLink = String.Format(DEEPLINK_HEALTH_RULE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.HealthRuleID, DEEPLINK_THIS_TIMERANGE); } if (isTokenPropertyNull(interestingEventObject, "affectedEntityDefinition") == false) { healthRuleViolationEvent.EntityID = getIntValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityId"); healthRuleViolationEvent.EntityName = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "name"); string entityType = getStringValueFromJToken(interestingEventObject["affectedEntityDefinition"], "entityType"); if (entityTypeStringMapping.ContainsKey(entityType) == true) { healthRuleViolationEvent.EntityType = entityTypeStringMapping[entityType]; } else { healthRuleViolationEvent.EntityType = entityType; } // Come up with links switch (entityType) { case ENTITY_TYPE_FLOWMAP_APPLICATION: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_APPLICATION_MOBILE: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_APPLICATION_MOBILE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_TIER: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_TIER, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_NODE: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_NODE, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; case ENTITY_TYPE_FLOWMAP_BACKEND: healthRuleViolationEvent.EntityLink = String.Format(DEEPLINK_BACKEND, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, healthRuleViolationEvent.EntityID, DEEPLINK_THIS_TIMERANGE); break; default: logger.Warn("Unknown entity type {0} in affectedEntityDefinition in health rule violations", entityType); break; } } healthRuleViolationEvent.ControllerLink = String.Format(DEEPLINK_CONTROLLER, healthRuleViolationEvent.Controller, DEEPLINK_THIS_TIMERANGE); healthRuleViolationEvent.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, healthRuleViolationEvent.Controller, healthRuleViolationEvent.ApplicationID, DEEPLINK_THIS_TIMERANGE); healthRuleViolationList.Add(healthRuleViolationEvent); } } loggerConsole.Info("{0} Health Rule Violations", healthRuleViolationList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + healthRuleViolationList.Count; // Sort them healthRuleViolationList = healthRuleViolationList.OrderBy(o => o.HealthRuleName).ThenBy(o => o.From).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <HealthRuleViolationEvent>(healthRuleViolationList, new HealthRuleViolationEventReportMap(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)); #endregion #region Events List <Event> eventsList = new List <Event>(); loggerConsole.Info("Index Events"); foreach (string eventType in EVENT_TYPES) { JArray eventsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ApplicationEventsDataFilePath(jobTarget, eventType)); if (eventsArray != null) { loggerConsole.Info("{0} Events", eventType); foreach (JObject interestingEventObject in eventsArray) { Event @event = new Event(); @event.Controller = jobTarget.Controller; @event.ApplicationName = jobTarget.Application; @event.ApplicationID = jobTarget.ApplicationID; @event.EventID = getLongValueFromJToken(interestingEventObject, "id"); @event.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEventObject, "eventTime")); @event.Occurred = @event.OccurredUtc.ToLocalTime(); @event.Type = getStringValueFromJToken(interestingEventObject, "type"); @event.SubType = getStringValueFromJToken(interestingEventObject, "subType"); @event.Severity = getStringValueFromJToken(interestingEventObject, "severity"); @event.EventLink = getStringValueFromJToken(interestingEventObject, "deepLinkUrl"); @event.Summary = getStringValueFromJToken(interestingEventObject, "summary"); if (isTokenPropertyNull(interestingEventObject, "triggeredEntity") == false) { @event.TriggeredEntityID = getLongValueFromJToken(interestingEventObject["triggeredEntity"], "entityId"); @event.TriggeredEntityName = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "name"); string entityType = getStringValueFromJToken(interestingEventObject["triggeredEntity"], "entityType"); if (entityTypeStringMapping.ContainsKey(entityType) == true) { @event.TriggeredEntityType = entityTypeStringMapping[entityType]; } else { @event.TriggeredEntityType = entityType; } } foreach (JObject affectedEntity in interestingEventObject["affectedEntities"]) { string entityType = getStringValueFromJToken(affectedEntity, "entityType"); switch (entityType) { case ENTITY_TYPE_FLOWMAP_APPLICATION: // already have this data break; case ENTITY_TYPE_FLOWMAP_TIER: @event.TierID = getIntValueFromJToken(affectedEntity, "entityId"); @event.TierName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_NODE: @event.NodeID = getIntValueFromJToken(affectedEntity, "entityId"); @event.NodeName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_MACHINE: @event.MachineID = getIntValueFromJToken(affectedEntity, "entityId"); @event.MachineName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_BUSINESS_TRANSACTION: @event.BTID = getIntValueFromJToken(affectedEntity, "entityId"); @event.BTName = getStringValueFromJToken(affectedEntity, "name"); break; case ENTITY_TYPE_FLOWMAP_HEALTH_RULE: @event.TriggeredEntityID = getLongValueFromJToken(affectedEntity, "entityId"); @event.TriggeredEntityType = entityTypeStringMapping[getStringValueFromJToken(affectedEntity, "entityType")]; @event.TriggeredEntityName = getStringValueFromJToken(affectedEntity, "name"); break; default: logger.Warn("Unknown entity type {0} in affectedEntities in events", entityType); break; } } @event.ControllerLink = String.Format(DEEPLINK_CONTROLLER, @event.Controller, DEEPLINK_THIS_TIMERANGE); @event.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, @event.Controller, @event.ApplicationID, DEEPLINK_THIS_TIMERANGE); if (@event.TierID != 0) { @event.TierLink = String.Format(DEEPLINK_TIER, @event.Controller, @event.ApplicationID, @event.TierID, DEEPLINK_THIS_TIMERANGE); } if (@event.NodeID != 0) { @event.NodeLink = String.Format(DEEPLINK_NODE, @event.Controller, @event.ApplicationID, @event.NodeID, DEEPLINK_THIS_TIMERANGE); } if (@event.BTID != 0) { @event.BTLink = String.Format(DEEPLINK_BUSINESS_TRANSACTION, @event.Controller, @event.ApplicationID, @event.BTID, DEEPLINK_THIS_TIMERANGE); } eventsList.Add(@event); } } } loggerConsole.Info("{0} Events", eventsList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + eventsList.Count; // Sort them eventsList = eventsList.OrderBy(o => o.Type).ThenBy(o => o.Occurred).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <Event>(eventsList, new EventReportMap(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget)); #endregion #region Application ApplicationEventSummary application = new ApplicationEventSummary(); application.Controller = jobTarget.Controller; application.ApplicationName = jobTarget.Application; application.ApplicationID = jobTarget.ApplicationID; application.Type = jobTarget.Type; application.NumEvents = eventsList.Count; application.NumEventsError = eventsList.Count(e => e.Severity == "ERROR"); application.NumEventsWarning = eventsList.Count(e => e.Severity == "WARN"); application.NumEventsInfo = eventsList.Count(e => e.Severity == "INFO"); application.NumHRViolations = healthRuleViolationList.Count; application.NumHRViolationsCritical = healthRuleViolationList.Count(e => e.Severity == "CRITICAL"); application.NumHRViolationsWarning = healthRuleViolationList.Count(e => e.Severity == "WARNING"); application.Duration = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; application.From = jobConfiguration.Input.TimeRange.From.ToLocalTime(); application.To = jobConfiguration.Input.TimeRange.To.ToLocalTime(); application.FromUtc = jobConfiguration.Input.TimeRange.From; application.ToUtc = jobConfiguration.Input.TimeRange.To; // Determine what kind of entity we are dealing with and adjust accordingly application.ControllerLink = String.Format(DEEPLINK_CONTROLLER, application.Controller, DEEPLINK_THIS_TIMERANGE); application.ApplicationLink = String.Format(DEEPLINK_APM_APPLICATION, application.Controller, application.ApplicationID, DEEPLINK_THIS_TIMERANGE); if (application.NumEvents > 0 || application.NumHRViolations > 0) { application.HasActivity = true; } List <ApplicationEventSummary> applicationList = new List <ApplicationEventSummary>(1); applicationList.Add(application); FileIOHelper.WriteListToCSVFile(applicationList, new ApplicationEventSummaryReportMap(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)); #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ApplicationEventsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ApplicationEventsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationHealthRuleViolationsReportFilePath(), FilePathMap.ApplicationHealthRuleViolationsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsReportFilePath(), FilePathMap.ApplicationEventsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ApplicationEventsSummaryReportFilePath(), FilePathMap.ApplicationEventsSummaryIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_DB) == 0) { logger.Warn("No {0} targets to process", APPLICATION_TYPE_DB); loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_DB); return(true); } bool reportFolderCleaned = false; List <MetricExtractMapping> entityMetricExtractMappingList = getMetricsExtractMappingList(jobConfiguration); // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_DB) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); int numEntitiesTotal = 0; ParallelOptions parallelOptions = new ParallelOptions(); if (programOptions.ProcessSequentially == true) { parallelOptions.MaxDegreeOfParallelism = 1; } Parallel.Invoke(parallelOptions, () => { #region Database metrics List <DBCollector> dbCollectorsList = FileIOHelper.ReadListFromCSVFile <DBCollector>(FilePathMap.DBCollectorsIndexFilePath(jobTarget), new DBCollectorReportMap()); if (dbCollectorsList != null) { Dictionary <string, DBEntityBase> entitiesDictionaryByName = dbCollectorsList.ToDictionary(e => e.CollectorName, e => (DBEntityBase)e); Dictionary <string, List <MetricValue> > metricValuesDictionary = new Dictionary <string, List <MetricValue> >(); for (int j = 0; j < jobConfiguration.Input.HourlyTimeRanges.Count; j++) { JobTimeRange jobTimeRange = jobConfiguration.Input.HourlyTimeRanges[j]; readGranularRangeOfMetricsIntoEntities(entitiesDictionaryByName, jobTimeRange, jobTarget, entityMetricExtractMappingList, DBApplication.ENTITY_FOLDER, DBApplication.ENTITY_TYPE, metricValuesDictionary); } // Save individual metric files and create index of their internal structure foreach (KeyValuePair <string, List <MetricValue> > metricValuesListContainer in metricValuesDictionary) { if (metricValuesListContainer.Value.Count > 0) { List <MetricValue> metricValuesSorted = metricValuesListContainer.Value.OrderBy(o => o.EntityID).ThenBy(o => o.MetricID).ThenBy(o => o.EventTimeStampUtc).ToList(); FileIOHelper.WriteListToCSVFile(metricValuesSorted, new MetricValueReportMap(), FilePathMap.MetricValuesIndexFilePath(jobTarget, DBApplication.ENTITY_FOLDER, metricValuesListContainer.Key)); FileIOHelper.WriteListToCSVFile(metricValuesSorted, new MetricValueReportMap(), FilePathMap.MetricReportPerAppFilePath(jobTarget, DBApplication.ENTITY_FOLDER, metricValuesListContainer.Key)); } } Interlocked.Add(ref numEntitiesTotal, metricValuesDictionary.Keys.Count); } #endregion } ); stepTimingTarget.NumEntities = numEntitiesTotal; #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.MetricsReportFolderPath(jobTarget)); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.MetricsReportFolderPath(jobTarget)); reportFolderCleaned = true; } // Combine the generated detailed metric value files foreach (MetricExtractMapping metricExtractMapping in entityMetricExtractMappingList) { switch (metricExtractMapping.EntityType) { case DBApplication.ENTITY_TYPE: FileIOHelper.AppendTwoCSVFiles( FilePathMap.MetricReportFilePath(DBApplication.ENTITY_FOLDER, metricExtractMapping.FolderName, jobTarget), FilePathMap.MetricValuesIndexFilePath(jobTarget, DBApplication.ENTITY_FOLDER, metricExtractMapping.FolderName)); break; default: break; } } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Target step variables List <HealthCheckRuleResult> healthCheckRuleResults = new List <HealthCheckRuleResult>(); #endregion #region Preload all the reports that will be filtered by the subsequent entities loggerConsole.Info("Entity Details Data Preloading"); // This file will always be there List <HealthCheckSettingMapping> healthCheckSettingsList = FileIOHelper.ReadListFromCSVFile <HealthCheckSettingMapping>(FilePathMap.HealthCheckSettingMappingFilePath(), new HealthCheckSettingMappingMap()); if (healthCheckSettingsList == null || healthCheckSettingsList.Count == 0) { loggerConsole.Warn("Health check settings file did not load. Exiting the health checks"); return(false); } Dictionary <string, HealthCheckSettingMapping> healthCheckSettingsDictionary = healthCheckSettingsList.ToDictionary(h => h.Name, h => h); List <ControllerSummary> controllerSummariesList = FileIOHelper.ReadListFromCSVFile <ControllerSummary>(FilePathMap.ControllerSummaryIndexFilePath(jobTarget), new ControllerSummaryReportMap()); List <ControllerSetting> controllerSettingsList = FileIOHelper.ReadListFromCSVFile <ControllerSetting>(FilePathMap.ControllerSettingsIndexFilePath(jobTarget), new ControllerSettingReportMap()); #endregion #region Controller Version and Properties healthCheckRuleResults.Add( evaluate_Controller_Version( new HealthCheckRuleDescription("Platform", "PLAT-001-PLATFORM-VERSION", "Controller Version"), jobTarget, healthCheckSettingsDictionary, controllerSummariesList)); healthCheckRuleResults.Add( evaluate_Controller_SaaS_OnPrem( new HealthCheckRuleDescription("Platform", "PLAT-002-PLATFORM-SAAS", "SaaS or OnPrem"), jobTarget, healthCheckSettingsDictionary)); healthCheckRuleResults.Add( evaluate_Controller_Setting_Performance_Profile( new HealthCheckRuleDescription("Platform", "PLAT-003-PLATFORM-PERFORMANCE-PROFILE", "Performance Profile"), jobTarget, healthCheckSettingsDictionary, controllerSettingsList)); healthCheckRuleResults.AddRange( evaluate_Controller_Setting_Buffer_Sizes( new HealthCheckRuleDescription("Platform", "PLAT-004-PLATFORM-BUFFER-SIZES", "Buffer Size"), jobTarget, healthCheckSettingsDictionary, controllerSettingsList)); healthCheckRuleResults.AddRange( evaluate_Controller_Setting_ADD_Limits( new HealthCheckRuleDescription("Platform", "PLAT-005-PLATFORM-ADD-LIMITS", "ADD Limit"), jobTarget, healthCheckSettingsDictionary, controllerSettingsList)); // TODO Add things like ADD limits, etc #endregion // Remove any health rule results that weren't very good healthCheckRuleResults.RemoveAll(h => h == null); // Sort them healthCheckRuleResults = healthCheckRuleResults.OrderBy(h => h.EntityType).ThenBy(h => h.EntityName).ThenBy(h => h.Category).ThenBy(h => h.Name).ToList(); // Set version to each of the health check rule results string versionOfDEXTER = Assembly.GetEntryAssembly().GetName().Version.ToString(); foreach (HealthCheckRuleResult healthCheckRuleResult in healthCheckRuleResults) { healthCheckRuleResult.Version = versionOfDEXTER; } FileIOHelper.WriteListToCSVFile(healthCheckRuleResults, new HealthCheckRuleResultReportMap(), FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = healthCheckRuleResults.Count; #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ControllerHealthCheckReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ControllerHealthCheckReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), FilePathMap.ControllerHealthCheckRuleResultsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.ReportJobFilePath; stepTimingFunction.StepName = programOptions.ReportJob.Status.ToString(); stepTimingFunction.StepID = (int)programOptions.ReportJob.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = 0; this.DisplayJobStepStartingStatus(programOptions); this.FilePathMap = new FilePathMap(programOptions); SnowSQLDriver snowSQLDriver = null; try { snowSQLDriver = new SnowSQLDriver(programOptions.ConnectionName); if (snowSQLDriver.ValidateToolInstalled() == false) { return(false); } ; FileIOHelper.CreateFolder(this.FilePathMap.Data_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Data_Connection_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Data_Account_FolderPath()); StringBuilder sb = new StringBuilder(1024); sb.AppendFormat("ALTER SESSION SET QUERY_TAG='Snowflake Grant Report Version {0}';", Assembly.GetEntryAssembly().GetName().Version); sb.AppendLine(); sb.AppendLine("!set output_format=csv"); sb.AppendLine("!set header=true"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentAccount_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_ACCOUNT() AS CURRENT_ACCOUNT;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentRegion_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_REGION() AS CURRENT_REGION;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentVersion_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_VERSION() AS CURRENT_VERSION;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentClient_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_CLIENT() AS CURRENT_VERSION;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentUser_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_USER() AS CURRENT_USER;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentRole_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_ROLE() AS CURRENT_ROLE;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentWarehouse_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_WAREHOUSE() AS CURRENT_WAREHOUSE;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentDatabase_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_DATABASE() AS CURRENT_DATABASE;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_CurrentSchema_FilePath()); sb.AppendLine(); sb.AppendLine("SELECT CURRENT_SCHEMA() AS CURRENT_SCHEMA;"); sb.AppendLine(@"!spool off"); FileIOHelper.SaveFileToPath(sb.ToString(), FilePathMap.Data_CurrentContext_SQLQuery_FilePath(), false); loggerConsole.Info("Retrieving current connection context info"); snowSQLDriver.ExecuteSQLStatementsInFile(this.FilePathMap.Data_CurrentContext_SQLQuery_FilePath(), programOptions.ReportFolderPath); return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(programOptions, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.ReportJobFilePath; stepTimingFunction.StepName = programOptions.ReportJob.Status.ToString(); stepTimingFunction.StepID = (int)programOptions.ReportJob.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = 0; this.DisplayJobStepStartingStatus(programOptions); this.FilePathMap = new FilePathMap(programOptions); try { FileIOHelper.CreateFolder(this.FilePathMap.Data_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Data_Role_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_Grant_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Report_Role_FolderPath()); #region Grants ON and Grants TO grants for everything loggerConsole.Info("Process Grants ON and TO"); List <RoleMember> grantsOfRolesList = new List <RoleMember>(); List <Grant> grantsOnRolesList = FileIOHelper.ReadListFromCSVFile <Grant>(FilePathMap.Input_RoleShowGrantsToAndOn_FilePath(), new GrantGrantToRolesMap(), new string[] { "Initiating login request with your identity provider" }); if (grantsOnRolesList != null) { loggerConsole.Info("Loaded {0} ON and TO grants", grantsOnRolesList.Count); // Unescape special names of objects foreach (Grant grant in grantsOnRolesList) { grant.GrantedTo = grant.GrantedTo.Trim('"'); grant.GrantedBy = grant.GrantedBy.Trim('"'); // Apparently the ACCOUNT_USAGE casts 'NOTIFICATION_SUBSCRIPTION' to 'NOTIFICATION SUBSCRIPTION' // And for others that have space if (grant.ObjectType.Contains(' ') == true) { grant.ObjectType = grant.ObjectType.Replace(' ', '_'); } // Escape periods if (grant.EntityName.Contains('.') == true) { grant.EntityName = String.Format("\"{0}\"", grant.EntityName); } if (grant.DBName.Contains('.') == true) { grant.DBName = String.Format("\"{0}\"", grant.DBName); } if (grant.SchemaName.Contains('.') == true) { grant.SchemaName = String.Format("\"{0}\"", grant.SchemaName); } // Come up with ObjectName from combination of EntityName, etc. if (grant.DBName.Length == 0) { // Account level object grant.ObjectName = grant.EntityName; } else { if (grant.SchemaName.Length == 0) { // DATABASE grant.ObjectName = grant.EntityName; grant.DBName = grant.EntityName; } else { if (grant.ObjectType == "SCHEMA") { grant.ObjectName = String.Format("{0}.{1}", grant.DBName, grant.EntityName); } else { grant.ObjectName = String.Format("{0}.{1}.{2}", grant.DBName, grant.SchemaName, grant.EntityName); } } } } grantsOnRolesList.RemoveAll(g => g.DeletedOn.HasValue == true); grantsOnRolesList = grantsOnRolesList.OrderBy(g => g.ObjectType).ThenBy(g => g.ObjectName).ThenBy(g => g.GrantedTo).ToList(); FileIOHelper.WriteListToCSVFile <Grant>(grantsOnRolesList, new GrantMap(), FilePathMap.Report_RoleGrant_FilePath()); List <Grant> roleUsageGrantsList = grantsOnRolesList.Where(g => g.ObjectType == "ROLE" && g.Privilege == "USAGE").ToList(); if (roleUsageGrantsList != null) { foreach (Grant grant in roleUsageGrantsList) { RoleMember roleMember = new RoleMember(); roleMember.CreatedOn = grant.CreatedOn; roleMember.Name = grant.ObjectName; roleMember.GrantedBy = grant.GrantedBy; roleMember.GrantedTo = grant.GrantedTo; roleMember.ObjectType = grant.ObjectType; grantsOfRolesList.Add(roleMember); } grantsOfRolesList = grantsOfRolesList.OrderBy(g => g.Name).ToList(); } #region Individual Object Types loggerConsole.Info("Processing individual Object Types"); // Break them up by the type var groupObjectTypesGrouped = grantsOnRolesList.GroupBy(g => g.ObjectType); List <SingleStringRow> objectTypesList = new List <SingleStringRow>(groupObjectTypesGrouped.Count()); foreach (var group in groupObjectTypesGrouped) { loggerConsole.Info("Processing grants for {0}", group.Key); SingleStringRow objectType = new SingleStringRow(); objectType.Value = group.Key; objectTypesList.Add(objectType); #region Save this set of grants for Object Type List <Grant> grantsOfObjectTypeList = group.ToList(); // Save this set as is for one of the tables in report FileIOHelper.WriteListToCSVFile <Grant>(grantsOfObjectTypeList, new GrantMap(), FilePathMap.Report_RoleGrant_ObjectType_FilePath(group.Key)); // Pivot each section into this kind of table // // ObjectType | ObjectName | GrantedTo | OWNERSHIP | USAGE | REFERENCE | GrantN // DATABASE | SomeDB | SomeRole | X | x+ | | // Where X+ means WithGrantOption=True // X means WithGrantOption=False List <ObjectTypeGrant> objectGrantsList = new List <ObjectTypeGrant>(grantsOfObjectTypeList.Count / 5); Dictionary <string, int> privilegeToColumnDictionary = new Dictionary <string, int>(20); #endregion #region Convert this set into pivot List <string> listOfPrivileges = grantsOfObjectTypeList.Select(g => g.Privilege).Distinct().OrderBy(g => g).ToList(); // Make USAGE and OWNERSHIP be the first columns switch (group.Key) { case "ACCOUNT": break; case "DATABASE": case "FILE_FORMAT": case "FUNCTION": case "INTEGRATION": case "PROCEDURE": case "ROLE": case "SCHEMA": case "SEQUENCE": case "WAREHOUSE": listOfPrivileges.Remove("OWNERSHIP"); listOfPrivileges.Insert(0, "OWNERSHIP"); listOfPrivileges.Remove("USAGE"); listOfPrivileges.Insert(1, "USAGE"); break; case "EXTERNAL_TABLE": case "MANAGED_ACCOUNT": case "MASKING_POLICY": case "MATERIALIZED_VIEW": case "NETWORK_POLICY": case "NOTIFICATION_SUBSCRIPTION": case "PIPE": case "RESOURCE_MONITOR": case "SHARE": case "STAGE": case "STREAM": case "TABLE": case "TASK": case "USER": case "VIEW": listOfPrivileges.Remove("OWNERSHIP"); listOfPrivileges.Insert(0, "OWNERSHIP"); break; default: break; } for (int i = 0; i < listOfPrivileges.Count; i++) { privilegeToColumnDictionary.Add(listOfPrivileges[i], i); } ObjectTypeGrant latestGrantRow = new ObjectTypeGrant(); foreach (Grant grant in grantsOfObjectTypeList) { // Loop through rows, starting new objects for each combination of ObjectType+ObjectName+GrantedTo when necessary // ObjectType is always the same in this grouping // ObjectName if (latestGrantRow.ObjectType != grant.ObjectType || latestGrantRow.ObjectName != grant.ObjectName || latestGrantRow.GrantedTo != grant.GrantedTo) { // Need to start new row latestGrantRow = new ObjectTypeGrant(); latestGrantRow.ObjectType = grant.ObjectType; latestGrantRow.ObjectName = grant.ObjectName; latestGrantRow.DBName = grant.DBName; latestGrantRow.SchemaName = grant.SchemaName; latestGrantRow.EntityName = grant.EntityName; latestGrantRow.GrantedTo = grant.GrantedTo; objectGrantsList.Add(latestGrantRow); } // Find out which column to use int privilegeColumnNumber = privilegeToColumnDictionary[grant.Privilege]; switch (privilegeColumnNumber) { case 0: latestGrantRow.Privilege0 = grant.DisplaySettingWithGrantOption; break; case 1: latestGrantRow.Privilege1 = grant.DisplaySettingWithGrantOption; break; case 2: latestGrantRow.Privilege2 = grant.DisplaySettingWithGrantOption; break; case 3: latestGrantRow.Privilege3 = grant.DisplaySettingWithGrantOption; break; case 4: latestGrantRow.Privilege4 = grant.DisplaySettingWithGrantOption; break; case 5: latestGrantRow.Privilege5 = grant.DisplaySettingWithGrantOption; break; case 6: latestGrantRow.Privilege6 = grant.DisplaySettingWithGrantOption; break; case 7: latestGrantRow.Privilege7 = grant.DisplaySettingWithGrantOption; break; case 8: latestGrantRow.Privilege8 = grant.DisplaySettingWithGrantOption; break; case 9: latestGrantRow.Privilege9 = grant.DisplaySettingWithGrantOption; break; case 10: latestGrantRow.Privilege10 = grant.DisplaySettingWithGrantOption; break; case 11: latestGrantRow.Privilege11 = grant.DisplaySettingWithGrantOption; break; case 12: latestGrantRow.Privilege12 = grant.DisplaySettingWithGrantOption; break; case 13: latestGrantRow.Privilege13 = grant.DisplaySettingWithGrantOption; break; case 14: latestGrantRow.Privilege14 = grant.DisplaySettingWithGrantOption; break; case 15: latestGrantRow.Privilege15 = grant.DisplaySettingWithGrantOption; break; case 16: latestGrantRow.Privilege16 = grant.DisplaySettingWithGrantOption; break; case 17: latestGrantRow.Privilege17 = grant.DisplaySettingWithGrantOption; break; case 18: latestGrantRow.Privilege18 = grant.DisplaySettingWithGrantOption; break; case 19: latestGrantRow.Privilege19 = grant.DisplaySettingWithGrantOption; break; default: // Can't fit more than 20 privileges logger.Warn("More then 20 Privileges reached with {0} privilege for object type {1}", grant.Privilege, grant.ObjectType); break; } } List <string> privilegeColumnNames = new List <string>(privilegeToColumnDictionary.Count); for (int i = 0; i < privilegeToColumnDictionary.Count; i++) { privilegeColumnNames.Add(String.Empty); } foreach (var entry in privilegeToColumnDictionary) { privilegeColumnNames[entry.Value] = entry.Key; } // Save the pivot FileIOHelper.WriteListToCSVFile <ObjectTypeGrant>(objectGrantsList, new ObjectTypeGrantMap(privilegeColumnNames), FilePathMap.Report_RoleGrant_ObjectType_Pivoted_FilePath(group.Key)); #endregion } FileIOHelper.WriteListToCSVFile <SingleStringRow>(objectTypesList, new SingleStringRowMap(), FilePathMap.Report_RoleGrant_ObjectTypes_FilePath()); #endregion } #endregion #region Grants OF - Members of Roles (Roles and Users) loggerConsole.Info("Process Grants OF Users"); List <RoleMember> grantsOfUsersList = FileIOHelper.ReadListFromCSVFile <RoleMember>(FilePathMap.Input_RoleShowGrantsOf_FilePath(), new RoleMemberGrantsToUsersMap(), new string[] { "Initiating login request with your identity provider" }); if (grantsOfUsersList != null) { foreach (RoleMember roleMember in grantsOfUsersList) { // Unescape special names of roles roleMember.Name = roleMember.Name.Trim('"'); roleMember.GrantedTo = roleMember.GrantedTo.Trim('"'); roleMember.GrantedBy = roleMember.GrantedBy.Trim('"'); } // Remove deleted items grantsOfUsersList.RemoveAll(g => g.DeletedOn.HasValue == true); grantsOfUsersList = grantsOfUsersList.OrderBy(g => g.Name).ToList(); List <RoleMember> grantsOfRolesAndUsersList = new List <RoleMember>(); grantsOfRolesAndUsersList.AddRange(grantsOfRolesList); grantsOfRolesAndUsersList.AddRange(grantsOfUsersList); FileIOHelper.WriteListToCSVFile <RoleMember>(grantsOfRolesAndUsersList, new RoleMemberMap(), FilePathMap.Report_RoleMember_FilePath()); } #endregion // Come up with roles list for later steps too if (grantsOnRolesList == null) { grantsOnRolesList = new List <Grant>(); } List <Role> rolesList = new List <Role>(); List <string> rolesInThisAccountList = grantsOnRolesList.Where(g => g.ObjectType == "ROLE").Select(g => g.ObjectName).Distinct().ToList(); foreach (string roleName in rolesInThisAccountList) { Role role = new Role(); role.CreatedOn = DateTime.Now; role.Name = roleName; rolesList.Add(role); } if (rolesList.Where(r => r.Name == "ACCOUNTADMIN").Count() == 0) { Role role = new Role(); role.CreatedOn = DateTime.Now; role.Name = "ACCOUNTADMIN"; rolesList.Add(role); } if (rolesList.Where(r => r.Name == "PUBLIC").Count() == 0) { Role role = new Role(); role.CreatedOn = DateTime.Now; role.Name = "PUBLIC"; rolesList.Add(role); } FileIOHelper.WriteListToCSVFile <Role>(rolesList, new RoleShowRolesMap(), FilePathMap.Data_ShowRoles_FilePath()); return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(programOptions, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_WEB) == 0) { logger.Warn("No {0} targets to process", APPLICATION_TYPE_WEB); loggerConsole.Warn("No {0} targets to process", APPLICATION_TYPE_WEB); return(true); } try { loggerConsole.Info("Prepare Detected WEB Entities Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER Detected WEB Entities Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER Detected WEB Entities Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivots // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_WEB_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_WEB_PAGES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WEB_PAGES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_WEB_PAGES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_WEB_PAGES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 3, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_RESOURCES_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_RESOURCES_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_RESOURCES_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_RESOURCES_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_BUSINESS_TRANSACTIONS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_PAGE_BUSINESS_TRANSACTIONS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_GEO_LOCATIONS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Pivot"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_GEO_LOCATIONS_TYPE_PIVOT); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_GEO_LOCATIONS_TYPE_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_GEO_LOCATIONS_LIST); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 2, 1); #endregion loggerConsole.Info("Fill Detected WEB Entities Report File"); #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications - All loggerConsole.Info("List of Applications - All"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, typeof(ControllerApplication), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications loggerConsole.Info("List of Applications"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_WEB_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBApplicationsReportFilePath(), 0, typeof(WEBApplication), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Web Pages loggerConsole.Info("List of Web Pages"); sheet = excelReport.Workbook.Worksheets[SHEET_WEB_PAGES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBPagesReportFilePath(), 0, typeof(WEBPage), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Web Page Resources loggerConsole.Info("List of Web Page Resources"); sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_RESOURCES_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBPageResourcesReportFilePath(), 0, typeof(WEBPageToWebPage), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Web Page Business Transactions loggerConsole.Info("List of Web Page Business Transactions"); sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBPageBusinessTransactionsReportFilePath(), 0, typeof(WEBPageToBusinessTransaction), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Geo Locations loggerConsole.Info("List of Geo Locations"); sheet = excelReport.Workbook.Worksheets[SHEET_GEO_LOCATIONS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.WEBGeoLocationsReportFilePath(), 0, typeof(WEBGeoLocation), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion loggerConsole.Info("Finalize Detected WEB Entities Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications - All // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; } #endregion #region Applications // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_WEB_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_WEB); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; ExcelAddress cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumPages"].Position + 1, sheet.Dimension.Rows, table.Columns["NumPages"].Position + 1); var cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumAJAXRequests"].Position + 1, sheet.Dimension.Rows, table.Columns["NumAJAXRequests"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumVirtualPages"].Position + 1, sheet.Dimension.Rows, table.Columns["NumVirtualPages"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumIFrames"].Position + 1, sheet.Dimension.Rows, table.Columns["NumIFrames"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumActivity"].Position + 1, sheet.Dimension.Rows, table.Columns["NumActivity"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); cfAddressNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["NumNoActivity"].Position + 1, sheet.Dimension.Rows, table.Columns["NumNoActivity"].Position + 1); cfNum = sheet.ConditionalFormatting.AddDatabar(cfAddressNum, colorLightBlueForDatabars); } #endregion #region Web Pages // Make table sheet = excelReport.Workbook.Worksheets[SHEET_WEB_PAGES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_WEB_PAGES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["PageType"].Position + 1).Width = 10; sheet.Column(table.Columns["PageName"].Position + 1).Width = 20; sheet.Column(table.Columns["FirstSegment"].Position + 1).Width = 20; sheet.Column(table.Columns["From"].Position + 1).Width = 20; sheet.Column(table.Columns["To"].Position + 1).Width = 20; sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["ToUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_WEB_PAGES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT + 1, 1], range, PIVOT_WEB_PAGES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "HasActivity"); addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending); addFilterFieldToPivot(pivot, "NumNameSegments", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "PageType"); addRowFieldToPivot(pivot, "FirstSegment"); addRowFieldToPivot(pivot, "PageName"); addDataFieldToPivot(pivot, "PageID", DataFieldFunctions.Count, "NumPages"); addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART"); addDataFieldToPivot(pivot, "TimeTotal", DataFieldFunctions.Sum, "Time"); addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls"); addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM"); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_WEB_PAGES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; } #endregion #region Web Page Resources // Make table sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_RESOURCES_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_PAGE_RESOURCES); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["PageType"].Position + 1).Width = 10; sheet.Column(table.Columns["PageName"].Position + 1).Width = 20; sheet.Column(table.Columns["ChildPageType"].Position + 1).Width = 10; sheet.Column(table.Columns["ChildPageName"].Position + 1).Width = 20; sheet.Column(table.Columns["From"].Position + 1).Width = 20; sheet.Column(table.Columns["To"].Position + 1).Width = 20; sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["ToUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_RESOURCES_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_PAGE_RESOURCES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "HasActivity"); addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "PageName"); addRowFieldToPivot(pivot, "ChildPageType"); addRowFieldToPivot(pivot, "ChildPageName"); addDataFieldToPivot(pivot, "ChildPageID", DataFieldFunctions.Count, "NumPages"); addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART"); addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls"); addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM"); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_PAGE_RESOURCES_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; } #endregion #region Web Page Business Transactions // Make table sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_BUSINESS_TRANSACTIONS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_PAGE_BUSINESS_TRANSACTIONS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["PageType"].Position + 1).Width = 10; sheet.Column(table.Columns["PageName"].Position + 1).Width = 20; sheet.Column(table.Columns["TierName"].Position + 1).Width = 20; sheet.Column(table.Columns["BTName"].Position + 1).Width = 20; sheet.Column(table.Columns["BTType"].Position + 1).Width = 15; sheet.Column(table.Columns["From"].Position + 1).Width = 20; sheet.Column(table.Columns["To"].Position + 1).Width = 20; sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["ToUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_PAGE_BUSINESS_TRANSACTIONS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_PAGE_RESOURCES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "HasActivity"); addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "PageName"); addRowFieldToPivot(pivot, "TierName"); addRowFieldToPivot(pivot, "BTName"); addDataFieldToPivot(pivot, "BTID", DataFieldFunctions.Count, "NumBTs"); addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART"); addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls"); addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM"); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_PAGE_BUSINESS_TRANSACTIONS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; } #endregion #region Geo Locations // Make table sheet = excelReport.Workbook.Worksheets[SHEET_GEO_LOCATIONS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_GEO_LOCATIONS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["LocationName"].Position + 1).Width = 15; sheet.Column(table.Columns["Country"].Position + 1).Width = 15; sheet.Column(table.Columns["Region"].Position + 1).Width = 15; sheet.Column(table.Columns["GeoCode"].Position + 1).Width = 15; sheet.Column(table.Columns["From"].Position + 1).Width = 20; sheet.Column(table.Columns["To"].Position + 1).Width = 20; sheet.Column(table.Columns["FromUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["ToUtc"].Position + 1).Width = 20; // Make pivot sheet = excelReport.Workbook.Worksheets[SHEET_GEO_LOCATIONS_TYPE_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT + PIVOT_SHEET_CHART_HEIGHT, 1], range, PIVOT_PAGE_RESOURCES_TYPE); setDefaultPivotTableSettings(pivot); addFilterFieldToPivot(pivot, "HasActivity"); addFilterFieldToPivot(pivot, "ARTRange", eSortType.Ascending); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "ApplicationName"); addRowFieldToPivot(pivot, "LocationType"); addRowFieldToPivot(pivot, "Country"); addRowFieldToPivot(pivot, "Region"); addRowFieldToPivot(pivot, "LocationName"); addDataFieldToPivot(pivot, "ART", DataFieldFunctions.Average, "ART"); addDataFieldToPivot(pivot, "Calls", DataFieldFunctions.Sum, "Calls"); addDataFieldToPivot(pivot, "CPM", DataFieldFunctions.Average, "CPM"); ExcelChart chart = sheet.Drawings.AddChart(GRAPH_GEO_LOCATIONS_TYPE, eChartType.ColumnClustered, pivot); chart.SetPosition(2, 0, 0, 0); chart.SetSize(800, 300); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 20; sheet.Column(6).Width = 20; } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.WEBEntitiesExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); if (this.ShouldExecute(programOptions, jobConfiguration) == false) { return(true); } try { loggerConsole.Info("Prepare APM Health Check Report File"); #region Prepare the report package // Prepare package ExcelPackage excelReport = new ExcelPackage(); excelReport.Workbook.Properties.Author = String.Format("AppDynamics DEXTER {0}", Assembly.GetEntryAssembly().GetName().Version); excelReport.Workbook.Properties.Title = "AppDynamics DEXTER APM Health Check Report"; excelReport.Workbook.Properties.Subject = programOptions.JobName; excelReport.Workbook.Properties.Comments = String.Format("Targets={0}\nFrom={1:o}\nTo={2:o}", jobConfiguration.Target.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To); #endregion #region Parameters sheet // Parameters sheet ExcelWorksheet sheet = excelReport.Workbook.Worksheets.Add(SHEET_PARAMETERS); var hyperLinkStyle = sheet.Workbook.Styles.CreateNamedStyle("HyperLinkStyle"); hyperLinkStyle.Style.Font.UnderLineType = ExcelUnderLineType.Single; hyperLinkStyle.Style.Font.Color.SetColor(colorBlueForHyperlinks); var timelineStyle = sheet.Workbook.Styles.CreateNamedStyle("TimelineStyle"); timelineStyle.Style.Font.Name = "Consolas"; timelineStyle.Style.Font.Size = 8; fillReportParametersSheet(sheet, jobConfiguration, "AppDynamics DEXTER APM Health Check Report"); #endregion #region TOC sheet // Navigation sheet with link to other sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_TOC); #endregion #region Entity sheets and their associated pivot // Entity sheets sheet = excelReport.Workbook.Worksheets.Add(SHEET_CONTROLLERS_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_APPLICATIONS_ALL_LIST); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_CHECK_RULE_RESULTS); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Rating"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.Cells[3, 1].Value = "See Summary"; sheet.Cells[3, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY); sheet.Cells[3, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_CHECK_RULE_RESULTS_DESCRIPTION_PIVOT); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(PIVOT_SHEET_START_PIVOT_AT - 4 + 2, 1); sheet = excelReport.Workbook.Worksheets.Add(SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); #endregion #region Report file variables ExcelRangeBase range = null; ExcelTable table = null; #endregion loggerConsole.Info("Fill APM Health Check Report File"); #region Controllers loggerConsole.Info("List of Controllers"); sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerSummaryReportFilePath(), 0, typeof(ControllerSummary), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Applications loggerConsole.Info("List of Applications - All"); sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerApplicationsReportFilePath(), 0, typeof(ControllerApplication), sheet, LIST_SHEET_START_TABLE_AT, 1); #endregion #region Health Check Results loggerConsole.Info("List of Health Check Results"); sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS]; EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.APMHealthCheckRuleResultsReportFilePath(), 0, typeof(HealthCheckRuleResult), sheet, LIST_SHEET_START_TABLE_AT, 1); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), 1, typeof(HealthCheckRuleResult), sheet, sheet.Dimension.Rows + 1, 1); } else { EPPlusCSVHelper.ReadCSVFileIntoExcelRange(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), 0, typeof(HealthCheckRuleResult), sheet, LIST_SHEET_START_TABLE_AT, 1); } #endregion loggerConsole.Info("Finalize APM Health Check Report File"); #region Controllers sheet // Make table sheet = excelReport.Workbook.Worksheets[SHEET_CONTROLLERS_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_CONTROLLERS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 25; sheet.Column(table.Columns["Version"].Position + 1).Width = 15; } #endregion #region Applications // Make table sheet = excelReport.Workbook.Worksheets[SHEET_APPLICATIONS_ALL_LIST]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_APPLICATIONS_ALL); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["ApplicationName"].Position + 1).Width = 20; sheet.Column(table.Columns["Description"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["UpdatedBy"].Position + 1).Width = 15; sheet.Column(table.Columns["CreatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOn"].Position + 1).Width = 20; sheet.Column(table.Columns["CreatedOnUtc"].Position + 1).Width = 20; sheet.Column(table.Columns["UpdatedOnUtc"].Position + 1).Width = 20; } #endregion #region Health Check Results // Make table sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS]; logger.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); loggerConsole.Info("{0} Sheet ({1} rows)", sheet.Name, sheet.Dimension.Rows); if (sheet.Dimension.Rows > LIST_SHEET_START_TABLE_AT) { range = sheet.Cells[LIST_SHEET_START_TABLE_AT, 1, sheet.Dimension.Rows, sheet.Dimension.Columns]; table = sheet.Tables.Add(range, TABLE_HEALTH_CHECK_RULE_RESULTS); table.ShowHeader = true; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; sheet.Column(table.Columns["Controller"].Position + 1).Width = 15; sheet.Column(table.Columns["Application"].Position + 1).Width = 20; sheet.Column(table.Columns["EntityName"].Position + 1).Width = 20; sheet.Column(table.Columns["Category"].Position + 1).Width = 30; sheet.Column(table.Columns["Code"].Position + 1).Width = 15; sheet.Column(table.Columns["Name"].Position + 1).Width = 50; sheet.Column(table.Columns["Description"].Position + 1).Width = 40; ExcelAddress cfAddressGrade = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, table.Columns["Grade"].Position + 1, sheet.Dimension.Rows, table.Columns["Grade"].Position + 1); var cfGrade = sheet.ConditionalFormatting.AddThreeColorScale(cfAddressGrade); cfGrade.LowValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.LowValue.Color = colorRedFor3ColorScales; cfGrade.LowValue.Value = 1; cfGrade.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.MiddleValue.Value = 3; cfGrade.MiddleValue.Color = colorYellowFor3ColorScales; cfGrade.HighValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.HighValue.Color = colorGreenFor3ColorScales; cfGrade.HighValue.Value = 5; sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS_DESCRIPTION_PIVOT]; ExcelPivotTable pivot = sheet.PivotTables.Add(sheet.Cells[PIVOT_SHEET_START_PIVOT_AT - 4, 1], range, PIVOT_HEALTH_CHECK_RULE_RESULTS_DESCRIPTION_TYPE); setDefaultPivotTableSettings(pivot); addRowFieldToPivot(pivot, "Controller"); addRowFieldToPivot(pivot, "Application"); addRowFieldToPivot(pivot, "Category"); addRowFieldToPivot(pivot, "EntityType"); addRowFieldToPivot(pivot, "Name"); addRowFieldToPivot(pivot, "Description"); addColumnFieldToPivot(pivot, "Grade", eSortType.Ascending); addDataFieldToPivot(pivot, "Name", DataFieldFunctions.Count, "Rating"); sheet.Column(1).Width = 20; sheet.Column(2).Width = 20; sheet.Column(3).Width = 20; sheet.Column(4).Width = 20; sheet.Column(5).Width = 30; sheet.Column(6).Width = 30; } #endregion #region Health Check Results Display sheet = excelReport.Workbook.Worksheets[SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY]; List <HealthCheckRuleResult> healthCheckRuleResults = new List <HealthCheckRuleResult>(); List <HealthCheckRuleResult> healthCheckRuleResultsController = FileIOHelper.ReadListFromCSVFile(FilePathMap.ControllerHealthCheckRuleResultsReportFilePath(), new HealthCheckRuleResultReportMap()); if (healthCheckRuleResultsController != null) { healthCheckRuleResults.AddRange(healthCheckRuleResultsController); } List <HealthCheckRuleResult> healthCheckRuleResultsAPM = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMHealthCheckRuleResultsReportFilePath(), new HealthCheckRuleResultReportMap()); if (healthCheckRuleResultsAPM != null) { healthCheckRuleResults.AddRange(healthCheckRuleResultsAPM); } if (healthCheckRuleResults != null) { #region Output summary of Applications by Category table // Make this following table out of the list of health rule evaluations // Controller | Application | Category1 | Category2 | Category 3 // ------------------------------------------------------------- // CntrVal | AppName | Avg(Grade)| Avg(Grade)| Avg(Grade) // To do this, we measure number of rows (Controller/Application pairs) and Columns (Category values), and build a table int numRows = healthCheckRuleResults.Select(h => String.Format("{0}/{1}", h.Controller, h.Application)).Distinct().Count(); int numColumns = healthCheckRuleResults.Select(h => h.Category).Distinct().Count(); Dictionary <string, int> categoryTableRowsLookup = new Dictionary <string, int>(numRows); Dictionary <string, int> categoryTableColumnsLookup = new Dictionary <string, int>(numColumns); List <HealthCheckRuleResult>[,] categoryTableValues = new List <HealthCheckRuleResult> [numRows, numColumns]; foreach (HealthCheckRuleResult healthCheckRuleResult in healthCheckRuleResults) { int rowIndex = 0; int columnIndex = 0; string rowIndexValue = String.Format("{0}/{1}", healthCheckRuleResult.Controller, healthCheckRuleResult.Application); string columnIndexValue = healthCheckRuleResult.Category; if (categoryTableRowsLookup.ContainsKey(rowIndexValue) == true) { rowIndex = categoryTableRowsLookup[rowIndexValue]; } else { rowIndex = categoryTableRowsLookup.Count; categoryTableRowsLookup.Add(rowIndexValue, rowIndex); } if (categoryTableColumnsLookup.ContainsKey(columnIndexValue) == true) { columnIndex = categoryTableColumnsLookup[columnIndexValue]; } else { columnIndex = categoryTableColumnsLookup.Count; categoryTableColumnsLookup.Add(columnIndexValue, columnIndex); } // Fill in the cell List <HealthCheckRuleResult> healthCheckRuleResultsInCell = categoryTableValues[rowIndex, columnIndex]; if (healthCheckRuleResultsInCell == null) { healthCheckRuleResultsInCell = new List <HealthCheckRuleResult>(); categoryTableValues[rowIndex, columnIndex] = healthCheckRuleResultsInCell; } healthCheckRuleResultsInCell.Add(healthCheckRuleResult); } // Output headers int rowTableStart = 4; int gradeColumnStart = 4; int fromRow = rowTableStart; int fromColumn = gradeColumnStart; sheet.Cells[fromRow, 1].Value = "Controller"; sheet.Cells[fromRow, 2].Value = "Application"; sheet.Cells[fromRow, 3].Value = "ApplicationID"; foreach (KeyValuePair <string, int> categoriesKVP in categoryTableColumnsLookup) { sheet.Cells[fromRow, fromColumn].Value = categoriesKVP.Key; sheet.Cells[fromRow - 1, fromColumn].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<See Details>"")", String.Format(SHEET_HEALTH_CHECK_RULE_CATEGORY_RESULTS_DISPLAY, categoriesKVP.Key)); sheet.Cells[fromRow - 1, fromColumn].StyleName = "HyperLinkStyle"; fromColumn++; } fromRow++; // Output table for (int rowIndex = 0; rowIndex < numRows; rowIndex++) { for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { List <HealthCheckRuleResult> healthCheckRuleResultsInCell = categoryTableValues[rowIndex, columnIndex]; if (healthCheckRuleResultsInCell != null && healthCheckRuleResultsInCell.Count > 0) { double gradeAverage = Math.Round((double)healthCheckRuleResultsInCell.Sum(h => h.Grade) / healthCheckRuleResultsInCell.Count, 1); sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = gradeAverage; sheet.Cells[fromRow + rowIndex, 1].Value = healthCheckRuleResultsInCell[0].Controller; sheet.Cells[fromRow + rowIndex, 2].Value = healthCheckRuleResultsInCell[0].Application; sheet.Cells[fromRow + rowIndex, 3].Value = healthCheckRuleResultsInCell[0].ApplicationID; } else { sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = "-"; } } } fromRow = fromRow + numRows; // Insert the table range = sheet.Cells[4, 1, 4 + numRows, 3 + numColumns]; table = sheet.Tables.Add(range, TABLE_HEALTH_CHECK_RULE_APPLICATIONS); table.ShowHeader = true; table.TableStyle = TableStyles.None; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; // Resize the columns sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["Application"].Position + 1).Width = 25; for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { sheet.Column(gradeColumnStart + columnIndex).Width = 15; // Make the header column cells wrap text for Categories headings sheet.Cells[rowTableStart, gradeColumnStart + columnIndex].Style.WrapText = true; } // Make header row taller sheet.Row(rowTableStart).Height = 40; if (sheet.Dimension.Rows > rowTableStart) { // Color code it ExcelAddress cfGradeNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, 4, sheet.Dimension.Rows, 4 + numColumns); var cfGrade = sheet.ConditionalFormatting.AddThreeColorScale(cfGradeNum); cfGrade.LowValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.LowValue.Color = colorRedFor3ColorScales; cfGrade.LowValue.Value = 1; cfGrade.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.MiddleValue.Value = 3; cfGrade.MiddleValue.Color = colorYellowFor3ColorScales; cfGrade.HighValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.HighValue.Color = colorGreenFor3ColorScales; cfGrade.HighValue.Value = 5; } #endregion #region Output individual categories on separate sheets // Get list of categories for which we'll be making things List <string> listOfCategories = healthCheckRuleResults.Select(h => h.Category).Distinct().ToList <string>(); foreach (string category in listOfCategories) { sheet = excelReport.Workbook.Worksheets.Add(String.Format(SHEET_HEALTH_CHECK_RULE_CATEGORY_RESULTS_DISPLAY, category)); sheet.Cells[1, 1].Value = "Table of Contents"; sheet.Cells[1, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_TOC); sheet.Cells[1, 2].StyleName = "HyperLinkStyle"; sheet.Cells[2, 1].Value = "See Table"; sheet.Cells[2, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS); sheet.Cells[2, 2].StyleName = "HyperLinkStyle"; sheet.Cells[3, 1].Value = "See Display"; sheet.Cells[3, 2].Formula = String.Format(@"=HYPERLINK(""#'{0}'!A1"", ""<Go>"")", SHEET_HEALTH_CHECK_RULE_RESULTS_DISPLAY); sheet.Cells[3, 2].StyleName = "HyperLinkStyle"; sheet.View.FreezePanes(LIST_SHEET_START_TABLE_AT + 1, 1); // Make this following table out of the list of health rule evaluations // Controller | Application | EntityType | EntityName | Rule 1 | Rule 2 | Rule 3 // ----------------------------------------------------------------------------- // CntrVal | AppName | APMApp | AppName | Grade | Grade | Grade (with comment of value) // To do this, we measure number of rows (Controller/Application/EntityType/EntityName quads) and Columns (Rules within Category), and build a table numRows = healthCheckRuleResults.Where(h => h.Category == category).Select(h => String.Format("{0}/{1}/{2}/{3}", h.Controller, h.Application, h.EntityType, h.EntityName)).Distinct().Count(); numColumns = healthCheckRuleResults.Where(h => h.Category == category).Select(h => h.Name).Distinct().Count(); Dictionary <string, int> nameTableRowsLookup = new Dictionary <string, int>(numRows); Dictionary <string, int> nameTableColumnsLookup = new Dictionary <string, int>(numColumns); List <HealthCheckRuleResult>[,] nameTableValues = new List <HealthCheckRuleResult> [numRows, numColumns]; foreach (HealthCheckRuleResult healthCheckRuleResult in healthCheckRuleResults) { // Only process the rules with the desired category if (healthCheckRuleResult.Category != category) { continue; } int rowIndex = 0; int columnIndex = 0; string rowIndexValue = String.Format("{0}/{1}/{2}/{3}", healthCheckRuleResult.Controller, healthCheckRuleResult.Application, healthCheckRuleResult.EntityType, healthCheckRuleResult.EntityName); string columnIndexValue = healthCheckRuleResult.Name; if (nameTableRowsLookup.ContainsKey(rowIndexValue) == true) { rowIndex = nameTableRowsLookup[rowIndexValue]; } else { rowIndex = nameTableRowsLookup.Count; nameTableRowsLookup.Add(rowIndexValue, rowIndex); } if (nameTableColumnsLookup.ContainsKey(columnIndexValue) == true) { columnIndex = nameTableColumnsLookup[columnIndexValue]; } else { columnIndex = nameTableColumnsLookup.Count; nameTableColumnsLookup.Add(columnIndexValue, columnIndex); } // Fill in the cell List <HealthCheckRuleResult> healthCheckRuleResultsInCell = nameTableValues[rowIndex, columnIndex]; if (healthCheckRuleResultsInCell == null) { healthCheckRuleResultsInCell = new List <HealthCheckRuleResult>(); nameTableValues[rowIndex, columnIndex] = healthCheckRuleResultsInCell; } healthCheckRuleResultsInCell.Add(healthCheckRuleResult); } // Output headers rowTableStart = 4; gradeColumnStart = 6; fromRow = rowTableStart; fromColumn = gradeColumnStart; sheet.Cells[fromRow, 1].Value = "Controller"; sheet.Cells[fromRow, 2].Value = "Application"; sheet.Cells[fromRow, 3].Value = "ApplicationID"; sheet.Cells[fromRow, 4].Value = "EntityType"; sheet.Cells[fromRow, 5].Value = "EntityName"; foreach (KeyValuePair <string, int> namesKVP in nameTableColumnsLookup) { sheet.Cells[fromRow, fromColumn].Value = namesKVP.Key; fromColumn++; } fromRow++; // Output table for (int rowIndex = 0; rowIndex < numRows; rowIndex++) { for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { List <HealthCheckRuleResult> healthCheckRuleResultsInCell = nameTableValues[rowIndex, columnIndex]; if (healthCheckRuleResultsInCell != null && healthCheckRuleResultsInCell.Count > 0) { double gradeAverage = Math.Round((double)healthCheckRuleResultsInCell.Sum(h => h.Grade) / healthCheckRuleResultsInCell.Count, 1); sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = gradeAverage; sheet.Cells[fromRow + rowIndex, 1].Value = healthCheckRuleResultsInCell[0].Controller; sheet.Cells[fromRow + rowIndex, 2].Value = healthCheckRuleResultsInCell[0].Application; sheet.Cells[fromRow + rowIndex, 3].Value = healthCheckRuleResultsInCell[0].ApplicationID; sheet.Cells[fromRow + rowIndex, 4].Value = healthCheckRuleResultsInCell[0].EntityType; sheet.Cells[fromRow + rowIndex, 5].Value = healthCheckRuleResultsInCell[0].EntityName; StringBuilder sb = new StringBuilder(healthCheckRuleResultsInCell.Count * 128); for (int k = 0; k < healthCheckRuleResultsInCell.Count; k++) { HealthCheckRuleResult healthCheckRuleResult = healthCheckRuleResultsInCell[k]; sb.AppendFormat("{0}: {1}\n", k + 1, wordWrapString(healthCheckRuleResult.Description, 100)); } // Limit the size of the comment generated to ~2K of text because I think the Excel barfs when the comments are too long. if (sb.Length > 2500) { sb.Length = 2547; sb.Append("..."); } // Excessive comments in the workbook lead to poor use experience. Need to rethink and refactor this ExcelComment comment = sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].AddComment(sb.ToString(), healthCheckRuleResultsInCell[0].Code); comment.AutoFit = true; } else { sheet.Cells[fromRow + rowIndex, gradeColumnStart + columnIndex].Value = "-"; } } } fromRow = fromRow + numRows; // Insert the table range = sheet.Cells[4, 1, 4 + numRows, 5 + numColumns]; table = sheet.Tables.Add(range, getExcelTableOrSheetSafeString(String.Format(TABLE_HEALTH_CHECK_RULE_CATEGORY_RESULTS, category))); table.ShowHeader = true; table.TableStyle = TableStyles.None; table.TableStyle = TableStyles.Medium2; table.ShowFilter = true; table.ShowTotal = false; // Resize the columns sheet.Column(table.Columns["Controller"].Position + 1).Width = 20; sheet.Column(table.Columns["Application"].Position + 1).Width = 25; sheet.Column(table.Columns["EntityName"].Position + 1).Width = 25; sheet.Column(table.Columns["EntityType"].Position + 1).Width = 25; for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { sheet.Column(gradeColumnStart + columnIndex).Width = 15; // Make the header column cells wrap text for Categories headings sheet.Cells[rowTableStart, gradeColumnStart + columnIndex].Style.WrapText = true; } // Make header row taller sheet.Row(rowTableStart).Height = 50; if (sheet.Dimension.Rows > rowTableStart) { // Color code it ExcelAddress cfGradeNum = new ExcelAddress(LIST_SHEET_START_TABLE_AT + 1, 5, sheet.Dimension.Rows, 5 + numColumns); var cfGrade = sheet.ConditionalFormatting.AddThreeColorScale(cfGradeNum); cfGrade.LowValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.LowValue.Color = colorRedFor3ColorScales; cfGrade.LowValue.Value = 1; cfGrade.MiddleValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.MiddleValue.Value = 3; cfGrade.MiddleValue.Color = colorYellowFor3ColorScales; cfGrade.HighValue.Type = eExcelConditionalFormattingValueObjectType.Num; cfGrade.HighValue.Color = colorGreenFor3ColorScales; cfGrade.HighValue.Value = 5; } } #endregion } #endregion #region TOC sheet // TOC sheet again sheet = excelReport.Workbook.Worksheets[SHEET_TOC]; fillTableOfContentsSheet(sheet, excelReport); #endregion #region Save file FileIOHelper.CreateFolder(FilePathMap.ReportFolderPath()); string reportFilePath = FilePathMap.HealthCheckResultsExcelReportFilePath(jobConfiguration.Input.TimeRange); logger.Info("Saving Excel report {0}", reportFilePath); loggerConsole.Info("Saving Excel report {0}", reportFilePath); try { // Save full report Excel files excelReport.SaveAs(new FileInfo(reportFilePath)); } catch (InvalidOperationException ex) { logger.Warn("Unable to save Excel file {0}", reportFilePath); logger.Warn(ex); loggerConsole.Warn("Unable to save Excel file {0}", reportFilePath); } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; stepTimingTarget.NumEntities = 0; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Prepare time variables long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From); long toTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To); long differenceInMinutes = (toTimeUnix - fromTimeUnix) / (60000); string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes); #endregion #region Notification Events loggerConsole.Info("Index Notification Events"); List <Event> eventsList = new List <Event>(); JObject notificationsContainer = FileIOHelper.LoadJObjectFromFile(FilePathMap.NotificationsDataFilePath(jobTarget)); if (notificationsContainer != null) { if (isTokenPropertyNull(notificationsContainer, "notifications") == false) { foreach (JObject interestingEvent in notificationsContainer["notifications"]) { if (isTokenPropertyNull(interestingEvent, "notificationData") == false && isTokenPropertyNull(interestingEvent["notificationData"], "affectedEntities") == false) { foreach (JObject affectedEntity in interestingEvent["notificationData"]["affectedEntities"]) { Event @event = new Event(); @event.Controller = jobTarget.Controller; @event.EventID = getLongValueFromJToken(interestingEvent, "id"); @event.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEvent["notificationData"], "time")); try { @event.Occurred = @event.OccurredUtc.ToLocalTime(); } catch { } @event.Type = getStringValueFromJToken(interestingEvent["notificationData"], "eventType"); @event.Severity = getStringValueFromJToken(interestingEvent["notificationData"], "severity"); @event.Summary = getStringValueFromJToken(interestingEvent["notificationData"], "summary"); @event.TriggeredEntityID = getLongValueFromJToken(affectedEntity, "entityId"); @event.TriggeredEntityType = getStringValueFromJToken(affectedEntity, "entityType"); @event.ApplicationID = getLongValueFromJToken(interestingEvent["notificationData"], "applicationId"); @event.TierID = getLongValueFromJToken(interestingEvent["notificationData"], "applicationComponentId"); @event.NodeID = getLongValueFromJToken(interestingEvent["notificationData"], "applicationComponentNodeId"); @event.BTID = getLongValueFromJToken(interestingEvent["notificationData"], "businessTransactionId"); @event.ControllerLink = String.Format(DEEPLINK_CONTROLLER, @event.Controller, DEEPLINK_THIS_TIMERANGE); eventsList.Add(@event); } } } } } loggerConsole.Info("{0} Notification Events", eventsList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + eventsList.Count; // Sort them eventsList = eventsList.OrderBy(o => o.Type).ThenBy(o => o.Occurred).ThenBy(o => o.Severity).ToList(); FileIOHelper.WriteListToCSVFile <Event>(eventsList, new EventReportMap(), FilePathMap.NotificationsIndexFilePath(jobTarget)); #endregion #region Audit Events loggerConsole.Info("Index Audit Log Events"); List <AuditEvent> auditEventsList = new List <AuditEvent>(); JArray auditEvents = FileIOHelper.LoadJArrayFromFile(FilePathMap.AuditEventsDataFilePath(jobTarget)); if (auditEvents != null) { foreach (JObject interestingEvent in auditEvents) { AuditEvent @event = new AuditEvent(); @event.Controller = jobTarget.Controller; @event.EntityID = getLongValueFromJToken(interestingEvent, "objectId"); @event.EntityType = getStringValueFromJToken(interestingEvent, "objectType"); @event.EntityName = getStringValueFromJToken(interestingEvent, "objectName"); @event.UserName = getStringValueFromJToken(interestingEvent, "userName"); @event.AccountName = getStringValueFromJToken(interestingEvent, "accountName"); @event.LoginType = getStringValueFromJToken(interestingEvent, "securityProviderType"); @event.Action = getStringValueFromJToken(interestingEvent, "action"); @event.EntityID = getLongValueFromJToken(interestingEvent, "objectId"); @event.EntityType = getStringValueFromJToken(interestingEvent, "objectType"); @event.EntityName = getStringValueFromJToken(interestingEvent, "objectName"); @event.OccurredUtc = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(interestingEvent, "timeStamp")); try { @event.Occurred = @event.OccurredUtc.ToLocalTime(); } catch { } auditEventsList.Add(@event); } } loggerConsole.Info("{0} Audit Events", auditEventsList.Count); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + auditEventsList.Count; // Sort them auditEventsList = auditEventsList.OrderBy(o => o.Occurred).ToList(); FileIOHelper.WriteListToCSVFile <AuditEvent>(auditEventsList, new AuditEventReportMap(), FilePathMap.AuditEventsIndexFilePath(jobTarget)); #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ControllerEventsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ControllerEventsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.NotificationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.NotificationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.NotificationsReportFilePath(), FilePathMap.NotificationsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.AuditEventsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.AuditEventsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.AuditEventsReportFilePath(), FilePathMap.AuditEventsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.ReportJobFilePath; stepTimingFunction.StepName = programOptions.ReportJob.Status.ToString(); stepTimingFunction.StepID = (int)programOptions.ReportJob.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = 0; this.DisplayJobStepStartingStatus(programOptions); this.FilePathMap = new FilePathMap(programOptions); SnowSQLDriver snowSQLDriver = null; try { snowSQLDriver = new SnowSQLDriver(programOptions.ConnectionName); if (snowSQLDriver.ValidateToolInstalled() == false) { return(false); } ; FileIOHelper.CreateFolder(this.FilePathMap.Data_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Data_User_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Data_Role_FolderPath()); FileIOHelper.CreateFolder(this.FilePathMap.Data_Grant_FolderPath()); #region List of roles and users loggerConsole.Info("Retrieving list of roles and users"); StringBuilder sb = new StringBuilder(1024); sb.AppendFormat("ALTER SESSION SET QUERY_TAG='Snowflake Grant Report Version {0}';", Assembly.GetEntryAssembly().GetName().Version); sb.AppendLine(); sb.AppendLine("!set output_format=csv"); sb.AppendLine("!set header=true"); sb.AppendLine("USE ROLE SECURITYADMIN;"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_ShowRoles_FilePath()); sb.AppendLine(); sb.AppendLine("SHOW ROLES;"); sb.AppendLine(@"!spool off"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_ShowUsers_FilePath()); sb.AppendLine(); sb.AppendLine("SHOW USERS;"); sb.AppendLine(@"!spool off"); FileIOHelper.SaveFileToPath(sb.ToString(), FilePathMap.Data_UsersAndRoles_SQLQuery_FilePath(), false); snowSQLDriver.ExecuteSQLStatementsInFile(this.FilePathMap.Data_UsersAndRoles_SQLQuery_FilePath(), programOptions.ReportFolderPath); #endregion #region User details List <User> usersList = FileIOHelper.ReadListFromCSVFile <User>(FilePathMap.Data_ShowUsers_FilePath(), new UserShowUsersMinimalMap()); if (usersList != null) { loggerConsole.Info("Retrieving user details for {0} users", usersList.Count); sb = new StringBuilder(256 * usersList.Count); sb.AppendFormat("ALTER SESSION SET QUERY_TAG='Snowflake Grant Report Version {0}';", Assembly.GetEntryAssembly().GetName().Version); sb.AppendLine(); sb.AppendLine("!set output_format=csv"); sb.AppendLine("!set header=true"); sb.AppendLine("USE ROLE SECURITYADMIN;"); sb.AppendLine("USE ROLE ACCOUNTADMIN;"); for (int i = 0; i < usersList.Count; i++) { User user = usersList[i]; sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_DescribeUser_FilePath(user.NAME)); sb.AppendLine(); sb.AppendFormat("DESCRIBE USER {0};", quoteObjectIdentifier(user.NAME)); sb.AppendLine(); sb.AppendLine(@"!spool off"); } FileIOHelper.SaveFileToPath(sb.ToString(), FilePathMap.DescribeUserSQLQuery_FilePath(), false); snowSQLDriver.ExecuteSQLStatementsInFile(FilePathMap.DescribeUserSQLQuery_FilePath(), programOptions.ReportFolderPath); } #endregion #region Role Grants List <Role> rolesList = FileIOHelper.ReadListFromCSVFile <Role>(FilePathMap.Data_ShowRoles_FilePath(), new RoleShowRolesMinimalMap()); if (rolesList != null) { #region Role Grants On loggerConsole.Info("Retrieving role grants ON for {0} roles", rolesList.Count); sb = new StringBuilder(256 * rolesList.Count); sb.AppendFormat("ALTER SESSION SET QUERY_TAG='Snowflake Grant Report Version {0}';", Assembly.GetEntryAssembly().GetName().Version); sb.AppendLine(); sb.AppendLine("!set output_format=csv"); sb.AppendLine("!set header=true"); sb.AppendLine("USE ROLE SECURITYADMIN;"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_RoleShowGrantsOn_FilePath()); sb.AppendLine(); for (int i = 0; i < rolesList.Count; i++) { Role role = rolesList[i]; sb.AppendFormat("SHOW GRANTS ON ROLE {0};", quoteObjectIdentifier(role.Name)); sb.AppendLine(); if (i == 0) { sb.AppendLine("!set header=false"); } } sb.AppendLine(@"!spool off"); FileIOHelper.SaveFileToPath(sb.ToString(), FilePathMap.Data_RoleGrantsOn_SQLQuery_FilePath(), false); snowSQLDriver.ExecuteSQLStatementsInFile(FilePathMap.Data_RoleGrantsOn_SQLQuery_FilePath(), programOptions.ReportFolderPath); #endregion #region Role Grants To loggerConsole.Info("Retrieving role grants TO for {0} roles", rolesList.Count); sb = new StringBuilder(256 * rolesList.Count); sb.AppendFormat("ALTER SESSION SET QUERY_TAG='Snowflake Grant Report Version {0}';", Assembly.GetEntryAssembly().GetName().Version); sb.AppendLine(); sb.AppendLine("!set output_format=csv"); sb.AppendLine("!set header=true"); sb.AppendLine("USE ROLE SECURITYADMIN;"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_RoleShowGrantsTo_FilePath()); sb.AppendLine(); for (int i = 0; i < rolesList.Count; i++) { Role role = rolesList[i]; sb.AppendFormat("SHOW GRANTS TO ROLE {0};", quoteObjectIdentifier(role.Name)); sb.AppendLine(); if (i == 0) { sb.AppendLine("!set header=false"); } } sb.AppendLine(@"!spool off"); FileIOHelper.SaveFileToPath(sb.ToString(), FilePathMap.Data_RoleGrantsTo_SQLQuery_FilePath(), false); snowSQLDriver.ExecuteSQLStatementsInFile(FilePathMap.Data_RoleGrantsTo_SQLQuery_FilePath(), programOptions.ReportFolderPath); #endregion #region Role Grants Of loggerConsole.Info("Retrieving role grants OF for {0} roles", rolesList.Count); sb = new StringBuilder(256 * rolesList.Count); sb.AppendFormat("ALTER SESSION SET QUERY_TAG='Snowflake Grant Report Version {0}';", Assembly.GetEntryAssembly().GetName().Version); sb.AppendLine(); sb.AppendLine("!set output_format=csv"); sb.AppendLine("!set header=true"); sb.AppendLine("USE ROLE SECURITYADMIN;"); sb.AppendFormat("!spool \"{0}\"", FilePathMap.Data_RoleShowGrantsOf_FilePath()); sb.AppendLine(); for (int i = 0; i < rolesList.Count; i++) { Role role = rolesList[i]; // Output header for only the first item sb.AppendFormat("SHOW GRANTS OF ROLE {0};", quoteObjectIdentifier(role.Name)); sb.AppendLine(); if (i == 0) { sb.AppendLine("!set header=false"); } } sb.AppendLine(@"!spool off"); FileIOHelper.SaveFileToPath(sb.ToString(), FilePathMap.Data_RoleGrantsOf_SQLQuery_FilePath(), false); snowSQLDriver.ExecuteSQLStatementsInFile(FilePathMap.Data_RoleGrantsOf_SQLQuery_FilePath(), programOptions.ReportFolderPath); #endregion } #endregion return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(programOptions, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_DB) == 0) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.Where(t => t.Type == APPLICATION_TYPE_DB).ToList().GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_DB) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Database Collector Definitions List <DBCollectorDefinition> dbCollectorDefinitionsList = null; JArray dbCollectorDefinitionsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.DBCollectorDefinitionsDataFilePath(jobTarget)); if (dbCollectorDefinitionsArray != null) { loggerConsole.Info("Index List of DB Collector Definitions ({0} entities)", dbCollectorDefinitionsArray.Count); dbCollectorDefinitionsList = new List <DBCollectorDefinition>(dbCollectorDefinitionsArray.Count); foreach (JToken dbCollectorDefinitionToken in dbCollectorDefinitionsArray) { if (isTokenPropertyNull(dbCollectorDefinitionToken, "config") == false) { JToken dbCollectorDefinitionConfigToken = dbCollectorDefinitionToken["config"]; DBCollectorDefinition dbCollectorDefinition = new DBCollectorDefinition(); dbCollectorDefinition.Controller = jobTarget.Controller; dbCollectorDefinition.CollectorName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "name"); dbCollectorDefinition.CollectorType = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "type"); dbCollectorDefinition.CollectorStatus = getStringValueFromJToken(dbCollectorDefinitionToken, "collectorStatus"); dbCollectorDefinition.AgentName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "agentName"); dbCollectorDefinition.Host = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostname"); dbCollectorDefinition.Port = getIntValueFromJToken(dbCollectorDefinitionConfigToken, "port"); dbCollectorDefinition.UserName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "username"); dbCollectorDefinition.IsEnabled = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "enabled"); dbCollectorDefinition.IsLoggingEnabled = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "loggingEnabled"); dbCollectorDefinition.DatabaseName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "databaseName"); dbCollectorDefinition.FailoverPartner = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "failoverPartner"); dbCollectorDefinition.SID = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "sid"); dbCollectorDefinition.CustomConnectionString = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "customConnectionString"); dbCollectorDefinition.UseWindowsAuth = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useWindowsAuth"); dbCollectorDefinition.ConnectAsSysDBA = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "connectAsSysdba"); dbCollectorDefinition.UseServiceName = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useServiceName"); dbCollectorDefinition.UseSSL = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useSSL"); dbCollectorDefinition.IsEnterpriseDB = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "enterpriseDB"); dbCollectorDefinition.IsOSMonitoringEnabled = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "enableOSMonitor"); dbCollectorDefinition.UseLocalWMI = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "useLocalWMI"); dbCollectorDefinition.HostOS = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostOS"); dbCollectorDefinition.HostDomain = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostDomain"); dbCollectorDefinition.HostUserName = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "hostUsername"); dbCollectorDefinition.UseCertificateAuth = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "certificateAuth"); dbCollectorDefinition.SSHPort = getIntValueFromJToken(dbCollectorDefinitionConfigToken, "sshPort"); dbCollectorDefinition.DBInstanceID = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "dbInstanceIdentifier"); dbCollectorDefinition.Region = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "region"); dbCollectorDefinition.RemoveLiterals = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "removeLiterals"); dbCollectorDefinition.IsLDAPEnabled = getBoolValueFromJToken(dbCollectorDefinitionConfigToken, "ldapEnabled"); dbCollectorDefinition.CreatedBy = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "createdBy"); dbCollectorDefinition.CreatedOn = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dbCollectorDefinitionConfigToken, "createdOn")); dbCollectorDefinition.ModifiedBy = getStringValueFromJToken(dbCollectorDefinitionConfigToken, "modifiedBy"); dbCollectorDefinition.ModifiedOn = UnixTimeHelper.ConvertFromUnixTimestamp(getLongValueFromJToken(dbCollectorDefinitionConfigToken, "modifiedOn")); dbCollectorDefinition.ConfigID = getLongValueFromJToken(dbCollectorDefinitionToken, "configId"); dbCollectorDefinition.ControllerLink = String.Format(DEEPLINK_CONTROLLER, dbCollectorDefinition.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); dbCollectorDefinition.ApplicationLink = String.Format(DEEPLINK_DB_APPLICATION, dbCollectorDefinition.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); dbCollectorDefinitionsList.Add(dbCollectorDefinition); } } // Sort them dbCollectorDefinitionsList = dbCollectorDefinitionsList.OrderBy(o => o.CollectorType).ThenBy(o => o.CollectorName).ToList(); FileIOHelper.WriteListToCSVFile(dbCollectorDefinitionsList, new DBCollectorDefinitionReportMap(), FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + dbCollectorDefinitionsList.Count; } #endregion #region Custom Metrics List <DBCustomMetric> dbCustomMetricsList = null; JArray dbCustomMetricsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.DBCustomMetricsDataFilePath(jobTarget)); if (dbCustomMetricsArray != null) { loggerConsole.Info("Index List of DB Custom Metrics ({0} entities)", dbCustomMetricsArray.Count); dbCustomMetricsList = new List <DBCustomMetric>(dbCustomMetricsArray.Count); foreach (JObject dbCustomMetricObject in dbCustomMetricsArray) { DBCustomMetric dbCustomMetric = new DBCustomMetric(); dbCustomMetric.Controller = jobTarget.Controller; dbCustomMetric.MetricName = getStringValueFromJToken(dbCustomMetricObject, "name"); dbCustomMetric.MetricID = getLongValueFromJToken(dbCustomMetricObject, "id"); dbCustomMetric.Frequency = getIntValueFromJToken(dbCustomMetricObject, "timeIntervalInMin"); dbCustomMetric.IsEvent = getBoolValueFromJToken(dbCustomMetricObject, "isEvent"); dbCustomMetric.Query = getStringValueFromJToken(dbCustomMetricObject, "queryText"); // Get SQL statement type dbCustomMetric.SQLClauseType = getSQLClauseType(dbCustomMetric.Query, 100); // Check other clauses dbCustomMetric.SQLWhere = doesSQLStatementContain(dbCustomMetric.Query, @"\bWHERE\s"); dbCustomMetric.SQLGroupBy = doesSQLStatementContain(dbCustomMetric.Query, @"\bGROUP BY\s"); dbCustomMetric.SQLOrderBy = doesSQLStatementContain(dbCustomMetric.Query, @"\bORDER BY\s"); dbCustomMetric.SQLHaving = doesSQLStatementContain(dbCustomMetric.Query, @"\bHAVING\s"); dbCustomMetric.SQLUnion = doesSQLStatementContain(dbCustomMetric.Query, @"\bUNION\s"); // Get join type if present dbCustomMetric.SQLJoinType = getSQLJoinType(dbCustomMetric.Query); // Now lookup the collector assigned if (dbCollectorDefinitionsList != null) { if (isTokenPropertyNull(dbCustomMetricObject, "dbaemc") == false) { if (isTokenPropertyNull(dbCustomMetricObject["dbaemc"], "dbServerIds") == false) { JValue configIDValue = null; try { configIDValue = (JValue)dbCustomMetricObject["dbaemc"]["dbServerIds"].First(); } catch { } if (configIDValue != null) { long configID = (long)configIDValue; DBCollectorDefinition dbCollectorDefinition = dbCollectorDefinitionsList.Where(d => d.ConfigID == configID).FirstOrDefault(); if (dbCollectorDefinition != null) { dbCustomMetric.CollectorName = dbCollectorDefinition.CollectorName; dbCustomMetric.CollectorType = dbCollectorDefinition.CollectorType; dbCustomMetric.ConfigID = dbCollectorDefinition.ConfigID; } } } } } dbCustomMetricsList.Add(dbCustomMetric); } // Sort them dbCustomMetricsList = dbCustomMetricsList.OrderBy(o => o.CollectorType).ThenBy(o => o.CollectorName).ToList(); FileIOHelper.WriteListToCSVFile(dbCustomMetricsList, new DBCustomMetricReportMap(), FilePathMap.DBCustomMetricsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + dbCustomMetricsList.Count; } #endregion #region Application loggerConsole.Info("Index Application"); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + 1; DBApplicationConfiguration applicationConfiguration = new DBApplicationConfiguration(); applicationConfiguration.Controller = jobTarget.Controller; applicationConfiguration.ControllerLink = String.Format(DEEPLINK_CONTROLLER, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); applicationConfiguration.ApplicationName = jobTarget.Application; applicationConfiguration.ApplicationLink = String.Format(DEEPLINK_DB_APPLICATION, applicationConfiguration.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); applicationConfiguration.ApplicationID = jobTarget.ApplicationID; if (dbCollectorDefinitionsList != null) { applicationConfiguration.NumCollectorDefinitions = dbCollectorDefinitionsList.Count; } if (dbCustomMetricsList != null) { applicationConfiguration.NumCustomMetrics = dbCustomMetricsList.Count; } List <DBApplicationConfiguration> applicationConfigurationsList = new List <DBApplicationConfiguration>(1); applicationConfigurationsList.Add(applicationConfiguration); FileIOHelper.WriteListToCSVFile(applicationConfigurationsList, new DBApplicationConfigurationReportMap(), FilePathMap.DBApplicationConfigurationIndexFilePath(jobTarget)); #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.DBConfigurationReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.DBConfigurationReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.DBCollectorDefinitionsReportFilePath(), FilePathMap.DBCollectorDefinitionsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.DBCustomMetricsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DBCustomMetricsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.DBCustomMetricsReportFilePath(), FilePathMap.DBCustomMetricsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.DBApplicationConfigurationIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.DBApplicationConfigurationIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.DBApplicationConfigurationReportFilePath(), FilePathMap.DBApplicationConfigurationIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } bool reportFolderCleaned = false; // Process each Controller once int i = 0; var controllers = jobConfiguration.Target.GroupBy(t => t.Controller); foreach (var controllerGroup in controllers) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = controllerGroup.ToList()[0]; StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; stepTimingTarget.NumEntities = 0; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Controller Settings loggerConsole.Info("Controller Settings"); List <ControllerSetting> controllerSettingsList = new List <ControllerSetting>(); JArray controllerSettingsArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.ControllerSettingsDataFilePath(jobTarget)); if (controllerSettingsArray != null) { foreach (JObject controllerSettingObject in controllerSettingsArray) { ControllerSetting controllerSetting = new ControllerSetting(); controllerSetting.Controller = jobTarget.Controller; controllerSetting.ControllerLink = String.Format(DEEPLINK_CONTROLLER, controllerSetting.Controller, DEEPLINK_TIMERANGE_LAST_15_MINUTES); controllerSetting.Name = getStringValueFromJToken(controllerSettingObject, "name"); controllerSetting.Description = getStringValueFromJToken(controllerSettingObject, "description"); controllerSetting.Value = getStringValueFromJToken(controllerSettingObject, "value"); controllerSetting.Updateable = getBoolValueFromJToken(controllerSettingObject, "updateable"); controllerSetting.Scope = getStringValueFromJToken(controllerSettingObject, "scope"); controllerSettingsList.Add(controllerSetting); } } controllerSettingsList = controllerSettingsList.OrderBy(c => c.Name).ToList(); FileIOHelper.WriteListToCSVFile(controllerSettingsList, new ControllerSettingReportMap(), FilePathMap.ControllerSettingsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + controllerSettingsList.Count; #endregion #region HTTP Templates loggerConsole.Info("HTTP Templates"); List <HTTPAlertTemplate> httpTemplatesList = new List <HTTPAlertTemplate>(); JArray httpTemplatesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.HTTPTemplatesDataFilePath(jobTarget)); JArray httpTemplatesDetailArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.HTTPTemplatesDetailDataFilePath(jobTarget)); if (httpTemplatesArray != null) { foreach (JObject httpTemplateObject in httpTemplatesArray) { HTTPAlertTemplate httpAlertTemplate = new HTTPAlertTemplate(); httpAlertTemplate.Controller = jobTarget.Controller; httpAlertTemplate.Name = getStringValueFromJToken(httpTemplateObject, "name"); httpAlertTemplate.Method = getStringValueFromJToken(httpTemplateObject, "method"); httpAlertTemplate.Scheme = getStringValueFromJToken(httpTemplateObject, "scheme"); httpAlertTemplate.Host = getStringValueFromJToken(httpTemplateObject, "host"); httpAlertTemplate.Port = getIntValueFromJToken(httpTemplateObject, "port"); httpAlertTemplate.Path = getStringValueFromJToken(httpTemplateObject, "path"); httpAlertTemplate.Query = getStringValueFromJToken(httpTemplateObject, "query"); httpAlertTemplate.AuthType = getStringValueFromJToken(httpTemplateObject, "authType"); httpAlertTemplate.AuthUsername = getStringValueFromJToken(httpTemplateObject, "authUsername"); httpAlertTemplate.AuthPassword = getStringValueFromJToken(httpTemplateObject, "authPassword"); httpAlertTemplate.Headers = getStringValueOfObjectFromJToken(httpTemplateObject, "headers", true); if (isTokenPropertyNull(httpTemplateObject, "payloadTemplate") == false) { httpAlertTemplate.ContentType = getStringValueFromJToken(httpTemplateObject["payloadTemplate"], "httpRequestActionMediaType"); httpAlertTemplate.FormData = getStringValueOfObjectFromJToken(httpTemplateObject["payloadTemplate"], "formDataPairs", true); httpAlertTemplate.Payload = getStringValueFromJToken(httpTemplateObject["payloadTemplate"], "payload"); } httpAlertTemplate.ConnectTimeout = getLongValueFromJToken(httpTemplateObject, "connectTimeoutInMillis"); httpAlertTemplate.SocketTimeout = getLongValueFromJToken(httpTemplateObject, "socketTimeoutInMillis"); httpAlertTemplate.ResponseAny = getStringValueOfObjectFromJToken(httpTemplateObject, "responseMatchCriteriaAnyTemplate"); httpAlertTemplate.ResponseNone = getStringValueOfObjectFromJToken(httpTemplateObject, "responseMatchCriteriaNoneTemplate"); if (httpTemplatesDetailArray != null) { JToken httpAlertTemplateToken = httpTemplatesDetailArray.Where(t => t["name"].ToString() == httpAlertTemplate.Name).FirstOrDefault(); if (httpAlertTemplateToken != null) { httpAlertTemplate.TemplateID = getLongValueFromJToken(httpAlertTemplateToken, "id"); } } httpTemplatesList.Add(httpAlertTemplate); } } httpTemplatesList = httpTemplatesList.OrderBy(c => c.Name).ToList(); FileIOHelper.WriteListToCSVFile(httpTemplatesList, new HTTPAlertTemplateReportMap(), FilePathMap.HTTPTemplatesIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + httpTemplatesList.Count; #endregion #region Email Templates loggerConsole.Info("Email Templates"); List <EmailAlertTemplate> emailTemplatesList = new List <EmailAlertTemplate>(); JArray emailTemplatesArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.EmailTemplatesDataFilePath(jobTarget)); JArray emailTemplatesDetailArray = FileIOHelper.LoadJArrayFromFile(FilePathMap.EmailTemplatesDetailDataFilePath(jobTarget)); if (emailTemplatesArray != null) { foreach (JObject emailTemplateObject in emailTemplatesArray) { EmailAlertTemplate emailAlertTemplate = new EmailAlertTemplate(); emailAlertTemplate.Controller = jobTarget.Controller; emailAlertTemplate.Name = getStringValueFromJToken(emailTemplateObject, "name"); emailAlertTemplate.OneEmailPerEvent = getBoolValueFromJToken(emailTemplateObject, "oneEmailPerEvent"); emailAlertTemplate.EventLimit = getLongValueFromJToken(emailTemplateObject, "eventClampLimit"); try { string[] emails = emailTemplateObject["toRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray(); emailAlertTemplate.To = String.Join(";", emails); } catch { } try { string[] emails = emailTemplateObject["ccRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray(); emailAlertTemplate.CC = String.Join(";", emails); } catch { } try { string[] emails = emailTemplateObject["bccRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray(); emailAlertTemplate.BCC = String.Join(";", emails); } catch { } try { string[] emails = emailTemplateObject["testToRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray(); emailAlertTemplate.TestTo = String.Join(";", emails); } catch { } try { string[] emails = emailTemplateObject["testCcRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray(); emailAlertTemplate.TestCC = String.Join(";", emails); } catch { } try { string[] emails = emailTemplateObject["testBccRecipients"].Select(s => getStringValueFromJToken(s, "value")).ToArray(); emailAlertTemplate.TestBCC = String.Join(";", emails); } catch { } emailAlertTemplate.TestLogLevel = getStringValueFromJToken(emailTemplateObject, "testLogLevel"); emailAlertTemplate.Headers = getStringValueOfObjectFromJToken(emailTemplateObject, "headers", true); emailAlertTemplate.Subject = getStringValueFromJToken(emailTemplateObject, "subject"); emailAlertTemplate.TextBody = getStringValueFromJToken(emailTemplateObject, "textBody"); emailAlertTemplate.HTMLBody = getStringValueFromJToken(emailTemplateObject, "htmlBody"); emailAlertTemplate.IncludeHTMLBody = getBoolValueFromJToken(emailTemplateObject, "includeHtmlBody"); emailAlertTemplate.Properties = getStringValueOfObjectFromJToken(emailTemplateObject, "defaultCustomProperties"); emailAlertTemplate.TestProperties = getStringValueOfObjectFromJToken(emailTemplateObject, "testPropertiesPairs"); emailAlertTemplate.EventTypes = getStringValueOfObjectFromJToken(emailTemplateObject, "eventTypeCountPairs"); if (emailTemplatesDetailArray != null) { JToken emailTemplateDetailToken = emailTemplatesDetailArray.Where(t => t["name"].ToString() == emailAlertTemplate.Name).FirstOrDefault(); if (emailTemplateDetailToken != null) { emailAlertTemplate.TemplateID = getLongValueFromJToken(emailTemplateDetailToken, "id"); } } emailTemplatesList.Add(emailAlertTemplate); } } emailTemplatesList = emailTemplatesList.OrderBy(c => c.Name).ToList(); FileIOHelper.WriteListToCSVFile(emailTemplatesList, new EmailAlertTemplateReportMap(), FilePathMap.EmailTemplatesIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + emailTemplatesList.Count; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.ControllerSettingsReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.ControllerSettingsReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.ControllerSettingsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.ControllerSettingsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.ControllerSettingsReportFilePath(), FilePathMap.ControllerSettingsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.HTTPTemplatesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.HTTPTemplatesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.HTTPTemplatesReportFilePath(), FilePathMap.HTTPTemplatesIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.EmailTemplatesIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.EmailTemplatesIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.EmailTemplatesReportFilePath(), FilePathMap.EmailTemplatesIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } i++; } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }
public override bool Execute(ProgramOptions programOptions, JobConfiguration jobConfiguration) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); StepTiming stepTimingFunction = new StepTiming(); stepTimingFunction.JobFileName = programOptions.OutputJobFilePath; stepTimingFunction.StepName = jobConfiguration.Status.ToString(); stepTimingFunction.StepID = (int)jobConfiguration.Status; stepTimingFunction.StartTime = DateTime.Now; stepTimingFunction.NumEntities = jobConfiguration.Target.Count; this.DisplayJobStepStartingStatus(jobConfiguration); FilePathMap = new FilePathMap(programOptions, jobConfiguration); try { if (this.ShouldExecute(jobConfiguration) == false) { return(true); } if (jobConfiguration.Target.Count(t => t.Type == APPLICATION_TYPE_MOBILE) == 0) { return(true); } bool reportFolderCleaned = false; // Process each target for (int i = 0; i < jobConfiguration.Target.Count; i++) { Stopwatch stopWatchTarget = new Stopwatch(); stopWatchTarget.Start(); JobTarget jobTarget = jobConfiguration.Target[i]; if (jobTarget.Type != null && jobTarget.Type.Length > 0 && jobTarget.Type != APPLICATION_TYPE_MOBILE) { continue; } StepTiming stepTimingTarget = new StepTiming(); stepTimingTarget.Controller = jobTarget.Controller; stepTimingTarget.ApplicationName = jobTarget.Application; stepTimingTarget.ApplicationID = jobTarget.ApplicationID; stepTimingTarget.JobFileName = programOptions.OutputJobFilePath; stepTimingTarget.StepName = jobConfiguration.Status.ToString(); stepTimingTarget.StepID = (int)jobConfiguration.Status; stepTimingTarget.StartTime = DateTime.Now; try { this.DisplayJobTargetStartingStatus(jobConfiguration, jobTarget, i + 1); #region Prepare time range long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.From); long toTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobConfiguration.Input.TimeRange.To); int differenceInMinutes = (int)(jobConfiguration.Input.TimeRange.To - jobConfiguration.Input.TimeRange.From).Duration().TotalMinutes; string DEEPLINK_THIS_TIMERANGE = String.Format(DEEPLINK_TIMERANGE_BETWEEN_TIMES, toTimeUnix, fromTimeUnix, differenceInMinutes); #endregion #region Network Requests List <MOBILENetworkRequest> networkRequestsList = null; List <MOBILENetworkRequestToBusinessTransaction> networkRequestToBTsList = null; JObject networkRequestsContainerObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILENetworkRequestsDataFilePath(jobTarget)); if (isTokenPropertyNull(networkRequestsContainerObject, "data") == false) { JArray networkRequestsArray = (JArray)networkRequestsContainerObject["data"]; loggerConsole.Info("Index List of Network Requests ({0} entities)", networkRequestsArray.Count); networkRequestsList = new List <MOBILENetworkRequest>(networkRequestsArray.Count); networkRequestToBTsList = new List <MOBILENetworkRequestToBusinessTransaction>(networkRequestsArray.Count * 4); foreach (JObject networkRequestObject in networkRequestsArray) { MOBILENetworkRequest networkRequest = new MOBILENetworkRequest(); networkRequest.Controller = jobTarget.Controller; networkRequest.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_THIS_TIMERANGE); networkRequest.ApplicationName = jobTarget.Application; networkRequest.ApplicationID = jobTarget.ApplicationID; networkRequest.ApplicationLink = String.Format(DEEPLINK_MOBILE_APPLICATION, networkRequest.Controller, jobTarget.ParentApplicationID, networkRequest.ApplicationID, DEEPLINK_THIS_TIMERANGE); networkRequest.RequestName = getStringValueFromJToken(networkRequestObject, "name"); networkRequest.RequestNameInternal = getStringValueFromJToken(networkRequestObject, "internalName"); networkRequest.RequestID = getLongValueFromJToken(networkRequestObject, "addId"); networkRequest.RequestLink = String.Format(DEEPLINK_NETWORK_REQUEST, networkRequest.Controller, jobTarget.ParentApplicationID, networkRequest.ApplicationID, networkRequest.RequestID, DEEPLINK_THIS_TIMERANGE); networkRequest.Platform = getStringValueFromJToken(networkRequestObject, "mobilePlatform"); networkRequest.IsCorrelated = getBoolValueFromJToken(networkRequestObject, "hasServerAgentCorrelation"); networkRequest.Duration = differenceInMinutes; networkRequest.From = jobConfiguration.Input.TimeRange.From.ToLocalTime(); networkRequest.To = jobConfiguration.Input.TimeRange.To.ToLocalTime(); networkRequest.FromUtc = jobConfiguration.Input.TimeRange.From; networkRequest.ToUtc = jobConfiguration.Input.TimeRange.To; networkRequest.IsExcluded = getBoolValueFromJToken(networkRequestObject, "excluded"); // Now to metrics networkRequest.MetricsIDs = new List <long>(16); JObject networkRequestDetailsObject = FileIOHelper.LoadJObjectFromFile(FilePathMap.MOBILENetworkRequestPerformanceDataFilePath(jobTarget, networkRequest.RequestName, networkRequest.RequestID, jobConfiguration.Input.TimeRange)); if (networkRequestDetailsObject != null) { networkRequest.UserExperience = getStringValueFromJToken(networkRequestDetailsObject, "performanceState"); if (isTokenPropertyNull(networkRequestDetailsObject, "networkRequestTime") == false) { networkRequest.ART = getLongValueFromJToken(networkRequestDetailsObject["networkRequestTime"], "value"); if (networkRequest.ART < 0) { networkRequest.ART = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["networkRequestTime"], "metricId")); } networkRequest.ARTRange = getDurationRangeAsString(networkRequest.ART); } if (isTokenPropertyNull(networkRequestDetailsObject, "networkRequestTime") == false && isTokenPropertyNull(networkRequestDetailsObject["networkRequestTime"], "graphData") == false && isTokenPropertyNull(networkRequestDetailsObject["networkRequestTime"]["graphData"], "data") == false) { networkRequest.TimeTotal = sumLongValuesInArray((JArray)networkRequestDetailsObject["networkRequestTime"]["graphData"]["data"]); } if (isTokenPropertyNull(networkRequestDetailsObject, "requestsPerMin") == false) { networkRequest.CPM = getLongValueFromJToken(networkRequestDetailsObject["requestsPerMin"], "value"); if (networkRequest.CPM < 0) { networkRequest.CPM = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["requestsPerMin"], "metricId")); } } if (isTokenPropertyNull(networkRequestDetailsObject, "totalNumOfRequests") == false) { networkRequest.Calls = getLongValueFromJToken(networkRequestDetailsObject["totalNumOfRequests"], "value"); if (networkRequest.Calls < 0) { networkRequest.Calls = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["totalNumOfRequests"], "metricId")); } } if (isTokenPropertyNull(networkRequestDetailsObject, "totalServerTime") == false) { networkRequest.Server = getLongValueFromJToken(networkRequestDetailsObject["totalServerTime"], "value"); if (networkRequest.Server < 0) { networkRequest.Server = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["totalServerTime"], "metricId")); } } if (isTokenPropertyNull(networkRequestDetailsObject, "totalNumHttpErrors") == false) { networkRequest.HttpErrors = getLongValueFromJToken(networkRequestDetailsObject["totalNumHttpErrors"], "value"); if (networkRequest.HttpErrors < 0) { networkRequest.HttpErrors = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["totalNumHttpErrors"], "metricId")); } } if (isTokenPropertyNull(networkRequestDetailsObject, "httpErrorsPerMin") == false) { networkRequest.HttpEPM = getLongValueFromJToken(networkRequestDetailsObject["httpErrorsPerMin"], "value"); if (networkRequest.HttpEPM < 0) { networkRequest.HttpEPM = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["httpErrorsPerMin"], "metricId")); } } if (isTokenPropertyNull(networkRequestDetailsObject, "totalNumNetworkErrors") == false) { networkRequest.NetworkErrors = getLongValueFromJToken(networkRequestDetailsObject["totalNumNetworkErrors"], "value"); if (networkRequest.NetworkErrors < 0) { networkRequest.NetworkErrors = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["totalNumNetworkErrors"], "metricId")); } } if (isTokenPropertyNull(networkRequestDetailsObject, "networkErrorsPerMin") == false) { networkRequest.NetworkEPM = getLongValueFromJToken(networkRequestDetailsObject["networkErrorsPerMin"], "value"); if (networkRequest.NetworkEPM < 0) { networkRequest.NetworkEPM = 0; } else { networkRequest.MetricsIDs.Add(getLongValueFromJToken(networkRequestDetailsObject["networkErrorsPerMin"], "metricId")); } } } // Has Activity if (networkRequest.ART == 0 && networkRequest.TimeTotal == 0 && networkRequest.CPM == 0 && networkRequest.Calls == 0) { networkRequest.HasActivity = false; } else { networkRequest.HasActivity = true; } // Create metric link if (networkRequest.MetricsIDs != null && networkRequest.MetricsIDs.Count > 0) { StringBuilder sb = new StringBuilder(256); foreach (long metricID in networkRequest.MetricsIDs) { if (metricID > 0) { sb.Append(String.Format(DEEPLINK_METRIC_APPLICATION_TARGET_METRIC_ID, jobTarget.ParentApplicationID, metricID)); sb.Append(","); } } sb.Remove(sb.Length - 1, 1); networkRequest.MetricLink = String.Format(DEEPLINK_METRIC, networkRequest.Controller, jobTarget.ParentApplicationID, sb.ToString(), DEEPLINK_THIS_TIMERANGE); } // Load Business Transactions if (networkRequestDetailsObject != null) { if (isTokenPropertyNull(networkRequestDetailsObject, "eumPageRelatedBusinessTransactionData") == false) { foreach (JToken btContainerToken in networkRequestDetailsObject["eumPageRelatedBusinessTransactionData"]) { JObject btContainerObject = (JObject)btContainerToken.First(); MOBILENetworkRequestToBusinessTransaction networkRequestToBT = new MOBILENetworkRequestToBusinessTransaction(); networkRequestToBT.Controller = networkRequest.Controller; networkRequestToBT.ControllerLink = networkRequest.ControllerLink; networkRequestToBT.ApplicationName = networkRequest.ApplicationName; networkRequestToBT.ApplicationID = networkRequest.ApplicationID; networkRequestToBT.ApplicationLink = networkRequest.ApplicationLink; networkRequestToBT.RequestName = networkRequest.RequestName; networkRequestToBT.RequestNameInternal = networkRequest.RequestNameInternal; networkRequestToBT.RequestID = networkRequest.RequestID; networkRequestToBT.Duration = networkRequest.Duration; networkRequestToBT.From = networkRequest.From; networkRequestToBT.To = networkRequest.To; networkRequestToBT.FromUtc = networkRequest.FromUtc; networkRequestToBT.ToUtc = networkRequest.ToUtc; networkRequestToBT.BTID = getLongValueFromJToken(btContainerObject, "businessTransactionId"); networkRequestToBT.BTName = getStringValueFromJToken(btContainerObject, "businessTransactionName"); JobTarget jobTargetofAPM = jobConfiguration.Target.Where(j => j.ApplicationID == getLongValueFromJToken(btContainerObject, "applicationId") && j.Type == APPLICATION_TYPE_WEB).FirstOrDefault(); List <APMBusinessTransaction> businessTransactionsList = null; if (jobTargetofAPM != null) { businessTransactionsList = FileIOHelper.ReadListFromCSVFile <APMBusinessTransaction>(FilePathMap.APMBusinessTransactionsIndexFilePath(jobTargetofAPM), new APMBusinessTransactionReportMap()); } if (businessTransactionsList != null && networkRequestToBT.BTID != 0) { APMBusinessTransaction businessTransaction = businessTransactionsList.Where(b => b.BTID == networkRequestToBT.BTID).FirstOrDefault(); if (businessTransaction != null) { networkRequestToBT.BTType = businessTransaction.BTType; networkRequestToBT.TierName = businessTransaction.TierName; networkRequestToBT.TierID = businessTransaction.TierID; } } if (isTokenPropertyNull(btContainerObject, "averageResponseTime") == false) { networkRequestToBT.ART = getLongValueFromJToken(btContainerObject["averageResponseTime"], "value"); if (networkRequestToBT.ART < 0) { networkRequestToBT.ART = 0; } networkRequestToBT.ARTRange = getDurationRangeAsString(networkRequestToBT.ART); } if (isTokenPropertyNull(btContainerObject, "callsPerMinute") == false) { networkRequestToBT.CPM = getLongValueFromJToken(btContainerObject["callsPerMinute"], "value"); if (networkRequestToBT.CPM < 0) { networkRequestToBT.CPM = 0; } } if (isTokenPropertyNull(btContainerObject, "totalNumberOfCalls") == false) { networkRequestToBT.Calls = getLongValueFromJToken(btContainerObject["totalNumberOfCalls"], "value"); if (networkRequestToBT.Calls < 0) { networkRequestToBT.Calls = 0; } } // Has Activity if (networkRequestToBT.ART == 0 && networkRequestToBT.CPM == 0 && networkRequestToBT.Calls == 0) { networkRequestToBT.HasActivity = false; } else { networkRequestToBT.HasActivity = true; } networkRequest.NumBTs++; networkRequestToBTsList.Add(networkRequestToBT); } } } networkRequestsList.Add(networkRequest); } // Sort them networkRequestsList = networkRequestsList.OrderBy(o => o.RequestName).ToList(); FileIOHelper.WriteListToCSVFile(networkRequestsList, new MOBILENetworkRequestReportMap(), FilePathMap.MOBILENetworkRequestsIndexFilePath(jobTarget)); networkRequestToBTsList = networkRequestToBTsList.OrderBy(o => o.RequestName).ThenBy(o => o.TierName).ThenBy(o => o.BTType).ThenBy(o => o.BTName).ToList(); FileIOHelper.WriteListToCSVFile(networkRequestToBTsList, new MOBILENetworkRequestToBusinessTransactionReportMap(), FilePathMap.MOBILENetworkRequestsBusinessTransactionsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + networkRequestsList.Count; } #endregion #region Application loggerConsole.Info("Index Application"); MOBILEApplication application = new MOBILEApplication(); application.Controller = jobTarget.Controller; application.ControllerLink = String.Format(DEEPLINK_CONTROLLER, jobTarget.Controller, DEEPLINK_THIS_TIMERANGE); application.ApplicationName = jobTarget.Application; application.ApplicationID = jobTarget.ApplicationID; application.ApplicationLink = String.Format(DEEPLINK_MOBILE_APPLICATION, application.Controller, jobTarget.ParentApplicationID, application.ApplicationID, DEEPLINK_THIS_TIMERANGE); if (networkRequestsList != null) { application.NumNetworkRequests = networkRequestsList.Count; application.NumActivity = networkRequestsList.Count(p => p.HasActivity == true); application.NumNoActivity = networkRequestsList.Count(p => p.HasActivity == false); } List <MOBILEApplication> applicationsList = new List <MOBILEApplication>(1); applicationsList.Add(application); FileIOHelper.WriteListToCSVFile(applicationsList, new MOBILEApplicationReportMap(), FilePathMap.MOBILEApplicationsIndexFilePath(jobTarget)); stepTimingTarget.NumEntities = stepTimingTarget.NumEntities + 1; #endregion #region Combine All for Report CSV // If it is the first one, clear out the combined folder if (reportFolderCleaned == false) { FileIOHelper.DeleteFolder(FilePathMap.MOBILEEntitiesReportFolderPath()); Thread.Sleep(1000); FileIOHelper.CreateFolder(FilePathMap.MOBILEEntitiesReportFolderPath()); reportFolderCleaned = true; } // Append all the individual report files into one if (File.Exists(FilePathMap.MOBILEApplicationsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILEApplicationsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILEApplicationsReportFilePath(), FilePathMap.MOBILEApplicationsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.MOBILENetworkRequestsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILENetworkRequestsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILENetworkRequestsReportFilePath(), FilePathMap.MOBILENetworkRequestsIndexFilePath(jobTarget)); } if (File.Exists(FilePathMap.MOBILENetworkRequestsBusinessTransactionsIndexFilePath(jobTarget)) == true && new FileInfo(FilePathMap.MOBILENetworkRequestsBusinessTransactionsIndexFilePath(jobTarget)).Length > 0) { FileIOHelper.AppendTwoCSVFiles(FilePathMap.MOBILENetworkRequestsBusinessTransactionsReportFilePath(), FilePathMap.MOBILENetworkRequestsBusinessTransactionsIndexFilePath(jobTarget)); } #endregion } catch (Exception ex) { logger.Warn(ex); loggerConsole.Warn(ex); return(false); } finally { stopWatchTarget.Stop(); this.DisplayJobTargetEndedStatus(jobConfiguration, jobTarget, i + 1, stopWatchTarget); stepTimingTarget.EndTime = DateTime.Now; stepTimingTarget.Duration = stopWatchTarget.Elapsed; stepTimingTarget.DurationMS = stopWatchTarget.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingTarget); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } } return(true); } catch (Exception ex) { logger.Error(ex); loggerConsole.Error(ex); return(false); } finally { stopWatch.Stop(); this.DisplayJobStepEndedStatus(jobConfiguration, stopWatch); stepTimingFunction.EndTime = DateTime.Now; stepTimingFunction.Duration = stopWatch.Elapsed; stepTimingFunction.DurationMS = stopWatch.ElapsedMilliseconds; List <StepTiming> stepTimings = new List <StepTiming>(1); stepTimings.Add(stepTimingFunction); FileIOHelper.WriteListToCSVFile(stepTimings, new StepTimingReportMap(), FilePathMap.StepTimingReportFilePath(), true); } }