/// <summary> /// Configures the request collect with one probeExecute with the error status. /// </summary> /// <param name="collectRequest">The request collect.</param> /// <param name="probe">The probe.</param> /// <param name="collectExecution">The collect execution.</param> /// <param name="error">The error.</param> private void ConfigureTheCollectRequestWithAnErrorProbeExecute(CollectRequest collectRequest, string probeCapability, CollectExecution collectExecution, Exception error, ExecutionLogBuilder executionLog) { executionLog.AnErrorOccurred(error.Message); executionLog.EndCollect(); ProbeExecution executionWithError = collectFactory.CreateAProbeExecutionWithError(probeCapability, executionLog.BuildExecutionLogs()); collectExecution.ProbeExecutions.Add(executionWithError); }
public override void PrepareCollectionOfObjects(IEnumerable <ObjectType> allItemsToCollect, VariablesEvaluated variables) { base.PrepareCollectionOfObjects(allItemsToCollect, variables); if (allItemsToCollect.Count() > 0) { var variableEvaluator = new VariableEntityEvaluator(variables); var allSapObjects = allItemsToCollect.OfType <sapcode_object>().ToList(); var issues = allSapObjects.SelectMany(x => variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)(x.Items[x.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.issue)])))).Distinct(); var systemNames = allSapObjects.SelectMany(x => variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)x.Items[x.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.system_name)]))).Distinct(); var systemIds = systemNames.Select(x => Convert.ToInt32(x)); if (systemIds.Count() > 1) { throw new NotSupportedException("Only concurrent collections of a single system is supported!"); } ExecutionLogBuilder.AddInfo(string.Format("Authenticating at code control with user '{0}'.", AuthUser)); var authResult = connectionProvider.authenticate(AuthUser, AuthPassword); if (authResult.error) { ExecutionLogBuilder.AnErrorOccurred(string.Format("Error authenticating at code control : {0}.", authResult.errorMessage)); } else { ExecutionLogBuilder.AddInfo(string.Format("Successfully authenticated.", AuthUser)); int nSystem = systemIds.Single(); var allIssues = issues.Select(x => (long)Convert.ToInt32(x)).ToArray(); ExecutionLogBuilder.AddInfo( string.Format("Starting scan request for system {0} and issues '{1}'.", nSystem, string.Join(",", allIssues))); issueResult = connectionProvider.scanIssueListBySystem(authResult.token, nSystem, allIssues); var scanCriteria = new ScanCriteriaDTO() { scanIdList = new[] { issueResult.scanId ?? 0 } }; var waitTime = 0L; //const int timeOut = 3600000; // 1 hour //const int timeOut = 10800000; // 3 hs const int timeOut = 18000000; while (((issueResult.status == "AWAITING") || (issueResult.status == "PROCESSING")) && (waitTime <= timeOut) ) { Thread.Sleep(40000); issueResult = connectionProvider.findScan(authResult.token, scanCriteria).FirstOrDefault(); // Wait time is desconsidering remote call duration, // should be done with a stop watch waitTime += 40000; } } } }
public void Should_be_possible_to_build_an_execution_log_in_steps_with_custom_errors_logs() { ExecutionLogBuilder executionLog = new ExecutionLogBuilder(); executionLog.StartCollectOf("Registry"); executionLog.TryConnectToHost("176.16.3.166"); executionLog.AnErrorOccurred("Erro trying connect to host 176.16.3.166"); executionLog.CollectingInformationFrom("oval:id:7589"); executionLog.EndCollect(); IEnumerable <ProbeLogItem> executionsLog = executionLog.BuildExecutionLogs(); Assert.AreEqual(5, executionsLog.Count()); Assert.AreEqual(TypeItemLog.Error, executionsLog.ElementAt(2).Type); }
public void Should_be_possible_to_build_a_probeExecution_with_error_status_and_execution_logs_if_not_collect_was_executed() { CollectFactory collectFactory = new CollectFactory(provider.GetSession()); ProbeResult probeResult = probeResultFactory.CreateProbeResultForRegostryCollectWithError(); ExecutionLogBuilder executionLog = new ExecutionLogBuilder(); executionLog.StartCollectOf("registry"); executionLog.TryConnectToHost("176.16.3.22"); executionLog.AnErrorOccurred("Error connecting to host"); executionLog.EndCollect(); ProbeExecution probeExecution = collectFactory.CreateAProbeExecutionWithError("registry", executionLog.BuildExecutionLogs()); Assert.IsNotNull(probeExecution); Assert.AreEqual("registry", probeExecution.Capability); Assert.IsTrue(probeExecution.ExecutionLogs.Count == 4, "the probe execution not have executionLogs expecteds"); Assert.IsTrue(probeExecution.HasErrors(), "the probe execution not have a status expected"); }