public void Add(AgentLog log) { lock (syncRoot) { if (log.Type == "Executing") { if (!activeAgents.ContainsKey(log.Agent)) { activeAgents.Add(log.Agent, new AgentCollector(log.Agent)); } activeAgents[log.Agent].Collect(log.Message); if (activeStep == null && steps.LastOrDefault()?.Contains(activeAgents[log.Agent]) != true) { activeStep = new ExecutionOrderStep(activeAgents.Values); } activeStep?.Collect(activeAgents[log.Agent]); } else if (activeAgents.ContainsKey(log.Agent)) { AgentCollector remainingCollector = activeAgents[log.Agent].Finish(log.Message); if (remainingCollector == null) { activeAgents.Remove(log.Agent); } if (activeStep != null) { steps.Add(activeStep); activeStep = null; } } } }
public void WaitForStartup() { AgentLog.WaitForConnect(Timing.TimeToConnect); var stopwatch = Stopwatch.StartNew(); while (stopwatch.Elapsed < TimeSpan.FromMinutes(5)) { try { using (var httpClient = new HttpClient()) { var guid = Guid.NewGuid().ToString(); var address = $"http://{DestinationServerName}:{Port}/Default/Ignored?data={guid}"; httpClient.Timeout = TimeSpan.FromSeconds(1); Task.Run(async() => Assert.Equal(guid, await httpClient.GetStringAsync(address))).Wait(); return; } } catch (Exception) { // try again in a bit, until we get a response in under 1 second (meaning server is up and stable) or 5 minutes passes Thread.Sleep(TimeSpan.FromSeconds(5)); } } Assert.True(false, @"Did not receive a stable response (less than 1 second) after 5 minutes of attempts every 6 seconds."); }
public void WaitForStartup() { AgentLog.WaitForConnect(Timing.TimeToConnect); var stopwatch = Stopwatch.StartNew(); while (stopwatch.Elapsed < TimeSpan.FromMinutes(5)) { try { var httpClient = new HttpClient(); var address = string.Format("http://{0}:{1}/api/IgnoreTransaction", DestinationServerName, Port); httpClient.Timeout = TimeSpan.FromSeconds(1); Task.Run(() => httpClient.GetStringAsync(address)).Wait(); return; } catch (Exception) { // try again in a bit, until we get a response in under 1 second (meaning server is up and stable) or 5 minutes passes Thread.Sleep(TimeSpan.FromSeconds(5)); } } Assert.True(false, @"Did not receive a stable response (less than 1 second) after 5 minutes of attempts every 6 seconds."); }
private string GetUntrustedXNewRelicId() { var invalidAccountId = "999999"; var applicationId = AgentLog.GetApplicationId(); var accountAndApp = $@"{invalidAccountId}#{applicationId}"; return(HeaderEncoder.Base64Encode(accountAndApp, HeaderEncoder.IntegrationTestEncodingKey)); }
public void GetLogTest() { AgentLog target = AgentLog.GetStartedInstance(); // TODO: Initialize to an appropriate value int taskId = 1; // TODO: Initialize to an appropriate value target.GetLog(taskId); Assert.AreEqual(AgentSetting.AddressUrl + AgentSetting.CommandLogDownload, TestCallerFactory.UrlString); Assert.AreEqual( @"{""TaskId"":0,""BusinessCredentials"":{""LicenseKey"":""xxxxx-xxxxxx""}}", TestCallerFactory.JsonString); }
public AgentUrlDictionaryLog() { AgentLog.Add("TSPC", new AgentUrlDictionary() { DirectUrl = "http://www.sspc.co.uk/40-Marine-Parade-Dundee-DD1-3BN-3-Bedroom-Flat-TSPC ", InDirectUrl = "http://www.tspc.co.uk/details.asp?id=112740 " }); AgentLog.Add("SSPC Moray", new AgentUrlDictionary() { DirectUrl = "", InDirectUrl = "http://www.spcmoray.com/property.php?id=5975 " }); AgentLog.Add("HSPC", new AgentUrlDictionary() { DirectUrl = "http://www.sspc.co.uk/Kenilworth-Glenlivet-Ballindalloch-AB37-9DB-4-Bedroom-Semi-Detached-Villa-HSPC ", InDirectUrl = "" }); AgentLog.Add("ESPC", new AgentUrlDictionary() { DirectUrl = "http://www.sspc.co.uk/79-Riverside-Road-Wormit-NEWPORT-ON-TAY-DD6-8LG-4-Bedroom-Detached-House-ESPC ", InDirectUrl = "http://www.espc.com/properties/details.aspx?pid=339790 " }); AgentLog.Add("FSPC", new AgentUrlDictionary() { DirectUrl = "", InDirectUrl = "http://www.fifespc.co.uk/property-search.cfm?Action=Results&ID=13732&T=1 " }); AgentLog.Add("BSPC", new AgentUrlDictionary() { DirectUrl = "", InDirectUrl = "http://www.bspc.co.uk/propertydetails.asp?pRef=19110&pPostCode=EH43%206AN " }); AgentLog.Add("GSPC", new AgentUrlDictionary() { DirectUrl = "http://www.sspc.co.uk/The-Hume-Wester-Grove-at-Bathgate-Bathgate-EH48-2GF-4-Bedroom-Detached-Villa-GSPC ", InDirectUrl = "http://www.gspc.co.uk/property/west-lothian/bathgate/the-hume-wester-grove-at-bathgate/203782/ " }); AgentLog.Add("PSPC", new AgentUrlDictionary() { DirectUrl = "http://www.sspc.co.uk/Tormore-15-High-Street-Kinross-KY13-8AN-4-Bedroom-Detached-Villa-PSPC ", InDirectUrl = "http://www.pspc.co.uk/property/52812/#location=&beds=0&budget=0&page=1 " }); AgentLog.Add("DGSPC", new AgentUrlDictionary() { DirectUrl = "http://www.sspc.co.uk/4-Old-Library-Row-Wanlockhead-ML12-6XL-ML12-6XL-3-Bedroom-Cottage-End-Terrace-DGSPC ", InDirectUrl = "http://www.dgspc.co.uk/4_Old_Library_Row_Wanlockhead_ML12_6XL_25573 " }); }
public LogsController() { var logPath = Path.Combine(Environment.GetEnvironmentVariable("NEWRELIC_HOME"), "logs"); _agentLog = new AgentLog(logPath); }
public virtual void Initialize() { lock (_initializeLock) { if (_initialized) { return; } _initialized = true; TestLogger?.WriteLine(RemoteServiceFixtures.RemoteApplication.AppName); var numberOfTries = 0; try { var appIsExercisedNormally = true; do { TestLogger?.WriteLine("Test Home" + RemoteApplication.DestinationNewRelicHomeDirectoryPath); appIsExercisedNormally = true; RemoteApplication.TestLogger = new XUnitTestLogger(TestLogger); RemoteApplication.DeleteWorkingSpace(); RemoteApplication.CopyToRemote(); SetupConfiguration(); var captureStandardOutput = RemoteApplication.CaptureStandardOutput; RemoteApplication.Start(CommandLineArguments, captureStandardOutput); try { ExerciseApplication(); } catch (Exception ex) { appIsExercisedNormally = false; TestLogger?.WriteLine("Exception occurred in try number " + (numberOfTries + 1) + " : " + ex.ToString()); } finally { if (!DelayKill) { ShutdownRemoteApplication(); if (captureStandardOutput) { RemoteApplication.CapturedOutput.WriteProcessOutputToLog("RemoteApplication:"); // Most of our tests run in HostedWebCore, but some don't, e.g. the self-hosted // WCF tests. For the HWC tests we carefully validate the console output in order // to detect process-level failures that may cause test flickers. For the self- // hosted tests, unfortunately, we just punt that. if (RemoteApplication.ValidateHostedWebCoreOutput) { SubprocessLogValidator.ValidateHostedWebCoreConsoleOutput(RemoteApplication.CapturedOutput.StandardOutput, TestLogger); } else { TestLogger?.WriteLine("Note: child process is not required for log validation because _remoteApplication.ValidateHostedWebCoreOutput = false"); } } else { TestLogger?.WriteLine("Note: child process application does not redirect output because _remoteApplication.CaptureStandardOutput = false. HostedWebCore validation cannot take place without the standard output. This is common for non-web and self-hosted applications."); } RemoteApplication.WaitForExit(); appIsExercisedNormally = RemoteApplication.ExitCode == 0; TestLogger?.WriteLine($"Remote application exited with a {(appIsExercisedNormally ? "success" : "failure")} exit code of {RemoteApplication.ExitCode}."); } else { TestLogger?.WriteLine("Note: Due to DelayKill being used, no process output or agent log validation was performed to verify that the application started and ran successfully."); } if (!appIsExercisedNormally && DelayKill) { RemoteApplication.Kill(); if (captureStandardOutput) { RemoteApplication.CapturedOutput.WriteProcessOutputToLog("[RemoteApplicationFixture]: Initialize"); } RemoteApplication.WaitForExit(); } Thread.Sleep(1000); numberOfTries++; } } while (!appIsExercisedNormally && numberOfTries < MaxTries); if (!appIsExercisedNormally) { TestLogger?.WriteLine($"Test App wasn't exercised normally after {MaxTries} tries."); throw new Exception($"Test App wasn't exercised normally after {MaxTries} tries."); } } finally { TestLogger?.WriteLine("===== Begin Agent log file ====="); try { TestLogger?.WriteLine(AgentLog.GetFullLogAsString()); } catch (Exception) { TestLogger?.WriteLine("No log file found."); } TestLogger?.WriteLine("----- End of Agent log file -----"); } } }
public virtual void Initialize() { lock (_initializeLock) { if (_initialized) { return; } _initialized = true; TestLogger?.WriteLine(RemoteServiceFixtures.RemoteApplication.AppName); var numberOfTries = 0; try { var retryTest = false; var exceptionInExerciseApplication = false; var applicationHadNonZeroExitCode = false; do { TestLogger?.WriteLine("Test Home" + RemoteApplication.DestinationNewRelicHomeDirectoryPath); // reset these for each loop iteration exceptionInExerciseApplication = false; applicationHadNonZeroExitCode = false; retryTest = false; RemoteApplication.TestLogger = new XUnitTestLogger(TestLogger); RemoteApplication.DeleteWorkingSpace(); RemoteApplication.CopyToRemote(); SetupConfiguration(); var captureStandardOutput = RemoteApplication.CaptureStandardOutput; RemoteApplication.Start(CommandLineArguments, captureStandardOutput); try { ExerciseApplication(); } catch (Exception ex) { exceptionInExerciseApplication = true; TestLogger?.WriteLine("Exception occurred in try number " + (numberOfTries + 1) + " : " + ex.ToString()); } finally { ShutdownRemoteApplication(); if (captureStandardOutput) { RemoteApplication.CapturedOutput.WriteProcessOutputToLog("RemoteApplication:"); // Most of our tests run in HostedWebCore, but some don't, e.g. the self-hosted // WCF tests. For the HWC tests we carefully validate the console output in order // to detect process-level failures that may cause test flickers. For the self- // hosted tests, unfortunately, we just punt that. if (RemoteApplication.ValidateHostedWebCoreOutput) { SubprocessLogValidator.ValidateHostedWebCoreConsoleOutput(RemoteApplication.CapturedOutput.StandardOutput, TestLogger); } else { TestLogger?.WriteLine("Note: child process is not required for log validation because _remoteApplication.ValidateHostedWebCoreOutput = false"); } } else { TestLogger?.WriteLine("Note: child process application does not redirect output because _remoteApplication.CaptureStandardOutput = false. HostedWebCore validation cannot take place without the standard output. This is common for non-web and self-hosted applications."); } RemoteApplication.WaitForExit(); applicationHadNonZeroExitCode = RemoteApplication.ExitCode != 0; TestLogger?.WriteLine($"Remote application exited with a {(applicationHadNonZeroExitCode ? "failure" : "success")} exit code of {RemoteApplication.ExitCode}."); retryTest = exceptionInExerciseApplication || applicationHadNonZeroExitCode; if (retryTest) { var message = $"Retrying test. Exception caught when exercising test app = {exceptionInExerciseApplication}, application had non-zero exit code = {applicationHadNonZeroExitCode}."; TestLogger?.WriteLine(message); Thread.Sleep(1000); numberOfTries++; } } } while (retryTest && numberOfTries < MaxTries); if (retryTest) { var message = ($"Test failed after {MaxTries} tries."); TestLogger?.WriteLine(message); throw new Exception(message); } } finally { TestLogger?.WriteLine("===== Begin Agent log file ====="); try { TestLogger?.WriteLine(AgentLog.GetFullLogAsString()); } catch (Exception) { TestLogger?.WriteLine("No log file found."); } TestLogger?.WriteLine("----- End of Agent log file -----"); } } }
public async Task <ActionResult> Create(AgentLogModel model) { try { if (ModelState.IsValid) { if (User.IsInRole("Admin")) { var entity = new AgentLog { DialingHours = model.DialingHours, TrainingHours = model.TrainingHours, Successes = model.Successes, AgentId = model.UserId, CampaignId = db.Projects.FirstOrDefault(x => x.Id == model.ProjectId).CampaignId, ProjectId = model.ProjectId, TimeZoneId = model.TimeZoneId, LastUpdate = DateTime.Now, CreationDate = model.Date, IsDeleted = false, }; db.AgentLogs.Add(entity); } else { var entity = new AgentLog { DialingHours = model.DialingHours, TrainingHours = model.TrainingHours, Successes = model.Successes, AgentId = User.Identity.GetUserId(), CampaignId = (Int32)Session["CampaignId"], ProjectId = (Int32)Session["ProjectId"], TimeZoneId = (Int32)Session["TimeZoneId"], LastUpdate = DateTime.Now, CreationDate = DateTime.Now, IsDeleted = false, }; db.AgentLogs.Add(entity); } await db.SaveChangesAsync(); return(RedirectToAction("Index")); } } catch (Exception e) { AddAlert($"Oops! something went wrong. Error code: {e.HResult}", "Create(model)", this.GetType().ToString(), AlertType.error, e); ViewBag.UserId = new SelectList(db.Users.Where(x => !x.IsDeleted).Where(x => x.Roles.Any(y => y.RoleId == "2" || y.RoleId == "3")), "Id", "DisplayName"); ViewBag.ProjectId = new SelectList(db.Projects.Where(x => !x.IsDeleted), "Id", "Name"); ViewBag.TimeZoneId = new SelectList(db.TimeZones, "Id", "Name"); return(View()); } ViewBag.UserId = new SelectList(db.Users.Where(x => !x.IsDeleted).Where(x => x.Roles.Any(y => y.RoleId == "2" || y.RoleId == "3")), "Id", "DisplayName"); ViewBag.ProjectId = new SelectList(db.Projects.Where(x => !x.IsDeleted), "Id", "Name"); ViewBag.TimeZoneId = new SelectList(db.TimeZones, "Id", "Name"); return(View()); }
public void CreateDomainLevel2() { try { var ctx = ApplicationDbContext.Create(); //already OK if (ctx.Forms.Any()) { return; } var reader = new ReadOnlyContext(); var db = MemoryDB.LoadDomainLevel2(reader); var container = new MemoryDB(); foreach (var item in db.Forms) { var form = new Form { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, CreationDate = item.CreationDate, Description = item.Description, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Name = item.Name, }; container.Forms.Add(form); } foreach (var item in db.AgentLogs) { var agentLog = new AgentLog { Id = item.Id, //Agent = agent, //AgentId = agent.Id, AgentId = item.AgentId, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, //TimeZone = timeZone, //TimeZoneId = timeZone.Id, TimeZoneId = item.TimeZoneId, CreationDate = item.CreationDate, DialingHours = item.DialingHours, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Project = item.Project, ProjectId = item.ProjectId, Successes = item.Successes, TrainingHours = item.TrainingHours, }; container.AgentLogs.Add(agentLog); } //foreach (var item in db.CampaignCallCodes) //{ // var campaignCallCodes = new CampaignCallCode // { // Id = item.Id, // //CallCode = callCode, // //CallCodeId = callCode.Id, // CallCodeId = item.CallCodeId, // //Campaign = campaign, // //CampaignId = campaign.Id, // CampaignId = item.CampaignId, // CreationDate = item.CreationDate, // IsDeleted = item.IsDeleted, // LastUpdate = item.LastUpdate, // }; // container.CampaignCallCodes.Add(campaignCallCodes); //} foreach (var item in db.ExtraFields) { var extraField = new ExtraField { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, CreationDate = item.CreationDate, // ExtraFieldOptions = item.ExtraFieldOptions, FieldName = item.FieldName, IsDeleted = item.IsDeleted, TypeId = item.TypeId, LastUpdate = item.LastUpdate, }; container.ExtraFields.Add(extraField); } foreach (var item in db.UserCampaigns) { var userCampaign = new UserCampaign { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, //User = user, //UserId = user.Id, UserId = item.UserId, BudgetedHours = item.BudgetedHours, CreationDate = item.CreationDate, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, PayRateDialingHours = item.PayRateDialingHours, PayRateSuccess = item.PayRateSuccess, PayRateTrainingHours = item.PayRateTrainingHours, }; container.UserCampaigns.Add(userCampaign); } foreach (var item in db.UserProjects) { var userProject = new UserProject { Id = item.Id, //UserCampaign = userCampaign, //UserCampaignId = userCampaign.Id, UserCampaignId = item.UserCampaignId, //Project = project, //ProjectId = project.Id, ProjectId = item.ProjectId, //User = user, //UserId = user.Id, UserId = item.UserId, CreationDate = item.CreationDate, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, }; container.UserProjects.Add(userProject); } foreach (var item in db.UsersHistory) { var userHistory = new UserHistory { Id = item.Id, //User = user, //UserId = user.Id, UserId = item.UserId, //Campaign = campaign, //CampaignId = campaign?.Id, CampaignId = item.CampaignId, ConnectionId = item.ConnectionId, CreationDate = item.CreationDate, Duration = item.Duration, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, LoggedIn = item.LoggedIn, LoggedOff = item.LoggedOff, }; container.UsersHistory.Add(userHistory); } ctx.Forms.AddRange(container.Forms); ctx.AgentLogs.AddRange(container.AgentLogs); //ctx.CampaignCallCodes.AddRange(container.CampaignCallCodes); ctx.ExtraFields.AddRange(container.ExtraFields); ctx.UserCampaigns.AddRange(container.UserCampaigns); ctx.UserProjects.AddRange(container.UserProjects); ctx.UsersHistory.AddRange(container.UsersHistory); ctx.SaveChanges(); } catch (Exception ex) { var str = ex.ToString(); System.Diagnostics.Debug.WriteLine(str); } }
public LogsController() { var logPath = @"c:\Home\LogFiles\NewRelic"; _agentLog = new AgentLog(logPath); }