Example #1
0
        /// <summary>
        /// Orchestrates a Logshark run from end to end.
        /// </summary>
        /// <param name="request">The user's processing request.</param>
        /// <param name="metadataWriter">The metadata writer responsible for writing information about the state of the run.</param>
        /// <returns>Run context containing the run outcome and details of what happened during the run.</returns>
        private LogsharkRunContext ExecuteLogsharkRun(LogsharkRequest request, ILogsharkRunMetadataWriter metadataWriter)
        {
            using (var runTimer = new LogsharkTimer("Logshark Run", request.Target, GlobalEventTimingData.Add))
            {
                var run = new LogsharkRunContext(request);
                try
                {
                    Log.InfoFormat("Preparing logset target '{0}' for processing..", request.Target);

                    StartPhase(ProcessingPhase.Initializing, run, metadataWriter);
                    run.InitializationResult = InitializeRun(request);
                    run.IsValidLogset        = true;

                    StartPhase(ProcessingPhase.Parsing, run, metadataWriter);
                    run.ParsingResult = ProcessLogset(request, run.InitializationResult);

                    StartPhase(ProcessingPhase.ExecutingPlugins, run, metadataWriter);
                    run.PluginExecutionResult = ExecutePlugins(request, run.InitializationResult);

                    run.SetRunSuccessful();
                    return(run);
                }
                catch (Exception ex)
                {
                    run.SetRunFailed(ex);
                    throw;
                }
                finally
                {
                    StartPhase(ProcessingPhase.Complete, run, metadataWriter);
                    TearDown(run);

                    Log.InfoFormat("Logshark run complete! [{0}]", runTimer.Elapsed.Print());
                    string runSummary = run.BuildRunSummary();
                    if (!String.IsNullOrWhiteSpace(runSummary))
                    {
                        Log.Info(runSummary);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Performs any teardown tasks.
        /// </summary>
        private void TearDown(LogsharkRunContext context)
        {
            // Purge application temp directory to free up disk space for the user.
            PurgeTempDirectory(context.Request.Configuration);

            // Drop logset if user didn't want to retain it, assuming they didn't piggyback on an existing processed logset.
            bool utilizedExistingLogset = context.ParsingResult != null && context.ParsingResult.UtilizedExistingProcessedLogset;

            if (context.Request.DropMongoDBPostRun && utilizedExistingLogset)
            {
                Log.InfoFormat("Dropping Mongo database {0}..", context.InitializationResult);
                try
                {
                    MongoAdminHelper.DropDatabase(context.Request.Configuration.MongoConnectionInfo.GetClient(), context.InitializationResult.LogsetHash);
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Failed to clean up Mongo database '{0}': {1}", context.InitializationResult.LogsetHash, ex.Message);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Starts the next phase of the given Logshark run and writes any associated metadata.
 /// </summary>
 /// <param name="phaseToStart">The phase to start.</param>
 /// <param name="context">The current Logshark run.</param>
 /// <param name="metadataWriter">The metadata writer responsible for tracking the state of the run.</param>
 private void StartPhase(ProcessingPhase phaseToStart, LogsharkRunContext context, ILogsharkRunMetadataWriter metadataWriter)
 {
     context.CurrentPhase = phaseToStart;
     metadataWriter.WriteMetadata(context);
 }