/// <summary> /// Sets up and issues the <see cref="LogsharkRequest"/> to the <see cref="LogsharkRequestProcessor"/>. /// </summary> /// <returns>Exit code</returns> public ExitCode Execute(LogsharkCommandLineOptions commandLineOptions) { if (commandLineOptions.ListPlugins) { try { LogsharkRequestProcessor.PrintAvailablePlugins(); return(ExitCode.Success); } catch (Exception ex) { Log.FatalFormat("Unable to retrieve list of available plugins: {0}", ex.Message); return(ExitCode.ExecutionError); } } try { LogsharkRequest request = BuildLogsharkRequest(commandLineOptions); var requestProcessor = new LogsharkRequestProcessor(); LogsharkRunContext outcome = requestProcessor.ProcessRequest(request); return(outcome.IsRunSuccessful.Equals(true) ? ExitCode.Success : ExitCode.ExecutionError); } catch (Exception ex) { Log.Debug(ex.GetFlattenedMessage()); Log.Debug(ex.StackTrace); return(ExitCode.ExecutionError); } }
public LogsharkTimer(LogsharkRunContext logsharkRunState, string eventName, string eventDetail) { this.logsharkRunState = logsharkRunState; this.eventName = eventName; this.eventDetail = eventDetail; creationTime = DateTime.UtcNow; stopwatch = Stopwatch.StartNew(); }
public void WriteMetadata(LogsharkRunContext run) { try { var metadata = new LogsharkRunMetadata(run); Log.DebugFormat("Started phase {0}: {1}", run.CurrentPhase, JsonConvert.SerializeObject(metadata)); } catch (Exception ex) { throw new MetadataWriterException(String.Format("Failed to write Logshark metadata for run '{0}': {1}", run.Id, ex.Message)); } }
public void WriteMetadata(LogsharkRunContext run) { try { var metadata = new LogsharkRunMetadata(run, metadataRecordId); using (IDbConnection db = connectionFactory.OpenDbConnection()) { // Create or migrate metadata db tables. if (!isDatabaseInitialized) { isDatabaseInitialized = InitializeTables(db); } // Update the existing record, if we have one; otherwise, create a new record. if (!metadataRecordId.HasValue) { Log.Debug("Creating metadata record for this Logshark run in database.."); db.Insert(metadata); metadataRecordId = Convert.ToInt32(db.GetLastInsertId()); metadata.Id = metadataRecordId.Value; } else { Log.DebugFormat("Updating metadata about the {0} phase of this Logshark run in database..", metadata.CurrentProcessingPhase); db.Update(metadata); } // Explicitly handle writing of data to foreign tables only once, due to limitations of the ORM. if (!isCustomMetadataWritten) { isCustomMetadataWritten = WriteMetadata(metadata.CustomMetadataRecords, db); } if (!isPluginExecutionMetadataWritten) { isPluginExecutionMetadataWritten = WriteMetadata(metadata.PluginExecutionMetadataRecords, db); } if (!isPublishedWorkbookMetadataWritten) { isPublishedWorkbookMetadataWritten = WriteMetadata(metadata.PublishedWorkbookMetadataRecords, db); } } } catch (Exception ex) { throw new MetadataWriterException(String.Format("Failed to update Logshark metadata for run '{0}' in database: {1}", run.Id, ex.Message)); } }
internal LogsharkRequest(string target, LogsharkConfiguration configuration) { Target = new LogsharkRequestTarget(target); Configuration = configuration; RequestCreationDate = DateTime.UtcNow; RunId = GenerateRunId(Target, RequestCreationDate); LocalMongoPort = LogsharkConstants.MONGO_LOCAL_PORT_DEFAULT; Metadata = new Dictionary <string, object>(); PluginsToExecute = new HashSet <string>(); PluginCustomArguments = new Dictionary <string, object>(); StartLocalMongo = configuration.LocalMongoOptions.AlwaysUseLocalMongo; WorkbookTags = new HashSet <string> { "Logshark", Environment.UserName }; RunContext = new LogsharkRunContext(); }
public LogsharkRunMetadata(LogsharkRunContext run, int?id = null) { // Update record id if it was passed in. if (id.HasValue) { Id = id.Value; } // Request & target metadata. CustomId = run.Request.CustomId; DatabaseName = run.Request.PostgresDatabaseName; RunId = run.Request.RunId; RunByUser = Environment.UserName; RunByMachine = Environment.MachineName; Source = run.Request.Source; Target = run.Request.Target; TargetSize = run.Request.Target.Size; VersionLogshark = typeof(LogsharkRequestProcessor).Assembly.GetName().Version.ToString(); // Timing metadata. FullRunStartTime = run.Request.RequestCreationDate; FullRunElapsedSeconds = (DateTime.UtcNow - run.Request.RequestCreationDate).TotalSeconds; LastMetadataUpdateTime = DateTime.UtcNow; LogsetExtractionStartTime = GlobalEventTimingData.GetStartTime("Unpack Archives"); LogsetExtractionElapsedSeconds = GlobalEventTimingData.GetElapsedTime("Unpack Archives"); LogParsingStartTime = GlobalEventTimingData.GetStartTime("Parsed Files"); LogParsingElapsedSeconds = GlobalEventTimingData.GetElapsedTime("Parsed Files"); PluginExecutionStartTime = GlobalEventTimingData.GetStartTime("Executed Plugins"); PluginExecutionElapsedSeconds = GlobalEventTimingData.GetElapsedTime("Executed Plugins"); // Context metadata. CurrentProcessingPhase = run.CurrentPhase.ToString(); CustomMetadataRecords = GetCustomMetadataRecords(run.Request); IsValidLogset = run.IsValidLogset; // Initialization metadata. if (run.InitializationResult != null) { LogsetHash = run.InitializationResult.LogsetHash; LogsetType = run.InitializationResult.ArtifactProcessor.ArtifactType; PluginsExecuted = GetExecutedPluginsString(run.InitializationResult); } // Parsing metadata. if (run.ParsingResult != null) { TargetProcessedSize = run.ParsingResult.ParsedDataVolumeBytes; UtilizedExistingLogsetHash = run.ParsingResult.UtilizedExistingProcessedLogset; } // Plugin execution metadata. if (run.PluginExecutionResult != null) { ContainsSuccessfulPluginExecution = run.PluginExecutionResult.PluginResponses.Any(pluginResponse => pluginResponse.SuccessfulExecution); PluginExecutionMetadataRecords = GetPluginExecutionMetadataRecords(run.PluginExecutionResult); PluginsFailed = String.Join(",", run.PluginExecutionResult.PluginResponses.Where(pluginResponse => !pluginResponse.SuccessfulExecution)); PublishedWorkbookMetadataRecords = GetPublishedWorkbookMetadataRecords(run.PluginExecutionResult, run.Request.Configuration.TableauConnectionInfo); } // Outcome metadata. IsRunSuccessful = run.IsRunSuccessful; if (run.CurrentPhase == ProcessingPhase.Complete) { IsRunComplete = true; } RunFailureExceptionType = run.RunFailureExceptionType; if (run.RunFailurePhase.HasValue) { RunFailurePhase = run.RunFailurePhase.ToString(); } RunFailureReason = run.RunFailureReason; }