Exemple #1
0
        private async Task ProcessEventRecord(KinesisEvent.KinesisEventRecord record, bool writeEventsToQueue)
        {
            _logger.Trace("Beginning ProcessEventRecord");

            _logger.Debug($"Kinesis EventId:{record.EventId} EventName: {record.EventName} EventSource: {record.EventSource} EventVersion: {record.EventVersion} EventSourceARN {record.EventSourceARN} InvokeIdentityARN: {record.InvokeIdentityArn} Kinesis Time: {record.Kinesis.ApproximateArrivalTimestamp} Kinesis ParitionKey: {record.Kinesis.PartitionKey} Kinesis SeqNum: {record.Kinesis.SequenceNumber}");

            string recordData = GetRecordContents(record.Kinesis);

            _logger.Debug($"RecordData:{recordData}");

            //FOR CREATING TEST DATA
            //var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(recordData);
            //string convertedRecordData = System.Convert.ToBase64String(plainTextBytes);
            //Logger.Info(convertedRecordData);

            if (!String.IsNullOrEmpty(recordData))
            {
                ConnectKinesisEventRecord streamRecord = ConvertRecordData(recordData);
                if (streamRecord.LastEventType != HEARTBEAT_EVENTTYPE)
                {
                    await ProcessEventToTable(streamRecord);
                }
                if (writeEventsToQueue)
                {
                    await ProcessEventToQueue(recordData);
                }
            }

            _logger.Trace("Ending ProcessEventRecord");
        }
        private ConnectKinesisEventRecord ConvertRecordData(string json, EventRecordData eventRecord)
        {
            _logger.Trace("Beginning ConvertRecordData");

            // if this record doesn't include an agent ARN, assume it doesn't match the
            // required format. Discard it.
            if (String.IsNullOrEmpty(eventRecord?.AgentARN))
            {
                _logger.Info("recordData does not include AgentARN. Discarding recordData.");
                return(null);
            }

            ConnectKinesisEventRecord streamRecord = new ConnectKinesisEventRecord()
            {
                AgentARN                 = eventRecord.AgentARN,
                AgentUsername            = eventRecord.CurrentAgentSnapshot?.Configuration?.Username,
                LastEventType            = eventRecord.EventType,
                LastEventTimeStamp       = eventRecord.EventTimestamp,
                LastStateChangeTimeStamp = eventRecord.CurrentAgentSnapshot?.AgentStatus.StartTimestamp,
                CurrentState             = eventRecord.CurrentAgentSnapshot?.AgentStatus?.Name,
                RawAgentEventJSon        = json
            };

            _logger.Debug($"Event Type: {eventRecord.EventType} Agent Username: {streamRecord.AgentUsername} Current State: {streamRecord.CurrentState} Event Time: {streamRecord.LastEventTimeStamp} State Change Time: {streamRecord.LastStateChangeTimeStamp}");

            _logger.Trace("Ending ConvertRecordData");

            return(streamRecord);
        }
Exemple #3
0
        private ConnectKinesisEventRecord ConvertRecordData(string recordData)
        {
            _logger.Trace("Beginning ConvertRecordData");

            EventRecordData recordDataObject;

            try
            {
                recordDataObject = JsonConvert.DeserializeObject <EventRecordData>(recordData);
            }
            catch (Exception e)
            {
                _logger.Error($"Exception deserializing recordData: {e}. Discarding recordData.");
                // This record doesn't match the EventRecordData format, return a value that
                // indicates that this record should be discarded.
                return(null);
            }

            // if this record doesn't include an agent ARN, assume it doesn't match the
            // required format. Discard it.
            if (String.IsNullOrEmpty(recordDataObject.AgentARN))
            {
                _logger.Info("recordData does not include AgentARN. Discarding recordData.");
                return(null);
            }

            ConnectKinesisEventRecord streamRecord = new ConnectKinesisEventRecord()
            {
                AgentARN                 = recordDataObject.AgentARN,
                AgentUsername            = recordDataObject.CurrentAgentSnapshot?.Configuration?.Username,
                LastEventType            = recordDataObject.EventType,
                LastEventTimeStamp       = recordDataObject.EventTimestamp,
                LastStateChangeTimeStamp = recordDataObject.CurrentAgentSnapshot?.AgentStatus.StartTimestamp,
                CurrentState             = recordDataObject.CurrentAgentSnapshot?.AgentStatus?.Name,
                RawAgentEventJSon        = recordData
            };

            _logger.Debug($"Event Type: {recordDataObject.EventType} Agent Username: {streamRecord.AgentUsername} Current State: {streamRecord.CurrentState} Event Time: {streamRecord.LastEventTimeStamp} State Change Time: {streamRecord.LastStateChangeTimeStamp}");

            _logger.Trace("Ending ConvertRecordData");

            return(streamRecord);
        }
