Add code for ExportCDRs with EventExporter

This commit is contained in:
TeoV
2020-08-30 11:38:45 +03:00
committed by Dan Christian Bogos
parent 711e628d4b
commit 84633fb480
2 changed files with 37 additions and 0 deletions

View File

@@ -1877,3 +1877,35 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st
*reply = utils.OK
return nil
}
func (apierSv1 *APIerSv1) ExportCDRs(args *utils.ArgExportCDRs, reply *string) error {
if len(apierSv1.Config.ApierCfg().EEsConns) == 0 {
return utils.NewErrNotConnected(utils.EEs)
}
cdrsFltr, err := args.RPCCDRsFilter.AsCDRsFilter(apierSv1.Config.GeneralCfg().DefaultTimezone)
if err != nil {
return utils.NewErrServerError(err)
}
cdrs, _, err := apierSv1.CdrDb.GetCDRs(cdrsFltr, false)
if err != nil {
return err
} else if len(cdrs) == 0 {
return utils.ErrNotFound
}
withErros := false
for _, cdr := range cdrs {
if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().EEsConns, nil, utils.EventExporterSv1ProcessEvent,
utils.CGREventWithIDs{
IDs: args.ExporterIDs,
CGREventWithOpts: &utils.CGREventWithOpts{CGREvent: cdr.AsCGREvent()},
}, &reply); err != nil {
utils.Logger.Warning(fmt.Sprintf("<%s> error: <%s> processing event: <%s> with <%s>",
utils.ApierS, err.Error(), utils.ToJSON(cdr.AsCGREvent()), utils.EventExporterS))
withErros = true
}
}
if withErros {
return utils.ErrPartiallyExecuted
}
return nil
}

View File

@@ -1511,3 +1511,8 @@ type TPIntervalRate struct {
Unit string
Increment string
}
type ArgExportCDRs struct {
ExporterIDs []string
RPCCDRsFilter
}