public async Task PublishFaultReport(DumpMetainfo dumpInfo) { var result = await dumpRepository.GetResult(dumpInfo.Id); var faultReport = FaultReportCreator.CreateFaultReport(result); var bundleInfo = bundleRepository.Get(dumpInfo.BundleId); if (bundleInfo.CustomProperties.ContainsKey("sourceId")) { faultReport.SourceId = bundleRepository.Get(dumpInfo.BundleId).CustomProperties["sourceId"]; } await faultReportSender.SendFaultReport(dumpInfo, faultReport); }
private static async Task <DumpViewModel> ToDumpViewModel(DumpMetainfo dumpMetainfo, DumpRepository dumpRepo, BundleRepository bundleRepo, SimilarityService similarityService = null) { if (dumpMetainfo == null) { return(null); } var similarities = similarityService == null ? null : new Similarities(await similarityService.GetSimilarities(dumpMetainfo.Id)); return(new DumpViewModel(dumpMetainfo, new BundleViewModel(bundleRepo.Get(dumpMetainfo.BundleId)), similarities)); }
public async Task AnalyzeAsync(DumpMetainfo dumpInfo, string dumpFilePath, string analysisWorkingDir) { await BlockIfBundleRepoNotReady($"AnalysisService.Analyze for {dumpInfo.Id}"); try { dumpRepo.SetDumpStatus(dumpInfo.Id, DumpStatus.Analyzing); if (new FileInfo(dumpFilePath).Length == 0) { dumpRepo.SetDumpStatus(dumpInfo.Id, DumpStatus.Failed, "The primary dump file is empty!"); return; } if (dumpInfo.DumpType == DumpType.WindowsDump) { await AnalyzeWindows(dumpInfo, new DirectoryInfo(analysisWorkingDir), dumpFilePath); } else if (dumpInfo.DumpType == DumpType.LinuxCoreDump) { await LinuxAnalyzationAsync(dumpInfo, new DirectoryInfo(analysisWorkingDir), dumpFilePath); } else { throw new Exception("unknown dumptype. here be dragons"); } // Re-fetch dump info as it was updated dumpInfo = dumpRepo.Get(dumpInfo.Id); SDResult result = await dumpRepo.GetResultAndThrow(dumpInfo.Id); if (result != null) { dumpRepo.WriteResult(dumpInfo.Id, result); dumpRepo.SetDumpStatus(dumpInfo.Id, DumpStatus.Finished); var bundle = bundleRepo.Get(dumpInfo.BundleId); await elasticSearch.PushResultAsync(result, bundle, dumpInfo); } } catch (Exception e) { Console.WriteLine(e.Message); dumpRepo.SetDumpStatus(dumpInfo.Id, DumpStatus.Failed, e.ToString()); } finally { if (settings.Value.DeleteDumpAfterAnalysis) { dumpStorage.DeleteDumpFile(dumpInfo.Id); } await notifications.NotifyDumpAnalysisFinished(dumpInfo); similarityService.ScheduleSimilarityAnalysis(dumpInfo, false, DateTime.Now - TimeSpan.FromDays(settings.Value.SimilarityDetectionMaxDays)); } }
private async Task <DumpViewModel> ToDumpViewModel(DumpMetainfo dumpMetainfo, bool includeSimilarities = false) { if (dumpMetainfo == null) { return(null); } var similarities = !includeSimilarities ? null : new Similarities(await similarityService.GetSimilarities(dumpMetainfo.Id)); return(new DumpViewModel(dumpMetainfo, new BundleViewModel(bundleRepo.Get(dumpMetainfo.BundleId)), similarities, new RetentionViewModel( dumpMetainfo, dumpRepo.IsPrimaryDumpAvailable(dumpMetainfo.Id), TimeSpan.FromDays(settings.WarnBeforeDeletionInDays), settings.UseJiraIntegration && jiraIssueRepository.IsPopulated && jiraIssueRepository.HasBundleOpenIssues(dumpMetainfo.BundleId)))); }
public async Task Analyze(DumpMetainfo dumpInfo, string dumpFilePath, string analysisWorkingDir) { try { dumpRepo.SetDumpStatus(dumpInfo.BundleId, dumpInfo.DumpId, DumpStatus.Analyzing); if (dumpInfo.DumpType == DumpType.WindowsDump) { await AnalyzeWindows(dumpInfo, new DirectoryInfo(analysisWorkingDir), dumpFilePath); } else if (dumpInfo.DumpType == DumpType.LinuxCoreDump) { await LinuxAnalyzationAsync(dumpInfo, new DirectoryInfo(analysisWorkingDir), dumpFilePath); } else { throw new Exception("unknown dumptype. here be dragons"); } dumpRepo.SetDumpStatus(dumpInfo.BundleId, dumpInfo.DumpId, DumpStatus.Finished); // Re-fetch dump info as it was updated dumpInfo = dumpRepo.Get(dumpInfo.BundleId, dumpInfo.DumpId); SDResult result = await dumpRepo.GetResult(dumpInfo.BundleId, dumpInfo.DumpId); if (result != null) { var bundle = bundleRepo.Get(dumpInfo.BundleId); await elasticSearch.PushResultAsync(result, bundle, dumpInfo); } } catch (Exception e) { Console.WriteLine(e.Message); dumpRepo.SetDumpStatus(dumpInfo.BundleId, dumpInfo.DumpId, DumpStatus.Failed, e.ToString()); } finally { if (settings.Value.DeleteDumpAfterAnalysis) { dumpStorage.DeleteDumpFile(dumpInfo.BundleId, dumpInfo.DumpId); } await notifications.NotifyDumpAnalysisFinished(dumpInfo); similarityService.ScheduleSimilarityAnalysis(dumpInfo, false, DateTime.Now - TimeSpan.FromDays(90)); // last 90 days. } }
public async Task Analyze(DumpMetainfo dumpInfo, string dumpFilePath, string analysisWorkingDir) { try { dumpRepo.SetDumpStatus(dumpInfo.BundleId, dumpInfo.DumpId, DumpStatus.Analyzing); if (dumpInfo.DumpType == DumpType.WindowsDump) { await AnalyzeWindows(dumpInfo, new DirectoryInfo(analysisWorkingDir), dumpFilePath); } else if (dumpInfo.DumpType == DumpType.LinuxCoreDump) { await LinuxAnalyzationAsync(dumpInfo, new DirectoryInfo(analysisWorkingDir), dumpFilePath); } else { throw new Exception("unknown dumptype. here be dragons"); } dumpRepo.SetDumpStatus(dumpInfo.BundleId, dumpInfo.DumpId, DumpStatus.Finished); SDResult result = dumpRepo.GetResult(dumpInfo.BundleId, dumpInfo.DumpId, out string err); if (result != null) { var bundle = bundleRepo.Get(dumpInfo.BundleId); await elasticSearch.PushResultAsync(result, bundle, dumpInfo); } } catch (Exception e) { Console.WriteLine(e.Message); dumpRepo.SetDumpStatus(dumpInfo.BundleId, dumpInfo.DumpId, DumpStatus.Failed, e.ToString()); } finally { if (settings.Value.DeleteDumpAfterAnalysis) { dumpStorage.DeleteDumpFile(dumpInfo.BundleId, dumpInfo.DumpId); } await notifications.NotifyDumpAnalysisFinished(dumpInfo); } }
public BundleMetainfo GetBundle(string bundleId) { return(bundleRepo.Get(bundleId)); }
public async Task PushAllResultsAsync(bool clean) { if (elasticClient == null) { throw new InvalidOperationException("ElasticSearch has not been initialized! Please verify that the settings specify a correct elastic search host."); } await BlockIfBundleRepoNotReady("ElasticSearchService.PushAllResultsAsync"); if (clean) { DeleteIndex(); CreateIndex(); // since we are clean, we can do everything in one bulk var dumps = dumpRepo.GetAll().OrderByDescending(x => x.Created); foreach (var dumpsBatch in dumps.Batch(100)) { var tasks = dumpsBatch.Select(x => Task.Run(async() => new { res = await dumpRepo.GetResult(x.Id), bundleInfo = bundleRepo.Get(x.BundleId), dumpInfo = x })); var results = (await Task.WhenAll(tasks)).Where(x => x.res != null); Console.WriteLine($"pushing {results.Count()} results into elasticsearch"); var sdResults = results.Select(x => ElasticSDResult.FromResultOrDefault(x.res, x.bundleInfo, x.dumpInfo, pathHelper)).Where(x => x != null); await PushBulk(sdResults); } return; } IEnumerable <string> documentIds = GetAllDocumentIds(); int nErrorsLogged = 0; var bundles = bundleRepo.GetAll(); if (bundles == null) { throw new InvalidOperationException("Bundle repository must be populated before pushing data into ES."); } // In order to check if a dump has already been added, we go through them all and add one at the time // There is potential to optimize this and still do a bulk add. foreach (BundleMetainfo bundle in bundles) { var dumps = dumpRepo.Get(bundle.BundleId); if (dumps == null) { continue; } foreach (DumpMetainfo dump in dumps) { if (documentIds.Contains(bundle.BundleId + "/" + dump.DumpId)) { continue; } SDResult result = await dumpRepo.GetResult(dump.Id); if (result != null) { bool success = await PushResultAsync(result, bundle, dump); if (!success && nErrorsLogged < 20) { Console.WriteLine($"Failed to create document for {dump.BundleId}/{dump.DumpId}"); nErrorsLogged++; } } } } }