From 8aa5540d23c983e49b166ec08160e0c8c06e8118 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 15 Jul 2014 18:33:46 +0300 Subject: [PATCH] action's execute now get stats queue --- engine/account.go | 8 +-- engine/action.go | 127 ++++++++++++++++++++++++++++++--------- engine/action_timing.go | 2 +- engine/action_trigger.go | 12 ++-- engine/actions_test.go | 32 +++++----- engine/stats_queue.go | 4 +- 6 files changed, 129 insertions(+), 56 deletions(-) diff --git a/engine/account.go b/engine/account.go index 6e82c6e7f..f547cea76 100644 --- a/engine/account.go +++ b/engine/account.go @@ -346,12 +346,12 @@ func (ub *Account) executeActionTriggers(a *Action) { if strings.Contains(at.ThresholdType, "*max") { if mb.MatchActionTrigger(at) && mb.Value >= at.ThresholdValue { // run the actions - at.Execute(ub) + at.Execute(ub, nil) } } else { //MIN if mb.MatchActionTrigger(at) && mb.Value <= at.ThresholdValue { // run the actions - at.Execute(ub) + at.Execute(ub, nil) } } } @@ -365,12 +365,12 @@ func (ub *Account) executeActionTriggers(a *Action) { if strings.Contains(at.ThresholdType, "*max") { if b.MatchActionTrigger(at) && b.Value >= at.ThresholdValue { // run the actions - at.Execute(ub) + at.Execute(ub, nil) } } else { //MIN if b.MatchActionTrigger(at) && b.Value <= at.ThresholdValue { // run the actions - at.Execute(ub) + at.Execute(ub, nil) } } } diff --git a/engine/action.go b/engine/action.go index 6512c4c2b..479ea64a6 100644 --- a/engine/action.go +++ b/engine/action.go @@ -67,7 +67,7 @@ const ( UNLIMITED = "*unlimited" ) -type actionTypeFunc func(*Account, *Action) error +type actionTypeFunc func(*Account, *StatsQueue, *Action) error func getActionFunc(typ string) (actionTypeFunc, bool) { switch typ { @@ -111,42 +111,70 @@ func getActionFunc(typ string) (actionTypeFunc, bool) { return nil, false } -func logAction(ub *Account, a *Action) (err error) { - ubMarshal, _ := json.Marshal(ub) - Logger.Info(fmt.Sprintf("Threshold reached, balance: %s", ubMarshal)) +func logAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + var o interface{} + if ub != nil { + o = ub + } + if sq != nil { + o = sq + } + body, _ := json.Marshal(o) + Logger.Info(fmt.Sprintf("Threshold reached, balance: %s", body)) return } -func resetTriggersAction(ub *Account, a *Action) (err error) { +func resetTriggersAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.ResetActionTriggers(a) return } -func setRecurrentAction(ub *Account, a *Action) (err error) { +func setRecurrentAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.SetRecurrent(a, true) return } -func unsetRecurrentAction(ub *Account, a *Action) (err error) { +func unsetRecurrentAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.SetRecurrent(a, false) return } -func allowNegativeAction(ub *Account, a *Action) (err error) { +func allowNegativeAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.AllowNegative = true return } -func denyNegativeAction(ub *Account, a *Action) (err error) { +func denyNegativeAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.AllowNegative = false return } -func resetAccountAction(ub *Account, a *Action) (err error) { +func resetAccountAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } return genericReset(ub) } -func topupResetAction(ub *Account, a *Action) (err error) { +func topupResetAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } if ub.BalanceMap == nil { // Init the map since otherwise will get error if nil ub.BalanceMap = make(map[string]BalanceChain, 0) } @@ -155,12 +183,18 @@ func topupResetAction(ub *Account, a *Action) (err error) { return genericDebit(ub, a) } -func topupAction(ub *Account, a *Action) (err error) { +func topupAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } genericMakeNegative(a) return genericDebit(ub, a) } -func debitResetAction(ub *Account, a *Action) (err error) { +func debitResetAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } if ub.BalanceMap == nil { // Init the map since otherwise will get error if nil ub.BalanceMap = make(map[string]BalanceChain, 0) } @@ -168,11 +202,17 @@ func debitResetAction(ub *Account, a *Action) (err error) { return genericDebit(ub, a) } -func debitAction(ub *Account, a *Action) (err error) { +func debitAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } return genericDebit(ub, a) } -func resetCounterAction(ub *Account, a *Action) (err error) { +func resetCounterAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } uc := ub.getUnitCounter(a) if uc == nil { uc = &UnitsCounter{BalanceType: a.BalanceType, Direction: a.Direction} @@ -182,7 +222,10 @@ func resetCounterAction(ub *Account, a *Action) (err error) { return } -func resetCountersAction(ub *Account, a *Action) (err error) { +func resetCountersAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.UnitCounters = make([]*UnitsCounter, 0) ub.initCounters() return @@ -195,6 +238,9 @@ func genericMakeNegative(a *Action) { } func genericDebit(ub *Account, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } if ub.BalanceMap == nil { ub.BalanceMap = make(map[string]BalanceChain) } @@ -202,12 +248,18 @@ func genericDebit(ub *Account, a *Action) (err error) { return } -func enableUserAction(ub *Account, a *Action) (err error) { +func enableUserAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.Disabled = false return } -func disableUserAction(ub *Account, a *Action) (err error) { +func disableUserAction(ub *Account, sq *StatsQueue, a *Action) (err error) { + if ub == nil { + return errors.New("Nil user balance") + } ub.Disabled = true return } @@ -221,25 +273,37 @@ func genericReset(ub *Account) error { return nil } -func callUrl(ub *Account, a *Action) error { +func callUrl(ub *Account, sq *StatsQueue, a *Action) (err error) { cfg := config.CgrConfig() - _, err := utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, ub) + if ub != nil { + _, err = utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, ub) + } + if sq != nil { + _, err = utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, sq) + } return err } // Does not block for posts, no error reports -func callUrlAsync(ub *Account, a *Action) error { - ubJson, err := json.Marshal(ub) +func callUrlAsync(ub *Account, sq *StatsQueue, a *Action) error { + var o interface{} + if ub != nil { + o = ub + } + if sq != nil { + o = sq.GetStats() + } + jsn, err := json.Marshal(o) if err != nil { return err } cfg := config.CgrConfig() go func() { for i := 0; i < 5; i++ { // Loop so we can increase the success rate on best effort - if _, err = utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, ub); err == nil { + if _, err = utils.HttpJsonPost(a.ExtraParameters, cfg.HttpSkipTlsVerify, o); err == nil { break // Success, no need to reinterate } else if i == 4 { // Last iteration, syslog the warning - Logger.Warning(fmt.Sprintf(" WARNING: Failed calling url: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), ubJson)) + Logger.Warning(fmt.Sprintf(" WARNING: Failed calling url: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), jsn)) break } time.Sleep(time.Duration(i) * time.Minute) @@ -250,8 +314,15 @@ func callUrlAsync(ub *Account, a *Action) error { } // Mails the balance hitting the threshold towards predefined list of addresses -func mailAsync(ub *Account, a *Action) error { - ubJson, err := json.Marshal(ub) +func mailAsync(ub *Account, sq *StatsQueue, a *Action) error { + var o interface{} + if ub != nil { + o = ub + } + if sq != nil { + o = sq.GetStats() + } + jsn, err := json.Marshal(o) if err != nil { return err } @@ -268,14 +339,14 @@ func mailAsync(ub *Account, a *Action) error { } toAddrStr += addr } - message := []byte(fmt.Sprintf("To: %s\r\nSubject: [CGR Notification] Threshold hit on balance: %s\r\n\r\nTime: \r\n\t%s\r\n\r\nBalance:\r\n\t%s\r\n\r\nYours faithfully,\r\nCGR Balance Monitor\r\n", toAddrStr, ub.Id, time.Now(), ubJson)) + message := []byte(fmt.Sprintf("To: %s\r\nSubject: [CGR Notification] Threshold hit on balance: %s\r\n\r\nTime: \r\n\t%s\r\n\r\nBalance:\r\n\t%s\r\n\r\nYours faithfully,\r\nCGR Balance Monitor\r\n", toAddrStr, ub.Id, time.Now(), jsn)) auth := smtp.PlainAuth("", cgrCfg.MailerAuthUser, cgrCfg.MailerAuthPass, strings.Split(cgrCfg.MailerServer, ":")[0]) // We only need host part, so ignore port go func() { for i := 0; i < 5; i++ { // Loop so we can increase the success rate on best effort if err := smtp.SendMail(cgrCfg.MailerServer, auth, cgrCfg.MailerFromAddr, toAddrs, message); err == nil { break } else if i == 4 { - Logger.Warning(fmt.Sprintf(" WARNING: Failed emailing, params: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), ubJson)) + Logger.Warning(fmt.Sprintf(" WARNING: Failed emailing, params: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), jsn)) break } time.Sleep(time.Duration(i) * time.Minute) diff --git a/engine/action_timing.go b/engine/action_timing.go index aa48498fe..4b9bba8a5 100644 --- a/engine/action_timing.go +++ b/engine/action_timing.go @@ -242,7 +242,7 @@ func (at *ActionTiming) Execute() (err error) { return 0, fmt.Errorf("User %s is disabled", ubId) } Logger.Info(fmt.Sprintf("Executing %v on %v", a.ActionType, ub.Id)) - err = actionFunction(ub, a) + err = actionFunction(ub, nil, a) accountingStorage.SetAccount(ub) return 0, nil }) diff --git a/engine/action_trigger.go b/engine/action_trigger.go index 1cfe025f8..e04904a09 100644 --- a/engine/action_trigger.go +++ b/engine/action_trigger.go @@ -46,13 +46,13 @@ type ActionTrigger struct { lastExecutionTime time.Time } -func (at *ActionTrigger) Execute(ub *Account) (err error) { +func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueue) (err error) { // check for min sleep time if at.Recurrent && !at.lastExecutionTime.IsZero() && time.Since(at.lastExecutionTime) < at.MinSleep { return } at.lastExecutionTime = time.Now() - if ub.Disabled { + if ub != nil && ub.Disabled { return fmt.Errorf("User %s is disabled and there are triggers in action!", ub.Id) } // does NOT need to Lock() because it is triggered from a method that took the Lock @@ -76,7 +76,7 @@ func (at *ActionTrigger) Execute(ub *Account) (err error) { return } go Logger.Info(fmt.Sprintf("Executing %v: %v", ub.Id, a)) - err = actionFunction(ub, a) + err = actionFunction(ub, sq, a) if err == nil { atLeastOneActionExecuted = true } @@ -84,8 +84,10 @@ func (at *ActionTrigger) Execute(ub *Account) (err error) { if !atLeastOneActionExecuted || at.Recurrent { at.Executed = false } - storageLogger.LogActionTrigger(ub.Id, RATER_SOURCE, at, aac) - accountingStorage.SetAccount(ub) + if ub != nil { + storageLogger.LogActionTrigger(ub.Id, RATER_SOURCE, at, aac) + accountingStorage.SetAccount(ub) + } return } diff --git a/engine/actions_test.go b/engine/actions_test.go index 6d1cda925..7fcd99abf 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -582,7 +582,7 @@ func TestActionResetTriggres(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - resetTriggersAction(ub, nil) + resetTriggersAction(ub, nil, nil) if ub.ActionTriggers[0].Executed == true || ub.ActionTriggers[1].Executed == true { t.Error("Reset triggers action failed!") } @@ -595,7 +595,7 @@ func TestActionResetTriggresExecutesThem(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - resetTriggersAction(ub, nil) + resetTriggersAction(ub, nil, nil) if ub.ActionTriggers[0].Executed == true || ub.BalanceMap[CREDIT][0].Value == 12 { t.Error("Reset triggers action failed!") } @@ -608,7 +608,7 @@ func TestActionResetTriggresActionFilter(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - resetTriggersAction(ub, &Action{BalanceType: SMS}) + resetTriggersAction(ub, nil, &Action{BalanceType: SMS}) if ub.ActionTriggers[0].Executed == false || ub.ActionTriggers[1].Executed == false { t.Error("Reset triggers action failed!") } @@ -621,7 +621,7 @@ func TestActionSetPostpaid(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - allowNegativeAction(ub, nil) + allowNegativeAction(ub, nil, nil) if !ub.AllowNegative { t.Error("Set postpaid action failed!") } @@ -635,7 +635,7 @@ func TestActionSetPrepaid(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - denyNegativeAction(ub, nil) + denyNegativeAction(ub, nil, nil) if ub.AllowNegative { t.Error("Set prepaid action failed!") } @@ -649,7 +649,7 @@ func TestActionResetPrepaid(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: SMS, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: SMS, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - resetAccountAction(ub, nil) + resetAccountAction(ub, nil, nil) if !ub.AllowNegative || ub.BalanceMap[CREDIT].GetTotalValue() != 0 || len(ub.UnitCounters) != 0 || @@ -667,7 +667,7 @@ func TestActionResetPostpaid(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: SMS, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: SMS, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - resetAccountAction(ub, nil) + resetAccountAction(ub, nil, nil) if ub.BalanceMap[CREDIT].GetTotalValue() != 0 || len(ub.UnitCounters) != 0 || ub.BalanceMap[MINUTES+OUTBOUND][0].Value != 0 || @@ -684,7 +684,7 @@ func TestActionTopupResetCredit(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: CREDIT, Direction: OUTBOUND, Balance: &Balance{Value: 10}} - topupResetAction(ub, a) + topupResetAction(ub, nil, a) if ub.AllowNegative || ub.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != 10 || len(ub.UnitCounters) != 1 || @@ -704,7 +704,7 @@ func TestActionTopupResetMinutes(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: MINUTES, Direction: OUTBOUND, Balance: &Balance{Value: 5, Weight: 20, DestinationId: "NAT"}} - topupResetAction(ub, a) + topupResetAction(ub, nil, a) if ub.AllowNegative || ub.BalanceMap[MINUTES+OUTBOUND].GetTotalValue() != 5 || ub.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != 100 || @@ -723,7 +723,7 @@ func TestActionTopupCredit(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: CREDIT, Direction: OUTBOUND, Balance: &Balance{Value: 10}} - topupAction(ub, a) + topupAction(ub, nil, a) if ub.AllowNegative || ub.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != 110 || len(ub.UnitCounters) != 1 || @@ -741,7 +741,7 @@ func TestActionTopupMinutes(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: MINUTES, Direction: OUTBOUND, Balance: &Balance{Value: 5, Weight: 20, DestinationId: "NAT"}} - topupAction(ub, a) + topupAction(ub, nil, a) if ub.AllowNegative || ub.BalanceMap[MINUTES+OUTBOUND].GetTotalValue() != 15 || ub.BalanceMap[CREDIT].GetTotalValue() != 100 || @@ -760,7 +760,7 @@ func TestActionDebitCredit(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: CREDIT, Direction: OUTBOUND, Balance: &Balance{Value: 10}} - debitAction(ub, a) + debitAction(ub, nil, a) if ub.AllowNegative || ub.BalanceMap[CREDIT+OUTBOUND].GetTotalValue() != 90 || len(ub.UnitCounters) != 1 || @@ -778,7 +778,7 @@ func TestActionDebitMinutes(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}, &ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: MINUTES, Direction: OUTBOUND, Balance: &Balance{Value: 5, Weight: 20, DestinationId: "NAT"}} - debitAction(ub, a) + debitAction(ub, nil, a) if ub.AllowNegative || ub.BalanceMap[MINUTES+OUTBOUND][0].Value != 5 || ub.BalanceMap[CREDIT].GetTotalValue() != 100 || @@ -801,7 +801,7 @@ func TestActionResetAllCounters(t *testing.T) { UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceType: CREDIT, Balances: BalanceChain{&Balance{Value: 1}}}}, ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } - resetCountersAction(ub, nil) + resetCountersAction(ub, nil, nil) if !ub.AllowNegative || ub.BalanceMap[CREDIT].GetTotalValue() != 100 || len(ub.UnitCounters) != 1 || @@ -830,7 +830,7 @@ func TestActionResetCounterMinutes(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, ThresholdType: "*max_counter", ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: MINUTES} - resetCounterAction(ub, a) + resetCounterAction(ub, nil, a) if !ub.AllowNegative || ub.BalanceMap[CREDIT].GetTotalValue() != 100 || len(ub.UnitCounters) != 2 || @@ -860,7 +860,7 @@ func TestActionResetCounterCREDIT(t *testing.T) { ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: CREDIT, Direction: OUTBOUND, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: CREDIT, Direction: OUTBOUND} - resetCounterAction(ub, a) + resetCounterAction(ub, nil, a) if !ub.AllowNegative || ub.BalanceMap[CREDIT].GetTotalValue() != 100 || len(ub.UnitCounters) != 2 || diff --git a/engine/stats_queue.go b/engine/stats_queue.go index 8640c5328..1a1e0983f 100644 --- a/engine/stats_queue.go +++ b/engine/stats_queue.go @@ -76,14 +76,14 @@ func (sq *StatsQueue) AppendCDR(cdr *utils.StoredCdr) { if strings.HasPrefix(at.ThresholdType, "*min_") { if value, ok := stats[at.ThresholdType[len("*min_"):]]; ok { if value <= at.ThresholdValue { - //at.Execute() + at.Execute(nil, sq) } } } if strings.HasPrefix(at.ThresholdType, "*max_") { if value, ok := stats[at.ThresholdType[len("*max_"):]]; ok { if value >= at.ThresholdValue { - //at.Execute() + at.Execute(nil, sq) } } }