diff --git a/agents/dmtagent.go b/agents/dmtagent.go index 57f80407c..5de24273e 100644 --- a/agents/dmtagent.go +++ b/agents/dmtagent.go @@ -144,7 +144,8 @@ func (self DiameterAgent) processCCR(ccr *CCR, reqProcessor *config.DARequestPro smgEv[utils.USAGE] = 0 // For CDR not to debit } } - if self.cgrCfg.DiameterAgentCfg().CreateCDR && err == nil || !strings.HasSuffix(err.Error(), utils.ErrNoActiveSession.Error()) { // NO CDR for no active session + if self.cgrCfg.DiameterAgentCfg().CreateCDR && + (!self.cgrCfg.DiameterAgentCfg().CDRRequiresSession || err == nil || !strings.HasSuffix(err.Error(), utils.ErrNoActiveSession.Error())) { // Check if CDR requires session if errCdr := self.smg.Call("SMGenericV1.ProcessCDR", smgEv, &rpl); errCdr != nil { err = errCdr } diff --git a/config/config_defaults.go b/config/config_defaults.go index 74609909b..79b15a930 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -336,10 +336,11 @@ const CGRATES_CFG_JSON = ` "listen": "127.0.0.1:3868", // address where to listen for diameter requests "dictionaries_dir": "/usr/share/cgrates/diameter/dict/", // path towards directory holding additional dictionaries to load "sm_generic_conns": [ - {"address": "*internal"} // connection towards SMG component for session management + {"address": "*internal"} // connection towards SMG component for session management ], "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> "create_cdr": true, // create CDR out of CCR terminate and send it to SMG component + "cdr_requires_session": true, // only create CDR if there is an active session at terminate "debit_interval": "5m", // interval for CCR updates "timezone": "", // timezone for timestamps where not specified, empty for general defaults <""|UTC|Local|$IANA_TZ_DB> "origin_host": "CGR-DA", // diameter Origin-Host AVP used in replies diff --git a/config/config_json_test.go b/config/config_json_test.go index de11c02fb..f60f48bcc 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -525,14 +525,15 @@ func TestDiameterAgentJsonCfg(t *testing.T) { &HaPoolJsonCfg{ Address: utils.StringPointer(utils.MetaInternal), }}, - Pubsubs_conns: &[]*HaPoolJsonCfg{}, - Create_cdr: utils.BoolPointer(true), - Debit_interval: utils.StringPointer("5m"), - Timezone: utils.StringPointer(""), - Origin_host: utils.StringPointer("CGR-DA"), - Origin_realm: utils.StringPointer("cgrates.org"), - Vendor_id: utils.IntPointer(0), - Product_name: utils.StringPointer("CGRateS"), + Pubsubs_conns: &[]*HaPoolJsonCfg{}, + Create_cdr: utils.BoolPointer(true), + Cdr_requires_session: utils.BoolPointer(true), + Debit_interval: utils.StringPointer("5m"), + Timezone: utils.StringPointer(""), + Origin_host: utils.StringPointer("CGR-DA"), + Origin_realm: utils.StringPointer("cgrates.org"), + Vendor_id: utils.IntPointer(0), + Product_name: utils.StringPointer("CGRateS"), Request_processors: &[]*DARequestProcessorJsnCfg{ &DARequestProcessorJsnCfg{ Id: utils.StringPointer("*default"), diff --git a/config/daconfig.go b/config/daconfig.go index 44fb7af9c..bafaab0f6 100644 --- a/config/daconfig.go +++ b/config/daconfig.go @@ -24,19 +24,20 @@ import ( ) type DiameterAgentCfg struct { - Enabled bool // enables the diameter agent: - Listen string // address where to listen for diameter requests - DictionariesDir string - SMGenericConns []*HaPoolConfig // connections towards SMG component - PubSubConns []*HaPoolConfig // connection towards pubsubs - CreateCDR bool - DebitInterval time.Duration - Timezone string // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> - OriginHost string - OriginRealm string - VendorId int - ProductName string - RequestProcessors []*DARequestProcessor + Enabled bool // enables the diameter agent: + Listen string // address where to listen for diameter requests + DictionariesDir string + SMGenericConns []*HaPoolConfig // connections towards SMG component + PubSubConns []*HaPoolConfig // connection towards pubsubs + CreateCDR bool + CDRRequiresSession bool + DebitInterval time.Duration + Timezone string // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> + OriginHost string + OriginRealm string + VendorId int + ProductName string + RequestProcessors []*DARequestProcessor } func (self *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg) error { @@ -69,6 +70,9 @@ func (self *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg) erro if jsnCfg.Create_cdr != nil { self.CreateCDR = *jsnCfg.Create_cdr } + if jsnCfg.Cdr_requires_session != nil { + self.CDRRequiresSession = *jsnCfg.Cdr_requires_session + } if jsnCfg.Debit_interval != nil { var err error if self.DebitInterval, err = utils.ParseDurationWithSecs(*jsnCfg.Debit_interval); err != nil { diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 7ac3e34b7..28906f3d1 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -282,19 +282,20 @@ type OsipsConnJsonCfg struct { // DiameterAgent configuration type DiameterAgentJsonCfg struct { - Enabled *bool // enables the diameter agent: - Listen *string // address where to listen for diameter requests - Dictionaries_dir *string // path towards additional dictionaries - Sm_generic_conns *[]*HaPoolJsonCfg // Connections towards generic SM - Pubsubs_conns *[]*HaPoolJsonCfg // connection towards pubsubs - Create_cdr *bool - Debit_interval *string - Timezone *string // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> - Origin_host *string - Origin_realm *string - Vendor_id *int - Product_name *string - Request_processors *[]*DARequestProcessorJsnCfg + Enabled *bool // enables the diameter agent: + Listen *string // address where to listen for diameter requests + Dictionaries_dir *string // path towards additional dictionaries + Sm_generic_conns *[]*HaPoolJsonCfg // Connections towards generic SM + Pubsubs_conns *[]*HaPoolJsonCfg // connection towards pubsubs + Create_cdr *bool + Cdr_requires_session *bool + Debit_interval *string + Timezone *string // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> + Origin_host *string + Origin_realm *string + Vendor_id *int + Product_name *string + Request_processors *[]*DARequestProcessorJsnCfg } // One Diameter request processor configuration