diff --git a/apier/apier.go b/apier/apier.go index ccdcef247..46c6677c4 100644 --- a/apier/apier.go +++ b/apier/apier.go @@ -477,12 +477,16 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string } type AttrResetTriggeredAction struct { - Tenant string - Account string - Direction string - BalanceType string - ThresholdType string - ThresholdValue float64 + Tenant string + Account string + Direction string + BalanceType string + ThresholdType string + ThresholdValue float64 + DestinationId string + BalanceWeight float64 + BalanceRatingSubject string + BalanceSharedGroup string } func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply *string) error { @@ -490,9 +494,20 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply attr.Direction = engine.OUTBOUND } extraParameters, err := json.Marshal(struct { - ThresholdType string - ThresholdValue float64 - }{attr.ThresholdType, attr.ThresholdValue}) + ThresholdType string + ThresholdValue float64 + DestinationId string + BalanceWeight float64 + BalanceRatingSubject string + BalanceSharedGroup string + }{ + attr.ThresholdType, + attr.ThresholdValue, + attr.DestinationId, + attr.BalanceWeight, + attr.BalanceRatingSubject, + attr.BalanceSharedGroup, + }) if err != nil { *reply = err.Error() return err diff --git a/engine/action_trigger.go b/engine/action_trigger.go index ac2810c8e..a8093b521 100644 --- a/engine/action_trigger.go +++ b/engine/action_trigger.go @@ -90,17 +90,25 @@ func (at *ActionTrigger) Match(a *Action) bool { } id := a.BalanceType == "" || at.BalanceType == a.BalanceType direction := a.Direction == "" || at.Direction == a.Direction - thresholdType, thresholdValue := true, true + thresholdType, thresholdValue, destinationId, weight, ratingSubject, sharedGroup := true, true, true, true, true, true if a.ExtraParameters != "" { t := struct { - ThresholdType string - ThresholdValue float64 + ThresholdType string + ThresholdValue float64 + DestinationId string + BalanceWeight float64 + BalanceRatingSubject string + BalanceSharedGroup string }{} json.Unmarshal([]byte(a.ExtraParameters), &t) thresholdType = t.ThresholdType == "" || at.ThresholdType == t.ThresholdType thresholdValue = t.ThresholdValue == 0 || at.ThresholdValue == t.ThresholdValue + destinationId = t.DestinationId == "" || at.DestinationId == t.DestinationId + weight = t.BalanceWeight == 0 || at.BalanceWeight == t.BalanceWeight + ratingSubject = t.BalanceRatingSubject == "" || at.BalanceRatingSubject == t.BalanceRatingSubject + sharedGroup = t.BalanceSharedGroup == "" || at.BalanceSharedGroup == t.BalanceSharedGroup } - return id && direction && thresholdType && thresholdValue + return id && direction && thresholdType && thresholdValue && destinationId && weight && ratingSubject && sharedGroup } // Structure to store actions according to weight diff --git a/engine/actions_test.go b/engine/actions_test.go index 6d1cda925..57df63cc1 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -563,6 +563,23 @@ func TestActionTriggerMatcAllFalse(t *testing.T) { } } +func TestActionTriggerMatchAll(t *testing.T) { + at := &ActionTrigger{ + Direction: OUTBOUND, + BalanceType: CREDIT, + ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdValue: 2, + DestinationId: "NAT", + BalanceWeight: 1.0, + BalanceRatingSubject: "test1", + BalanceSharedGroup: "test2", + } + a := &Action{Direction: OUTBOUND, BalanceType: CREDIT, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "DestinationId": "%v", "BalanceWeight": %v, "BalanceRatingSubject": "%v", "BalanceSharedGroup": "%v"}`, TRIGGER_MAX_BALANCE, 2, "NAT", 1.0, "test1", "test2")} + if !at.Match(a) { + t.Errorf("Action trigger [%v] does not match action [%v]", at, a) + } +} + func TestActionTriggerPriotityList(t *testing.T) { at1 := &ActionTrigger{Weight: 10} at2 := &ActionTrigger{Weight: 20}