Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

CDR action http_post

133 views
Skip to first unread message

Salvinder Parhar

unread,
Mar 4, 2025, 2:06:52 PMMar 4
to cgr...@googlegroups.com
Hello CGRateS team,

Is it possible to trigger an ActionID every time a new CDR is processed and an entry is added to cdrs?

Also, with ActioneType *http_post is it possible to define/customize what the body of the HTTP POST request should look like, using the contents of the CDR event? HTTP POST body in my case should be something like this;

{
  "event": {
    "transaction_id": "<string>",                   # randomly generated uuid per event (Call-ID/cgrid)
    "external_subscription_id": "<string>",         # unique uuid per customer (either tenant ID or some key/value pair from the 'extra_fields' column from cdrs)
    "code": "<string>",                             # rating plan ID from cdrs
    "timestamp": "<integer>",                       # unix timestamp of the event (value of 'created_at' column from cdrs)
    "total_amount_cents": "<string>",               # cost in cents of the event (value of 'cost' column from cdrs, value in cents only)
    "properties": {                                 # custom variables defined as properties
      "custom_field01": "<string>",                 # maybe 'usage' column from cdrs as key/value pair, value in secs only
      "custom_field02": "<string>",                 # maybe another key/value pair from the 'extra_fields' column from cdrs
      ...                                           # maybe a few more key/value pairs from cdrs
    }
  }
}

Thanks,
Sal

Armir Veliaj

unread,
Mar 5, 2025, 9:40:52 AMMar 5
to CGRateS
Hi Sal,

EventExporterService should be what you're looking for. You can customize what you're exporting using 'fields' templates. See https://cgrates.readthedocs.io/en/latest/ees.html#ees.

Thanks,
Armir

Salvinder Parhar

unread,
Mar 5, 2025, 6:04:46 PMMar 5
to CGRateS
Thank you Armir. I'll read on it. Are there are any EEs tutorials available? I couldn't find any in the repo. 

Sal

Armir Veliaj

unread,
Mar 6, 2025, 6:53:14 AMMar 6
to CGRateS

Salvinder Parhar

unread,
Apr 8, 2025, 10:54:17 PMApr 8
to CGRateS
Hello Armir,

So I started working on building the EES config block, and here's what I've got so far.  

"ees": {
      "enabled": true,
      "attributes_conns":["*localhost"],
      "exporters": [
        {
          "id": "cdr_billing_event",
          "type": "*http_post",
          "synchronous": true,
          "field_separator": ",",
          "flags": ["*cdrs","*log"],
          "attempts": 1,
          "fields": [
            {"tag": "transaction_id","path": "*exp.transaction_id","type": "*variable","value": "~*req.OriginID"},
            {"tag": "external_subscription_id","path": "*exp.external_subscription_id", "type": "*variable","value": "~*req.Account"},
            {"tag": "code", "path": "*exp.code", "type": "*variable", "value": "hpbx_mins_usage"},
            {"tag": "precise_total_amount_cents", "path": "*exp.precise_total_amount_cents", "type": "*variable", "value": "~*req.Cost{*multiply:100}", "width": 7, "strip": "*right", "padding": "*zeroleft"},
            {"tag": "hpbx_mins_count", "path": "*exp.hpbx_mins_count", "type": "*variable", "value": "~*req.Usage{*divide:60000000000}"},
            {"tag": "hpbx_mins_direction","path": "*exp.hpbx_mins_direction","type": "*variable","value": "~*req.Category"},
            {"tag": "hpbx_mins_type","path": "*exp.hpbx_mins_type","type": "*constant","value": "local"}
          ],
          "opts": {
                "httpParameters": {
                  "method": "POST",
                  "headers": {
                    "Content-Type": "application/json",
                  },
                  "body": {
                      "event": {
                            "transaction_id": "~*exp.transaction_id",
                            "external_subscription_id": "~*exp.external_subscription_id",
                            "code": "~*exp.code",
                            "precise_total_amount_cents": "~*exp.precise_total_amount_cents",
                            "properties": {
                                "hpbx_mins_count": "~*exp.hpbx_mins_count",
                                "hpbx_mins_direction": "~*exp.hpbx_mins_direction",
                                "hpbx_mins_type": "~*exp.hpbx_mins_type"
                            }  
                        }
                    }
                }
            }
        }
    ]
}

The "opts {}" block is something I'm not very sure about here, and thats exactly where I'm stuck right now. I used this example in one of these other recent threads here https://groups.google.com/g/cgrates/c/sKJwSHSZpqs where the user shared their own EES config. Is "opts {}" even a valid config block that CGrateS expects in the EES config? The way I thought this will work was that the "fields [ ]" will be used to extract the values from the CDR event, and then those values can be used in the "opts {}" body parameter to structure the JSON payload how I want it (In my case a nested JSON payload).

I've tried using both "*http_post" and "*http_json_map" for type, and both times the payload that came out was what's defined/composed in the "field [ ]" block, and not how I structured it in the "opts{}" block's body parameter.

With type "*http_post"
code=hpbx_mins_usage&external_subscription_id=CUSTOMER006&hpbx_mins_count=0.13333333333333333&hpbx_mins_direction=call-out&hpbx_mins_type=local&precise_total_amount_cents=00000.4&transaction_id=0277dcce-8f8b-123e-9394-bc2411256e4a

With type "*http_json_map"
{
  "code": "hpbx_mins_usage",
  "external_subscription_id": "CUSTOMER006",
  "hpbx_mins_count": "0.05",
  "hpbx_mins_direction": "call-out",
  "hpbx_mins_type": "local",
  "precise_total_amount_cents": "0000.15",
  "transaction_id": "22cc08ac-8f8a-123e-9394-bc2411256e4a"
}

Can you please help me how and if I should be using this "opts" block in my EES config or not? and if "opts" is not the correct way of doing this, then how can I structure the JSON payload the way I want it to be?

Thanks,
Sal

Armir Veliaj

unread,
Apr 10, 2025, 8:57:04 AMApr 10
to CGRateS
Hi Sal,

Your config for EES is not aligned with our template of EEs as we have: https://github.com/cgrates/cgrates/blob/c186952aa9fcc832d3e34b5b5c4f96d627d15a9e/config/config_defaults.go#L515C1-L645C3.
For the moment we don't support nested parameters, so you have to keep export event at one level only.

Thanks,
Armir

Salvinder Parhar

unread,
Apr 10, 2025, 10:05:38 AMApr 10
to CGRateS
Thank you for your response Armir and confirming that nested parameters are not supported right now. Yes, I was aware about my EES config above not really aligned with the expected CGrateS config syntax for EES, but that was only because I saw someone else using it that way in another thread, and I was only trying to see if it will work in my case or not. 
Can you please let me know if there's already a feature request for nested parameters support in EES or should I open one? I didn't find any in github issues. 

Thanks,
Sal

Armir Veliaj

unread,
Apr 11, 2025, 8:45:38 AMApr 11
to CGRateS
Hi Sal,

Yes, feel free to open it as a feature request on GitHub, since it hasn’t been requested before.
Maybe it can be considered for a future implementation.

Thanks,
Armir

Salvinder Parhar

unread,
Apr 11, 2025, 11:03:00 AMApr 11
to CGRateS
Thank you Armir. I've opened a github feature request for this. https://github.com/cgrates/cgrates/issues/4720
I hope more people support this feature request and it makes it to the project roadmap soon.

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