private LogsharkRequest BuildLogsharkRequest(string target, LogsharkConfiguration configuration, string projectName, string postgresDatabaseName, bool forceParse, bool startLocalMongo, int localMongoPort, bool dropMongoDbPostRun, bool publishWorkbooks, ISet <string> pluginsToExecute, IEnumerable <string> pluginCustomArguments, string currentWorkingDirectory) { if (String.IsNullOrWhiteSpace(target)) { throw new ArgumentException("No logset target specified! Please pass in the correct location of your logset."); } // If the target is a relative path, we first need to convert it to an absolute path. if (!target.IsValidMD5() && !Path.IsPathRooted(target)) { target = Path.Combine(currentWorkingDirectory, target); } return(new LogsharkRequestBuilder(target, configuration) .WithProjectName(projectName) .WithPostgresDatabaseName(postgresDatabaseName) .WithForceParse(forceParse) .WithDropParsedLogset(dropMongoDbPostRun) .WithPublishWorkbooks(publishWorkbooks) .WithPluginsToExecute(pluginsToExecute) .WithPluginCustomArguments(ParseCommandLineArgToDictionary(pluginCustomArguments)) .WithStartLocalMongo(startLocalMongo) .WithLocalMongoPort(localMongoPort) .GetRequest()); }
public PluginExecutor(LogsharkConfiguration config) { mongoConnectionInfo = config.MongoConnectionInfo; postgresConnectionInfo = config.PostgresConnectionInfo; tableauConnectionInfo = config.TableauConnectionInfo; applicationTempDirectory = config.ApplicationTempDirectory; applicationOutputDirectory = config.ApplicationOutputDirectory; }
public LogsharkRunner() { // Initialize log4net settings. var assemblyLocation = Assembly.GetExecutingAssembly().Location; Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyLocation)); XmlConfigurator.Configure(new FileInfo(@"Config\Log.config")); configuration = LogsharkConfigReader.LoadConfiguration(); }
/// <summary> /// Encapsulates extracting and parsing logset. /// </summary> private LogsetParsingResult ParseLogset(LogsetParsingRequest parsingRequest, LogsharkConfiguration config) { try { var parser = new MongoLogsetParser(config.MongoConnectionInfo, config.TuningOptions); return(parser.ParseLogset(parsingRequest)); } catch (Exception ex) { Log.FatalFormat("Encountered a fatal error while processing logset: {0}", ex.Message); if (ex.InnerException != null) { Log.DebugFormat(ex.InnerException.StackTrace); } throw; } }
internal LogsharkRequest(string target, LogsharkConfiguration configuration) { Target = new LogsharkRequestTarget(target); Configuration = configuration; RequestCreationDate = DateTime.UtcNow; RunId = GenerateRunId(Target, RequestCreationDate); Source = "Unspecified"; LocalMongoPort = MongoLocalPortDefault; 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 }; }
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(); }
/// <summary> /// Removes all contents of the root application temp directory. /// </summary> private static void PurgeTempDirectory(LogsharkConfiguration config) { var tempDirectoryPath = config.ApplicationTempDirectory; if (string.IsNullOrWhiteSpace(tempDirectoryPath) || !Directory.Exists(tempDirectoryPath)) { return; } try { DirectoryHelper.DeleteDirectory(tempDirectoryPath); } catch (Exception ex) { Log.ErrorFormat($"Failed to gracefully clean up logsets left over from previous run(s): {ex.Message}"); } }
/// <summary> /// Removes all contents of the root application temp directory. /// </summary> private bool PurgeTempDirectory(LogsharkConfiguration config) { string tempDirectoryPath = config.ApplicationTempDirectory; if (String.IsNullOrWhiteSpace(tempDirectoryPath) || !Directory.Exists(tempDirectoryPath)) { return(false); } try { DirectoryHelper.DeleteDirectory(tempDirectoryPath); return(true); } catch (Exception ex) { Log.ErrorFormat("Failed to gracefully clean up logsets left over from previous run(s): {0}", ex.Message); return(false); } }
/// <summary> /// Prunes all but the most recent N run output directories from the application output directory. /// </summary> private static void PruneRunOutputDirectory(LogsharkConfiguration config) { Log.DebugFormat($"Pruning all but the most recent {config.DataRetentionOptions.MaxRuns} runs from '{config.ApplicationOutputDirectory}'.."); try { var expiredDirectories = Directory.EnumerateDirectories(config.ApplicationOutputDirectory) .Select(subdirectoryPath => new DirectoryInfo(subdirectoryPath)) .OrderByDescending(directory => directory.CreationTime) .Skip(config.DataRetentionOptions.MaxRuns); foreach (var expiredDirectory in expiredDirectories) { Log.DebugFormat($"Deleting expired run data directory '{expiredDirectory.Name}'.."); expiredDirectory.Delete(recursive: true); } } catch (Exception ex) { Log.WarnFormat($"Failed to prune directories exceeding the data retention threshold: {ex.Message}"); } }
public LogsharkCLI(LogsharkCommandLineOptions commandLineOptions, string currentWorkingDirectory) { configuration = LogsharkConfigReader.LoadConfiguration(); this.commandLineOptions = commandLineOptions; this.currentWorkingDirectory = currentWorkingDirectory; }
public ServiceDependencyValidator(LogsharkConfiguration configuration) { this.configuration = configuration; }
public ArchiveTargetProcessingStrategy(Func <LogsetParsingRequest, LogsetParsingResult> parseLogset, Action <string> dropExistingLogset, LogsharkConfiguration config) { this.parseLogset = parseLogset; this.dropExistingLogset = dropExistingLogset; this.config = config; }
public static IRunInitializer GetRunInitializer(LogsharkRequestTarget target, LogsharkConfiguration config) { switch (target.Type) { case LogsetTarget.File: case LogsetTarget.Directory: return(new ArchiveRunInitializer(config.ApplicationTempDirectory)); case LogsetTarget.Hash: return(new HashRunInitializer(config.MongoConnectionInfo)); default: throw new ArgumentException($"Cannot get run initializer for unknown target type '{target.Type}'", nameof(target)); } }
public LogsharkRequestBuilder(string target, LogsharkConfiguration configuration) { request = new LogsharkRequest(target, configuration); }
public LogsharkCLI(string currentWorkingDirectory) { _configuration = LogsharkConfigReader.LoadConfiguration(); _currentWorkingDirectory = currentWorkingDirectory; }
/// <summary> /// Builds a metadata writer that will persist information about the run. /// </summary> private static ILogsharkRunMetadataWriter BuildRunMetadataWriter(LogsharkConfiguration config) { return(config.PostgresConnectionInfo.Map(postgresConnection => new LogsharkRunMetadataPostgresWriter(postgresConnection) as ILogsharkRunMetadataWriter) .ValueOr(new LogsharkRunMetadataLogger())); }
public PluginExecutor(LogsharkConfiguration config) { mongoConnectionInfo = config.MongoConnectionInfo; postgresConnectionInfo = config.PostgresConnectionInfo; tableauConnectionInfo = config.TableauConnectionInfo; }
public static ILogsetProcessingStrategy GetLogsetProcessingStrategy(LogsharkRequestTarget target, Func <LogsetParsingRequest, LogsetParsingResult> parseLogset, Action <string> dropExistingLogset, LogsharkConfiguration config) { switch (target.Type) { case LogsetTarget.File: case LogsetTarget.Directory: return(new ArchiveTargetProcessingStrategy(parseLogset, dropExistingLogset, config)); case LogsetTarget.Hash: return(new HashTargetProcessingStrategy()); default: throw new ArgumentException(String.Format("Cannot get run processing strategy for unknown target type '{0}'", target.Type), "target"); } }