diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index f9204d666..960fa7070 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -269,7 +269,35 @@ {"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage"}, {"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}, ], - } + }, + { + "id": "CSVMaskedDestination", + "type": "*file_csv", + "export_path": "/tmp/testCSVMasked", + "tenant": "cgrates.org", + "flags": ["*attributes"], + "attribute_context": "customContext", + "attempts": 1, + "field_separator": ",", + "filters": ["*string:~*req.ExporterUsed:CSVMaskedDestination"], + "fields":[ + {"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": "OriginID", "path": "*exp.OriginID", "type": "*variable", "value": "~*req.OriginID"}, + {"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": "*masked_destination", + "value": "~*req.Destination", "mask_destinationd_id": "MASKED_DESTINATIONS", "mask_length": 3}, + {"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}"}, + ], + }, ] }, diff --git a/ees/eereq.go b/ees/eereq.go index 3004740e3..3a92aa4aa 100644 --- a/ees/eereq.go +++ b/ees/eereq.go @@ -363,10 +363,9 @@ func (eeR *EventExporterRequest) ParseField( if dst, err := eeR.req.FieldAsString([]string{utils.Destination}); err != nil { return nil, fmt.Errorf("error <%s> getting destination for %s", err, utils.ToJSON(cfgFld)) - } else if len(cfgFld.MaskDestID) != 0 && engine.CachedDestHasPrefix(cfgFld.MaskDestID, dst) { - out = "1" - } else { - out = "0" + } else if cfgFld.MaskLen != -1 && len(cfgFld.MaskDestID) != 0 && + engine.CachedDestHasPrefix(cfgFld.MaskDestID, dst) { + out = utils.MaskSuffix(dst, cfgFld.MaskLen) } } diff --git a/ees/filecsv_it_test.go b/ees/filecsv_it_test.go index 9c5169a66..4598f1523 100644 --- a/ees/filecsv_it_test.go +++ b/ees/filecsv_it_test.go @@ -54,6 +54,8 @@ var ( testCsvVerifyExports, testCsvExportComposedEvent, testCsvVerifyComposedExports, + testCsvExportMaskedDestination, + testCsvVerifyMaskedDestination, testStopCgrEngine, testCleanDirectory, } @@ -326,3 +328,68 @@ func testCsvVerifyComposedExports(t *testing.T) { t.Errorf("Expecting: \n<%q>, \nreceived: \n<%q>", eCnt, string(outContent1)) } } + +func testCsvExportMaskedDestination(t *testing.T) { + + attrs := utils.AttrSetDestination{Id: "MASKED_DESTINATIONS", Prefixes: []string{"+4986517174963"}} + var reply string + if err := csvRpc.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil { + t.Error("Unexpected error", err.Error()) + } else if reply != utils.OK { + t.Error("Unexpected reply returned", reply) + } + + eventVoice := &utils.CGREventWithOpts{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "voiceEvent", + Time: utils.TimePointer(time.Now()), + Event: map[string]interface{}{ + utils.CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), + utils.ToR: utils.VOICE, + utils.OriginID: "dsafdsaf", + utils.OriginHost: "192.168.1.1", + utils.RequestType: utils.META_RATED, + utils.Tenant: "cgrates.org", + utils.Category: "call", + utils.Account: "1001", + utils.Subject: "1001", + utils.Destination: "+4986517174963", + utils.SetupTime: time.Unix(1383813745, 0).UTC(), + utils.AnswerTime: time.Unix(1383813746, 0).UTC(), + utils.Usage: time.Duration(10) * time.Second, + utils.RunID: utils.MetaDefault, + utils.Cost: 1.01, + "ExporterUsed": "CSVMaskedDestination", + }, + }, + } + if err := csvRpc.Call(utils.EventExporterSv1ProcessEvent, eventVoice, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("Expected %+v, received: %+v", utils.OK, reply) + } + time.Sleep(1 * time.Second) +} + +func testCsvVerifyMaskedDestination(t *testing.T) { + var files []string + err := filepath.Walk("/tmp/testCSVMasked/", func(path string, info os.FileInfo, err error) error { + if strings.HasSuffix(path, utils.CSVSuffix) { + files = append(files, path) + } + return nil + }) + if err != nil { + t.Error(err) + } + if len(files) != 1 { + t.Errorf("Expected %+v, received: %+v", 1, len(files)) + } + eCnt := "dbafe9c8614c785a65aabd116dd3959c3c56f7f6,*default,*voice,dsafdsaf,*rated,cgrates.org,call,1001,1001,+4986517174***,2013-11-07T08:42:25Z,2013-11-07T08:42:26Z,10000000000,1.01\n" + if outContent1, err := ioutil.ReadFile(files[0]); err != nil { + t.Error(err) + } else if eCnt != string(outContent1) { + t.Errorf("Expecting: \n<%q>, \nreceived: \n<%q>", eCnt, string(outContent1)) + } +} diff --git a/ees/lib_test.go b/ees/lib_test.go index f4a06c2ae..52dddd657 100644 --- a/ees/lib_test.go +++ b/ees/lib_test.go @@ -49,7 +49,7 @@ func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { } } -var exportPath = []string{"/tmp/testCSV", "/tmp/testComposedCSV", "/tmp/testFWV"} +var exportPath = []string{"/tmp/testCSV", "/tmp/testComposedCSV", "/tmp/testFWV", "/tmp/testCSVMasked"} func testCreateDirectory(t *testing.T) { for _, dir := range exportPath {