How to run data/tariffplans/tutorial to test filters/thresholds

302 views
Skip to first unread message

Tomas Silny

unread,
Aug 10, 2018, 6:42:52 AM8/10/18
to CGRateS
Hi,

We would like to test new filters/threshold features. We started with example tutorials https://github.com/cgrates/cgrates/tree/master/data/tariffplans/tutorial but it seems, the thresholds are not triggered. 

Could the issue be caused by the issue with loading CGRates plans? The error: Attributes.csv, record on line 2: wrong number of fields

Is there an option to see triggered actions via logs or API calls? What is the best approach for testing filters and triggers?

The cgrates.json configuration is attached below. Could you please confirm there is or there is not an issue with configuration?

CGRageS version:
CGRateS 0.9.1~rc8 git+834f130 (2018-07-09T19:25:00+02:00)

Thank you.


cgrates.json
Message has been deleted

Tomas Silny

unread,
Aug 12, 2018, 3:09:04 AM8/12/18
to CGRateS
I fixed the issue with the Attributes.csv and reload the tariff plan via ApierV1.LoadTariffPlanFromFolder.

After that, I checked if the threshold has been hit
Request:
{
 
"method": "ThresholdSv1.GetThreshold",
 
"params": [{
 
"Tenant": "cgrates.org",
 
"ID": "THD_ACNT_1002"
 
}]
}


Response:
{
   
"id": null,
   
"result": {
       
"Tenant": "cgrates.org",
       
"ID": "THD_ACNT_1002",
       
"Hits": 0,
       
"Snooze": "0001-01-01T00:00:00Z"
   
},
   
"error": null
}


I expect the filter should be triggered after the account 1002 is created by LoadTariffPlanFromFolder. Is that correct?

When I call the event manually by

Request:
{
 
"method":"ThresholdSv1.ProcessEvent",
 
"params":[
   
{
     
"ThresholdIDs":[
       
"THD_ACNT_1002"],
     
"Tenant":"cgrates.org",
     
"ID":"c6b75b5a-4654-4582-9940-740cc7874c1c",
     
"Context":null,
     
"Time":null,
     
"Event":{
     
"Account": "1002",
     
"BalanceID": "data",
     
"EventSource": "AccountS",
     
"EventType": "StatUpdate",
     
"Units": 100000000.0
   
}}
   
],
 
"id":8
}


and then check if the threshold again

Request:
{
 
"method": "ThresholdSv1.GetThreshold",
 
"params": [{
 
"Tenant": "cgrates.org",
 
"ID": "THD_ACNT_1002"
 
}]
}


Response:
{
   
"id": null,
   
"result": {
       
"Tenant": "cgrates.org",
       
"ID": "THD_ACNT_1002",
       
"Hits": 1,
       
"Snooze": "2018-08-12T07:02:38.2015689Z"
   
},
   
"error": null
}


I can see the "Hits": 1

DanB

unread,
Aug 12, 2018, 6:31:47 AM8/12/18
to cgr...@googlegroups.com
Hey Thomas,

There are chances that only real-time operations are informing about
account status changes. We did not focus on loader which is offline
process(inserts tasks into DataDB to be processed later by scheduler).
We did not need to have offline monitored but if that is important to
you, please open an issue on github and we will try to fix that.

DanB

PS: to be more confident on thresholds being executed, I suggest
configuring the connection between RALs and ThresholdS over tcp 2012
and use transport *json. In that way you will be able to see events
being triggered with a simple tool like ngrep (ngrep -t -W byline port
2012 -d lo).
> --
> You received this message because you are subscribed to the Google
> Groups "CGRateS" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to cgrates+u...@googlegroups.com.
> To post to this group, send email to cgr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cgrates/8a1105c0-86e9-4401-9d00-98a6fc12ebae%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

Tomas Silny

unread,
Aug 12, 2018, 7:15:11 AM8/12/18
to CGRateS
Hi Dan,

thank you for the answer. My final goal is to configure actions based on account balance update. However, I decided to start with the tutorial examples to figure out how filters and thresholds work.

So if I adjust the tutorial CSVs by the following way

