Using Attributes to change Category of CDR

114 views
Skip to first unread message

Eugen Shevchenko

unread,
May 21, 2025, 9:06:18 AMMay 21
to CGRateS
Hi All,

I'm a bit stuck with a thing which supposed to be simple

I'm using Attributes to change Category of CDR. In turn it's used to rate CDR with different RatingProfile

My idea is to use Destination Prefix for this, I was inspired by this example https://groups.google.com/g/cgrates/c/1STfjRzUlBw/m/IyNWTYgjCAAJ

So if I make Attributes.csv like this - with a Subject
# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR_COIN_20250101000000_PREFX,*sessions;*cdrs,*prefix:~*req.Subject:319,,,,,,false,10
cgrates.org,ATTR_COIN_20250101000000_PREFX,,,,,*req.Category,*constant,COIN_20250101000000,false,10

Everything works ideally

But if I use Destination, instead of a Subject - it doesn't work anymore
# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR_COIN_20250101000000_PREFX,*sessions;*cdrs,*prefix:~*req.Destination:319,,,,,,false,10
cgrates.org,ATTR_COIN_20250101000000_PREFX,,,,,*req.Category,*constant,COIN_20250101000000,false,10

My Cgrates.json file is attached

Any help is greatly appreciated

cgrates_toupload.json

Armir Veliaj

unread,
May 23, 2025, 5:48:31 AMMay 23
to CGRateS

Hi Eugene,

Using "*prefix:~*req.Destination" should normally work too. Could you please provide the ngrep output at the moment you are sending the event, as well as the cgr-engine logs if any errors are shown there?

Thanks,
Armir

Eugen Shevchenko

unread,
May 23, 2025, 9:36:47 AMMay 23
to CGRateS
Hi Armin,

I have run same test cdrs under different Attributes setup

Setup 1: FAILES

Attributes.csv

# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR_COIN_20250101000000_PREFX,*sessions;*cdrs,*prefix:~*req.Destination:319,,,,,,false,10
cgrates.org,ATTR_COIN_20250101000000_PREFX,,,,,*req.Category,*constant,COIN_20250101000000,false,10

cdr:
# ID,Account,Subject,Destination,SetupTime,AnswerTime,Usage,Tenant,Source,OriginHost
test_3001,qwe2,319060812,319060812,2024-11-20T15:07:48Z,2025-05-05T13:00:00Z,226s,cgrates.org,31615000878,GSM1

Setup 2: WORKS

Attributes.csv

# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
cgrates.org,ATTR_COIN_20250101000000_PREFX,*sessions;*cdrs,*prefix:~*req.Subject:319,,,,,,false,10
cgrates.org,ATTR_COIN_20250101000000_PREFX,,,,,*req.Category,*constant,COIN_20250101000000,false,10

cdr:
# ID,Account,Subject,Destination,SetupTime,AnswerTime,Usage,Tenant,Source,OriginHost
test_4001,qwe2,319060812,319060812,2024-11-20T15:07:48Z,2025-05-05T13:00:00Z,226s,cgrates.org,31615000878,GSM1

------------------------
syslog
######################################################
root@ba22fe80192e:/app# tail /var/log/syslog
May 23 13:24:19 ba22fe80192e CGRateS <4246fe8> [1]: <ERs> parsing </var/spool/cgrates/cdrc/in/cdr_0.csv>
May 23 13:24:19 ba22fe80192e CGRateS <4246fe8> [1]: <ERs> LOG, reader: <ers_jonaz>, message: {#012 "Tenant": "cgrates.org",#012 "ID": "5a59891",#012 "Time": "2025-05-23T13:24:19.188317423Z",#012 "Event": {#012  "Account": "qwe2",#012  "AnswerTime": "2025-05-05T13:00:00Z",#012  "Category": "call",#012  "Destination": "319060812",#012  "OriginHost": "GSM1",#012  "OriginID": "test_3001",#012  "RequestType": "*raw",#012  "SetupTime": "2024-11-20T15:07:48Z",#012  "Source": "31615000878",#012  "Subject": "319060812",#012  "Tenant": "cgrates.org",#012  "ToR": "*monetary",#012  "Usage": "226s"#012 },#012 "APIOpts": {}#012}
May 23 13:24:19 ba22fe80192e CGRateS <4246fe8> [1]: ERs finished processing file </var/spool/cgrates/cdrc/in/cdr_0.csv>. Total records processed: 1, events posted: 1, run duration: 1.701234ms
May 23 13:26:38 ba22fe80192e CGRateS <4246fe8> [1]: APIerSv1.LoadTariffPlanFromStorDb, reloading cache.
May 23 13:26:38 ba22fe80192e CGRateS <4246fe8> [1]: APIerSv1.LoadTariffPlanFromStorDb, reloading scheduler.
May 23 13:27:02 ba22fe80192e CGRateS <4246fe8> [1]: <ERs> parsing </var/spool/cgrates/cdrc/in/cdr_0.csv>
May 23 13:27:02 ba22fe80192e CGRateS <4246fe8> [1]: <ERs> LOG, reader: <ers_jonaz>, message: {#012 "Tenant": "cgrates.org",#012 "ID": "2581417",#012 "Time": "2025-05-23T13:27:02.486919428Z",#012 "Event": {#012  "Account": "qwe2",#012  "AnswerTime": "2025-05-05T13:00:00Z",#012  "Category": "call",#012  "Destination": "319060812",#012  "OriginHost": "GSM1",#012  "OriginID": "test_4001",#012  "RequestType": "*raw",#012  "SetupTime": "2024-11-20T15:07:48Z",#012  "Source": "31615000878",#012  "Subject": "319060812",#012  "Tenant": "cgrates.org",#012  "ToR": "*monetary",#012  "Usage": "226s"#012 },#012 "APIOpts": {}#012}
May 23 13:27:02 ba22fe80192e CGRateS <4246fe8> [1]: ERs finished processing file </var/spool/cgrates/cdrc/in/cdr_0.csv>. Total records processed: 1, events posted: 1, run duration: 585.044µs
###############################################################

ngrep
### FAILED Destinations ATTEMPT - Setup 1 ###
#################
T 2025/05/23 13:24:19.189060 127.0.0.1:36502 -> 127.0.0.1:2012 [AP] #17
{"method":"AttributeSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"5a59891","Time":"2025-05-23T13:24:19.188317423Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"83d21d74895f88b80e7f12d277f5094d87ad3e4d","Category":"call","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_3001","RequestType":"*raw","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*context":"*cdrs","*subsys":"*cdrs"}}],"id":19}

