Add MinHits in Threshold

This commit is contained in:
TeoV
2017-10-23 11:58:41 +03:00
committed by Dan Christian Bogos
parent 15a0793ff6
commit 70fbd6d71d
10 changed files with 40 additions and 26 deletions

View File

@@ -461,6 +461,7 @@ CREATE TABLE tp_thresholds (
`filter_field_values` varchar(256) NOT NULL,
`activation_interval` varchar(64) NOT NULL,
`recurrent` BOOLEAN NOT NULL,
`min_hits` int(11) NOT NULL,
`min_sleep` varchar(16) NOT NULL,
`blocker` BOOLEAN NOT NULL,
`weight` decimal(8,2) NOT NULL,

View File

@@ -456,6 +456,7 @@ CREATE TABLE tp_thresholds (
"filter_field_values" varchar(256) NOT NULL,
"activation_interval" varchar(64) NOT NULL,
"recurrent" BOOLEAN NOT NULL,
"min_hits" INTEGER NOT NULL,
"min_sleep" varchar(16) NOT NULL,
"blocker" BOOLEAN NOT NULL,
"weight" decimal(8,2) NOT NULL,

View File

@@ -1,2 +1,2 @@
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10],Async[11]
cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2,true
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinHits[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11],Async[12]
cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,10,1s,true,10,THRESH1;THRESH2,true
1 #Tenant[0] Id[1] FilterType[2] FilterFieldName[3] FilterFieldValues[4] ActivationInterval[5] Recurrent[6] MinSleep[7] MinHits[7] Blocker[8] MinSleep[8] Weight[9] Blocker[9] ActionIDs[10] Weight[10] Async[11] ActionIDs[11] Async[12]
2 cgrates.org Threshold1 *string Account 1001;1002 2014-07-29T15:00:00Z true 1s 10 true 1s 10 true THRESH1;THRESH2 10 true THRESH1;THRESH2 true

View File

@@ -1,18 +1,18 @@
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinHits[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11],Async[12]
cgrates.org,THD_ACNT_BALANCE_1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING,
cgrates.org,THD_ACNT_BALANCE_1,*string,EventType,BalanceUpdate,,,,,,,
cgrates.org,THD_ACNT_BALANCE_1,*gte,Units,10.0,,,,,,,
cgrates.org,THD_ACNT_EXPIRED,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING,
cgrates.org,THD_ACNT_EXPIRED,*gte,ExpiryTime,*now,,,,,,,
cgrates.org,THD_STATS_1,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING,
cgrates.org,THD_STATS_1,*lt,ASR,40.0,,,,,,,
cgrates.org,THD_STATS_1,*lt,ACD,3m,,,,,,,
cgrates.org,THD_STATS_2,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,true,1s,false,10,DISABLE_AND_LOG,
cgrates.org,THD_STATS_2,*string,StatID,STATS_HOURLY_DE,,,,,,,
cgrates.org,THD_STATS_2,*gt,TCD,30m,,,,,,,
cgrates.org,THD_STATS_3,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,false,1s,false,10,TOPUP_100SMS_DE_MOBILE,
cgrates.org,THD_STATS_3,*string,StatID,STATS_DAILY_DE,,,,,,,
cgrates.org,THD_STATS_3,*gt,TCD,3h,,,,,,,
cgrates.org,THD_RES_1,*string,EventType,ResourceUpdate,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING,
cgrates.org,THD_RES_1,*string,ResourceID,RES_GRP_1,,,,,,,
cgrates.org,THD_RES_1,*gte,Usage,10.0,,,,,,,
cgrates.org,THD_ACNT_BALANCE_1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false
cgrates.org,THD_ACNT_BALANCE_1,*string,EventType,BalanceUpdate,,,,,,,,
cgrates.org,THD_ACNT_BALANCE_1,*gte,Units,10.0,,,,,,,,
cgrates.org,THD_ACNT_EXPIRED,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false
cgrates.org,THD_ACNT_EXPIRED,*gte,ExpiryTime,*now,,,,,,,,
cgrates.org,THD_STATS_1,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false
cgrates.org,THD_STATS_1,*lt,ASR,40.0,,,,,,,,
cgrates.org,THD_STATS_1,*lt,ACD,3m,,,,,,,,
cgrates.org,THD_STATS_2,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,true,1,1s,false,10,DISABLE_AND_LOG,false
cgrates.org,THD_STATS_2,*string,StatID,STATS_HOURLY_DE,,,,,,,,
cgrates.org,THD_STATS_2,*gt,TCD,30m,,,,,,,,
cgrates.org,THD_STATS_3,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,false,1,1s,false,10,TOPUP_100SMS_DE_MOBILE,false
cgrates.org,THD_STATS_3,*string,StatID,STATS_DAILY_DE,,,,,,,,
cgrates.org,THD_STATS_3,*gt,TCD,3h,,,,,,,,
cgrates.org,THD_RES_1,*string,EventType,ResourceUpdate,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false
cgrates.org,THD_RES_1,*string,ResourceID,RES_GRP_1,,,,,,,,
cgrates.org,THD_RES_1,*gte,Usage,10.0,,,,,,,,
1 #Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinHits[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11],Async[12] #Tenant[0] Id[1] FilterType[2] FilterFieldName[3] FilterFieldValues[4] ActivationInterval[5] Recurrent[6] MinHits[7] MinSleep[8] Blocker[9] Weight[10] ActionIDs[11] Async[12]
2 cgrates.org,THD_ACNT_BALANCE_1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING, cgrates.org THD_ACNT_BALANCE_1 *string Account 1001;1002 2014-07-29T15:00:00Z true 1 1s false 10 LOG_WARNING false
3 cgrates.org,THD_ACNT_BALANCE_1,*string,EventType,BalanceUpdate,,,,,,, cgrates.org THD_ACNT_BALANCE_1 *string EventType BalanceUpdate
4 cgrates.org,THD_ACNT_BALANCE_1,*gte,Units,10.0,,,,,,, cgrates.org THD_ACNT_BALANCE_1 *gte Units 10.0
5 cgrates.org,THD_ACNT_EXPIRED,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING, cgrates.org THD_ACNT_EXPIRED *string Account 1001;1002 2014-07-29T15:00:00Z true 1 1s false 10 LOG_WARNING false
6 cgrates.org,THD_ACNT_EXPIRED,*gte,ExpiryTime,*now,,,,,,, cgrates.org THD_ACNT_EXPIRED *gte ExpiryTime *now
7 cgrates.org,THD_STATS_1,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING, cgrates.org THD_STATS_1 *string EventType StatUpdate 2014-07-29T15:00:00Z true 1 1s false 10 LOG_WARNING false
8 cgrates.org,THD_STATS_1,*lt,ASR,40.0,,,,,,, cgrates.org THD_STATS_1 *lt ASR 40.0
9 cgrates.org,THD_STATS_1,*lt,ACD,3m,,,,,,, cgrates.org THD_STATS_1 *lt ACD 3m
10 cgrates.org,THD_STATS_2,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,true,1s,false,10,DISABLE_AND_LOG, cgrates.org THD_STATS_2 *string EventType StatUpdate 2014-07-29T15:00:00Z true 1 1s false 10 DISABLE_AND_LOG false
11 cgrates.org,THD_STATS_2,*string,StatID,STATS_HOURLY_DE,,,,,,, cgrates.org THD_STATS_2 *string StatID STATS_HOURLY_DE
12 cgrates.org,THD_STATS_2,*gt,TCD,30m,,,,,,, cgrates.org THD_STATS_2 *gt TCD 30m
13 cgrates.org,THD_STATS_3,*string,EventType,StatUpdate,2014-07-29T15:00:00Z,false,1s,false,10,TOPUP_100SMS_DE_MOBILE, cgrates.org THD_STATS_3 *string EventType StatUpdate 2014-07-29T15:00:00Z false 1 1s false 10 TOPUP_100SMS_DE_MOBILE false
14 cgrates.org,THD_STATS_3,*string,StatID,STATS_DAILY_DE,,,,,,, cgrates.org THD_STATS_3 *string StatID STATS_DAILY_DE
15 cgrates.org,THD_STATS_3,*gt,TCD,3h,,,,,,, cgrates.org THD_STATS_3 *gt TCD 3h
16 cgrates.org,THD_RES_1,*string,EventType,ResourceUpdate,2014-07-29T15:00:00Z,true,1s,false,10,LOG_WARNING, cgrates.org THD_RES_1 *string EventType ResourceUpdate 2014-07-29T15:00:00Z true 1 1s false 10 LOG_WARNING false
17 cgrates.org,THD_RES_1,*string,ResourceID,RES_GRP_1,,,,,,, cgrates.org THD_RES_1 *string ResourceID RES_GRP_1
18 cgrates.org,THD_RES_1,*gte,Usage,10.0,,,,,,, cgrates.org THD_RES_1 *gte Usage 10.0

View File

@@ -277,9 +277,10 @@ cgrates.org,Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*a
`
thresholds = `
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10],Async[11]
cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2,true
#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinHits[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11],Async[12]
cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,10,1s,true,10,THRESH1;THRESH2,true
`
filters = `
#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5]
cgrates.org,FLTR_1,*string,Account,1001;1002,2014-07-29T15:00:00Z
@@ -1494,6 +1495,7 @@ func TestLoadThresholdProfiles(t *testing.T) {
ActivationTime: "2014-07-29T15:00:00Z",
},
Recurrent: true,
MinHits: 10,
MinSleep: "1s",
Blocker: true,
Weight: 10,

