Getting NumberOfEvents, TotalDuration, TotalCost EES

47 views
Skip to first unread message

selim jabou

unread,
Jul 1, 2025, 12:52:55 PMJul 1
to CGRateS
Hello, i hope you are doing fine, i need some help please. I am trying to export some data using the EES, i want to export the data in JSON format, so i am using " "type": "*http_json_map" ". I want to get the NumberOfEvents, TotalDuration, TotalCost( will call them stats) of the events(CDRs) but it does not give me a correct value, it just gives me the stats of the last CDR ( NumberOfEvents = 1,  TotalDuration = Usage,  TotalCost= cost of the call). However the same functionality works when i export the EES in CSV format. here is an example, and the config : 

here is the CONFIG.JSON : 
{
    "general": {
        "log_level": 15,
        "node_id": "DIGIVOIP BILLING SYSTEM",
        "default_tenant": "DIGIVOIP",
        "poster_attempts": 1
    },
    "listen": {
        "rpc_json": ":2012",
        "rpc_gob": ":2013",
        "http": ":2080",
        "http_tls": ":2280"
    },
    "tls": {
        "server_certificate": "/etc/cgrates/ssl/fullchain.pem",
        "server_key": "/etc/cgrates/ssl/privkey.pem",
        "client_certificate" : "",
        "client_key":"",
        "ca_certificate":"" ,
        "server_policy":0,
        "server_name":"cg.digivoip.fr"
    },
    "stor_db": {
        "db_password": "CGRateS.org"
    },
    "schedulers": {
        "enabled": true,
        "cdrs_conns": ["*localhost"]
    },

    "rals": {
        "enabled": true,
        "thresholds_conns": ["*localhost"],
        "stats_conns": ["*localhost"]
    },
    "cdrs": {
        "enabled": true,
        "stats_conns": ["*localhost"],
        "chargers_conns": ["*localhost"],
        "attributes_conns": ["*localhost"],
        "rals_conns": ["*localhost"],
        "sessions_cost_retries": 5
    },
   
    "chargers": {
        "enabled": true,
        "attributes_conns": ["*localhost"]
    },
    "sessions": {
        "enabled": true,
        "rals_conns": ["*localhost"],
        "cdrs_conns": ["*localhost"],
        "resources_conns": ["*localhost"],
        "routes_conns": ["*localhost"],
        "attributes_conns": ["*localhost"],
        "stats_conns": ["*localhost"],
        "thresholds_conns": ["*localhost"],
        "chargers_conns": ["*localhost"],
        "debit_interval": "5s",
        "channel_sync_interval": "5s"
    },
    "freeswitch_agent": {
        "enabled": true,
        "event_socket_conns": [
            {"address": "172.16.2.101:8021", "password": "ClueCon", "reconnects": -1, "alias": "fs1.digivoip.fr"},
            {"address": "172.16.2.102:8021", "password": "ClueCon", "reconnects": -1, "alias": "fs2.digivoip.fr"}
        ],
        "sessions_conns": ["*birpc_internal"],
        "extra_fields": [
            "~*req.Caller-Caller-ID-Name",
            "~*req.Caller-Callee-ID-Number",
            "~*req.variable_caller_id_name",
            "~*req.variable_caller_id_number",
            "~*req.Caller-Channel-Hangup-Time",
            "~*req.Call-Direction"
        ],
        "create_cdr": true
    },

    "filters": {
        "enabled": true,
        "apiers_conns": ["*localhost"],
        "ees_conns":    ["*localhost"]
        },


    "attributes": {
        "enabled": true,
        "stats_conns": ["*localhost"],
        "resources_conns": ["*localhost"],
        "apiers_conns": ["*localhost"],
        "ees_conns":    ["*localhost"]
    },
    "resources": {
        "enabled": true,
        "string_indexed_fields": ["*req.Account"]
    },
    "stats": {
        "enabled": true,
        "store_interval": "0",
        "indexed_selects": false
    },
    "thresholds": {
        "enabled": true,
        "string_indexed_fields": ["*req.Account"]
    },
    "routes": {
        "enabled": true,
        "resources_conns": ["*localhost"],
        "stats_conns": ["*localhost"],
        "rals_conns": ["*localhost"],
        "string_indexed_fields": ["*req.Account"]
    },
    "apiers": {
        "enabled": true,
        "scheduler_conns": ["*localhost"],
        "ees_conns": ["*localhost"]
    },
    "ees": {
        "enabled": true,
        "attributes_conns": ["*localhost"],
        "filters_conns":    ["*localhost"],
        "cache": {
            "*file_csv": {
                "limit": -1,
                "ttl": "1s",
                "static_ttl": false
            }
        },
        "exporters": [
        {
                "id": "HTTPJsonMapExporter",
                "type": "*http_json_map",
                "filters": [],
                "synchronous": true,

                "export_path": "http://172.16.2.110/event_json_map_http",
                "fields": [
                    {"tag": "Number", "path": "*exp.Number", "type": "*variable", "value": "~*dc.NumberOfEvents"},
                    {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"},
                    {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"},
                    {"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"},
            {"tag": "DestinationID", "path": "*exp.Destination", "type": "*variable", "value": "~*ec.Charges[0].Rating.RatingFilter.DestinationID"},
                    {"tag": "RequestType", "path": "*exp.RequestType", "type": "*variable", "value": "~*req.RequestType"},
                    {"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*req.Tenant"},
                    {"tag": "Category", "path": "*exp.Category", "type": "*variable", "value": "~*req.Category"},
                    {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"},
                    {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"},
                    {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"},
                    {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime", "layout": "2006-01-02T15:04:05Z07:00"},
                    {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime", "layout": "2006-01-02T15:04:05Z07:00"},
                    {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage"},
                    {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"},
                    {"tag": "RatingPlan", "path": "*exp.RatingPlan", "type": "*variable", "value": "~*ec.Charges[0].Rating.RatingFilter.RatingPlanID"},
                    {"tag": "RatingPlanSubject", "path": "*exp.RatingPlanSubject", "type": "*variable", "value": "~*ec.Charges[0].Rating.RatingFilter.Subject"},
   
                    {"tag": "NumberOfEvents", "path": "*trl.NumberOfEvents", "type": "*variable", "value": "~*dc.NumberOfEvents"},
                    {"tag": "TotalDuration", "path": "*trl.TotalDuration", "type": "*variable", "value": "~*dc.TotalDuration"},
                    {"tag": "TotalCost", "path": "*trl.TotalCost", "type": "*variable", "value": "~*dc.TotalCost{*round:4}"}
                   
                ]
            },
            {
                "id": "CSVExporter",
                "type": "*file_csv",
                "filters": [],
                "synchronous": true,

                "export_path": "/home/export",
                "opts": {
                    "csvFileName": "CSVExporter_works.csv",
                    "csvAppend": false,
                    "csvFieldSeparator": ","
                },
                "fields": [
                    {"tag": "Number", "path": "*exp.Number", "type": "*variable", "value": "~*dc.NumberOfEvents"},
                    {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"},
                    {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"},
                    {"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"},
            {"tag": "DestinationID", "path": "*exp.Destination", "type": "*variable", "value": "~*ec.Charges[0].Rating.RatingFilter.DestinationID"},
                    {"tag": "RequestType", "path": "*exp.RequestType", "type": "*variable", "value": "~*req.RequestType"},
                    {"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*req.Tenant"},
                    {"tag": "Category", "path": "*exp.Category", "type": "*variable", "value": "~*req.Category"},
                    {"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"},
                    {"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"},
                    {"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"},
                    {"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime", "layout": "2006-01-02T15:04:05Z07:00"},
                    {"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime", "layout": "2006-01-02T15:04:05Z07:00"},
                    {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage"},
                    {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"},
                    {"tag": "RatingPlan", "path": "*exp.RatingPlan", "type": "*variable", "value": "~*ec.Charges[0].Rating.RatingFilter.RatingPlanID"},
                    {"tag": "RatingPlanSubject", "path": "*exp.RatingPlanSubject", "type": "*variable", "value": "~*ec.Charges[0].Rating.RatingFilter.Subject"},

                    {"tag": "NumberOfEvents", "path": "*trl.NumberOfEvents", "type": "*variable", "value": "~*dc.NumberOfEvents"},
                    {"tag": "TotalDuration", "path": "*trl.TotalDuration", "type": "*variable", "value": "~*dc.TotalDuration"},
                    {"tag": "TotalCost", "path": "*trl.TotalCost", "type": "*variable", "value": "~*dc.TotalCost{*round:4}"}
                ]

            },
            {
"id": "HTTPPostExporter",
"type": "*http_post",
"export_path": "http://172.16.2.110/event_json_map_http",
"flags": ["*attributes"],
"attribute_context": "customContext",
"attempts": 1,
"fields":[

]
}
                 ]
    }

}

here is the export functionality for the JSON Export: 
{
    "method": "APIerSv1.ExportCDRs",
    "params": [
        {
            "ExporterIDs": ["HTTPJsonMapExporter"],
            "Verbose": true,
            "SetupTimeStart": "",
            "SetupTimeEnd": "",
            "Destinations": [],
            "Accounts": ["OPTIMIS"],
            "Subjects": [],
            "Tenants": ["DIGIVOIP"]
        }  
    ]
}  


here is the result of the postman(verbose : true ):
{
    "id": null,
    "result": {
        "HTTPJsonMapExporter": {
            "FirstEventATime": "2025-07-01T08:00:00+01:00",
            "FirstExpOrderID": 359,
            "LastEventATime": "2025-07-01T08:00:00+01:00",
            "LastExpOrderID": 359,
            "NegativeExports": [],
            "NumberOfEvents": 1,
            "PositiveExports": [
                "022d199"
            ],
            "TimeNow": "2025-07-01T17:45:00.19511431+01:00",
            "TotalCost": 1
        }
    },
    "error": null
}
here is the JSON file( i deleted some lines)  : 
{"Account":"OPTIMIS","AnswerTime":"0001-01-01T00:00:00Z","CGRID":"010ccc0fa3033d03b9610083d3ce4deb66d49c65","Category":"CALL-OUT","Cost":"0","Destination":"33184140117","Number":"1","RequestType":"*prepaid","RunID":"*default","SetupTime":"2025-06-15T10:54:01+01:00","Subject":"FRANCE_STANDARD_PACK1","Tenant":"DIGIVOIP","ToR":"*voice","Usage":"0"}
{"Account":"OPTIMIS","AnswerTime":"2025-06-15T10:59:54+01:00","CGRID":"aa9e6dfd10e4405c19ce4a0b1767091230affb9a","Category":"SUPPLIER-OUT","Cost":"0.0007","Destination":"33184140117","Number":"1","RatingPlan":"SUPPLIER_OUT_1","RatingPlanSubject":"*out:DIGIVOIP:SUPPLIER-OUT:*any","RequestType":"*rated","RunID":"SupplierCharger-OUT","SetupTime":"2025-06-15T10:59:45+01:00","Subject":"FRANCE_STANDARD_PACK1","Tenant":"DIGIVOIP","ToR":"*voice","Usage":"12000000000"}
{"Account":"OPTIMIS","AnswerTime":"2025-06-15T10:59:54+01:00","CGRID":"aa9e6dfd10e4405c19ce4a0b1767091230affb9a","Category":"CALL-OUT","Cost":"0.2","Destination":"33184140117","Number":"1","RatingPlan":"FRANCE_STANDARD","RatingPlanSubject":"*out:DIGIVOIP:CALL-OUT:FRANCE_STANDARD_PACK1","RequestType":"*prepaid","RunID":"*default","SetupTime":"2025-06-15T10:59:45+01:00","Subject":"FRANCE_STANDARD_PACK1","Tenant":"DIGIVOIP","ToR":"*voice","Usage":"12000000000"}
{"Account":"OPTIMIS","AnswerTime":"2025-06-15T11:25:09+01:00","CGRID":"43ebf61b24f233864eddd7670b8afbf3bb45783d","Category":"SUPPLIER-OUT","Cost":"0.001","Destination":"33184140117","Number":"1","RatingPlan":"SUPPLIER_OUT_1","RatingPlanSubject":"*out:DIGIVOIP:SUPPLIER-OUT:*any","RequestType":"*rated","RunID":"SupplierCharger-OUT","SetupTime":"2025-06-15T11:25:00+01:00","Subject":"FRANCE_STANDARD_PACK1","Tenant":"DIGIVOIP","ToR":"*voice","Usage":"17000000000"}
{"Account":"OPTIMIS","AnswerTime":"0001-01-01T00:00:00Z","CGRID":"f5d9de394c9941a53552cdbb8c17853b0583b690","Category":"CALL-OUT","Cost":"0","Destination":"33184140117","Number":"1","RequestType":"*prepaid","RunID":"*default","SetupTime":"2025-06-27T08:47:22+01:00","Subject":"FRANCE_STANDARD_PACK1","Tenant":"DIGIVOIP","ToR":"*voice","Usage":"0"}
{"Account":"OPTIMIS","AnswerTime":"2025-07-01T08:00:00+01:00","CGRID":"f4521dd33de3c3084906ee9dfb0e5d177a12a1d2","Category":"call","Cost":"1","Destination":"","Number":"1","RequestType":"*none","RunID":"*debit","SetupTime":"2025-07-01T08:00:00+01:00","Subject":"OPTIMIS","Tenant":"DIGIVOIP","ToR":"*monetary","Usage":"1"}



now the CSV, here is the api : 
{
    "method": "APIerSv1.ExportCDRs",
    "params": [
        {
            "ExporterIDs": ["CSVExporter"],
            "Verbose": true,
            "SetupTimeStart": "",
            "SetupTimeEnd": "",
            "Destinations": [],
            "Accounts": ["OPTIMIS"],
            "Subjects": [],
            "Tenants": ["DIGIVOIP"]
        }  
    ]
}  
 
response api : 
{
    "id": null,
    "result": {
        "CSVExporter": {
            "ExportPath": "/home/export/CSVExporter_5ffc38c.csv",
            "FirstEventATime": "2025-07-01T08:00:00+01:00",
            "FirstExpOrderID": 7,
            "LastEventATime": "2025-07-01T08:00:00+01:00",
            "LastExpOrderID": 359,
            "NegativeExports": [],
            "NumberOfEvents": 107,
            "PositiveExports": [
                "52bd4a5",
                "1e24810",
                "9437187",
                "32de56e",
                "782bcdc",
                "a889f1a",
                "0c1aa2c",
                "f4f40d3",
                "81d417b",
                "3073e11",
                "c136a17",
                "f8d4ed2",
                "58907c8",
                "6873f3b",
                "49fdf3f",
                "7883366",
                "1f5e82b",
                "31b9c8f",
                "b9f30e8",
                "4fd0a89",
                "3da8433",
                "197e4a9",
                "7c8e46c",
                "e6f25e2",
                "1e9c51a",
                "4c04328",
                "a9f79ad",
                "12c7544",
                "a1f5c1e",
                "bd19a22",
                "a5e22eb",
                "7525a82",
                "a43a946",
                "2bdfa3c",
                "38d17ff",
                "9cc208c",
                "6d0fa61",
                "a9c0755",
                "d19d5a7",
                "5919a3a",
                "871745f",
                "4f67a5e",
                "8ad7db4",
                "f412554",
                "88533da",
                "60dfb68",
                "be88519",
                "656d75c",
                "bf76825",
                "ef9df7c",
                "19392d4",
                "5ffd23d",
                "7ab32d7",
                "f33d69f",
                "9065ab9",
                "1448351",
                "69f4404",
                "edc040c",
                "46f7147",
                "e0c78a4",
                "e8e4e31",
                "61f67db",
                "a965bf1",
                "7f70e18",
                "50beea1",
                "fec47e2",
                "8d5150b",
                "0e2ba0b",
                "c6c1adf",
                "4a73d4a",
                "d235a4b",
                "1a8e7ee",
                "1a3c679",
                "b30bd43",
                "d06ed59",
                "716c54b",
                "837ee0e",
                "6a84797",
                "67dfc13",
                "27a1900",
                "81480b4",
                "4e7dd0f",
                "ae43230",
                "c121c80",
                "0e72378",
                "2491468",
                "1154b80",
                "beb38ec",
                "1e6f714",
                "52b1bee",
                "59d7c98",
                "6e63a7f",
                "8142524",
                "a63edba",
                "2fb1ac4",
                "2575049",
                "6beb980",
                "cc5258b",
                "6dfdd7e",
                "4bb9ea6",
                "2bc9c10",
                "41658f7",
                "abe752b",
                "301a018",
                "61a18c3",
                "4a892cd",
                "9ddfce6"
            ],
            "TimeNow": "2025-07-01T17:49:05.178832223+01:00",
            "TotalCost": 107.08600000000003,
            "TotalDuration": 608000000001
        }
    },
    "error": null
}


File CSV (deleted some lines): 
1,0141645cb7e3c7d3bdb6a9ae79ee7743fb07cc47,*default,*voice,*prepaid,DIGIVOIP,CALL-OUT,OPTIMIS,FRANCE_STANDARD_PACK1,33184140117,2025-04-14T14:58:58+01:00,0001-01-01T00:00:00Z,0,0
106,f5d9de394c9941a53552cdbb8c17853b0583b690,*default,*voice,*prepaid,DIGIVOIP,CALL-OUT,OPTIMIS,FRANCE_STANDARD_PACK1,33184140117,2025-06-27T08:47:22+01:00,0001-01-01T00:00:00Z,0,0
107,f4521dd33de3c3084906ee9dfb0e5d177a12a1d2,*debit,*monetary,*none,DIGIVOIP,call,OPTIMIS,OPTIMIS,,2025-07-01T08:00:00+01:00,2025-07-01T08:00:00+01:00,1,1

107,10m8.000000001s,107.086


as seen in this example, i want to get : 
"NumberOfEvents": 107
"TotalCost": 107.08600000000003,
"TotalDuration": 608000000001

which are found in the csv file but not in the json. 

Armir Veliaj

unread,
Jul 4, 2025, 11:35:32 AMJul 4
to CGRateS
Hi Selim,

There was a misconfiguration in your json file. When using *http_json_map, it calculates only the latest CDRs because we compute metrics only when exporters are cached. In your config, you cached only the CSV exporters, which is why it works for that. You need to cache the same for *http_json_map as well, and then it will work correctly, like this:



{
  "method": "APIerSv1.ExportCDRs",
  "params": [{
    "ExporterIDs": ["HTTPJsonMapExporter"],
    "RunID": "",

    "Verbose": true,
    "SetupTimeStart": "",
    "SetupTimeEnd": "",
    "Destinations": [],
    "Accounts": ["1001"],
    "Subjects": [],
    "Tenants": ["cgrates.org"]
  }]
}

{
  "id": null,
  "result": {
    "HTTPJsonMapExporter": {
      "FirstEventATime": "2024-07-17T05:03:19-04:00",
      "FirstExpOrderID": 1,
      "LastEventATime": "2024-07-17T10:00:05-04:00",
      "LastExpOrderID": 6,
      "NegativeExports": [],
      "NumberOfEvents": 6,
      "PositiveExports": [
        "af2ff29",
        "4b644e1",
        "7c801e6",
        "5aed966",
        "b0a39d1",
        "f1200a4"
      ],
      "TimeNow": "2025-07-02T15:53:30.096887258-04:00",
      "TotalCost": 1.0665,
      "TotalDuration": 558000001400
    }
  },
  "error": null
}




Thanks,
Armir

selim jabou

unread,
Jul 4, 2025, 12:37:12 PMJul 4
to CGRateS
ah okay, thank you Armir, it works .
Reply all
Reply to author
Forward
0 new messages