Rerating CDRs in CGrateS

There’s a bunch of reasons you might want to re-rate CDRs in CGrateS.

For me recently I wanted to introduce StatS to process historical CDR data, and I’d messed up some rates and wanting to correct it without deleting the existing data.

We can re-rate CDRs with the *rerate flag like so:

{
  "method": "CDRsV1.RateCDRs",
  "params": [
    {
        "Flags": ["*rerate", "*cdrs"],
        "SetupTimeStart": "2024-01-01 00:00:00",
        "SetupTimeEnd": "2024-01-05 00:00:00",
        "Tenants": ["cgrates.org"],
        "Categories": ["call"]
    }
  ],
  "id": 0
}

Something to be aware of that’s tripped me up, is that if while re-rating any of the CDRs fails, CGrateS will stop rating the CDRs after it. For example if you get something like this:

{'method': 'CDRsV1.RateCDRs', 'params': [{'Flags': ['*rerate', '*stats'], 'SetupTimeStart': '2025-01-01 00:00:00', 'SetupTimeEnd': '2025-01-28 23:59:59', 'Limit': 10}]}


{'error': 'SERVER_ERROR: PARTIALLY_EXECUTED', 'id': None, 'result': None}

Then the full list of CDRs you’ve requested to be re-rated won’t have been re-rated, only the CDRs up to the error, then CGrateS will stop processing the records after it.

So keep an eye on ngrep and make sure you’ve got all your rates and destinations defined correctly, I found putting:

{
"method": "CDRsV1.RateCDRs",
"params": [
{
"Flags": ["*rerate", "*cdrs"],
"SetupTimeStart": "2024-01-01 00:00:00",
"SetupTimeEnd": "2024-01-05 00:00:00",
"Tenants": ["cgrates.org"],
"Categories": ["call"],
"NotCosts" : [-1, 0]
}
],
"id": 0
}

To filter out any CDRs with a -1 cost in the CDR filters means I filter out any CDRs that had failed to rate last time (Assuming you don’t want to fix CDRs that have failed to get rated).

Leave a Reply

Your email address will not be published. Required fields are marked *