diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 61b53ec2e..d593815ca 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -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, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 6e2e6ffb6..435a77d0d 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -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, diff --git a/data/tariffplans/testtp/Thresholds.csv b/data/tariffplans/testtp/Thresholds.csv index 9f6286555..ddab38400 100644 --- a/data/tariffplans/testtp/Thresholds.csv +++ b/data/tariffplans/testtp/Thresholds.csv @@ -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 diff --git a/data/tariffplans/tutorial/Thresholds.csv b/data/tariffplans/tutorial/Thresholds.csv index 9cfbe904c..40c53f597 100644 --- a/data/tariffplans/tutorial/Thresholds.csv +++ b/data/tariffplans/tutorial/Thresholds.csv @@ -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,,,,,,,, diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index c8afc485f..a615427d2 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -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, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 3469edab4..62fa477db 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -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, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 47fa9266e..5c0e4ab02 100755 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -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"}, } diff --git a/engine/models.go b/engine/models.go index 7f8eef608..596d55221 100755 --- a/engine/models.go +++ b/engine/models.go @@ -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 } diff --git a/engine/thresholds.go b/engine/thresholds.go index 61d7aad8f..1021a6e7c 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -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 diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 7e7c89b53..08c5d78af 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -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