passing *accountID instead of *account in opts

This commit is contained in:
gezimbll
2025-05-21 10:27:59 +02:00
committed by Dan Christian Bogos
parent 2b27c681bc
commit 8bbe36c088
5 changed files with 29 additions and 12 deletions

View File

@@ -30,7 +30,7 @@
"thresholds": {
"enabled": true,
"apiers_conns": ["*localhost"],
"exists_indexed_fields": ["*opts.*account"],
"exists_indexed_fields": ["*opts.*accountID"],
"store_interval": "-1",
},

View File

@@ -56,7 +56,7 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) {
ThresholdProfile: &engine.ThresholdProfile{
Tenant: "cgrates.org",
ID: "THD_DYNAMIC_STATS_AND_THRESHOLD_INIT",
FilterIDs: []string{"*exists:~*opts.*account:"},
FilterIDs: []string{"*exists:~*opts.*accountID:"},
ActionIDs: []string{"ACT_DYN_THRESHOLD_AND_STATS_CREATION"},
MinHits: 1,
MaxHits: -1,
@@ -97,7 +97,7 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) {
// dynamic threshold for already created dynamic accounts, needed so we can ignore matching thresholds the events (which dont come from stats) where an account has already been dynamicaly created by the initial threhold THD_DYNAMIC_STATS_AND_THRESHOLD_INIT. The threshold itself is only used for blocking
Identifier: utils.MetaDynamicThreshold,
// get tenant and accountID from event, threshold triggers when the event account matches the already dynamicaly created account. If it matches the filter, it will block other thresholds from matching with the event. Make sure dynamic thresholds weight is higher than the initiative threshold THD_DYNAMIC_STATS_AND_THRESHOLD_INIT
ExtraParameters: "*tenant;THD_BLOCKER_ACNT_<~*req.Account>;*string:~*opts.*account:<~*req.Account>;*now;-1;1;;true;3;;true;",
ExtraParameters: "*tenant;THD_BLOCKER_ACNT_<~*req.Account>;*string:~*opts.*accountID:<~*req.Account>;*now;-1;1;;true;3;;true;",
},
{
Identifier: utils.MetaDynamicThreshold,
@@ -106,8 +106,8 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) {
},
{
Identifier: utils.MetaDynamicStats,
// get tenant and accountID from event, stat triggers when an event contains account with dynamicaly created accountID and also has a *account field in APIOpts, each encounter that matches the filters will raise the *sum number and call the thresholdIDs specified. when the ttl is reached, *sum will go down also
ExtraParameters: "*tenant;Stat_<~*req.Account>;*string:~*req.Account:<~*req.Account>&*exists:~*opts.*account:;*now;;5s;;*sum#1;;true;false;10;THD_ACNT_<~*req.Account>&THD_BLOCKER_ACNT_<~*req.Account>;",
// get tenant and accountID from event, stat triggers when an event contains account with dynamicaly created accountID and also has a *accountID field in APIOpts, each encounter that matches the filters will raise the *sum number and call the thresholdIDs specified. when the ttl is reached, *sum will go down also
ExtraParameters: "*tenant;Stat_<~*req.Account>;*string:~*req.Account:<~*req.Account>&*exists:~*opts.*accountID:;*now;;5s;;*sum#1;;true;false;10;THD_ACNT_<~*req.Account>&THD_BLOCKER_ACNT_<~*req.Account>;",
},
},
}
@@ -157,7 +157,7 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) {
utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
utils.Usage: 1024,
},
APIOpts: map[string]any{"*account": "CreatedAccount"}, // account has to be in apiopts for stats to push it to threhsoldsv1ProcessEvent so that it knows which account to disable
APIOpts: map[string]any{"*accountID": "CreatedAccount"}, // account has to be in apiopts for stats to push it to threhsoldsv1ProcessEvent so that it knows which account to disable
},
}
var rply1 sessions.V1AuthorizeReply
@@ -186,7 +186,7 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) {
utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
utils.Usage: 1024,
},
APIOpts: map[string]any{"*account": "CreatedAccount"}, // account has to be in apiopts for stats to push it to threhsoldsv1ProcessEvent so that it knows which account to disable
APIOpts: map[string]any{"*accountID": "CreatedAccount"}, // account has to be in apiopts for stats to push it to threhsoldsv1ProcessEvent so that it knows which account to disable
},
}
var rply1 sessions.V1AuthorizeReply

