CDR Extra Fields

298 views
Skip to first unread message

paul...@voxbit.net

unread,
Dec 11, 2016, 4:06:14 AM12/11/16
to CGRateS
Hi, 
I'm stuck again ... I want to get some extra fields into the exported CDR.

Kamailio is sending the extra fields to the session manager, and the data is being stored in the stordb... so far so good.  Now how do I get that extra data included in the exported cdrs csv file?


I'm sure I should be putting something into the cgrates.json cdre content_fields section... but after a few permutations I'm still only getting a blank field in the output.
kamailio-cgrates/cfg:
route[CGR_CALL_END] {
        if $sht(cgrconn=>cgr) == $null {
                xlog("Charging controller unreachable");
                exit;
        }
        $var(callDur) = $TS - $dlg(start_ts);
         evapi_relay("{\"event\":\"CGR_CALL_END\",
                \"callid\":\"$dlg(callid)\",
                \"from_tag\":\"$dlg(from_tag)\",
                \"cgr_reqtype\":\"$dlg_var(cgrReqType)\",
                \"cgr_tenant\":\"$dlg_var(cgrTenant)\",
                \"cgr_account\":\"$dlg_var(cgrAccount)\",
                \"cgr_destination\":\"$dlg_var(cgrDestination)\",
                \"cgr_answertime\":\"$dlg(start_ts)\",
                \"cgr_duration\":\"$var(callDur)\",
                \"cgr_supplier\":\"$dlg_var(cgrSupplier)\",
                \"cgr_disconnectcause\":\"$T_reply_code\",
                \"origin_ip\":\"3.3.3.3\",
                \"origin_user\":\"777\"}");
}

| 33 | 5b0d5ce22a6f271c7c74cd2b6b0111949ce594c5 | *default     | 127.0.0.1   | KAMAILIO_CGR_CALL_END | N2IzODFlYThkNGIzNmUwMDAxM2MxNDRlMDIwYmIyYWE.;3905fb55 | *voice | *prepaid     | *out      | cgrates.org | call     | 1001    | 1001    | 1002        | 2016-12-11 08:38:48 | 0.000000000 | 2016-12-11 08:38:48 |  4.000000000 | suppl2   | 0                | {"origin_ip":"3.3.3.3","origin_user":"777"}                                                                                                                                                                                                                                                                      | SMR         |  0.3000 | {"Direction":"*out","Category":"call","Tenant":"cgrates.org","Subject":"1001","Account":"1001","Destination":"1002","TOR":"*voice","Cost":0.3,"Timespans":[{"TimeStart":"2016-12-11T08:38:48Z","TimeEnd":"2016-12-11T08:39:48Z","Cost":0.1,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[6,0],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0.2,"RoundingMethod":"*up","RoundingDecimals":4,"MaxCost":0,"MaxCostStrategy":"","Rates":[{"GroupIntervalStart":0,"Value":0.1,"RateIncrement":60000000000,"RateUnit":60000000000},{"GroupIntervalStart":60000000000,"Value":0.05,"RateIncrement":1000000000,"RateUnit":60000000000}]},"Weight":10},"DurationIndex":60000000000,"Increments":[{"Duration":60000000000,"Cost":0.1,"BalanceInfo":{"Unit":null,"Monetary":{"UUID":"d5a576f3-e5d3-4155-a910-c748bd478735","ID":"","Value":2.29,"RateInterval":null},"AccountID":"cgrates.org:1001"},"CompressFactor":1}],"RoundIncrement":null,"MatchedSubject":"*out:cgrates.org:call:1001","MatchedPrefix":"1002","MatchedDestId":"DST_1002","RatingPlanId":"RP_RETAIL2","CompressFactor":1}],"RatedUsage":60} | null            |            | 2016-12-11 08:38:52 | 2016-12-11 08:38:52 | NULL       |
| 34 | 5b0d5ce22a6f271c7c74cd2b6b0111949ce594c5 | derived_run1 | 127.0.0.1   | KAMAILIO_CGR_CALL_END | N2IzODFlYThkNGIzNmUwMDAxM2MxNDRlMDIwYmIyYWE.;3905fb55 | *voice | *rated       | *out      | cgrates.org | call     | 1001    | 1002    | 1002        | 2016-12-11 08:38:48 | 0.000000000 | 2016-12-11 08:38:48 |  4.000000000 | suppl2   | 0                | {"origin_ip":"3.3.3.3","origin_user":"777"}                                                                                                                                                                                                                                                                      | CDRS        |  0.3000 | {"Direction":"*out","Category":"call","Tenant":"cgrates.org","Subject":"1002","Account":"1001","Destination":"1002","TOR":"*voice","Cost":0.3,"Timespans":[{"TimeStart":"2016-12-11T08:38:48Z","TimeEnd":"2016-12-11T08:39:48Z","Cost":0.1,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[6,0],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0.2,"RoundingMethod":"*up","RoundingDecimals":4,"MaxCost":0,"MaxCostStrategy":"","Rates":[{"GroupIntervalStart":0,"Value":0.1,"RateIncrement":60000000000,"RateUnit":60000000000},{"GroupIntervalStart":60000000000,"Value":0.05,"RateIncrement":1000000000,"RateUnit":60000000000}]},"Weight":10},"DurationIndex":60000000000,"Increments":[{"Duration":60000000000,"Cost":0.1,"BalanceInfo":{"Unit":null,"Monetary":null,"AccountID":""},"CompressFactor":1}],"RoundIncrement":null,"MatchedSubject":"*out:cgrates.org:call:*any","MatchedPrefix":"10","MatchedDestId":"DST_FS","RatingPlanId":"RP_RETAIL1","CompressFactor":1}],"RatedUsage":60}                      | null            |            | 2016-12-11 08:38:52 | 2016-12-11 08:38:52 | NULL       |


