Query about CDR-CGR

79 views
Skip to first unread message

Pete Kelly

unread,
May 22, 2018, 2:02:43 AM5/22/18
to CGRateS
Hi

I am just starting to work with CGRates and I have been following some of the tutorials to gain an understanding of how the various components work together.

I am in a situation where I can successfully rate calls by using the inbuilt OpenSIPS module, and I have some derived chargers set up too so I am hopefully well onto the learning curve.

As a next step I have been experimenting with sending data directly into CGRates (instead of relying on the OpenSIPS module) so that I can send decoupled information in and gain some more understanding of what is going on.

I have been reading the article outlined here http://cgrates.readthedocs.io/en/latest/cdrserver.html#cdr-cgr about the CDR-CGR and I have duly tried to use the CURL example that is documented at the bottom of that section.

However whenever I try this CURL example, it generates an unique indexing error when inserting into PostgreSQL - it seems that the unique index which is in place across these columns is being violated:
 (cgrid, run_id, origin_id)

When I check the raw SQL that CGRates is trying to insert, it seems that the origin_id column is being set to NULL:
(cgrid, run_id, origin_id)=(95c7e5ccf93f207c64150b0b0b74bfb184c48cb9, *raw, )

I am making the following curl request:
curl --data "tor=*voice&accid=iiaasbsfgfddfggsfgdsaf&cdrhost=192.168.1.2&cdrsource=curl_cdr&reqtype=rated&direction=*out&ten
ant=100000.v.com&category=call2345&account=100000.v.com&subject=dan12&destination=33234&answer_time=1383813748&usage=3&sip_user=Jitsi23&subject2=1005&origin_id=1234&origin_host=sdfgd

The output from CGRates is this:
(pq: duplicate key value violates unique constraint "cdrs_cgrid_run_id_origin_id_key")
[2018-05-21 14:51:16]
2018/05/21 14:51:16 CGRateS <b0faaf2> [ERROR] <CDRS> Storing primary CDR {"CGRID":"95c7e5ccf93f207c64150b0b0b74bfb184c48cb9","RunID":"*raw","OrderID":0,"OriginHost":"","Source":"127.0.0.1:37
608","OriginID":"","ToR":"","RequestType":"*rated","Tenant":"cgrates.org","Category":"call","Account":"","Subject":"","Destination":"","SetupTime":"0001-01-01T00:00:00Z","AnswerTime":"0001-0
1-01T00:00:00Z","Usage":0,"ExtraFields":{"accid":"iiaasbsfgfddfggsfgdsaf","account":"100000.v.com","answer_time":"1383813748","category":"call2345","cdrhost":"192.168.1.2","cdrsource":"curl_
cdr","destination":"33234","direction":"*out","origin_host":"sdfgdfgf","origin_id":"1234","reqtype":"rated","sip_user":"Jitsi23","subject":"dan12","subject2":"1005","tenant":"100000.v.ibrows
e.com","tor":"*voice","usage":"3"},"ExtraInfo":"","Partial":false,"Rated":false,"CostSource":"","Cost":-1,"CostDetails":null}, got error: pq: duplicate key value violates unique constraint "
cdrs_cgrid_run_id_origin_id_key"
2018/05/21 14:51:16 CGRateS <b0faaf2> [ERROR] <CDRS> Errors when storing CDR entry: pq: duplicate key value violates unique constraint "cdrs_cgrid_run_id_origin_id_key"


If anybody could shed any light onto this situation I would be grateful - it seems that somehow the origin_id is not being set correctly within cgrates.

Pete

DanB

unread,
May 22, 2018, 4:58:16 AM5/22/18
to cgr...@googlegroups.com
Hey Pete,

As you have correctly spotted, the docs are behind the code in this
case. We have changed in rc8 (I think docs are for released rc7) CDR
fields matching 1-1 internal CDR structure from here:
https://github.com/cgrates/cgrates/blob/master/engine/cdr.go#L78

Please let me know if any issue after changing field names.

Thanks,
DanB

PS: Once you figure the correct field names, would be great if you
could send us a PR for docs folder with correct post format.
> --
> 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/3c8cef0e-a51b-43c0-89b9-63c6e696b2fe%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

Pete Kelly

unread,
May 22, 2018, 5:34:22 AM5/22/18
to CGRateS
Thanks Dan

That link is perfect, I've figured it out and will put in the pull request.

Pete

DanB

unread,
May 22, 2018, 5:37:23 AM5/22/18
to cgr...@googlegroups.com
Pete,

Great!
Once you figure out working with tests you will realize that all is
well documented there since we got quite some test coverage ;).

DanB

Pete Kelly

unread,
May 22, 2018, 5:47:32 AM5/22/18
to CGRateS

Pete Kelly

unread,
May 22, 2018, 6:02:20 AM5/22/18
to CGRateS
Hi Dan

Actually something else interesting I have noticed is that even if I force a failure for the CURL request (e.g. if I force a unique index clash), then I am still getting a 200 status for the HTTP request.

Pete

DanB

unread,
May 22, 2018, 6:06:09 AM5/22/18
to cgr...@googlegroups.com
Hey Pete,

The 200 OK will just reflect the ability to process the HTTP, not the
errors of the CDR processing.

DanB
> --
> 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/93e98aed-6c16-4467-ab5e-6b2e54b14e87%40googlegroups.com
Reply all
Reply to author
Forward
0 new messages