public override IPluginResponse Execute(IPluginRequest pluginRequest) { IPluginResponse response = CreatePluginResponse(); logsetHash = pluginRequest.LogsetHash; InitializeDatabaseTables(); IPersister <NetstatActiveConnection> activeConnectionsPersister = GetConcurrentBatchPersister <NetstatActiveConnection>(pluginRequest); // Process netstat entries for all available workers. var netstatCollection = MongoDatabase.GetCollection <BsonDocument>(ParserConstants.NetstatCollectionName); foreach (string workerId in MongoQueryHelper.GetDistinctWorkers(netstatCollection)) { Log.InfoFormat("Retrieving netstat information for worker '{0}'..", workerId); IEnumerable <NetstatActiveConnection> activeConnectionsForWorker = GetActiveConnectionEntriesForWorker(workerId, netstatCollection); activeConnectionsPersister.Enqueue(activeConnectionsForWorker); } // Shutdown persister and wait for data to flush. activeConnectionsPersister.Shutdown(); Log.Info("Finished processing netstat data!"); // Check if we persisted any data. if (!PersistedData()) { Log.Info("Failed to persist any netstat data!"); response.GeneratedNoData = true; } return(response); }
public ICollection <PublishedWorkbookResult> PublishWorkbooks(IPluginResponse pluginResponse) { ICollection <string> workbooksToPublish = pluginResponse.WorkbooksOutput; ICollection <PublishedWorkbookResult> publishedWorkbookResults = new List <PublishedWorkbookResult>(); // Short circuit out if we have no work to do. if (!workbooksToPublish.Any()) { return(publishedWorkbookResults); } Log.InfoFormat("Publishing {0} {1} to Tableau Server..", workbooksToPublish.Count, "workbook".Pluralize(workbooksToPublish.Count)); try { publishedWorkbookResults.AddRange(PublishWorkbooks(pluginResponse.PluginName, workbooksToPublish)); } catch (Exception ex) { throw new PublishingException(ex.Message, ex); } // Display summary and append results to the request run context. Log.Info(BuildPublishingSummary(publishedWorkbookResults)); // If we had any publishing failures, we want to alert the user. if (publishedWorkbookResults.Any(result => !result.IsSuccessful)) { IEnumerable <string> failedWorkbookNames = publishedWorkbookResults.Where(result => !result.IsSuccessful) .Select(result => result.Request.WorkbookName); string errorMessage = String.Format("The following workbooks failed to publish: {0}", String.Join(", ", failedWorkbookNames)); throw new PublishingException(errorMessage); } return(publishedWorkbookResults); }
public override IPluginResponse Execute(IPluginRequest pluginRequest) { pluginResponse = CreatePluginResponse(); if (PluginResponses.All(response => response.GeneratedNoData)) { Log.WarnFormat("No plugins associated with this run generated any data; skipping execution of this plugin."); pluginResponse.GeneratedNoData = true; } else { try { var dependencyManager = new WorkbookDependencyManager(PluginResponses, WorkbookDirectory, WorkbookConfigFilename); workbookNames = dependencyManager.GetValidWorkbooks(); } catch (Exception ex) { string errorMessage = String.Format("Failed to generate custom workbooks: {0}", ex.Message); Log.Error(errorMessage); pluginResponse.SetExecutionOutcome(false, errorMessage); } } return(pluginResponse); }
/// <summary> /// Writes all workbooks associated with a workbook creation plugin to the output directory. /// </summary> /// <param name="plugin">The workbook creation plugin that ran.</param> /// <param name="response">The response object, containing information about the results of executing the plugin.</param> protected void WriteWorkbooksToDisk(IWorkbookCreationPlugin plugin, IPluginResponse response) { // Replace connection information in workbook and flush to disk. if (response.SuccessfulExecution) { ICollection <string> workbookNames = plugin.WorkbookNames; if (response.GeneratedNoData) { Log.InfoFormat("Skipped saving {0} {1} because the plugin did not generate any backing data.", plugin.GetType().Name, "workbook".Pluralize(workbookNames.Count)); return; } foreach (var workbookName in workbookNames) { WorkbookEditor workbookEditor = new WorkbookEditor(workbookName, plugin.GetWorkbookXml(workbookName)); workbookEditor.ReplacePostgresConnections(logsharkRequest.Configuration.PostgresConnectionInfo, logsharkRequest.PostgresDatabaseName); workbookEditor.RemoveThumbnails(); string workbookFilePath = workbookEditor.Save(GetOutputLocation(logsharkRequest.RunId)); response.WorkbooksOutput.Add(workbookFilePath); Log.InfoFormat("Saved workbook to '{0}'!", workbookFilePath); } } }
public override IPluginResponse Execute(IPluginRequest pluginRequest) { pluginResponse = CreatePluginResponse(); // TODO: Your plugin logic goes here. return(pluginResponse); }
public LogsharkPluginExecutionMetadata(IPluginResponse pluginResponse, LogsharkRunMetadata runMetadata, DateTime timestamp, string pluginVersion) { this.runMetadata = runMetadata; PluginVersion = pluginVersion; PluginName = pluginResponse.PluginName; IsSuccessful = pluginResponse.SuccessfulExecution; FailureReason = pluginResponse.FailureReason; Timestamp = timestamp; ElapsedSeconds = pluginResponse.PluginRunTime.TotalSeconds; }
/// <summary> /// Executes multiple plugins. /// </summary> protected ICollection <IPluginResponse> ExecutePlugins(IEnumerable <Type> pluginsToExecute, PluginExecutionRequest request) { var pluginResponses = new List <IPluginResponse>(); foreach (Type plugin in pluginsToExecute.OrderBy(PluginLoader.IsPostExecutionPlugin)) { IPluginResponse pluginResponse = ExecutePlugin(plugin, request, pluginResponses); pluginResponses.Add(pluginResponse); } return(pluginResponses); }
/// <summary> /// Handles tasks associated with a failed plugin execution. /// </summary> protected void HandlePluginExecutionFailure(IPluginResponse pluginResponse, string failureReason, Exception associatedException = null) { pluginResponse.SetExecutionOutcome(isSuccessful: false, failureReason: failureReason); // Log out error and stack, if possible. if (!String.IsNullOrWhiteSpace(failureReason)) { Log.Error(failureReason); } if (associatedException != null) { Log.DebugFormat(associatedException.ToString()); } }
/// <summary> /// Prints the outcome of executing a plugin. /// </summary> /// <param name="response">The response from executing the plugin.</param> protected void LogExecutionOutcome(IPluginResponse response) { if (response == null) { Log.Error("Plugin response is invalid!"); } else if (!response.SuccessfulExecution) { Log.ErrorFormat("{0} failed to execute successfully.", response.PluginName); } else { Log.InfoFormat("{0} execution completed! [{1}]", response.PluginName, response.PluginRunTime.Print()); } }
public override IPluginResponse Execute(IPluginRequest pluginRequest) { pluginResponse = CreatePluginResponse(); ProcessEvents <HyperError>(pluginRequest, MongoQueryHelper.GetErrors); ProcessEvents <HyperQuery>(pluginRequest, MongoQueryHelper.GetQueryEndEvents); if (!PersistedData()) { Log.Info("Failed to persist any data from Hyper logs!"); pluginResponse.GeneratedNoData = true; } return(pluginResponse); }
public override IPluginResponse Execute() { IPluginResponse pluginResponse = CreatePluginResponse(); var collection = MongoDatabase.GetCollection <NetstatDocument>(ParserConstants.NetstatCollectionName); using (var persister = ExtractFactory.CreateExtract <NetstatActiveConnection>("NetstatEntries.hyper")) using (GetPersisterStatusWriter(persister)) { foreach (var worker in NetstatQueries.GetDistinctWorkers(collection)) { var activeConnectionsForWorker = GetActiveConnectionsForWorker(worker, collection); persister.Enqueue(activeConnectionsForWorker); } if (persister.ItemsPersisted <= 0) { Log.Warn("Failed to persist any Netstat data!"); pluginResponse.GeneratedNoData = true; } return(pluginResponse); } }
/// <summary> /// Writes all workbooks associated with a workbook creation plugin to the output directory. /// </summary> /// <param name="outputLocation">The absolute path where plugin output was written.</param> /// <param name="plugin">The workbook creation plugin that ran.</param> /// <param name="response">The response object, containing information about the results of executing the plugin.</param> /// <param name="outputDatabaseName">The name of the Postgres database that the workbook should connect to.</param> protected IEnumerable <string> WriteWorkbooksToDisk(string outputLocation, IWorkbookCreationPlugin plugin, IPluginResponse response, string outputDatabaseName) { var workbookFilePaths = new List <string>(); // Make sure we have something to do. if (!response.SuccessfulExecution) { return(workbookFilePaths); } if (response.GeneratedNoData) { Log.InfoFormat("Skipped saving workbooks for {0} because the plugin did not generate any backing data.", plugin.GetType().Name); return(workbookFilePaths); } // Replace connection information in workbook and flush to disk. if (plugin.WorkbookNames != null) { foreach (var workbookName in plugin.WorkbookNames) { var workbookEditor = new WorkbookEditor(outputLocation, postgresConnectionInfo, outputDatabaseName); using (var workbookInputStream = plugin.GetWorkbook(workbookName)) { var processedWorkbook = workbookEditor.Process(workbookInputStream, workbookName); workbookFilePaths.Add(processedWorkbook.FullName); Log.InfoFormat("Saved workbook to '{0}'!", processedWorkbook.FullName); } } } return(workbookFilePaths); }
/// <summary> /// Writes all workbooks associated with a workbook creation plugin to the output directory. /// </summary> /// <param name="outputLocation">The absolute path where the workbooks should be written.</param> /// <param name="plugin">The workbook creation plugin that ran.</param> /// <param name="response">The response object, containing information about the results of executing the plugin.</param> /// <param name="postgresDatabaseName">The name of the Postgres database that the workbook should connect to.</param> protected IEnumerable <string> WriteWorkbooksToDisk(string outputLocation, IWorkbookCreationPlugin plugin, IPluginResponse response, string postgresDatabaseName) { var workbookFilePaths = new List <string>(); // Make sure we have something to do. if (!response.SuccessfulExecution) { return(workbookFilePaths); } if (response.GeneratedNoData) { Log.InfoFormat("Skipped saving workbooks for {0} because the plugin did not generate any backing data.", plugin.GetType().Name); return(workbookFilePaths); } // Replace connection information in workbook and flush to disk. if (plugin.WorkbookNames != null) { foreach (var workbookName in plugin.WorkbookNames) { WorkbookEditor workbookEditor = new WorkbookEditor(workbookName, plugin.GetWorkbookXml(workbookName)); workbookEditor.ReplacePostgresConnections(postgresConnectionInfo, postgresDatabaseName); workbookEditor.RemoveThumbnails(); string workbookFilePath = workbookEditor.Save(outputLocation); workbookFilePaths.Add(workbookFilePath); Log.InfoFormat("Saved workbook to '{0}'!", workbookFilePath); } } return(workbookFilePaths); }
public void RegisterPluginResponse(IPluginResponse pluginResponse) { PluginResponses.Add(pluginResponse); }