cgrates.json (note the tutorial example file has 2 typos in the field values: cost should be Cost, and usage should be Usage)
...
"cdre": {
        "*default": {
                "cdr_format": "csv",
                "field_separator": ",",
                "data_usage_multiply_factor": 1,
                "sms_usage_multiply_factor": 1,
        "generic_usage_multiply_factor": 1,
                "cost_multiply_factor": 1,
                "cost_rounding_decimals": -1,
                "cost_shift_digits": 0,
                "mask_destination_id": "MASKED_DESTINATIONS",
                "mask_length": 0,
                "export_dir": "/tmp/cgr_kamevapi/cgrates/cdre",
                "header_fields": [],
                "content_fields": [
                        {"tag": "CgrId", "type": "*composed", "value": "CGRID"},
                        {"tag":"RunId", "type": "*composed", "value": "RunID"},
                        {"tag":"Tor", "type": "*composed", "value": "ToR"},
                        {"tag":"AccId", "type": "*composed", "value": "OriginID"},
                        {"tag":"ReqType", "type": "*composed", "value": "RequestType"},
                        {"tag":"Direction", "type": "*composed", "value": "Direction"},
                        {"tag":"Tenant", "type": "*composed", "value": "Tenant"},
                        {"tag":"Category", "type": "*composed", "value": "Category"},
                        {"tag":"Account", "type": "*composed", "value": "Account"},
                        {"tag":"Subject", "type": "*composed", "value": "Subject"},
                        {"tag":"Destination", "type": "*composed", "value": "Destination"},
                        {"tag":"SetupTime", "type": "*datetime", "value": "SetupTime", "layout": "2006-01-02T15:04:05Z07:00"},
                        {"tag":"AnswerTime", "type": "*datetime", "value": "AnswerTime", "layout": "2006-01-02T15:04:05Z07:00"},
                        {"tag":"Usage", "type": "*composed", "value": "Usage"},
                        {"tag":"Cost", "type": "*composed", "value": "Cost"},
                        {"tag":"OriginIP", "type": "*composed", "value": "Extra_cdr_fields"},
                ],
                "trailer_fields": [],
        },
        ...



 
cgr-console 'cdrs_export CdrFormat="csv" ExportDir="/tmp"'


# tail -3 /var/spool/cgrates/cdre/cdre_1481445567.csv 
5b0d5ce22a6f271c7c74cd2b6b0111949ce594c5,*raw,*voice,N2IzODFlYThkNGIzNmUwMDAxM2MxNDRlMDIwYmIyYWE.;3905fb55,*prepaid,*out,cgrates.org,call,1001,1001,1002,2016-12-11T08:38:48Z,2016-12-11T08:38:48Z,4,-1,
5b0d5ce22a6f271c7c74cd2b6b0111949ce594c5,*default,*voice,N2IzODFlYThkNGIzNmUwMDAxM2MxNDRlMDIwYmIyYWE.;3905fb55,*prepaid,*out,cgrates.org,call,1001,1001,1002,2016-12-11T08:38:48Z,2016-12-11T08:38:48Z,4,0,
5b0d5ce22a6f271c7c74cd2b6b0111949ce594c5,derived_run1,*voice,N2IzODFlYThkNGIzNmUwMDAxM2MxNDRlMDIwYmIyYWE.;3905fb55,*rated,*out,cgrates.org,call,1001,1002,1002,2016-12-11T08:38:48Z,2016-12-11T08:38:48Z,4,0,


Dan-Cristian Bogos

unread,
Dec 11, 2016, 4:18:20 AM12/11/16
to cgr...@googlegroups.com

Hi Paul

Just put as Value in the export template name of the extra field you want to include.

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+unsubscribe@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/6812f626-adb1-4da7-b668-1387e9acf3d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

paul...@voxbit.net

unread,
Dec 11, 2016, 4:50:27 AM12/11/16
to CGRateS
Wow,
That was simple!  I had a typo in the field names.
Thanks

cdre config : 
                        {"tag":"Usage", "type": "*composed", "value": "Usage"},
                        {"tag":"Cost", "type": "*composed", "value": "Cost"},
                        {"tag":"OriginIP", "type": "*composed", "value": "origin_ip"},
                        {"tag":"OriginUser", "type": "*composed", "value": "origin_user"},

produces the expected csv lines:
 
ef9ec79f39c2c91d0e8c998784f8ed9eb5ce4b57,*raw,*voice,ODI5YTVkN2Q1YzY1MGZjNjhlNmMwOTA5ZGU2NzMwMTY.;0be29905,*prepaid,*out,cgrates.org,call,1001,1001,1002,2016-12-11T09:42:26Z,2016-12-11T09:42:26Z,3,-1,3.3.3.3,777
ef9ec79f39c2c91d0e8c998784f8ed9eb5ce4b57,*default,*voice,ODI5YTVkN2Q1YzY1MGZjNjhlNmMwOTA5ZGU2NzMwMTY.;0be29905,*prepaid,*out,cgrates.org,call,1001,1001,1002,2016-12-11T09:42:26Z,2016-12-11T09:42:26Z,3,0,3.3.3.3,777
ef9ec79f39c2c91d0e8c998784f8ed9eb5ce4b57,derived_run1,*voice,ODI5YTVkN2Q1YzY1MGZjNjhlNmMwOTA5ZGU2NzMwMTY.;0be29905,*rated,*out,cgrates.org,call,1001,1002,1002,2016-12-11T09:42:26Z,2016-12-11T09:42:26Z,3,0,3.3.3.3,777
To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages