// Extracts the value specified by cfgHdr out of cdr, used for export values func (cdr *CDR) exportFieldValue(cfgCdrFld *config.CfgCdrField) (string, error) { passesFilters := true for _, cdfFltr := range cfgCdrFld.FieldFilter { if !cdfFltr.FilterPasses(cdr.FieldAsString(cdfFltr)) { passesFilters = false break } } if !passesFilters { // Not passes filters, ignore this replication return "", fmt.Errorf("filters not passing") } var retVal string // Concatenate the resulting values for _, rsrFld := range cfgCdrFld.Value { var cdrVal string switch rsrFld.Id { case utils.COST: cdrVal = cdr.FormatCost(cfgCdrFld.CostShiftDigits, cfgCdrFld.RoundingDecimals) case utils.USAGE: cdrVal = cdr.FormatUsage(cfgCdrFld.Layout) case utils.SETUP_TIME: cdrVal = cdr.SetupTime.Format(cfgCdrFld.Layout) case utils.ANSWER_TIME: // Format time based on layout cdrVal = cdr.AnswerTime.Format(cfgCdrFld.Layout) case utils.DESTINATION: cdrVal = cdr.FieldAsString(rsrFld) if cfgCdrFld.MaskLen != -1 && len(cfgCdrFld.MaskDestID) != 0 && CachedDestHasPrefix(cfgCdrFld.MaskDestID, cdrVal) { cdrVal = utils.MaskSuffix(cdrVal, cfgCdrFld.MaskLen) } default: cdrVal = cdr.FieldAsString(rsrFld) } retVal += cdrVal } return retVal, nil }
// Extracts the value specified by cfgHdr out of cdr, used for export values func (cdr *CDR) exportFieldValue(cfgCdrFld *config.CfgCdrField, costShiftDigits, roundDecimals int, layout string, maskLen int, maskDestID string) (string, error) { passesFilters := true for _, cdfFltr := range cfgCdrFld.FieldFilter { if !cdfFltr.FilterPasses(cdr.FieldAsString(cdfFltr)) { passesFilters = false break } } if !passesFilters { // Not passes filters, ignore this replication return "", fmt.Errorf("Filters not passing") } var retVal string // Concatenate the resulting values for _, rsrFld := range cfgCdrFld.Value { var cdrVal string switch rsrFld.Id { case utils.COST_DETAILS: // Special case when we need to further extract cost_details out of logDb if cdr.CostDetails == nil { cdrVal = "" } else { jsonVal, _ := json.Marshal(cdr.CostDetails) cdrVal = string(jsonVal) } case utils.COST: cdrVal = cdr.FormatCost(costShiftDigits, roundDecimals) case utils.USAGE: cdrVal = cdr.FormatUsage(layout) case utils.SETUP_TIME: cdrVal = cdr.SetupTime.Format(layout) case utils.ANSWER_TIME: // Format time based on layout cdrVal = cdr.AnswerTime.Format(layout) case utils.DESTINATION: cdrVal = cdr.FieldAsString(rsrFld) if maskLen != -1 && len(maskDestID) != 0 && CachedDestHasPrefix(maskDestID, cdrVal) { cdrVal = utils.MaskSuffix(cdrVal, maskLen) } default: cdrVal = cdr.FieldAsString(rsrFld) } retVal += cdrVal } return retVal, nil }