/// <summary> /// Method to collect data in case of Amazon service exception /// </summary> private static void CaptureAmazonException(MonitoringAPICallAttempt monitoringAPICallAttempt, AmazonServiceException e) { if ((int)e.StatusCode > 0) { monitoringAPICallAttempt.HttpStatusCode = (int)e.StatusCode; } if (e.ErrorCode == null) { CaptureSDKExceptionMessage(monitoringAPICallAttempt, e); return; } monitoringAPICallAttempt.AWSException = e.ErrorCode.Length <= 128 ? e.ErrorCode : string.Empty; monitoringAPICallAttempt.AWSExceptionMessage = e.Message.Length <= 512 ? e.Message : string.Empty; }
/// <summary> /// Method to collect data in case of connection exception /// </summary> private static void CaptureSDKExceptionMessage(MonitoringAPICallAttempt monitoringAPICallAttempt, Exception e) { monitoringAPICallAttempt.SdkException = e.GetType().Name.ToString().Length <= 128 ? e.GetType().Name.ToString() : string.Empty; monitoringAPICallAttempt.SdkExceptionMessage = e.Message.Length <= 512 ? e.Message : string.Empty; }
/// <summary> /// Method to serialize MonitoringAPICallAttempt CSM event to json. /// </summary> private static bool CreateUDPMessage(MonitoringAPICallAttempt monitoringAPICallAttempt, out string response) { JsonWriter jw = new JsonWriter(); jw.WriteObjectStart(); jw = CreateUDPMessage(monitoringAPICallAttempt, jw); if (!string.IsNullOrEmpty(monitoringAPICallAttempt.AccessKey)) { jw.WritePropertyName("AccessKey"); jw.Write(monitoringAPICallAttempt.AccessKey); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.AWSException)) { jw.WritePropertyName("AWSException"); jw.Write(monitoringAPICallAttempt.AWSException); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.Fqdn)) { jw.WritePropertyName("Fqdn"); jw.Write(monitoringAPICallAttempt.Fqdn); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.SdkException)) { jw.WritePropertyName("SdkException"); jw.Write(monitoringAPICallAttempt.SdkException); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.AWSExceptionMessage)) { jw.WritePropertyName("AWSExceptionMessage"); jw.Write(monitoringAPICallAttempt.AWSExceptionMessage); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.SdkExceptionMessage)) { jw.WritePropertyName("SdkExceptionMessage"); jw.Write(monitoringAPICallAttempt.SdkExceptionMessage); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.SessionToken)) { jw.WritePropertyName("SessionToken"); jw.Write(monitoringAPICallAttempt.SessionToken); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.XAmzId2)) { jw.WritePropertyName("XAmzId2"); jw.Write(monitoringAPICallAttempt.XAmzId2); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.XAmznRequestId)) { jw.WritePropertyName("XAmznRequestId"); jw.Write(monitoringAPICallAttempt.XAmznRequestId); } if (!string.IsNullOrEmpty(monitoringAPICallAttempt.XAmzRequestId)) { jw.WritePropertyName("XAmzRequestId"); jw.Write(monitoringAPICallAttempt.XAmzRequestId); } if (monitoringAPICallAttempt.HttpStatusCode != null) { jw.WritePropertyName("HttpStatusCode"); jw.Write((int)monitoringAPICallAttempt.HttpStatusCode); } jw.WritePropertyName("AttemptLatency"); jw.Write(monitoringAPICallAttempt.AttemptLatency); jw.WriteObjectEnd(); response = jw.ToString(); return(ASCIIEncoding.Unicode.GetByteCount(response) <= (8 * 1024)); }