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); } 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, 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); } }