Filters.csv
#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5]
cgrates
.org,FLTR_ACNT_BALANCE,*string,EventType,BalanceUpdate,2014-07-29T15:00:00Z


Thresholds.csv
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10]
cgrates
.org,THD_ACNT_BALANCE,FLTR_ACNT_BALANCE,2014-07-29T15:00:00Z,-1,1,1s,false,10,ACT_LOG_WARNING,false


and call
Request
{
 
"method":"ApierV1.AddBalance",
 
"params":[
   
{
"Tenant":"cgrates.org",
"Account":"1002",
     
"BalanceType":"*monetary",
     
"Value":0.1,
     
"ExpiryTime":"",
     
"RatingSubject":"",
     
"DestinationId":"",
     
"Weight":666,
     
"SharedGroup":"",
     
"Overwrite":false,
     
"BalanceId":"data"
   
}],
 
"id":0
}


The action ACT_LOG_WARNING should be triggered. Is that correct?

PS:  Thanks for the advice. I will change the configuration port and transport as you suggest. 

DanB

unread,
Aug 12, 2018, 7:27:04 AM8/12/18
to cgr...@googlegroups.com
Tomas,

Sorry for the previous re-naming ;).
If your final goal is to monitor each account update, could worth going
deeper on the issue with offline loading too.

Anyway, the action should be called if the FLTR_ACNT_BALANCE contains
the correct matching info. Before going into that, make sure the
ThresholdSv1.ProcessEvent is called, so the info gets to ThresholdS.
That you should do with the ngrep command I sent you.

Please post here if any issue.

DanB
> https://groups.google.com/d/msgid/cgrates/f2c4c871-f47e-44e3-ab5e-37c71047c32c%40googlegroups.com

Tomas Silny

unread,
Aug 12, 2018, 7:43:46 AM8/12/18
to CGRateS
Dan,

Thank you for the quick response over the weekend! Appreciate it.

Will try your suggestions and let you know if any issue will occur.  

Tomas

Tomas Silny

unread,
Aug 12, 2018, 9:31:06 AM8/12/18
to CGRateS
Dan,

My final goal is to check BalanceID "data" after BalanceUpdate. If a value of balance is greater than the defined value, call the action the ACT_LOG_WARNING. 

For now, I tried just call Action after the balance of BalanceID "data" is updated but without success.
Am I missing something?

Thresholds.csv
#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10]
cgrates
.org,THD_ACNT_BALANCE,FLTR_ACNT_BALANCE,2014-07-29T15:00:00Z,-1,1,1s,false,10,ACT_LOG_WARNING,false


Filter.csv
#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5]
cgrates
.org,FLTR_ACNT_BALANCE,*string,EventType,BalanceUpdate,2014-07-29T15:00:00Z

cgrates
.org,FLTR_ACNT_BALANCE,*string,BalanceID,data,2014-07-29T15:00:00Z


Request:
{
 
"method":"ApierV1.AddBalance",
 
"params":[
   
{
   
"Tenant":"cgrates.org",
   
"Account":"1002",
     
"BalanceType":"*monetary",
     
"Value":0.1,
     
"ExpiryTime":"",
     
"RatingSubject":"",
     
"DestinationId":"",
     
"Weight":666,
     
"SharedGroup":"",
     
"Overwrite":false,

     
"BalanceID":"data"
   
}],
 
"id":0
}


Ngrep result:
root@841b62cecdc1:/# ngrep -t -W byline port 2012 -d lo
interface: lo (127.0.0.0/
255.0.0.0)
filter
: (ip or ip6) and ( port 2012 )
#
T
2018/08/12 13:01:00.200483 127.0.0.1:55796 -> 127.0.0.1:2012 [AP]
{"method":"PubSubV1.Publish","params":[{"ActionIds":"","EventName":"ACTION_TRIGGER_FIRED","Id":"","Uuid":""}],"id":267}


#
T
2018/08/12 13:01:00.200708 127.0.0.1:2012 -> 127.0.0.1:55796 [AP]
{"id":267,"result":"OK","error":null}



