Exemplo n.º 1
0
        public static DashboardEventParsed FromRawEvent(DashboardEventRaw rawEvent)
        {
            try
            {
                DashboardEventParsed parsed = new DashboardEventParsed();
                parsed.Service  = rawEvent.GetServiceShortName();
                parsed.Region   = rawEvent.GetRegion();
                parsed.Timeline = EventTimelineUtilities.GetEventTimeline(rawEvent);

                if (Int32.TryParse(rawEvent.Status, out int status))
                {
                    parsed.Status = (DashboardEventStatus)status;
                }
                else
                {
                    parsed.Status = 0;
                }

                if (parsed.Region.Equals("global"))
                {
                    // If the returned region was global, it means the listed service name
                    // didn't contain a region element, like ec2-us-east-1, but it may not
                    // be an expected global service, like resourcegroups
                    if (!Config.Instance.GlobalServices.Contains(parsed.Service))
                    {
                        parsed.Region = parsed.Service;
                    }
                }

                parsed.Description = parsed.GetDescriptionStringFromUpdates();
                parsed.Summary     = rawEvent.Summary;
                parsed.Date        = Int64.Parse(rawEvent.Date);

                parsed.Start = parsed.Timeline.Start == default(DateTime) ? parsed.Date : ServiceUtilities.ConvertToUnixTimestamp(parsed.Timeline.Start);
                parsed.End   = parsed.Timeline.End == default(DateTime) ? parsed.Date : ServiceUtilities.ConvertToUnixTimestamp(parsed.Timeline.End);

                return(parsed);
            }
            catch (Exception e)
            {
                throw new Exception($"Could not parse event:\r\n{JsonConvert.SerializeObject(rawEvent)}", e);
            }
        }
Exemplo n.º 2
0
        private async Task LoadData(IEnumerable <DashboardEventRaw> data, string source)
        {
            if (data == null)
            {
                this._context.LogError("Null was provided to LoadData, no data to load.");
                return;
            }

            BatchWrite <DashboardEventParsed> batch = ddbContext.CreateBatchWrite <DashboardEventParsed>();

            int misses = 0;

            foreach (DashboardEventRaw item in data)
            {
                DashboardEventParsed parsed;

                try
                {
                    parsed = DashboardEventParsed.FromRawEvent(item);
                    batch.AddPutItem(parsed);

                    if (parsed.Timeline.StartTimeWasFoundInDescription == false)
                    {
                        this._context.LogError($"Did not find start/end in description: {item.Description}");
                        misses += 1;
                    }
                }
                catch (Exception e)
                {
                    this._context.LogError(e);
                }
            }

            try
            {
                await batch.ExecuteAsync();
            }
            catch (Exception e)
            {
                this._context.LogError(e);
            }

            await cwClient.PutMetricDataAsync(new PutMetricDataRequest()
            {
                MetricData = new List <MetricDatum>()
                {
                    new MetricDatum()
                    {
                        Value        = misses,
                        MetricName   = Environment.GetEnvironmentVariable("ExtractionFailureMetricName"),
                        TimestampUtc = DateTime.UtcNow,
                        Unit         = StandardUnit.Count,
                        Dimensions   = new List <Dimension>()
                        {
                            new Dimension()
                            {
                                Name  = "source",
                                Value = source
                            }
                        }
                    }
                },
                Namespace = "SHD"
            });
        }