示例#1
0
        private List <JobStatistic> GetJobStatistics(
            AlertingRule rule,
            IEnumerable <Guid> jobIds,
            IEnumerable <string> jobNameFilters,
            IDictionary <string, string> userAliases,
            int lookbackDays)
        {
            using (var context = new DatabaseObjectsDataContext(_databaseConnectionString))
            {
                DateTime minimumJobEndTime = DateTime.UtcNow.AddDays(-lookbackDays);

                return(jobIds
                       .Select(id => context.JobStatistics.Where(stat => stat.Id == id).First())
                       .Where(jobStat => jobStat.EndTime == null || jobStat.EndTime > minimumJobEndTime)
                       .Where(jobStat => !rule.ShouldFilterJobName || jobNameFilters.All(filter => jobStat.Name.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) < 0))
                       .Where(jobStat => userAliases.ContainsKey(jobStat.TrueUserName.ToLowerInvariant()))
                       .ToList());
            }
        }
        public static AlertingRules GenerateSample()
        {
            return(new AlertingRules()
            {
                Rules = new List <AlertingRule>()
                {
                    AlertingRule.GenerateSample()
                },

                MailSettings = MailSettings.GenerateSample(),

                JobNameFilters = new List <string>()
                {
                    "APPROVED_BY_TECHBOARD",
                    "APPROVED_BY_ADMIN",
                },

                LookbackDays = 3,
            });
        }
示例#3
0
        private List <Guid> ExecuteRule(AlertingRule rule)
        {
            List <Guid> jobIds = new List <Guid>();

            using (SqlConnection connection = new SqlConnection(_databaseConnectionString))
            {
                connection.Open();

                SqlCommand command = new SqlCommand(rule.SqlQuery, connection);
                command.CommandTimeout = _commandTimeout;

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    int idColumnIndex = -1;
                    try
                    {
                        idColumnIndex = reader.GetOrdinal(IdColumnName);
                    }
                    catch (IndexOutOfRangeException)
                    {
                    }

                    if (idColumnIndex < 0)
                    {
                        throw new InvalidOperationException(
                                  string.Format("The sql query in rule [{0}] does not contain column[{1}]",
                                                rule.SqlQuery,
                                                IdColumnName));
                    }

                    while (reader.Read())
                    {
                        Guid guid = reader.GetGuid(idColumnIndex);

                        jobIds.Add(guid);
                    }
                }
            }

            return(jobIds);
        }