protected void btnSave_Click(object sender, EventArgs e) { RockContext rockContext = new RockContext(); SystemTestService monitorTestService = new SystemTestService(rockContext); var monitorTest = GetMonitorTest(monitorTestService); var entityTypeId = ddlComponent.SelectedValueAsId(); if (monitorTest.Id == 0) { if (entityTypeId.HasValue) { monitorTest.EntityTypeId = entityTypeId; monitorTestService.Add(monitorTest); } else { return; } } monitorTest.Name = tbName.Text; monitorTest.RunIntervalMinutes = tbInterval.Text.AsIntegerOrNull(); monitorTest.AlarmCondition = ddlAlarmCondition.SelectedValueAsEnum <AlarmCondition>(); rockContext.SaveChanges(); monitorTest.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phAttributes, monitorTest); monitorTest.SaveAttributeValues(); NavigateToParentPage(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { RockContext rockContext = new RockContext(); SystemTestService monitorTestService = new SystemTestService(rockContext); var qry = monitorTestService.Queryable().OrderBy(t => t.Id); // set the datasource as a query. This allows the grid to only fetch the records that need to be shown based on the grid page and page size gList.SetLinqDataSource(qry); gList.DataBind(); }
protected void btnRun_Click(object sender, RowEventArgs e) { var testId = e.RowKeyId; RockContext rockContext = new RockContext(); SystemTestService monitorTestService = new SystemTestService(rockContext); var monitorTest = monitorTestService.Get(testId); var response = monitorTest.Run(); maNotification.Show("Result: " + response.Passed.ToString(), ModalAlertType.Information); }
private SystemTest GetMonitorTest(SystemTestService monitorTestService) { var testId = PageParameter("MonitorTestId").AsInteger(); var monitorTest = monitorTestService.Get(testId); if (monitorTest == null) { monitorTest = new SystemTest(); } return(monitorTest); }
public string RunTest(int id) { RockContext rockContext = new RockContext(); SystemTestService systemTestService = new SystemTestService(rockContext); var test = systemTestService.Get(id); var result = test.Run(); if (result.Passed) { return("Passed"); } //if we fail throw an exception for a 500 status throw new Exception("Failed"); }
public IHttpActionResult RunTest(int id) { RockContext rockContext = new RockContext(); SystemTestService systemTestService = new SystemTestService(rockContext); var test = systemTestService.Get(id); var result = test.Run(); if (result.Passed) { return(Ok("Passed")); } //if we fail throw an exception for a 500 status return(InternalServerError(new Exception("System Test Failed"))); }
public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; var rockContext = new RockContext(); var systemCommunication = dataMap.GetString("NotificationCommunication").AsGuid(); var notificationGroup = dataMap.GetString("NotificationGroup").AsGuid(); SystemTestService systemTestService = new SystemTestService(rockContext); SystemTestHistoryService systemTestHistoryService = new SystemTestHistoryService(rockContext); var systemTests = systemTestService.Queryable() .Where(t => t.RunIntervalMinutes.HasValue) .ToList(); int count = 0; List <string> alarms = new List <string>(); foreach (var test in systemTests) { var cutOffDate = RockDateTime.Now.AddMinutes(test.RunIntervalMinutes.Value * -1); var histories = systemTestHistoryService.Queryable() .Where(h => h.SystemTestId == test.Id && h.CreatedDateTime > cutOffDate).Any(); if (!histories) { count++; var result = test.Run(); if (test.MeetsAlarmCondition(result)) { alarms.Add(test.Name); } } } if (alarms.Any()) { SendNotifications(alarms, systemCommunication, notificationGroup); context.Result = string.Format($"Ran {count} test{( count != 1 ? "s" : "" )}. Alarms: {string.Join( ", ", alarms )}"); } else { context.Result = string.Format($"Ran {count} test{( count != 1 ? "s" : "" )}."); } }