diff --git a/config/configsanity.go b/config/configsanity.go index 8e069bfb5..4c517e476 100644 --- a/config/configsanity.go +++ b/config/configsanity.go @@ -693,6 +693,35 @@ func (cfg *CGRConfig) checkConfigSanity() error { if !possibleReaderTypes.Has(rdr.Type) { return fmt.Errorf("<%s> unsupported data type: %s for reader with ID: %s", utils.ERs, rdr.Type, rdr.ID) } + var pAct string + if act, has := rdr.Opts[utils.PartialCacheActionOpt]; has { // check the action from opts + if pAct = utils.IfaceAsString(act); pAct != utils.MetaDumpToFile && + pAct != utils.MetaNone && + pAct != utils.MetaPostCDR { + return fmt.Errorf("<%s> wrong partial expiry action for reader with ID: %s", utils.ERs, rdr.ID) + } + } + if pAct != utils.MetaNone { // if is *none we do not process the evicted events + if fldSep, has := rdr.Opts[utils.PartialOrderFieldOpt]; has && // the field we order after must not be empty + utils.IfaceAsString(fldSep) == utils.EmptyString { + return fmt.Errorf("<%s> empty %s for reader with ID: %s", utils.ERs, utils.PartialOrderFieldOpt, rdr.ID) + } + } else if pAct == utils.MetaDumpToFile { // only if the action is *dump_to_file + path := rdr.ProcessedPath + if pathVal, has := rdr.Opts[utils.PartialPathOpt]; has { // the path from options needs to exists if overwriten by reader + path = utils.IfaceAsString(pathVal) + } + if _, err := os.Stat(utils.IfaceAsString(path)); err != nil && os.IsNotExist(err) { + return fmt.Errorf("<%s> nonexistent partial folder: %s for reader with ID: %s", utils.ERs, path, rdr.ID) + } + if fldSep, has := rdr.Opts[utils.PartialCSVFieldSepartorOpt]; has && // the separtor must not be empty + utils.IfaceAsString(fldSep) == utils.EmptyString { + return fmt.Errorf("<%s> empty %s for reader with ID: %s", utils.ERs, utils.PartialCSVFieldSepartorOpt, rdr.ID) + } + if len(rdr.CacheDumpFields) == 0 { + return fmt.Errorf("<%s> empty %s for reader with ID: %s", utils.ERs, utils.CacheDumpFieldsCfg, rdr.ID) + } + } switch rdr.Type { case utils.MetaFileCSV: paths := []string{rdr.ProcessedPath, rdr.SourcePath} diff --git a/ers/ers.go b/ers/ers.go index 88ffc8070..5b8f86a44 100644 --- a/ers/ers.go +++ b/ers/ers.go @@ -396,9 +396,9 @@ func (erS *ERService) onEvicted(id string, value interface{}) { } erS.rdrEvents <- &erEvent{cgrEvent: cgrEv, rdrCfg: eEvs.rdrCfg} case utils.MetaDumpToFile: // apply the cacheDumpFields to the united events and write the record to file - var expPath string - if path, has := eEvs.rdrCfg.Opts[utils.PartialPathOpt]; has { - expPath = utils.IfaceAsString(path) + expPath := eEvs.rdrCfg.ProcessedPath + if pathVal, has := eEvs.rdrCfg.Opts[utils.PartialPathOpt]; has { + expPath = utils.IfaceAsString(pathVal) } if expPath == utils.EmptyString { // do not write the partial event to file return