From 4e1776d6fd6c02e1907987ea61bb748656e57655 Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 11 Apr 2014 17:12:27 +0200 Subject: [PATCH] Discarding FS microseconds information, reverting to seconds since MySQL errors in older versions and default FS csv file uses seconds --- cdrs/fscdr.go | 8 ++++---- cdrs/fscdr_test.go | 4 ++-- sessionmanager/fsevent.go | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cdrs/fscdr.go b/cdrs/fscdr.go index 9d3410938..ed95d2a00 100644 --- a/cdrs/fscdr.go +++ b/cdrs/fscdr.go @@ -43,10 +43,10 @@ const ( FS_UUID = "uuid" // -Unique ID for this call leg FS_CSTMID = "cgr_tenant" FS_CALL_DEST_NR = "dialed_extension" - FS_PARK_TIME = "start_uepoch" - FS_SETUP_TIME = "start_uepoch" - FS_ANSWER_TIME = "answer_uepoch" - FS_HANGUP_TIME = "end_uepoch" + FS_PARK_TIME = "start_epoch" + FS_SETUP_TIME = "start_epoch" + FS_ANSWER_TIME = "answer_epoch" + FS_HANGUP_TIME = "end_epoch" FS_DURATION = "billsec" FS_USERNAME = "user_name" FS_IP = "sip_local_network_addr" diff --git a/cdrs/fscdr_test.go b/cdrs/fscdr_test.go index e24334be2..4441f5049 100644 --- a/cdrs/fscdr_test.go +++ b/cdrs/fscdr_test.go @@ -78,12 +78,12 @@ func TestCDRFields(t *testing.T) { if fsCdr.GetReqType() != utils.RATED { t.Error("Error parsing cdr: ", fsCdr) } - expectedSTime := time.Date(2013, 8, 4, 9, 50, 54, 385581000, time.UTC) + expectedSTime := time.Date(2013, 8, 4, 9, 50, 54, 0, time.UTC) if setupTime.UTC() != expectedSTime { t.Error("Error parsing setupTime: ", setupTime.UTC()) } answerTime, _ := fsCdr.GetAnswerTime() - expectedATime := time.Date(2013, 8, 4, 9, 50, 56, 285587000, time.UTC) + expectedATime := time.Date(2013, 8, 4, 9, 50, 56, 0, time.UTC) if answerTime.UTC() != expectedATime { t.Error("Error parsing answerTime: ", answerTime.UTC()) } diff --git a/sessionmanager/fsevent.go b/sessionmanager/fsevent.go index b06f0612d..5ee8d9009 100644 --- a/sessionmanager/fsevent.go +++ b/sessionmanager/fsevent.go @@ -150,14 +150,24 @@ func (fsev FSEvent) MissingParameter() bool { strings.TrimSpace(fsev.GetCallDestNr("")) == "" } func (fsev FSEvent) GetSetupTime(fieldName string) (t time.Time, err error) { - sTimeStr := utils.FirstNonEmpty(fsev[fieldName], fsev[SETUP_TIME]) + fsSTimeStr, hasKey := fsev[SETUP_TIME] + if hasKey { + // Discard the nanoseconds information since MySQL cannot store them in early versions and csv uses default seconds so cgrid will not corelate + fsSTimeStr = fsSTimeStr[:len(fsSTimeStr)-6] + } + sTimeStr := utils.FirstNonEmpty(fsev[fieldName], fsSTimeStr) if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value sTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):] } return utils.ParseTimeDetectLayout(sTimeStr) } func (fsev FSEvent) GetAnswerTime(fieldName string) (t time.Time, err error) { - aTimeStr := utils.FirstNonEmpty(fsev[fieldName], fsev[ANSWER_TIME]) + fsATimeStr, hasKey := fsev[ANSWER_TIME] + if hasKey { + // Discard the nanoseconds information since MySQL cannot store them in early versions and csv uses default seconds so cgrid will not corelate + fsATimeStr = fsATimeStr[:len(fsATimeStr)-6] + } + aTimeStr := utils.FirstNonEmpty(fsev[fieldName], fsATimeStr) if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value aTimeStr = fieldName[len(utils.STATIC_VALUE_PREFIX):] }