Пример #1
0
        /// <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();
        }
Пример #2
0
        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" : "" )}.");
            }
        }