action's execute now get stats queue

This commit is contained in:
Radu Ioan Fericean
2014-07-15 18:33:46 +03:00
parent e6a6910a46
commit 8aa5540d23
6 changed files with 129 additions and 56 deletions

View File

@@ -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)
}
}
}

View File

@@ -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("<Triggers> WARNING: Failed calling url: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), ubJson))
Logger.Warning(fmt.Sprintf("<Triggers> 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("<Triggers> WARNING: Failed emailing, params: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), ubJson))
Logger.Warning(fmt.Sprintf("<Triggers> WARNING: Failed emailing, params: [%s], error: [%s], balance: %s", a.ExtraParameters, err.Error(), jsn))
break
}
time.Sleep(time.Duration(i) * time.Minute)

View File

@@ -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
})

View File

@@ -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
}

View File

@@ -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 ||

View File

@@ -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)
}
}
}