internal IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string originId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                healthLevels = query.StatusLevels;
            }

            var origId      = originId.GuidToOriginId();
            var alertstring = CloudCache.Get(origId + "Alerts");
            List <OriginAlert> alerts;

            if (alertstring != null)
            {
                alerts = JsonConvert.DeserializeObject <List <OriginAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                alerts = dataAccess.ExecuteReadQuery(context =>
                {
                    var dbAlerts = context.OriginAlerts.Where(alert =>
                                                              alert.OriginId == originId &&
                                                              alert.Timestamp >= startTime &&
                                                              alert.Timestamp <= endTime);

                    if (healthLevels != null)
                    {
                        var predicate = CreatePredicate(healthLevels, "ErrorLevel");
                        dbAlerts      = dbAlerts.Where(predicate);
                    }
                    return(dbAlerts.ToList());
                });
            }

            return(alerts.Select(alert => new MetricAlert
            {
                Name = alert.OriginId,
                Date = alert.Timestamp,
                Description = alert.Details,
                Status = alert.ErrorLevel
            }).OrderByDescending(alt => alt.Date));
        }
Пример #2
0
        protected List <T> GetAlertsFromCache <T>(string id)
        {
            string alertstring = CloudCache.Get(id + "Alerts");

            if (alertstring != null)
            {
                return(JsonConvert.DeserializeObject <List <T> >(alertstring));
            }
            return(null);
        }
Пример #3
0
        internal IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string originId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                healthLevels = query.StatusLevels;
            }

            //var origId = originId.GuidToOriginId();
            string             alertstring = CloudCache.Get(originId + "Alerts");
            List <OriginAlert> originAlerts;

            if (alertstring != null)
            {
                originAlerts = JsonConvert.DeserializeObject <List <OriginAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                if (healthLevels == null)
                {
                    originAlerts = dataAccess.GetOriginAlerts(originId);
                }
                else
                {
                    originAlerts = dataAccess.GetOriginAlerts(originId, healthLevels);
                }
            }

            List <MetricAlert> alerts = new List <MetricAlert>();

            if (originAlerts != null && originAlerts.Count > 0)
            {
                foreach (var orgAlt in originAlerts)
                {
                    alerts.Add(new MetricAlert
                    {
                        AlertID     = orgAlt.AlertID,
                        Name        = orgAlt.OriginName,
                        Date        = orgAlt.AlertDate.AddTicks(orgAlt.AlertTime.Ticks),
                        Description = orgAlt.Details,
                        Status      = orgAlt.ErrorLevel
                    });
                }
            }
            return(alerts);
        }
        private IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string channelId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;
            MetricType[]   metricTypes  = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                metricTypes  = query.MetricTypes;
                healthLevels = query.StatusLevels;
            }

            var    chid        = channelId.NimbusIdToGuid();
            string alertstring = CloudCache.Get(chid + "Alerts");
            List <ChannelAlert> channelAlerts;

            if (alertstring != null)
            {
                channelAlerts = JsonConvert.DeserializeObject <List <ChannelAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                channelAlerts = dataAccess.GetChannelAlerts(chid.ToString(), healthLevels, metricTypes);
                #region Not used
                //channelAlerts = dataAccess.ExecuteReadQuery(context =>
                //{
                //    var dbAlerts = context.ChannelAlerts.Where(alert =>
                //       alert.ChannelId == channelId &&
                //       alert.AlertDate >= startTime.AddTicks(alert.AlertTime.Ticks) &&
                //       alert.AlertDate <= endTime);

                //    if (healthLevels != null)
                //    {
                //        var predicate = CreatePredicate(healthLevels, "ErrorLevel");
                //        dbAlerts = dbAlerts.Where(predicate);
                //    }
                //    if (metricTypes != null)
                //    {
                //        var condition = CreatePredicate(metricTypes, "MetricType");
                //        dbAlerts = dbAlerts.Where(condition);
                //    }



                //    return dbAlerts.ToList();
                //});
                #endregion
            }
            List <MetricAlert> alerts = new List <MetricAlert>();
            if (channelAlerts != null)
            {
                foreach (var chAlt in channelAlerts)
                {
                    alerts.Add(new MetricAlert
                    {
                        AlertID     = chAlt.AlertID,
                        Name        = chAlt.ChannelName,
                        Date        = chAlt.AlertDate.AddTicks(chAlt.AlertTime.Ticks),
                        Description = chAlt.Details,
                        Status      = chAlt.ErrorLevel
                    });
                }
            }
            return(alerts);
        }