#
T 2025/05/23 13:24:19.189977 127.0.0.1:2012 -> 127.0.0.1:36502 [AP] #18
{"id":19,"result":null,"error":"NOT_FOUND"}

##
T 2025/05/23 13:24:19.190281 127.0.0.1:36502 -> 127.0.0.1:2012 [AP] #20
{"method":"ChargerSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"5a59891","Time":"2025-05-23T13:24:19.188317423Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"83d21d74895f88b80e7f12d277f5094d87ad3e4d","Category":"call","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_3001","RequestType":"*raw","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*context":"*cdrs","*subsys":"*cdrs"}}],"id":20}

#
T 2025/05/23 13:24:19.194107 127.0.0.1:2012 -> 127.0.0.1:36502 [AP] #21
{"id":20,"result":[{"ChargerSProfile":"CGR_DEFAULT","AttributeSProfiles":null,"AlteredFields":["*req.RunID"],"CGREvent":{"Tenant":"cgrates.org","ID":"5a59891","Time":"2025-05-23T13:24:19.188317423Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"83d21d74895f88b80e7f12d277f5094d87ad3e4d","Category":"call","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_3001","RequestType":"*raw","RunID":"*default","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*context":"*cdrs","*subsys":"*chargers"}}}],"error":null}

#
T 2025/05/23 13:24:19.213677 127.0.0.1:36502 -> 127.0.0.1:2012 [AP] #22
{"method":"ThresholdSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"ef334c3","Time":null,"Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"83d21d74895f88b80e7f12d277f5094d87ad3e4d","Category":"call","Cost":0.0027,"CostDetails":{"CGRID":"83d21d74895f88b80e7f12d277f5094d87ad3e4d","RunID":"*default","StartTime":"2025-05-05T13:00:00Z","Usage":226000000000,"Cost":0.0026366742,"Charges":[{"RatingID":"386ef8e","Increments":[{"Usage":0,"Cost":0,"AccountingID":"","CompressFactor":1},{"Usage":1000000000,"Cost":0.0000116667,"AccountingID":"","CompressFactor":226}],"CompressFactor":1}],"AccountSummary":null,"Rating":{"386ef8e":{"ConnectFee":0,"RoundingMethod":"*up","RoundingDecimals":4,"MaxCost":0,"MaxCostStrategy":"","TimingID":"840fe0f","RatesID":"1206e30","RatingFiltersID":"f7aabb4"}},"Accounting":{},"RatingFilters":{"f7aabb4":{"DestinationID":"DEST_Nederland_31_National","DestinationPrefix":"31","RatingPlanID":"RPLAN_COIN","Subject":"*out:cgrates.org:call:*any"}},"Rates":{"1206e30":[{"GroupIntervalStart":0,"Value":0.0007,"RateIncrement":1000000000,"RateUnit":60000000000}]},"Timings":{"840fe0f":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00"}}},"CostSource":"*cdrs","Destination":"319060812","ExtraInfo":"","OrderID":0,"OriginHost":"GSM1","OriginID":"test_3001","Partial":false,"PreRated":false,"RequestType":"*raw","RunID":"*default","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":226000000000},"APIOpts":{"*context":"*cdrs","*eventType":"CDR","*subsys":"*chargers"}}],"id":21}

#
T 2025/05/23 13:24:19.215310 127.0.0.1:2012 -> 127.0.0.1:36502 [AP] #23
{"id":21,"result":null,"error":"NOT_FOUND"}

#############

### SUCCESFULL Subject ATTEMPT - Setup 2 ###

#########
T 2025/05/23 13:27:02.487197 127.0.0.1:36502 -> 127.0.0.1:2012 [AP] #75
{"method":"AttributeSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"2581417","Time":"2025-05-23T13:27:02.486919428Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"f2aaa8d4e4783135ac60c4560405f9f21531f9eb","Category":"call","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_4001","RequestType":"*raw","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*context":"*cdrs","*subsys":"*cdrs"}}],"id":22}

##
T 2025/05/23 13:27:02.532956 127.0.0.1:2012 -> 127.0.0.1:36502 [AP] #77
{"id":22,"result":{"MatchedProfiles":["cgrates.org:ATTR_COIN_20250101000000_PREFX"],"AlteredFields":["*req.Category"],"Tenant":"cgrates.org","ID":"2581417","Time":"2025-05-23T13:27:02.486919428Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"f2aaa8d4e4783135ac60c4560405f9f21531f9eb","Category":"COIN_20250101000000","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_4001","RequestType":"*raw","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*context":"*cdrs","*subsys":"*cdrs"}},"error":null}

##
T 2025/05/23 13:27:02.533178 127.0.0.1:36502 -> 127.0.0.1:2012 [AP] #79
{"method":"ChargerSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"2581417","Time":"2025-05-23T13:27:02.486919428Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"f2aaa8d4e4783135ac60c4560405f9f21531f9eb","Category":"COIN_20250101000000","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_4001","RequestType":"*raw","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*subsys":"*cdrs"}}],"id":23}

##
T 2025/05/23 13:27:02.555856 127.0.0.1:2012 -> 127.0.0.1:36502 [AP] #81
{"id":23,"result":[{"ChargerSProfile":"CGR_DEFAULT","AttributeSProfiles":null,"AlteredFields":["*req.RunID"],"CGREvent":{"Tenant":"cgrates.org","ID":"2581417","Time":"2025-05-23T13:27:02.486919428Z","Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"f2aaa8d4e4783135ac60c4560405f9f21531f9eb","Category":"COIN_20250101000000","Destination":"319060812","OriginHost":"GSM1","OriginID":"test_4001","RequestType":"*raw","RunID":"*default","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":"226s"},"APIOpts":{"*subsys":"*chargers"}}}],"error":null}

#
T 2025/05/23 13:27:02.577575 127.0.0.1:36502 -> 127.0.0.1:2012 [AP] #82
{"method":"ThresholdSv1.ProcessEvent","params":[{"Tenant":"cgrates.org","ID":"8a92231","Time":null,"Event":{"Account":"qwe2","AnswerTime":"2025-05-05T13:00:00Z","CGRID":"f2aaa8d4e4783135ac60c4560405f9f21531f9eb","Category":"COIN_20250101000000","Cost":4.14334,"CostDetails":{"CGRID":"f2aaa8d4e4783135ac60c4560405f9f21531f9eb","RunID":"*default","StartTime":"2025-05-05T13:00:00Z","Usage":226000000000,"Cost":4.1433333258,"Charges":[{"RatingID":"8d39806","Increments":[{"Usage":0,"Cost":0,"AccountingID":"","CompressFactor":1},{"Usage":1000000000,"Cost":0.0183333333,"AccountingID":"","CompressFactor":226}],"CompressFactor":1}],"AccountSummary":null,"Rating":{"8d39806":{"ConnectFee":0,"RoundingMethod":"*up","RoundingDecimals":5,"MaxCost":0,"MaxCostStrategy":"","TimingID":"40fd3ea","RatesID":"476ed98","RatingFiltersID":"b6b2a1c"}},"Accounting":{},"RatingFilters":{"b6b2a1c":{"DestinationID":"dest_090_1.100000_tarifftype_4_vattype_3_ServiceNumber","DestinationPrefix":"319060812","RatingPlanID":"RPLAN_COIN_20250101000000","Subject":"*out:cgrates.org:COIN_20250101000000:*any"}},"Rates":{"476ed98":[{"GroupIntervalStart":0,"Value":1.1,"RateIncrement":1000000000,"RateUnit":60000000000}]},"Timings":{"40fd3ea":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00"}}},"CostSource":"*cdrs","Destination":"319060812","ExtraInfo":"","OrderID":0,"OriginHost":"GSM1","OriginID":"test_4001","Partial":false,"PreRated":false,"RequestType":"*raw","RunID":"*default","SetupTime":"2024-11-20T15:07:48Z","Source":"31615000878","Subject":"319060812","Tenant":"cgrates.org","ToR":"*monetary","Usage":226000000000},"APIOpts":{"*eventType":"CDR","*subsys":"*chargers"}}],"id":24}

#
T 2025/05/23 13:27:02.579141 127.0.0.1:2012 -> 127.0.0.1:36502 [AP] #83
{"id":24,"result":null,"error":"NOT_FOUND"}

#####

Hope this helps

Armir Veliaj

unread,
May 30, 2025, 11:48:35 AMMay 30
to CGRateS
Hi Eugene,

I tried to reproduce your scenario but could not get that error.
Please make sure to check if attributes are properly loaded via APIerSv1.GetAttributeProfile.
And if would be possible you could try with a clean environment after flushing the database and reloading the cache.

Thanks,
Armir
Reply all
Reply to author
Forward
0 new messages