View File

@@ -170,7 +170,7 @@ ACT_TOPUP_RST_10,*topup_reset,,,test,*monetary,,*any,,,*unlimited,,10,10,false,f
// Create and populate Attributes.csv
if err := writeFile(utils.AttributesCsv, `
#Tenant,ID,Context,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR_FRD,*cdrs,,,,*opts.*account,*variable,~*req.Account,false,0
cgrates.org,ATTR_FRD,*cdrs,,,,*opts.*accountID,*variable,~*req.Account,false,0
`); err != nil {
t.Fatal(err)
}

View File

@@ -150,7 +150,7 @@ DST_1002,1002`,
utils.RatesCsv: `#Id,ConnectFee,Rate,RateUnit,RateIncrement,GroupIntervalStart
RT1,0.2,0.1,1s,1s,0`,
utils.AttributesCsv: `#Tenant,ID,Context,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR_ACNT,*any,,,,*opts.*account,*variable,~*req.Account,false,10`,
cgrates.org,ATTR_ACNT,*any,,,,*opts.*accountID,*variable,~*req.Account,false,10`,
utils.StatsCsv: `#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],MinItems[6],Metrics[7],MetricFilterIDs[8],Stored[9],Blocker[10],Weight[11],ThresholdIDs[12]
cgrates.org,STATS_1001,*string:~*req.Account:1001,,,-1,,*sum#1,,true,,,THD_1001`,
utils.ThresholdsCsv: `#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10]
@@ -161,7 +161,7 @@ cgrates.org,THD_1001,*string:~*req.StatID:STATS_1001,,-1,5,0,false,,DISABLE_ACC,
}
//defer t.Log(ng.LogBuffer)
client, _ := ng.Run(t)
t.Run("TestAuthorizeEvent", func(t *testing.T) {
t.Run("AuthorizeEvent", func(t *testing.T) {
var accRepl engine.Account
if err := client.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &accRepl); err != nil {
t.Error(err)
@@ -195,7 +195,7 @@ cgrates.org,THD_1001,*string:~*req.StatID:STATS_1001,,-1,5,0,false,,DISABLE_ACC,
}
})
t.Run("TestDisableAccountFromThresholds", func(t *testing.T) {
t.Run("DisableAccountFromThresholds", func(t *testing.T) {
var replyStr string
rmReq := v1.AttrRemoveAccountActionTriggers{Tenant: "cgrates.org", Account: "1001", GroupID: "DISABLE_TRIGGER"}
if err := client.Call(context.Background(), utils.APIerSv1RemoveAccountActionTriggers, rmReq, &replyStr); err != nil {
@@ -240,6 +240,23 @@ cgrates.org,THD_1001,*string:~*req.StatID:STATS_1001,,-1,5,0,false,,DISABLE_ACC,
if !accRepl.Disabled {
t.Errorf("expected account to be disabled")
}
t.Run("AuthorizeEventWithAccountDisabled", func(t *testing.T) {
var reply string
if err := client.Call(context.Background(), utils.SessionSv1AuthorizeEvent, &sessions.V1AuthorizeArgs{GetAttributes: true,
GetMaxUsage: true,
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.GenUUID(),
Time: utils.TimePointer(time.Now()),
Event: map[string]any{"Account": "1001",
"Destination": "1002",
"OriginHost": "127.0.0.1:8448",
"RequestType": "*prepaid",
"SetupTime": "1747212851",
"Source": "KamailioAgent"}}}, &reply); err == nil || err.Error() != utils.NewErrRALs(utils.ErrAccountDisabled).Error() {
t.Errorf("expected: ACCOUNT_DISABLED error, got: %v", err)
}
})
})
}

View File

@@ -350,7 +350,7 @@ const (
MetaBalance = "*balance"
MetaLimit = "*limit"
MetaEventConnect = "*event_connect"
MetaAccount = "*account"
MetaAccount = "*accountID"
EventName = "EventName"
// action trigger threshold types
TriggerMinEventCounter = "*min_event_counter"