diff --git a/sessionmanager/smg_event.go b/sessionmanager/smg_event.go index aefe28dfb..be0d319a7 100644 --- a/sessionmanager/smg_event.go +++ b/sessionmanager/smg_event.go @@ -161,6 +161,14 @@ func (self SMGenericEvent) GetUsage(fieldName string) (time.Duration, error) { return utils.ParseDurationWithSecs(result) } +func (self SMGenericEvent) GetLastUsed(fieldName string) (time.Duration, error) { + if fieldName == utils.META_DEFAULT { + fieldName = utils.LastUsed + } + result, _ := utils.ConvertIfaceToString(self[fieldName]) + return utils.ParseDurationWithSecs(result) +} + func (self SMGenericEvent) GetMaxUsage(fieldName string, cfgMaxUsage time.Duration) (time.Duration, error) { if fieldName == utils.META_DEFAULT { fieldName = utils.USAGE @@ -212,7 +220,7 @@ func (self SMGenericEvent) GetCdrSource() string { func (self SMGenericEvent) GetExtraFields() map[string]string { extraFields := make(map[string]string) for key, val := range self { - primaryFields := append(utils.PrimaryCdrFields, utils.EVENT_NAME) + primaryFields := append(utils.PrimaryCdrFields, utils.EVENT_NAME, utils.LastUsed) if utils.IsSliceMember(primaryFields, key) { continue } diff --git a/sessionmanager/smg_event_test.go b/sessionmanager/smg_event_test.go index 091453f65..4cc80781c 100644 --- a/sessionmanager/smg_event_test.go +++ b/sessionmanager/smg_event_test.go @@ -45,6 +45,7 @@ func TestSMGenericEventParseFields(t *testing.T) { smGev[utils.SETUP_TIME] = "2015-11-09 14:21:24" smGev[utils.ANSWER_TIME] = "2015-11-09 14:22:02" smGev[utils.USAGE] = "1m23s" + smGev[utils.LastUsed] = "21s" smGev[utils.PDD] = "300ms" smGev[utils.SUPPLIER] = "supplier1" smGev[utils.DISCONNECT_CAUSE] = "NORMAL_DISCONNECT" @@ -107,6 +108,11 @@ func TestSMGenericEventParseFields(t *testing.T) { } else if dur != time.Duration(83)*time.Second { t.Error("Unexpected: ", dur) } + if lastUsed, err := smGev.GetLastUsed(utils.META_DEFAULT); err != nil { + t.Error(err) + } else if lastUsed != time.Duration(21)*time.Second { + t.Error("Unexpected: ", lastUsed) + } if pdd, err := smGev.GetPdd(utils.META_DEFAULT); err != nil { t.Error(err) } else if pdd != time.Duration(300)*time.Millisecond { diff --git a/utils/consts.go b/utils/consts.go index a2324b8e0..e197a5083 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -124,6 +124,7 @@ const ( SETUP_TIME = "SetupTime" ANSWER_TIME = "AnswerTime" USAGE = "Usage" + LastUsed = "LastUsed" PDD = "PDD" SUPPLIER = "Supplier" MEDI_RUNID = "RunID"