diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index c85086f99..2fdff8fb6 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -54,6 +54,7 @@ var sTestsAlsPrf = []func(t *testing.T){ testAttributeSGetAttributeForEventNotFound, testAttributeSGetAttributeForEventWithMetaAnyContext, testAttributeSProcessEvent, + testAttributeSProcessEventMissing, testAttributeSProcessEventWithNoneSubstitute, testAttributeSProcessEventWithNoneSubstitute2, testAttributeSProcessEventWithNoneSubstitute3, @@ -349,6 +350,24 @@ func testAttributeSProcessEvent(t *testing.T) { } } +func testAttributeSProcessEventMissing(t *testing.T) { + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testAttributeSProcessEvent", + Context: utils.StringPointer(utils.MetaSessionS), + Event: map[string]interface{}{ + utils.Account: "NonExist", + utils.Category: "*attributes", + utils.Destination: "+491511231234", + }, + } + var rplyEv engine.AttrSProcessEventReply + if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + ev, &rplyEv); err == nil && err != utils.ErrMandatoryIeMissing { + t.Error(err) + } +} + func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { ev := &utils.CGREvent{ Tenant: "cgrates.org", diff --git a/engine/attributes.go b/engine/attributes.go index 0f350c189..92549340f 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -165,6 +165,15 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( rply *AttrSProcessEventReply, err error) { attrPrf, err := alS.attributeProfileForEvent(args) if err != nil { + if err == utils.ErrNotFound { + // change the error in case that at least one field need to be processed by attributes + for _, valIface := range args.CGREvent.Event { + if valIface == interface{}(utils.MetaAttributes) { + err = utils.ErrMandatoryIeMissing + break + } + } + } return nil, err } rply = &AttrSProcessEventReply{ @@ -204,11 +213,12 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( } for _, valIface := range rply.CGREvent.Event { if valIface == interface{}(utils.MetaAttributes) { + // mandatory IE missing return nil, utils.NewCGRError( utils.AttributeSv1ProcessEvent, - utils.AttributesNotFound, - utils.AttributesNotFound, - utils.AttributesNotFound) + utils.ErrMandatoryIeMissing.Error(), + utils.ErrMandatoryIeMissing.Error(), + utils.ErrMandatoryIeMissing.Error()) } } return @@ -239,7 +249,7 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, for i := 0; i < *args.ProcessRuns; i++ { evRply, err := alS.processEvent(args) if err != nil { - if err != utils.ErrNotFound { + if err != utils.ErrNotFound && err != utils.ErrMandatoryIeMissing { err = utils.NewErrServerError(err) } else if i != 0 { // ignore "not found" in a loop different than 0 err = nil diff --git a/engine/stats_metrics.go b/engine/stats_metrics.go index ede4b453c..12654bb00 100644 --- a/engine/stats_metrics.go +++ b/engine/stats_metrics.go @@ -30,6 +30,8 @@ type Metric interface { GetValue() float64 } +// Old metric (deprecated) +// New mtric are in statmetrics.go const ASR = "ASR" const ACD = "ACD" const TCD = "TCD"