The ProcessEvent Request:
{
 
"method":"ThresholdSv1.ProcessEvent",
 
"params":[
   
{
     
"ThresholdIDs":[

       
"THD_ACNT_BALANCE"],
     
"Tenant":"cgrates.org",
     
"ID":"api-test",

     
"Context":null,
     
"Time":null,
     
"Event":{
     
"Account": "1002",

     
"Value":1,
     
"BalanceID":"data",
     
"EventType":"BalanceUpdate"
   
}}
   
],
 
"id":8
}


gives me result which is ok

ProcessEvent
T 2018/08/12 13:02:48.127283 127.0.0.1:55796 -> 127.0.0.1:2012 [AP]
{"method":"PubSubV1.Publish","params":[{"ActionIds":"ACT_LOG_WARNING","EventName":"ACTION_TRIGGER_FIRED","Id":"","Uuid":"35579b08-38b2-4a60-b8c0-964cb5bbd53e"}],"id":268}


#
T
2018/08/12 13:02:48.127438 127.0.0.1:2012 -> 127.0.0.1:55796 [AP]
{"id":268,"result":"OK","error":null}


Tomas

#


On Sunday, August 12, 2018 at 1:27:04 PM UTC+2, DanB wrote:

DanB

unread,
Aug 12, 2018, 11:42:24 AM8/12/18
to cgr...@googlegroups.com
Tomas,

I am not sure I get it, was the ThresholdSv1.ProcessEvent triggered by
your AddBalance? It should be no issue with checking the Data balance
once you get the event.

DanB

On Sun, 2018-08-12 at 06:31 -0700, Tomas Silny wrote:
> Dan,
>
> My final goal is to check BalanceID "data" after BalanceUpdate. If a
> value of balance is greater than the defined value, call the action
> the ACT_LOG_WARNING.
>
> For now, I tried just call Action after the balance
> of BalanceID "data" is updated but without success.
> Am I missing something?
>
> Thresholds.csv
> #Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],MaxHits[4],MinHit
> s[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10]
> cgrates.org,THD_ACNT_BALANCE,FLTR_ACNT_BALANCE,2014-07-29T15:00:00Z,-
> 1,1,1s,false,10,ACT_LOG_WARNING,false
>
>
> https://groups.google.com/d/msgid/cgrates/f4fc4dd3-4263-42fd-9960-c63c81d82387%40googlegroups.com

Tomas Silny

unread,
Aug 12, 2018, 12:51:51 PM8/12/18
to CGRateS
Dan,

No, the ThresholdSv1.ProcessEvent has been triggered manually. The request:
{

 
"method":"ApierV1.AddBalance",
 
"params":[
   
{
   
"Tenant":"cgrates.org",
   
"Account":"1002",
     
"BalanceType":"*monetary",
     
"Value":0.1,
     
"ExpiryTime":"",
     
"RatingSubject":"",
     
"DestinationId":"",
     
"Weight":666,
     
"SharedGroup":"",
     
"Overwrite":false,


     
"BalanceID":"data"
   
}],
 
"id":0
}


gives me the ngrep result:
root@841b62cecdc1:/# ngrep -t -W byline port 2012 -d lo
interface: lo (127.0.0.0/
255.0.0.0)
filter
: (ip or ip6) and ( port 2012 )
#
T
2018/08/12 13:01:00.200483 127.0.0.1:55796 -> 127.0.0.1:2012 [AP]
{"method":"PubSubV1.Publish","params":[{"ActionIds":"","EventName":"ACTION_TRIGGER_FIRED","Id":"","Uuid":""}],"id":267}





#
T
2018/08/12 13:01:00.200708 127.0.0.1:2012 -> 127.0.0.1:55796 [AP]
{"id":267,"result":"OK","error":null}


and any action is not triggered. So it seems there is no correct matching with the filter. However, I'm not sure why. Hope it is clear now.

Tomas

Dan B

unread,
Aug 12, 2018, 12:53:17 PM8/12/18
to cgr...@googlegroups.com
Thomas, 

Please open an issue on github and we should treat it there.

DanB

Tomas Silny

unread,
Aug 12, 2018, 1:12:39 PM8/12/18
to CGRateS
Dan,

the issue is created
https://github.com/cgrates/cgrates/issues/1172

Thanks for your support.

Tomas
Reply all
Reply to author
Forward
0 new messages