mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
Added filtration in export zip api
This commit is contained in:
committed by
Dan Christian Bogos
parent
efc429dd60
commit
2c69a89f8d
19
ees/ees.go
19
ees/ees.go
@@ -335,9 +335,9 @@ func (eeS *EeS) V1ArchiveEventsInReply(ctx *context.Context, args *ArchiveEvents
|
||||
}
|
||||
expID, has := args.APIOpts[utils.MetaExporterID]
|
||||
if !has {
|
||||
return fmt.Errorf("ExporterID is missing from argument's options: <%v>", utils.ToJSON(args))
|
||||
return fmt.Errorf("ExporterID is missing from argument's options")
|
||||
}
|
||||
//var validExporter bool
|
||||
// var validExporter bool
|
||||
var eesCfg *config.EventExporterCfg
|
||||
for _, exporter := range eeS.cfg.EEsCfg().Exporters {
|
||||
if exporter.ID == expID {
|
||||
@@ -364,7 +364,6 @@ func (eeS *EeS) V1ArchiveEventsInReply(ctx *context.Context, args *ArchiveEvents
|
||||
|
||||
buff := new(bytes.Buffer)
|
||||
zBuff := zip.NewWriter(buff)
|
||||
//
|
||||
var wrtr io.Writer
|
||||
if wrtr, err = zBuff.Create("events.csv"); err != nil {
|
||||
return err
|
||||
@@ -380,7 +379,21 @@ func (eeS *EeS) V1ArchiveEventsInReply(ctx *context.Context, args *ArchiveEvents
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cgrDp := utils.MapStorage{
|
||||
utils.MetaOpts: args.APIOpts,
|
||||
}
|
||||
for _, event := range args.Events {
|
||||
if len(eesCfg.Filters) != 0 {
|
||||
utils.Logger.Debug(fmt.Sprintf("ev: %v", utils.ToJSON(event)))
|
||||
tnt := utils.FirstNonEmpty(args.Tenant, eeS.cfg.GeneralCfg().DefaultTenant)
|
||||
cgrDp[utils.MetaReq] = event
|
||||
if pass, errPass := eeS.fltrS.Pass(ctx, tnt,
|
||||
eesCfg.Filters, cgrDp); errPass != nil {
|
||||
return errPass
|
||||
} else if !pass {
|
||||
continue // does not pass the filters, ignore the exporter
|
||||
}
|
||||
}
|
||||
cgrEv := &utils.CGREvent{
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Tenant: args.Tenant,
|
||||
|
||||
@@ -394,7 +394,6 @@ func testCsvExportBufferedEvent(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := `NumberOfEvent,CGRID,RunID,ToR,OriginID,RequestType,Tenant,Category,Account,Subject,Destination,SetupTime,AnswerTime,Usage,Cost` + "\n" +
|
||||
`1,dbafe9c8614c785a65aabd116dd3959c3c56f7f6,*default,*voice,dsafdsaf,*rated,cgrates.org,call,1001,1001,1002,2013-11-07T08:42:25Z,2013-11-07T08:42:26Z,10000000000,1.0164` + "\n" +
|
||||
`2,ea1f1968cc207859672c332364fc7614c86b04c5,*default,*data,*rated,AnotherTenant,call,1001,1001,1002,2013-11-07T08:42:25Z,2013-11-07T08:42:26Z,10,0.012` + "\n" +
|
||||
|
||||
Reference in New Issue
Block a user