View File

@@ -2137,6 +2137,7 @@ func (tps TpThresholdS) AsTPThreshold() (result []*utils.TPThreshold) {
ID: tp.ID,
Blocker: tp.Blocker,
Recurrent: tp.Recurrent,
MinHits: tp.MinHits,
MinSleep: tp.MinSleep,
Async: tp.Async,
}
@@ -2188,6 +2189,7 @@ func APItoModelTPThreshold(th *utils.TPThreshold) (mdls TpThresholdS) {
mdl.Blocker = th.Blocker
mdl.Weight = th.Weight
mdl.Recurrent = th.Recurrent
mdl.MinHits = th.MinHits
mdl.MinSleep = th.MinSleep
mdl.Async = th.Async
if th.ActivationInterval != nil {
@@ -2225,6 +2227,7 @@ func APItoThresholdProfile(tpTH *utils.TPThreshold, timezone string) (th *Thresh
Tenant: tpTH.Tenant,
ID: tpTH.ID,
Recurrent: tpTH.Recurrent,
MinHits: tpTH.MinHits,
Weight: tpTH.Weight,
Blocker: tpTH.Blocker,
Async: tpTH.Async,

View File

@@ -945,6 +945,7 @@ func TestAsTPThresholdAsAsTPThreshold(t *testing.T) {
FilterFieldValues: "1001;1002",
ActivationInterval: "2014-07-29T15:00:00Z",
Recurrent: false,
MinHits: 10,
MinSleep: "1s",
Blocker: false,
Weight: 20.0,
@@ -967,6 +968,7 @@ func TestAsTPThresholdAsAsTPThreshold(t *testing.T) {
},
MinSleep: tps[0].MinSleep,
Recurrent: tps[0].Recurrent,
MinHits: tps[0].MinHits,
Blocker: tps[0].Blocker,
Weight: tps[0].Weight,
ActionIDs: []string{"WARN3"},
@@ -987,6 +989,7 @@ func TestAPItoTPThreshold(t *testing.T) {
},
ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"},
Recurrent: false,
MinHits: 10,
MinSleep: "1s",
Blocker: false,
Weight: 20.0,
@@ -998,6 +1001,7 @@ func TestAPItoTPThreshold(t *testing.T) {
Filters: make([]*RequestFilter, len(tps.Filters)),
Recurrent: tps.Recurrent,
Blocker: tps.Blocker,
MinHits: tps.MinHits,
Weight: tps.Weight,
ActionIDs: []string{"WARN3"},
}

View File

@@ -510,11 +510,12 @@ type TpThreshold struct {
FilterFieldValues string `index:"4" re:""`
ActivationInterval string `index:"5" re:""`
Recurrent bool `index:"6" re:""`
MinSleep string `index:"7" re:""`
Blocker bool `index:"8" re:""`
Weight float64 `index:"9" re:"\d+\.?\d*"`
ActionIDs string `index:"10" re:""`
Async bool `index:"8" re:""`
MinHits int `index:"7" re:""`
MinSleep string `index:"8" re:""`
Blocker bool `index:"9" re:""`
Weight float64 `index:"10" re:"\d+\.?\d*"`
ActionIDs string `index:"11" re:""`
Async bool `index:"12" re:""`
CreatedAt time.Time
}

View File

@@ -39,6 +39,7 @@ type ThresholdProfile struct {
Filters []*RequestFilter // Filters for the request
ActivationInterval *utils.ActivationInterval // Time when this limit becomes active and expires
Recurrent bool
MinHits int
MinSleep time.Duration
Blocker bool // blocker flag to stop processing on filters matched
Weight float64 // Weight to sort the thresholds

View File

@@ -1362,6 +1362,7 @@ type TPThreshold struct {
Filters []*TPRequestFilter // Filters for the request
ActivationInterval *TPActivationInterval // Time when this limit becomes active and expires
Recurrent bool
MinHits int
MinSleep string
Blocker bool // blocker flag to stop processing on filters matched
Weight float64 // Weight to sort the thresholds