diff --git a/data/conf/samples/ers_internal/cgrates.json b/data/conf/samples/ers_internal/cgrates.json index a6847aef3..46419d9d0 100644 --- a/data/conf/samples/ers_internal/cgrates.json +++ b/data/conf/samples/ers_internal/cgrates.json @@ -499,9 +499,9 @@ "processed_path": "/tmp/flatstoreMMErs/out", "flags": ["*cdrs"], "fields":[ - {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatStoreACK", "mandatory": true}, + {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatstoreMMErs", "mandatory": true}, {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable","value":"~*req.4;~*req.2;~*req.3", "mandatory": true}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*postpaid", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, + {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*none", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.14", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, @@ -514,7 +514,7 @@ {"tag": "Invite", "path": "*opts.invite", "type": "*constant", "value": "true", "filters":["*string:~*req.1:INVITE"]}, {"tag": "Bye", "path": "*opts.bye", "type": "*constant", "value": "true", "filters":["*string:~*req.1:BYE"]}, {"tag": "Ack", "path": "*opts.ack", "type": "*constant", "value": "true", "filters":["*string:~*req.1:ACK"]}, - {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.1"}, + {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.0"}, {"tag": "Partial", "path": "*opts.*partial", "type": "*constant", "value": "false", "filters": ["*string:~*req.1:CANCEL"]}, {"tag": "Usage", "path": "*cgreq.Usage", "type": "*constant","value": "0", "mandatory": true, "filters": ["*string:~*req.1:CANCEL"]}, diff --git a/data/conf/samples/ers_mongo/cgrates.json b/data/conf/samples/ers_mongo/cgrates.json index a9b995894..783a81eb1 100644 --- a/data/conf/samples/ers_mongo/cgrates.json +++ b/data/conf/samples/ers_mongo/cgrates.json @@ -501,9 +501,9 @@ "processed_path": "/tmp/flatstoreMMErs/out", "flags": ["*cdrs"], "fields":[ - {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatStoreACK", "mandatory": true}, + {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatstoreMMErs", "mandatory": true}, {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable","value":"~*req.4;~*req.2;~*req.3", "mandatory": true}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*postpaid", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, + {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*none", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.14", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, @@ -516,7 +516,7 @@ {"tag": "Invite", "path": "*opts.invite", "type": "*constant", "value": "true", "filters":["*string:~*req.1:INVITE"]}, {"tag": "Bye", "path": "*opts.bye", "type": "*constant", "value": "true", "filters":["*string:~*req.1:BYE"]}, {"tag": "Ack", "path": "*opts.ack", "type": "*constant", "value": "true", "filters":["*string:~*req.1:ACK"]}, - {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.1"}, + {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.0"}, {"tag": "Partial", "path": "*opts.*partial", "type": "*constant", "value": "false", "filters": ["*string:~*req.1:CANCEL"]}, {"tag": "Usage", "path": "*cgreq.Usage", "type": "*constant","value": "0", "mandatory": true, "filters": ["*string:~*req.1:CANCEL"]}, diff --git a/data/conf/samples/ers_mysql/cgrates.json b/data/conf/samples/ers_mysql/cgrates.json index a7da2f2a9..a7fe350c9 100644 --- a/data/conf/samples/ers_mysql/cgrates.json +++ b/data/conf/samples/ers_mysql/cgrates.json @@ -498,24 +498,24 @@ "processed_path": "/tmp/flatstoreMMErs/out", "flags": ["*cdrs"], "fields":[ - {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatStoreACK", "mandatory": true}, + {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatstoreMMErs", "mandatory": true}, {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable","value":"~*req.4;~*req.2;~*req.3", "mandatory": true}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*postpaid", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, - {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, - {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, - {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.14", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, - {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.7", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, - {"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.7", "mandatory": true,"filters": ["*string:~*req.1:ACK"]}, - {"tag": "EndTime", "path": "*cgreq.EndTime", "type": "*variable","value": "~*req.7", "mandatory": true, "filters": ["*string:~*req.1:BYE"]}, + {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*none", "mandatory": true}, + {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE|CANCEL"]}, + {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE|CANCEL"]}, + {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.14", "mandatory": true,"filters": ["*string:~*req.1:INVITE|CANCEL"]}, + {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.7", "mandatory": true,"filters": ["*string:~*req.1:INVITE|CANCEL"]}, + {"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.7", "mandatory": true,"filters": ["*string:~*req.1:ACK|CANCEL"]}, + {"tag": "EndTime", "path": "*cgreq.EndTime", "type": "*variable","value": "~*req.7", "mandatory": true, "filters": ["*string:~*req.1:BYE|CANCEL"]}, {"tag": "DisconnectCause", "path": "*cgreq.DisconnectCause", "type": "*variable", "value": "~*req.5; ;~*req.6", "mandatory": true}, {"tag": "DialogId", "path": "*cgreq.DialogId", "type": "*variable", "value": "~*req.12"}, {"tag": "Partial", "path": "*opts.*partial", "type": "*constant", "value": "true", "filters": ["*notstring:~*req.1:CANCEL"]}, {"tag": "Invite", "path": "*opts.invite", "type": "*constant", "value": "true", "filters":["*string:~*req.1:INVITE"]}, {"tag": "Bye", "path": "*opts.bye", "type": "*constant", "value": "true", "filters":["*string:~*req.1:BYE"]}, {"tag": "Ack", "path": "*opts.ack", "type": "*constant", "value": "true", "filters":["*string:~*req.1:ACK"]}, - {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.1"}, + {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.0"}, - {"tag": "Partial", "path": "*opts.*partial", "type": "*constant", "value": "false", "filters": ["*string:~*req.1:CANCEL"]}, + //{"tag": "Partial", "path": "*opts.*partial", "type": "*constant", "value": "false", "filters": ["*string:~*req.1:CANCEL"]}, {"tag": "Usage", "path": "*cgreq.Usage", "type": "*constant","value": "0", "mandatory": true, "filters": ["*string:~*req.1:CANCEL"]}, ], diff --git a/data/conf/samples/ers_postgres/cgrates.json b/data/conf/samples/ers_postgres/cgrates.json index 1bb06eb52..d7ba24cd8 100644 --- a/data/conf/samples/ers_postgres/cgrates.json +++ b/data/conf/samples/ers_postgres/cgrates.json @@ -495,9 +495,9 @@ "processed_path": "/tmp/flatstoreMMErs/out", "flags": ["*cdrs"], "fields":[ - {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatStoreACK", "mandatory": true}, + {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*constant","value":"flatstoreMMErs", "mandatory": true}, {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable","value":"~*req.4;~*req.2;~*req.3", "mandatory": true}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*postpaid", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, + {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", "value": "*none", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.8", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.14", "mandatory": true,"filters": ["*string:~*req.1:INVITE"]}, @@ -510,7 +510,7 @@ {"tag": "Invite", "path": "*opts.invite", "type": "*constant", "value": "true", "filters":["*string:~*req.1:INVITE"]}, {"tag": "Bye", "path": "*opts.bye", "type": "*constant", "value": "true", "filters":["*string:~*req.1:BYE"]}, {"tag": "Ack", "path": "*opts.ack", "type": "*constant", "value": "true", "filters":["*string:~*req.1:ACK"]}, - {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.1"}, + {"tag": "Order", "path": "*opts.orderID", "type": "*variable", "value": "~*req.0"}, {"tag": "Partial", "path": "*opts.*partial", "type": "*constant", "value": "false", "filters": ["*string:~*req.1:CANCEL"]}, {"tag": "Usage", "path": "*cgreq.Usage", "type": "*constant","value": "0", "mandatory": true, "filters": ["*string:~*req.1:CANCEL"]}, diff --git a/ers/flatstore_it_test.go b/ers/flatstore_it_test.go index 522957faf..d9e05098a 100644 --- a/ers/flatstore_it_test.go +++ b/ers/flatstore_it_test.go @@ -70,6 +70,14 @@ INVITE|3111f3c9|49ca4c42|a58ebaae40d08d6757d8424fb09c4c54@0:0:0:0:0:0:0:0|200|OK ACK|3111f3c9|49ca4c42|a58ebaae40d08d6757d8424fb09c4c54@0:0:0:0:0:0:0:0|200|OK|1436454690|*prepaid|1001|1002||3099:1909036290|flatstore"1.0 BYE|3111f3c9|49ca4c42|a58ebaae40d08d6757d8424fb09c4c54@0:0:0:0:0:0:0:0|200|OK|1436454692|||||3099:1909036290|flatstore"1.0` + ackSuccessfull2 = `"1","INVITE","CG123456789-1","123456789","CGqwerty-asd5sdf456s1f53a1sf51s648486h4et86h46","200","OK","2021-06-01 00:00:09","1001","1001@192.168.56.203","192.168.56.203","192.168.56.20","sip:1001@192.168.56.203:5060;transport=UDP","1002","1002","local","1","test" +"2","ACK","CG123456789-1","123456789","CGqwerty-asd5sdf456s1f53a1sf51s648486h4et86h46","200","OK","2021-06-01 00:00:09","1001","1001@192.168.56.203","192.168.56.203","192.168.56.20",,"1002","1002","192.168.57.203","1","test" +"3","INVITE","CG123456789-2","123456799","CGqwerty-56dfghs56hj4fg56j56sdgf516351drfg","200","OK","2021-06-01 00:00:10","1003","1003@192.168.56.204","192.168.56.204","192.168.56.21","sip:1003@192.168.56.204:5060;transport=UDP","1004","1004","local","1","test" +"4","ACK","CG123456789-2","123456799","CGqwerty-56dfghs56hj4fg56j56sdgf516351drfg","200","OK","2021-06-01 00:00:10","1003","1003@192.168.56.204","192.168.56.204","192.168.56.21",,"1004","1004","192.168.57.204","1","test" +"5","BYE","CG123456789-1","123456789","CGqwerty-asd5sdf456s1f53a1sf51s648486h4et86h46","200","OK","2021-06-01 00:00:37","1001","1001@192.168.56.203","192.168.56.203","192.168.56.20",,"1002","1002","192.168.57.203","1","test" +"6","CANCEL","CG123456789-3",,"CGqwerty-dfgdfhdfgjfgdh534dfg563h56dr56deghed6r5","200","OK","2021-06-01 00:00:42","1005","1005@192.168.56.201","192.168.56.201","192.168.56.2",,"1006","1006","192.168.56.301","0","test" +"7","BYE","CG123456789-2","123456799","CGqwerty-56dfghs56hj4fg56j56sdgf516351drfg","200","OK","2021-06-01 00:00:50","1003","1003@192.168.56.204","192.168.56.204","192.168.56.21",,"1004","1004","192.168.57.204","1","test"` + flatstoreTests = []func(t *testing.T){ testCreateDirs, testFlatstoreITInitConfig, @@ -82,6 +90,8 @@ BYE|3111f3c9|49ca4c42|a58ebaae40d08d6757d8424fb09c4c54@0:0:0:0:0:0:0:0|200|OK|14 testFlatstoreITAnalyseCDRs, testFlatstoreITHandleCdr2File, testFlatstoreITAnalyseCDRs2, + testFlatstoreITHandleCdr3File, + testFlatstoreITAnalyseCDRs3, testCleanupFiles, testFlatstoreITKillEngine, } @@ -266,6 +276,49 @@ func testFlatstoreITAnalyseCDRs2(t *testing.T) { t.Error("Unexpected number of CDRs returned: ", len(reply)) } } + +func testFlatstoreITHandleCdr3File(t *testing.T) { + if err := os.WriteFile(path.Join("/tmp", "acc_1.log"), []byte(ackSuccessfull2), 0644); err != nil { + t.Fatal(err.Error()) + } + //Rename(oldpath, newpath string) + if err := os.Rename(path.Join("/tmp", "acc_1.log"), path.Join("/tmp/flatstoreMMErs/in", "acc_1.log")); err != nil { + t.Fatal(err) + } + time.Sleep(time.Second) + // check the files to be processed + filesInDir, _ := os.ReadDir("/tmp/flatstoreErs/in") + if len(filesInDir) != 0 { + fls := make([]string, len(filesInDir)) + for i, fs := range filesInDir { + fls[i] = fs.Name() + } + t.Errorf("Files in ersInDir: %+v", fls) + } + filesOutDir, _ := os.ReadDir("/tmp/flatstoreMMErs/out") + ids := []string{} + for _, fD := range filesOutDir { + ids = append(ids, fD.Name()) + } + if len(filesOutDir) != 1 { + t.Errorf("Unexpected number of files in output directory: %+v, %q", len(filesOutDir), ids) + } +} + +func testFlatstoreITAnalyseCDRs3(t *testing.T) { + var reply []*engine.ExternalCDR + if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatstoreMMErs"}}, &reply); err != nil { + t.Error("Unexpected error: ", err.Error()) + } else if len(reply) != 3 { + t.Error("Unexpected number of CDRs returned: ", len(reply)) + } + if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatstoreMMErs"}, MinUsage: "1"}, &reply); err != nil { + t.Error("Unexpected error: ", err.Error()) + } else if len(reply) != 2 { + t.Error("Unexpected number of CDRs returned: ", len(reply)) + } +} + func testFlatstoreITKillEngine(t *testing.T) { if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) diff --git a/ers/lib_test.go b/ers/lib_test.go index d99c6ac8b..aa3e19bc4 100644 --- a/ers/lib_test.go +++ b/ers/lib_test.go @@ -74,7 +74,7 @@ func testCleanupFiles(t *testing.T) { "/tmp/cdrs", "/tmp/ers_with_filters", "/tmp/xmlErs", "/tmp/fwvErs", "/tmp/partErs1", "/tmp/partErs2", "tmp/flatstoreErs", "/tmp/ErsJSON", "/tmp/readerWithTemplate", - "/tmp/flatstoreACKErs"} { + "/tmp/flatstoreACKErs", "/tmp/flatstoreMMErs"} { if err := os.RemoveAll(dir); err != nil { t.Fatal("Error removing folder: ", dir, err) }