diff --git a/cdrs/fscdr.go b/cdrs/fscdr.go index ed95d2a00..b56b97a39 100644 --- a/cdrs/fscdr.go +++ b/cdrs/fscdr.go @@ -165,9 +165,8 @@ func (fsCdr FSCdr) GetHangupTime() (t time.Time, err error) { } // Extracts duration as considered by the telecom switch -func (fsCdr FSCdr) GetDuration() time.Duration { - dur, _ := utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION]) - return dur +func (fsCdr FSCdr) GetDuration() (time.Duration, error) { + return utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION]) } func (fsCdr FSCdr) Store() (result string, err error) { @@ -192,7 +191,8 @@ func (fsCdr FSCdr) Store() (result string, err error) { return "", err } result += strconv.FormatInt(et.UnixNano(), 10) + "|" - result += strconv.FormatInt(int64(fsCdr.GetDuration().Seconds()), 10) + "|" + dur, _ := fsCdr.GetDuration() + result += strconv.FormatInt(int64(dur.Seconds()), 10) + "|" return } diff --git a/cdrs/fscdr_test.go b/cdrs/fscdr_test.go index 4441f5049..53b30a5b8 100644 --- a/cdrs/fscdr_test.go +++ b/cdrs/fscdr_test.go @@ -87,8 +87,9 @@ func TestCDRFields(t *testing.T) { if answerTime.UTC() != expectedATime { t.Error("Error parsing answerTime: ", answerTime.UTC()) } - if fsCdr.GetDuration() != 4000000000 { - t.Error("Error parsing duration: ", fsCdr.GetDuration()) + dur, _ := fsCdr.GetDuration() + if dur != 4000000000 { + t.Error("Error parsing duration: ", dur) } cfg.CDRSExtraFields = []*utils.RSRField{&utils.RSRField{Id: "sip_user_agent"}, &utils.RSRField{Id: "read_codec"}, &utils.RSRField{Id: "write_codec"}} extraFields := fsCdr.GetExtraFields() diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 51e44ab95..d8cf07987 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -523,6 +523,7 @@ func (self *SQLStorage) SetCdr(cdr utils.RawCDR) (err error) { // map[account:1001 direction:out orig_ip:172.16.1.1 tor:call accid:accid23 answer_time:2013-02-03 19:54:00 cdrsource:freeswitch_csv destination:+4986517174963 duration:62 reqtype:prepaid subject:1001 supplier:supplier1 tenant:cgrates.org] setupTime, _ := cdr.GetSetupTime() // Ignore errors, we want to store the cdr no matter what answerTime, _ := cdr.GetAnswerTime() // Ignore errors, we want to store the cdr no matter what + dur, _ := cdr.GetDuration() _, err = self.Db.Exec(fmt.Sprintf("INSERT INTO %s VALUES (NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s', %d)", utils.TBL_CDRS_PRIMARY, cdr.GetCgrId(), @@ -538,7 +539,7 @@ func (self *SQLStorage) SetCdr(cdr utils.RawCDR) (err error) { cdr.GetDestination(), setupTime, answerTime, - cdr.GetDuration(), + dur, )) if err != nil { Logger.Err(fmt.Sprintf("failed to execute cdr insert statement: %v", err)) diff --git a/utils/cgrcdr.go b/utils/cgrcdr.go index 15b11b560..fca743817 100644 --- a/utils/cgrcdr.go +++ b/utils/cgrcdr.go @@ -104,9 +104,8 @@ func (cgrCdr CgrCdr) GetAnswerTime() (t time.Time, err error) { } // Extracts duration as considered by the telecom switch -func (cgrCdr CgrCdr) GetDuration() time.Duration { - dur, _ := ParseDurationWithSecs(cgrCdr[DURATION]) - return dur +func (cgrCdr CgrCdr) GetDuration() (time.Duration, error) { + return ParseDurationWithSecs(cgrCdr[DURATION]) } // Used in mediation, fieldsMandatory marks whether missing field out of request represents error or can be ignored @@ -126,6 +125,10 @@ func (cgrCdr CgrCdr) AsStoredCdr(runId, reqTypeFld, directionFld, tenantFld, tor return nil, errors.New(fmt.Sprintf("%s:%s", ERR_MANDATORY_IE_MISSING, ACCID)) } } + // MetaDefault will automatically be converted to their standard values + //if reqTypeFld == META_DEFAULT { + // reqTypeFld = + //} if rtCdr.CdrHost, hasKey = cgrCdr[CDRHOST]; !hasKey && fieldsMandatory { return nil, errors.New(fmt.Sprintf("%s:%s", ERR_MANDATORY_IE_MISSING, CDRHOST)) } diff --git a/utils/cgrcdr_test.go b/utils/cgrcdr_test.go index f9428052b..8f78acf93 100644 --- a/utils/cgrcdr_test.go +++ b/utils/cgrcdr_test.go @@ -72,7 +72,8 @@ func TestCgrCdrFields(t *testing.T) { if answerTime.UTC() != expectedATime { t.Error("Error parsing cdr: ", cgrCdr) } - if cgrCdr.GetDuration() != time.Duration(10)*time.Second { + dur, _ := cgrCdr.GetDuration() + if dur != time.Duration(10)*time.Second { t.Error("Error parsing cdr: ", cgrCdr) } extraFields := cgrCdr.GetExtraFields() diff --git a/utils/rawcdr.go b/utils/rawcdr.go index efe077c69..59ad618ca 100644 --- a/utils/rawcdr.go +++ b/utils/rawcdr.go @@ -39,7 +39,7 @@ type RawCDR interface { GetReqType() string GetSetupTime() (time.Time, error) // Time when the call was set-up GetAnswerTime() (time.Time, error) // Time when the call was answered - GetDuration() time.Duration + GetDuration() (time.Duration, error) GetExtraFields() map[string]string //Stores extra CDR Fields AsStoredCdr(string, string, string, string, string, string, string, string, string, string, string, []string, bool) (*StoredCdr, error) // Based on fields queried will return a particular instance of RatedCDR } diff --git a/utils/storedcdr.go b/utils/storedcdr.go index aa9b32906..18ab5a5a3 100644 --- a/utils/storedcdr.go +++ b/utils/storedcdr.go @@ -45,7 +45,7 @@ func NewStoredCdrFromRawCDR(rawcdr RawCDR) (*StoredCdr, error) { if rtCdr.AnswerTime, err = rawcdr.GetAnswerTime(); err != nil { return nil, err } - rtCdr.Duration = rawcdr.GetDuration() + rtCdr.Duration, _ = rawcdr.GetDuration() rtCdr.ExtraFields = rawcdr.GetExtraFields() rtCdr.MediationRunId = DEFAULT_RUNID rtCdr.Cost = -1 @@ -128,8 +128,8 @@ func (storedCdr *StoredCdr) GetAnswerTime() (time.Time, error) { return storedCdr.AnswerTime, nil } -func (storedCdr *StoredCdr) GetDuration() time.Duration { - return storedCdr.Duration +func (storedCdr *StoredCdr) GetDuration() (time.Duration, error) { + return storedCdr.Duration, nil } func (storedCdr *StoredCdr) GetExtraFields() map[string]string { diff --git a/utils/storedcdr_test.go b/utils/storedcdr_test.go index b41a52d71..03b0fa03b 100644 --- a/utils/storedcdr_test.go +++ b/utils/storedcdr_test.go @@ -90,7 +90,8 @@ func TestStoredCdrFields(t *testing.T) { if answerTime.UTC() != expectedATime { t.Error("Error parsing cdr: ", ratedCdr) } - if ratedCdr.GetDuration() != 10 { + dur, _ := ratedCdr.GetDuration() + if dur != 10 { t.Error("Error parsing cdr: ", ratedCdr) } extraFields := ratedCdr.GetExtraFields()