Exemple #4
0
        private async Task ProcessEventToTable(ConnectKinesisEventRecord streamRecord)
        {
            _logger.Trace("Beginning ProcessEventsToDynamoTable");

            var dynamoRecord = await _ddbContext.LoadAsync <ConnectKinesisEventRecord>(streamRecord.AgentARN);

            if (dynamoRecord == null || streamRecord.LastEventTimeStamp >= dynamoRecord.LastEventTimeStamp)
            {
                await _ddbContext.SaveAsync(streamRecord);
            }
            else
            {
                _logger.Warn($"Stream record event timestamp {streamRecord.LastEventTimeStamp} is prior to dynamo record event timestamp {dynamoRecord.LastEventTimeStamp}.");
                _logger.Warn($"Current Stream Record Json {streamRecord.RawAgentEventJSon}");
                _logger.Warn($"Current Dynamo Record Json {dynamoRecord.RawAgentEventJSon}");
            }
            //NOTE: ignores if record old/out-of-order since all info out-of-date; not excepted to be out of order - very rare possiblity

            _logger.Trace("Ending ProcessEventsToDynamoTable");
        }
        private async Task ProcessEventRecord(KinesisEvent.KinesisEventRecord record, bool writeEventsToQueue)
        {
            _logger.Trace("Beginning ProcessEventRecord");

            _logger.Debug($"Kinesis EventId:{record.EventId} EventName: {record.EventName} EventSource: {record.EventSource} EventVersion: {record.EventVersion} EventSourceARN {record.EventSourceARN} InvokeIdentityARN: {record.InvokeIdentityArn} Kinesis Time: {record.Kinesis.ApproximateArrivalTimestamp} Kinesis ParitionKey: {record.Kinesis.PartitionKey} Kinesis SeqNum: {record.Kinesis.SequenceNumber}");

            string recordData = GetRecordContents(record.Kinesis);

            _logger.Debug($"RecordData:{recordData}");

            //FOR CREATING TEST DATA
            //var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(recordData);
            //string convertedRecordData = System.Convert.ToBase64String(plainTextBytes);
            //Logger.Info(convertedRecordData);

            if (!String.IsNullOrEmpty(recordData))
            {
                var minimizedJSON = ShrinkEvent(recordData);
                var eventRecord   = ParseEvent(minimizedJSON);
                if (eventRecord != null && MatchFilter(eventRecord))
                {
                    _logger.Debug("Event matches filter");
                    ConnectKinesisEventRecord streamRecord = ConvertRecordData(minimizedJSON, eventRecord);
                    // if we were able to parse this event, send to DynamoDB and SQS.
                    if (streamRecord != null)
                    {
                        if (streamRecord.LastEventType != HEARTBEAT_EVENTTYPE)
                        {
                            await ProcessEventToTable(streamRecord);
                        }
                        if (writeEventsToQueue)
                        {
                            await ProcessEventToQueue(minimizedJSON, streamRecord.AgentARN);
                        }
                    }
                }
            }

            _logger.Trace("Ending ProcessEventRecord");
        }
Exemple #6
0
        private ConnectKinesisEventRecord ConvertRecordData(string recordData)
        {
            _logger.Trace("Beginning ConvertRecordData");

            EventRecordData recordDataObject = JsonConvert.DeserializeObject <EventRecordData>(recordData);

            ConnectKinesisEventRecord streamRecord = new ConnectKinesisEventRecord()
            {
                AgentARN                 = recordDataObject.AgentARN,
                AgentUsername            = recordDataObject.CurrentAgentSnapshot?.Configuration?.Username,
                LastEventType            = recordDataObject.EventType,
                LastEventTimeStamp       = recordDataObject.EventTimestamp,
                LastStateChangeTimeStamp = recordDataObject.CurrentAgentSnapshot?.AgentStatus.StartTimestamp,
                CurrentState             = recordDataObject.CurrentAgentSnapshot?.AgentStatus?.Name,
                RawAgentEventJSon        = recordData
            };

            _logger.Debug($"Event Type: {recordDataObject.EventType} Agent Username: {streamRecord.AgentUsername} Current State: {streamRecord.CurrentState} Event Time: {streamRecord.LastEventTimeStamp} State Change Time: {streamRecord.LastStateChangeTimeStamp}");

            _logger.Trace("Ending ConvertRecordData");

            return(streamRecord);
        }