當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.StoredCdr類代碼示例

本文整理匯總了Golang中github.com/cgrates/cgrates/utils.StoredCdr的典型用法代碼示例。如果您正苦於以下問題:Golang StoredCdr類的具體用法?Golang StoredCdr怎麽用?Golang StoredCdr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了StoredCdr類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cdrFieldValue

// Extracts the value specified by cfgHdr out of cdr
func (cdre *CdrExporter) cdrFieldValue(cdr *utils.StoredCdr, fltrRl, rsrFld *utils.RSRField, layout string) (string, error) {
	if rsrFld == nil {
		return "", nil
	}
	if fltrPass, _ := cdr.PassesFieldFilter(fltrRl); !fltrPass {
		return "", fmt.Errorf("Field: %s not matching filter rule %v", fltrRl.Id, fltrRl)
	}
	if len(layout) == 0 {
		layout = time.RFC3339
	}
	var cdrVal string
	switch rsrFld.Id {
	case COST_DETAILS: // Special case when we need to further extract cost_details out of logDb
		if cdrVal, err = cdre.getCdrCostDetails(cdr.CgrId, cdr.MediationRunId); err != nil {
			return "", err
		}
	case utils.COST:
		cdrVal = cdr.FormatCost(cdre.costShiftDigits, cdre.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(&utils.RSRField{Id: utils.DESTINATION})
		if cdre.maskLen != -1 && cdre.maskedDestination(cdrVal) {
			cdrVal = MaskDestination(cdrVal, cdre.maskLen)
		}
	default:
		cdrVal = cdr.FieldAsString(rsrFld)
	}
	return rsrFld.ParseValue(cdrVal), nil
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:35,代碼來源:cdrexporter.go

示例2: getCombimedCdrFieldVal

func (cdre *CdrExporter) getCombimedCdrFieldVal(processedCdr *utils.StoredCdr, filterRule, fieldRule *utils.RSRField) (string, error) {
	fltrPass, ftrPassValue := processedCdr.PassesFieldFilter(filterRule)
	if !fltrPass {
		return "", nil
	}
	for _, cdr := range cdre.cdrs {
		if cdr.CgrId != processedCdr.CgrId {
			continue // We only care about cdrs with same primary cdr behind
		}
		if cdr.FieldAsString(&utils.RSRField{Id: filterRule.Id}) == ftrPassValue {
			return cdr.FieldAsString(fieldRule), nil
		}
	}
	return "", nil
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:15,代碼來源:cdrexporter.go

示例3: getDateTimeFieldVal

func (cdre *CdrExporter) getDateTimeFieldVal(cdr *utils.StoredCdr, fltrRl, fieldRl *utils.RSRField, layout string) (string, error) {
	if fieldRl == nil {
		return "", nil
	}
	if fltrPass, _ := cdr.PassesFieldFilter(fltrRl); !fltrPass {
		return "", fmt.Errorf("Field: %s not matching filter rule %v", fltrRl.Id, fltrRl)
	}
	if len(layout) == 0 {
		layout = time.RFC3339
	}
	if dtFld, err := utils.ParseTimeDetectLayout(cdr.FieldAsString(fieldRl)); err != nil {
		return "", err
	} else {
		return dtFld.Format(layout), nil
	}
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:16,代碼來源:cdrexporter.go

示例4: rateCDR

func (self *Mediator) rateCDR(storedCdr *utils.StoredCdr) error {
	var qryCC *CallCost
	var errCost error
	if storedCdr.ReqType == utils.PREPAID {
		// Should be previously calculated and stored in DB
		qryCC, errCost = self.getCostsFromDB(storedCdr.CgrId, storedCdr.MediationRunId)
	} else {
		qryCC, errCost = self.getCostFromRater(storedCdr)
	}
	if errCost != nil {
		return errCost
	} else if qryCC == nil {
		return errors.New("No cost returned from rater")
	}
	storedCdr.Cost = qryCC.Cost
	return nil
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:17,代碼來源:mediator.go

示例5: AsStoredCdr

func (fsev FSEvent) AsStoredCdr() *utils.StoredCdr {
	storCdr := new(utils.StoredCdr)
	storCdr.CgrId = fsev.GetCgrId()
	storCdr.TOR = utils.VOICE
	storCdr.AccId = fsev.GetUUID()
	storCdr.CdrHost = fsev.GetOriginatorIP(utils.META_DEFAULT)
	storCdr.CdrSource = "FS_" + fsev.GetName()
	storCdr.ReqType = fsev.GetReqType(utils.META_DEFAULT)
	storCdr.Direction = fsev.GetDirection(utils.META_DEFAULT)
	storCdr.Tenant = fsev.GetTenant(utils.META_DEFAULT)
	storCdr.Category = fsev.GetCategory(utils.META_DEFAULT)
	storCdr.Account = fsev.GetAccount(utils.META_DEFAULT)
	storCdr.Subject = fsev.GetSubject(utils.META_DEFAULT)
	storCdr.Destination = fsev.GetDestination(utils.META_DEFAULT)
	storCdr.SetupTime, _ = fsev.GetSetupTime(utils.META_DEFAULT)
	storCdr.AnswerTime, _ = fsev.GetAnswerTime(utils.META_DEFAULT)
	storCdr.Usage, _ = fsev.GetDuration(utils.META_DEFAULT)
	storCdr.ExtraFields = fsev.GetExtraFields()
	storCdr.Cost = -1
	return storCdr
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:21,代碼來源:fsevent.go

示例6: processCdr

// Write individual cdr into content buffer, build stats
func (cdre *CdrExporter) processCdr(cdr *utils.StoredCdr) error {
	if cdr == nil || len(cdr.CgrId) == 0 { // We do not export empty CDRs
		return nil
	}
	if cdre.dataUsageMultiplyFactor != 0.0 && cdr.TOR == utils.DATA {
		cdr.UsageMultiply(cdre.dataUsageMultiplyFactor, cdre.cgrPrecision)
	}
	if cdre.costMultiplyFactor != 0.0 {
		cdr.CostMultiply(cdre.costMultiplyFactor, cdre.cgrPrecision)
	}
	var err error
	cdrRow := make([]string, len(cdre.exportTemplate.ContentFields))
	for idx, cfgFld := range cdre.exportTemplate.ContentFields {
		var outVal string
		switch cfgFld.Type {
		case FILLER:
			outVal = cfgFld.Value
			cfgFld.Padding = "right"
		case CONSTANT:
			outVal = cfgFld.Value
		case utils.CDRFIELD:
			outVal, err = cdre.cdrFieldValue(cdr, cfgFld.Filter, cfgFld.ValueAsRSRField(), cfgFld.Layout)
		case DATETIME:
			outVal, err = cdre.getDateTimeFieldVal(cdr, cfgFld.Filter, cfgFld.ValueAsRSRField(), cfgFld.Layout)
		case HTTP_POST:
			var outValByte []byte
			if outValByte, err = utils.HttpJsonPost(cfgFld.Value, cdre.httpSkipTlsCheck, cdr); err == nil {
				outVal = string(outValByte)
				if len(outVal) == 0 && cfgFld.Mandatory {
					err = fmt.Errorf("Empty result for http_post field: %s", cfgFld.Name)
				}
			}
		case COMBIMED:
			outVal, err = cdre.getCombimedCdrFieldVal(cdr, cfgFld.Filter, cfgFld.ValueAsRSRField())
		case CONCATENATED_CDRFIELD:
			for _, fld := range strings.Split(cfgFld.Value, ",") {
				if fldOut, err := cdre.cdrFieldValue(cdr, cfgFld.Filter, &utils.RSRField{Id: fld}, cfgFld.Layout); err != nil {
					break // The error will be reported bellow
				} else {
					outVal += fldOut
				}
			}
		case METATAG:
			if cfgFld.Value == META_MASKDESTINATION {
				outVal, err = cdre.metaHandler(cfgFld.Value, cdr.FieldAsString(&utils.RSRField{Id: utils.DESTINATION}))
			} else {
				outVal, err = cdre.metaHandler(cfgFld.Value, cfgFld.Layout)
			}
		}
		if err != nil {
			engine.Logger.Err(fmt.Sprintf("<CdreFw> Cannot export CDR with cgrid: %s and runid: %s, error: %s", cdr.CgrId, cdr.MediationRunId, err.Error()))
			return err
		}
		fmtOut := outVal
		if fmtOut, err = FmtFieldWidth(outVal, cfgFld.Width, cfgFld.Strip, cfgFld.Padding, cfgFld.Mandatory); err != nil {
			engine.Logger.Err(fmt.Sprintf("<CdreFw> Cannot export CDR with cgrid: %s, runid: %s, fieldName: %s, fieldValue: %s, error: %s", cdr.CgrId, cdr.MediationRunId, cfgFld.Name, outVal, err.Error()))
			return err
		}
		cdrRow[idx] += fmtOut
	}
	if len(cdrRow) == 0 { // No CDR data, most likely no configuration fields defined
		return nil
	} else {
		cdre.content = append(cdre.content, cdrRow)
	}
	// Done with writing content, compute stats here
	if cdre.firstCdrATime.IsZero() || cdr.AnswerTime.Before(cdre.firstCdrATime) {
		cdre.firstCdrATime = cdr.AnswerTime
	}
	if cdr.AnswerTime.After(cdre.lastCdrATime) {
		cdre.lastCdrATime = cdr.AnswerTime
	}
	cdre.numberOfRecords += 1
	if cdr.TOR == utils.VOICE { // Only count duration for non data cdrs
		cdre.totalDuration += cdr.Usage
	}
	if cdr.TOR == utils.SMS { // Count usage for SMS
		cdre.totalSmsUsage += cdr.Usage
	}
	if cdr.TOR == utils.DATA { // Count usage for SMS
		cdre.totalDataUsage += cdr.Usage
	}
	if cdr.Cost != -1 {
		cdre.totalCost += cdr.Cost
		cdre.totalCost = utils.Round(cdre.totalCost, cdre.roundDecimals, utils.ROUNDING_MIDDLE)
	}
	if cdre.firstExpOrderId > cdr.OrderId || cdre.firstExpOrderId == 0 {
		cdre.firstExpOrderId = cdr.OrderId
	}
	if cdre.lastExpOrderId < cdr.OrderId {
		cdre.lastExpOrderId = cdr.OrderId
	}
	return nil
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:95,代碼來源:cdrexporter.go

示例7: AsStoredCdr

func (fsCdr FSCdr) AsStoredCdr() *utils.StoredCdr {
	storCdr := new(utils.StoredCdr)
	storCdr.CgrId = fsCdr.getCgrId()
	storCdr.TOR = utils.VOICE
	storCdr.AccId = fsCdr.vars[FS_UUID]
	storCdr.CdrHost = fsCdr.vars[FS_IP]
	storCdr.CdrSource = FS_CDR_SOURCE
	storCdr.ReqType = utils.FirstNonEmpty(fsCdr.vars[FS_REQTYPE], cfg.DefaultReqType)
	storCdr.Direction = "*out"
	storCdr.Tenant = utils.FirstNonEmpty(fsCdr.vars[FS_CSTMID], cfg.DefaultTenant)
	storCdr.Category = utils.FirstNonEmpty(fsCdr.vars[FS_CATEGORY], cfg.DefaultCategory)
	storCdr.Account = utils.FirstNonEmpty(fsCdr.vars[FS_ACCOUNT], fsCdr.vars[FS_USERNAME])
	storCdr.Subject = utils.FirstNonEmpty(fsCdr.vars[FS_SUBJECT], fsCdr.vars[FS_USERNAME])
	storCdr.Destination = utils.FirstNonEmpty(fsCdr.vars[FS_DESTINATION], fsCdr.vars[FS_CALL_DEST_NR], fsCdr.vars[FS_SIP_REQUSER])
	storCdr.SetupTime, _ = utils.ParseTimeDetectLayout(fsCdr.vars[FS_SETUP_TIME]) // Not interested to process errors, should do them if necessary in a previous step
	storCdr.AnswerTime, _ = utils.ParseTimeDetectLayout(fsCdr.vars[FS_ANSWER_TIME])
	storCdr.Usage, _ = utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION])
	storCdr.ExtraFields = fsCdr.getExtraFields()
	storCdr.Cost = -1
	return storCdr
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:21,代碼來源:fscdr.go

示例8: RateCdr

func (self *Mediator) RateCdr(storedCdr *utils.StoredCdr, sendToStats bool) error {
	storedCdr.MediationRunId = utils.DEFAULT_RUNID
	cdrRuns := []*utils.StoredCdr{storedCdr} // Start with initial storCdr, will add here all to be mediated
	attrsDC := utils.AttrDerivedChargers{Tenant: storedCdr.Tenant, Category: storedCdr.Category, Direction: storedCdr.Direction,
		Account: storedCdr.Account, Subject: storedCdr.Subject}
	var dcs utils.DerivedChargers
	if err := self.connector.GetDerivedChargers(attrsDC, &dcs); err != nil {
		errText := fmt.Sprintf("Could not get derived charging for cgrid %s, error: %s", storedCdr.CgrId, err.Error())
		Logger.Err(errText)
		return errors.New(errText)
	}
	for _, dc := range dcs {
		runFilters, _ := utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP)
		matchingAllFilters := true
		for _, dcRunFilter := range runFilters {
			if fltrPass, _ := storedCdr.PassesFieldFilter(dcRunFilter); !fltrPass {
				matchingAllFilters = false
				break
			}
		}
		if !matchingAllFilters { // Do not process the derived charger further if not all filters were matched
			continue
		}
		dcReqTypeFld, _ := utils.NewRSRField(dc.ReqTypeField)
		dcDirFld, _ := utils.NewRSRField(dc.DirectionField)
		dcTenantFld, _ := utils.NewRSRField(dc.TenantField)
		dcCategoryFld, _ := utils.NewRSRField(dc.CategoryField)
		dcAcntFld, _ := utils.NewRSRField(dc.AccountField)
		dcSubjFld, _ := utils.NewRSRField(dc.SubjectField)
		dcDstFld, _ := utils.NewRSRField(dc.DestinationField)
		dcSTimeFld, _ := utils.NewRSRField(dc.SetupTimeField)
		dcATimeFld, _ := utils.NewRSRField(dc.AnswerTimeField)
		dcDurFld, _ := utils.NewRSRField(dc.UsageField)
		forkedCdr, err := storedCdr.ForkCdr(dc.RunId, dcReqTypeFld, dcDirFld, dcTenantFld, dcCategoryFld, dcAcntFld, dcSubjFld, dcDstFld, dcSTimeFld, dcATimeFld, dcDurFld,
			[]*utils.RSRField{}, true)
		if err != nil { // Errors on fork, cannot calculate further, write that into db for later analysis
			self.cdrDb.SetRatedCdr(&utils.StoredCdr{CgrId: storedCdr.CgrId, CdrSource: utils.FORKED_CDR, MediationRunId: dc.RunId, Cost: -1},
				err.Error()) // Cannot fork CDR, important just runid and error
			continue
		}
		cdrRuns = append(cdrRuns, forkedCdr)
	}
	for _, cdr := range cdrRuns {
		extraInfo := ""
		if err := self.rateCDR(cdr); err != nil {
			extraInfo = err.Error()
		}
		if !self.cgrCfg.MediatorStoreDisable {
			if err := self.cdrDb.SetRatedCdr(cdr, extraInfo); err != nil {
				Logger.Err(fmt.Sprintf("<Mediator> Could not record cost for cgrid: <%s>, ERROR: <%s>, cost: %f, extraInfo: %s",
					cdr.CgrId, err.Error(), cdr.Cost, extraInfo))
			}
		}
		if sendToStats && self.stats != nil { // We send to stats only after saving to db since there are chances we cannot store and then no way to reproduce stats offline
			go func(cdr *utils.StoredCdr) { // Pass it by value since the variable will be overwritten by for
				if err := self.stats.AppendCDR(cdr, nil); err != nil {
					Logger.Err(fmt.Sprintf("Could not append cdr to stats (mediator): %s", err.Error()))
				}
			}(cdr)
		}
	}
	return nil
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:63,代碼來源:mediator.go


注:本文中的github.com/cgrates/cgrates/utils.StoredCdr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。