// Used to retrieve fields as string, primary fields are const labeled func (storedCdr *StoredCdr) FieldAsString(rsrFld *utils.RSRField) string { if rsrFld.IsStatic() { // Static values do not care about headers return rsrFld.ParseValue("") } switch rsrFld.Id { case utils.CGRID: return rsrFld.ParseValue(storedCdr.CgrId) case utils.ORDERID: return rsrFld.ParseValue(strconv.FormatInt(storedCdr.OrderId, 10)) case utils.TOR: return rsrFld.ParseValue(storedCdr.TOR) case utils.ACCID: return rsrFld.ParseValue(storedCdr.AccId) case utils.CDRHOST: return rsrFld.ParseValue(storedCdr.CdrHost) case utils.CDRSOURCE: return rsrFld.ParseValue(storedCdr.CdrSource) case utils.REQTYPE: return rsrFld.ParseValue(storedCdr.ReqType) case utils.DIRECTION: return rsrFld.ParseValue(storedCdr.Direction) case utils.TENANT: return rsrFld.ParseValue(storedCdr.Tenant) case utils.CATEGORY: return rsrFld.ParseValue(storedCdr.Category) case utils.ACCOUNT: return rsrFld.ParseValue(storedCdr.Account) case utils.SUBJECT: return rsrFld.ParseValue(storedCdr.Subject) case utils.DESTINATION: return rsrFld.ParseValue(storedCdr.Destination) case utils.SETUP_TIME: return rsrFld.ParseValue(storedCdr.SetupTime.Format(time.RFC3339)) case utils.PDD: return strconv.FormatFloat(storedCdr.Pdd.Seconds(), 'f', -1, 64) case utils.ANSWER_TIME: return rsrFld.ParseValue(storedCdr.AnswerTime.Format(time.RFC3339)) case utils.USAGE: return strconv.FormatFloat(storedCdr.Usage.Seconds(), 'f', -1, 64) case utils.SUPPLIER: return rsrFld.ParseValue(storedCdr.Supplier) case utils.DISCONNECT_CAUSE: return rsrFld.ParseValue(storedCdr.DisconnectCause) case utils.MEDI_RUNID: return rsrFld.ParseValue(storedCdr.MediationRunId) case utils.RATED_ACCOUNT: return rsrFld.ParseValue(storedCdr.RatedAccount) case utils.RATED_SUBJECT: return rsrFld.ParseValue(storedCdr.RatedSubject) case utils.RATED_FLD: return rsrFld.ParseValue(strconv.FormatBool(storedCdr.Rated)) case utils.COST: return rsrFld.ParseValue(strconv.FormatFloat(storedCdr.Cost, 'f', -1, 64)) // Recommended to use FormatCost case utils.COST_DETAILS: return rsrFld.ParseValue(storedCdr.CostDetailsJson()) default: return rsrFld.ParseValue(storedCdr.ExtraFields[rsrFld.Id]) } }
func (storedCdr *StoredCdr) PassesFieldFilter(fieldFilter *utils.RSRField) (bool, string) { if fieldFilter == nil { return true, "" } if fieldFilter.IsStatic() && storedCdr.FieldAsString(&utils.RSRField{Id: fieldFilter.Id}) == storedCdr.FieldAsString(fieldFilter) { return true, storedCdr.FieldAsString(&utils.RSRField{Id: fieldFilter.Id}) } preparedFilter := &utils.RSRField{Id: fieldFilter.Id, RSRules: make([]*utils.ReSearchReplace, len(fieldFilter.RSRules))} // Reset rules so they do not point towards same structures as original fieldFilter for idx := range fieldFilter.RSRules { // Hardcode the template with maximum of 5 groups ordered preparedFilter.RSRules[idx] = &utils.ReSearchReplace{SearchRegexp: fieldFilter.RSRules[idx].SearchRegexp, ReplaceTemplate: utils.FILTER_REGEXP_TPL} } preparedVal := storedCdr.FieldAsString(preparedFilter) filteredValue := storedCdr.FieldAsString(fieldFilter) if preparedFilter.RegexpMatched() && (len(preparedVal) == 0 || preparedVal == filteredValue) { return true, filteredValue } return false, "" }
func (fsev FSEvent) PassesFieldFilter(fieldFilter *utils.RSRField) (bool, string) { // Keep in sync (or merge) with StoredCdr.PassesFieldFielter() if fieldFilter == nil { return true, "" } if fieldFilter.IsStatic() && fsev.ParseEventValue(&utils.RSRField{Id: fieldFilter.Id}, config.CgrConfig().DefaultTimezone) == fsev.ParseEventValue(fieldFilter, config.CgrConfig().DefaultTimezone) { return true, fsev.ParseEventValue(&utils.RSRField{Id: fieldFilter.Id}, config.CgrConfig().DefaultTimezone) } preparedFilter := &utils.RSRField{Id: fieldFilter.Id, RSRules: make([]*utils.ReSearchReplace, len(fieldFilter.RSRules))} // Reset rules so they do not point towards same structures as original fieldFilter for idx := range fieldFilter.RSRules { // Hardcode the template with maximum of 5 groups ordered preparedFilter.RSRules[idx] = &utils.ReSearchReplace{SearchRegexp: fieldFilter.RSRules[idx].SearchRegexp, ReplaceTemplate: utils.FILTER_REGEXP_TPL} } preparedVal := fsev.ParseEventValue(preparedFilter, config.CgrConfig().DefaultTimezone) filteredValue := fsev.ParseEventValue(fieldFilter, config.CgrConfig().DefaultTimezone) if preparedFilter.RegexpMatched() && (len(preparedVal) == 0 || preparedVal == filteredValue) { return true, filteredValue } return false, "" }