本文整理汇总了Golang中github.com/cgrates/cgrates/utils.ParseRSRFields函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseRSRFields函数的具体用法?Golang ParseRSRFields怎么用?Golang ParseRSRFields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseRSRFields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCdreCfgClone
func TestCdreCfgClone(t *testing.T) {
cgrIdRsrs, _ := utils.ParseRSRFields("cgrid", utils.INFIELD_SEP)
runIdRsrs, _ := utils.ParseRSRFields("mediation_runid", utils.INFIELD_SEP)
emptyFields := []*CfgCdrField{}
initContentFlds := []*CfgCdrField{
&CfgCdrField{Tag: "CgrId",
Type: "*composed",
FieldId: "cgrid",
Value: cgrIdRsrs},
&CfgCdrField{Tag: "RunId",
Type: "*composed",
FieldId: "mediation_runid",
Value: runIdRsrs},
}
initCdreCfg := &CdreConfig{
CdrFormat: "csv",
FieldSeparator: rune(','),
DataUsageMultiplyFactor: 1.0,
CostMultiplyFactor: 1.0,
ExportDirectory: "/var/spool/cgrates/cdre",
ContentFields: initContentFlds,
}
eClnContentFlds := []*CfgCdrField{
&CfgCdrField{Tag: "CgrId",
Type: "*composed",
FieldId: "cgrid",
Value: cgrIdRsrs},
&CfgCdrField{Tag: "RunId",
Type: "*composed",
FieldId: "mediation_runid",
Value: runIdRsrs},
}
eClnCdreCfg := &CdreConfig{
CdrFormat: "csv",
FieldSeparator: rune(','),
DataUsageMultiplyFactor: 1.0,
CostMultiplyFactor: 1.0,
ExportDirectory: "/var/spool/cgrates/cdre",
HeaderFields: emptyFields,
ContentFields: eClnContentFlds,
TrailerFields: emptyFields,
}
clnCdreCfg := initCdreCfg.Clone()
if !reflect.DeepEqual(eClnCdreCfg, clnCdreCfg) {
t.Errorf("Cloned result: %+v", clnCdreCfg)
}
initCdreCfg.DataUsageMultiplyFactor = 1024.0
if !reflect.DeepEqual(eClnCdreCfg, clnCdreCfg) { // MOdifying a field after clone should not affect cloned instance
t.Errorf("Cloned result: %+v", clnCdreCfg)
}
initContentFlds[0].Tag = "Destination"
if !reflect.DeepEqual(eClnCdreCfg, clnCdreCfg) { // MOdifying a field after clone should not affect cloned instance
t.Errorf("Cloned result: %+v", clnCdreCfg)
}
clnCdreCfg.ContentFields[0].FieldId = "destination"
if initCdreCfg.ContentFields[0].FieldId != "cgrid" {
t.Error("Unexpected change of FieldId: ", initCdreCfg.ContentFields[0].FieldId)
}
}
示例2: ParseCdrcCdrFields
func ParseCdrcCdrFields(torFld, accIdFld, reqtypeFld, directionFld, tenantFld, categoryFld, acntFld, subjectFld, destFld,
setupTimeFld, answerTimeFld, durFld, extraFlds string) (map[string][]*utils.RSRField, error) {
cdrcCdrFlds := make(map[string][]*utils.RSRField)
if len(extraFlds) != 0 {
if sepExtraFlds, err := ConfigSlice(extraFlds); err != nil {
return nil, err
} else {
for _, fldStr := range sepExtraFlds {
// extra fields defined as: <label_extrafield_1>:<index_extrafield_1>
if spltLbl := strings.Split(fldStr, utils.CONCATENATED_KEY_SEP); len(spltLbl) != 2 {
return nil, fmt.Errorf("Wrong format for cdrc.extra_fields: %s", fldStr)
} else {
if rsrFlds, err := utils.ParseRSRFields(spltLbl[1], utils.INFIELD_SEP); err != nil {
return nil, err
} else {
cdrcCdrFlds[spltLbl[0]] = rsrFlds
}
}
}
}
}
for fldTag, fldVal := range map[string]string{utils.TOR: torFld, utils.ACCID: accIdFld, utils.REQTYPE: reqtypeFld, utils.DIRECTION: directionFld, utils.TENANT: tenantFld,
utils.CATEGORY: categoryFld, utils.ACCOUNT: acntFld, utils.SUBJECT: subjectFld, utils.DESTINATION: destFld, utils.SETUP_TIME: setupTimeFld,
utils.ANSWER_TIME: answerTimeFld, utils.USAGE: durFld} {
if len(fldVal) != 0 {
if rsrFlds, err := utils.ParseRSRFields(fldVal, utils.INFIELD_SEP); err != nil {
return nil, err
} else {
cdrcCdrFlds[fldTag] = rsrFlds
}
}
}
return cdrcCdrFlds, nil
}
示例3: TestGetDateTimeFieldVal
func TestGetDateTimeFieldVal(t *testing.T) {
cdreTst := new(CdrExporter)
cdrTst := &engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID, Cost: 1.01,
ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}}
val, _ := utils.ParseRSRFields("stop_time", utils.INFIELD_SEP)
layout := "2006-01-02 15:04:05"
cfgCdrFld := &config.CfgCdrField{Tag: "stop_time", Type: "cdrfield", FieldId: "stop_time", Value: val, Layout: layout}
if cdrVal, err := cdreTst.getDateTimeFieldVal(cdrTst, cfgCdrFld); err != nil {
t.Error(err)
} else if cdrVal != "2014-06-11 19:19:00" {
t.Error("Expecting: 2014-06-11 19:19:00, got: ", cdrVal)
}
// Test filter
fltr, _ := utils.ParseRSRFields("~tenant:s/(.+)/itsyscom.com/", utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: "stop_time", Type: "cdrfield", FieldId: "stop_time", Value: val, FieldFilter: fltr, Layout: layout}
if _, err := cdreTst.getDateTimeFieldVal(cdrTst, cfgCdrFld); err == nil {
t.Error(err)
}
val, _ = utils.ParseRSRFields("fieldextr2", utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: "stop_time", Type: "cdrfield", FieldId: "stop_time", Value: val, Layout: layout}
// Test time parse error
if _, err := cdreTst.getDateTimeFieldVal(cdrTst, cfgCdrFld); err == nil {
t.Error("Should give error here, got none.")
}
}
示例4: NewCfgCdrFieldFromCdrFieldJsonCfg
func NewCfgCdrFieldFromCdrFieldJsonCfg(jsnCfgFld *CdrFieldJsonCfg) (*CfgCdrField, error) {
var err error
cfgFld := new(CfgCdrField)
if jsnCfgFld.Tag != nil {
cfgFld.Tag = *jsnCfgFld.Tag
}
if jsnCfgFld.Type != nil {
cfgFld.Type = *jsnCfgFld.Type
}
if jsnCfgFld.Field_id != nil {
cfgFld.FieldId = *jsnCfgFld.Field_id
}
if jsnCfgFld.Handler_id != nil {
cfgFld.HandlerId = *jsnCfgFld.Handler_id
}
if jsnCfgFld.Value != nil {
if cfgFld.Value, err = utils.ParseRSRFields(*jsnCfgFld.Value, utils.INFIELD_SEP); err != nil {
return nil, err
}
}
if jsnCfgFld.Append != nil {
cfgFld.Append = *jsnCfgFld.Append
}
if jsnCfgFld.Field_filter != nil {
if cfgFld.FieldFilter, err = utils.ParseRSRFields(*jsnCfgFld.Field_filter, utils.INFIELD_SEP); err != nil {
return nil, err
}
}
if jsnCfgFld.Width != nil {
cfgFld.Width = *jsnCfgFld.Width
}
if jsnCfgFld.Strip != nil {
cfgFld.Strip = *jsnCfgFld.Strip
}
if jsnCfgFld.Padding != nil {
cfgFld.Padding = *jsnCfgFld.Padding
}
if jsnCfgFld.Layout != nil {
cfgFld.Layout = *jsnCfgFld.Layout
}
if jsnCfgFld.Mandatory != nil {
cfgFld.Mandatory = *jsnCfgFld.Mandatory
}
if jsnCfgFld.Cost_shift_digits != nil {
cfgFld.CostShiftDigits = *jsnCfgFld.Cost_shift_digits
}
if jsnCfgFld.Rounding_decimals != nil {
cfgFld.RoundingDecimals = *jsnCfgFld.Rounding_decimals
}
if jsnCfgFld.Timezone != nil {
cfgFld.Timezone = *jsnCfgFld.Timezone
}
if jsnCfgFld.Mask_length != nil {
cfgFld.MaskLen = *jsnCfgFld.Mask_length
}
if jsnCfgFld.Mask_destinationd_id != nil {
cfgFld.MaskDestID = *jsnCfgFld.Mask_destinationd_id
}
return cfgFld, nil
}
示例5: loadFromJsonCfg
func (self *DARequestProcessor) loadFromJsonCfg(jsnCfg *DARequestProcessorJsnCfg) error {
if jsnCfg == nil {
return nil
}
if jsnCfg.Id != nil {
self.Id = *jsnCfg.Id
}
if jsnCfg.Dry_run != nil {
self.DryRun = *jsnCfg.Dry_run
}
if jsnCfg.Publish_event != nil {
self.PublishEvent = *jsnCfg.Publish_event
}
var err error
if jsnCfg.Request_filter != nil {
if self.RequestFilter, err = utils.ParseRSRFields(*jsnCfg.Request_filter, utils.INFIELD_SEP); err != nil {
return err
}
}
if jsnCfg.CCR_fields != nil {
if self.CCRFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.CCR_fields); err != nil {
return err
}
}
if jsnCfg.CCA_fields != nil {
if self.CCAFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.CCA_fields); err != nil {
return err
}
}
return nil
}
示例6: Subscribe
func (ps *PubSub) Subscribe(si SubscribeInfo, reply *string) error {
ps.mux.Lock()
defer ps.mux.Unlock()
if si.Transport != utils.META_HTTP_POST {
*reply = "Unsupported transport type"
return errors.New(*reply)
}
var expTime time.Time
if si.LifeSpan > 0 {
expTime = time.Now().Add(si.LifeSpan)
}
rsr, err := utils.ParseRSRFields(si.EventFilter, utils.INFIELD_SEP)
if err != nil {
*reply = err.Error()
return err
}
key := utils.InfieldJoin(si.Transport, si.Address)
ps.subscribers[key] = &SubscriberData{
ExpTime: expTime,
Filters: rsr,
}
ps.saveSubscriber(key)
*reply = utils.OK
return nil
}
示例7: TestCdreGetCombimedCdrFieldVal
func TestCdreGetCombimedCdrFieldVal(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
cdrs := []*engine.CDR{
&engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: "RUN_RTL", Cost: 1.01},
&engine.CDR{CGRID: utils.Sha1("dsafdsaf2", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: "CUSTOMER1", Cost: 2.01},
&engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: "CUSTOMER1", Cost: 3.01},
&engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID, Cost: 4.01},
&engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1000", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: "RETAIL1", Cost: 5.01},
}
cdre, err := NewCdrExporter(cdrs, nil, cfg.CdreProfiles["*default"], cfg.CdreProfiles["*default"].CdrFormat, cfg.CdreProfiles["*default"].FieldSeparator,
"firstexport", 0.0, 0.0, 0.0, 0.0, 0.0, 0, 4, cfg.RoundingDecimals, "", 0, cfg.HttpSkipTlsVerify, "")
if err != nil {
t.Error("Unexpected error received: ", err)
}
fltrRule, _ := utils.ParseRSRFields("~RunID:s/default/RUN_RTL/", utils.INFIELD_SEP)
val, _ := utils.ParseRSRFields(utils.COST, utils.INFIELD_SEP)
cfgCdrFld := &config.CfgCdrField{Tag: "cost", Type: "cdrfield", FieldId: utils.COST, Value: val, FieldFilter: fltrRule}
if costVal, err := cdre.getCombimedCdrFieldVal(cdrs[3], cfgCdrFld); err != nil {
t.Error(err)
} else if costVal != "1.01" {
t.Error("Expecting: 1.01, received: ", costVal)
}
fltrRule, _ = utils.ParseRSRFields("~RunID:s/default/RETAIL1/", utils.INFIELD_SEP)
val, _ = utils.ParseRSRFields(utils.ACCOUNT, utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: utils.ACCOUNT, Type: "cdrfield", FieldId: utils.ACCOUNT, Value: val, FieldFilter: fltrRule}
if acntVal, err := cdre.getCombimedCdrFieldVal(cdrs[3], cfgCdrFld); err != nil {
t.Error(err)
} else if acntVal != "1000" {
t.Error("Expecting: 1000, received: ", acntVal)
}
}
示例8: NewCfgCdrFieldFromCdrFieldJsonCfg
func NewCfgCdrFieldFromCdrFieldJsonCfg(jsnCfgFld *CdrFieldJsonCfg) (*CfgCdrField, error) {
var err error
cfgFld := new(CfgCdrField)
if jsnCfgFld.Tag != nil {
cfgFld.Tag = *jsnCfgFld.Tag
}
if jsnCfgFld.Type != nil {
cfgFld.Type = *jsnCfgFld.Type
}
if jsnCfgFld.Field_id != nil {
cfgFld.FieldId = *jsnCfgFld.Field_id
}
if jsnCfgFld.Handler_id != nil {
cfgFld.HandlerId = *jsnCfgFld.Handler_id
}
if jsnCfgFld.Value != nil {
if cfgFld.Value, err = utils.ParseRSRFields(*jsnCfgFld.Value, utils.INFIELD_SEP); err != nil {
return nil, err
}
}
if jsnCfgFld.Append != nil {
cfgFld.Append = *jsnCfgFld.Append
}
if jsnCfgFld.Field_filter != nil {
if cfgFld.FieldFilter, err = utils.ParseRSRFields(*jsnCfgFld.Field_filter, utils.INFIELD_SEP); err != nil {
return nil, err
}
}
if jsnCfgFld.Width != nil {
cfgFld.Width = *jsnCfgFld.Width
}
if jsnCfgFld.Strip != nil {
cfgFld.Strip = *jsnCfgFld.Strip
}
if jsnCfgFld.Padding != nil {
cfgFld.Padding = *jsnCfgFld.Padding
}
if jsnCfgFld.Layout != nil {
cfgFld.Layout = *jsnCfgFld.Layout
}
if jsnCfgFld.Mandatory != nil {
cfgFld.Mandatory = *jsnCfgFld.Mandatory
}
return cfgFld, nil
}
示例9: deriveCdrs
func (self *CdrServer) deriveCdrs(storedCdr *StoredCdr) ([]*StoredCdr, error) {
if len(storedCdr.MediationRunId) == 0 {
storedCdr.MediationRunId = utils.META_DEFAULT
}
cdrRuns := []*StoredCdr{storedCdr}
if storedCdr.Rated { // Do not derive already rated CDRs since they should be already derived
return cdrRuns, nil
}
attrsDC := &utils.AttrDerivedChargers{Tenant: storedCdr.Tenant, Category: storedCdr.Category, Direction: storedCdr.Direction,
Account: storedCdr.Account, Subject: storedCdr.Subject, Destination: storedCdr.Destination}
var dcs utils.DerivedChargers
if err := self.rater.GetDerivedChargers(attrsDC, &dcs); err != nil {
utils.Logger.Err(fmt.Sprintf("Could not get derived charging for cgrid %s, error: %s", storedCdr.CgrId, err.Error()))
return nil, err
}
for _, dc := range dcs.Chargers {
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)
dcPddFld, _ := utils.NewRSRField(dc.PddField)
dcATimeFld, _ := utils.NewRSRField(dc.AnswerTimeField)
dcDurFld, _ := utils.NewRSRField(dc.UsageField)
dcSupplFld, _ := utils.NewRSRField(dc.SupplierField)
dcDCauseFld, _ := utils.NewRSRField(dc.DisconnectCauseField)
dcRatedFld, _ := utils.NewRSRField(dc.RatedField)
dcCostFld, _ := utils.NewRSRField(dc.CostField)
forkedCdr, err := storedCdr.ForkCdr(dc.RunId, dcReqTypeFld, dcDirFld, dcTenantFld, dcCategoryFld, dcAcntFld, dcSubjFld, dcDstFld,
dcSTimeFld, dcPddFld, dcATimeFld, dcDurFld, dcSupplFld, dcDCauseFld, dcRatedFld, dcCostFld, []*utils.RSRField{}, true, self.cgrCfg.DefaultTimezone)
if err != nil {
utils.Logger.Err(fmt.Sprintf("Could not fork CGR with cgrid %s, run: %s, error: %s", storedCdr.CgrId, dc.RunId, err.Error()))
continue // do not add it to the forked CDR list
}
if !forkedCdr.Rated {
forkedCdr.Cost = -1.0 // Make sure that un-rated CDRs start with Cost -1
}
cdrRuns = append(cdrRuns, forkedCdr)
}
return cdrRuns, nil
}
示例10: TestCdreCdrFieldValue
func TestCdreCdrFieldValue(t *testing.T) {
cdre := new(CdrExporter)
cdr := &engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID, Cost: 1.01}
val, _ := utils.ParseRSRFields(utils.DESTINATION, utils.INFIELD_SEP)
cfgCdrFld := &config.CfgCdrField{Tag: "destination", Type: "cdrfield", FieldId: utils.DESTINATION, Value: val}
if val, err := cdre.cdrFieldValue(cdr, cfgCdrFld); err != nil {
t.Error(err)
} else if val != cdr.Destination {
t.Errorf("Expecting: %s, received: %s", cdr.Destination, val)
}
fltr, _ := utils.ParseRSRFields("~tenant:s/(.+)/itsyscom.com/", utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: "destination", Type: "cdrfield", FieldId: utils.DESTINATION, Value: val, FieldFilter: fltr}
if _, err := cdre.cdrFieldValue(cdr, cfgCdrFld); err == nil {
t.Error("Failed to use filter")
}
}
示例11: LoadDerivedChargers
func (csvr *CSVReader) LoadDerivedChargers() (err error) {
csvReader, fp, err := csvr.readerFunc(csvr.derivedChargersFn, csvr.sep, utils.DERIVED_CHARGERS_NRCOLS)
if err != nil {
log.Print("Could not load derivedChargers file: ", err)
// allow writing of the other values
return nil
}
if fp != nil {
defer fp.Close()
}
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
if _, err = utils.ParseRSRFields(record[6], utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db
return err
}
tag := utils.DerivedChargersKey(record[0], record[1], record[2], record[3], record[4])
if _, found := csvr.derivedChargers[tag]; found {
if csvr.derivedChargers[tag], err = csvr.derivedChargers[tag].Append(&utils.DerivedCharger{
RunId: ValueOrDefault(record[5], "*default"),
RunFilters: record[6],
ReqTypeField: ValueOrDefault(record[7], "*default"),
DirectionField: ValueOrDefault(record[8], "*default"),
TenantField: ValueOrDefault(record[9], "*default"),
CategoryField: ValueOrDefault(record[10], "*default"),
AccountField: ValueOrDefault(record[11], "*default"),
SubjectField: ValueOrDefault(record[12], "*default"),
DestinationField: ValueOrDefault(record[13], "*default"),
SetupTimeField: ValueOrDefault(record[14], "*default"),
AnswerTimeField: ValueOrDefault(record[15], "*default"),
UsageField: ValueOrDefault(record[16], "*default"),
}); err != nil {
return err
}
} else {
if record[5] == utils.DEFAULT_RUNID {
return errors.New("Reserved RunId")
}
csvr.derivedChargers[tag] = utils.DerivedChargers{&utils.DerivedCharger{
RunId: ValueOrDefault(record[5], "*default"),
RunFilters: record[6],
ReqTypeField: ValueOrDefault(record[7], "*default"),
DirectionField: ValueOrDefault(record[8], "*default"),
TenantField: ValueOrDefault(record[9], "*default"),
CategoryField: ValueOrDefault(record[10], "*default"),
AccountField: ValueOrDefault(record[11], "*default"),
SubjectField: ValueOrDefault(record[12], "*default"),
DestinationField: ValueOrDefault(record[13], "*default"),
SetupTimeField: ValueOrDefault(record[14], "*default"),
AnswerTimeField: ValueOrDefault(record[15], "*default"),
UsageField: ValueOrDefault(record[16], "*default"),
}}
}
}
return
}
示例12: TestCDRAsExportRecord
func TestCDRAsExportRecord(t *testing.T) {
cdr := &CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID, Cost: 1.01,
ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}}
val, _ := utils.ParseRSRFields(utils.DESTINATION, utils.INFIELD_SEP)
cfgCdrFld := &config.CfgCdrField{Tag: "destination", Type: utils.META_COMPOSED, FieldId: utils.DESTINATION, Value: val}
if expRecord, err := cdr.AsExportRecord([]*config.CfgCdrField{cfgCdrFld}, 0, 0, "UTC", false, 0, "", nil); err != nil {
t.Error(err)
} else if expRecord[0] != cdr.Destination {
t.Errorf("Expecting: %s, received: %s", cdr.Destination, expRecord[0])
}
fltr, _ := utils.ParseRSRFields("Tenant(itsyscom.com)", utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: "destination", Type: utils.META_COMPOSED, FieldId: utils.DESTINATION, Value: val, FieldFilter: fltr}
if _, err := cdr.AsExportRecord([]*config.CfgCdrField{cfgCdrFld}, 0, 0, "UTC", false, 0, "", nil); err == nil {
t.Error("Failed to use filter")
}
// Test MetaDateTime
val, _ = utils.ParseRSRFields("stop_time", utils.INFIELD_SEP)
layout := "2006-01-02 15:04:05"
cfgCdrFld = &config.CfgCdrField{Tag: "stop_time", Type: utils.MetaDateTime, FieldId: "stop_time", Value: val, Layout: layout}
if expRecord, err := cdr.AsExportRecord([]*config.CfgCdrField{cfgCdrFld}, 0, 0, "UTC", false, 0, "", nil); err != nil {
t.Error(err)
} else if expRecord[0] != "2014-06-11 19:19:00" {
t.Error("Expecting: 2014-06-11 19:19:00, got: ", expRecord[0])
}
// Test filter
fltr, _ = utils.ParseRSRFields("Tenant(itsyscom.com)", utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: "stop_time", Type: utils.MetaDateTime, FieldId: "stop_time", Value: val, FieldFilter: fltr, Layout: layout}
if _, err := cdr.AsExportRecord([]*config.CfgCdrField{cfgCdrFld}, 0, 0, "UTC", false, 0, "", nil); err == nil {
t.Error("Received empty error", err)
}
val, _ = utils.ParseRSRFields("fieldextr2", utils.INFIELD_SEP)
cfgCdrFld = &config.CfgCdrField{Tag: "stop_time", Type: utils.MetaDateTime, FieldId: "stop_time", Value: val, Layout: layout}
// Test time parse error
if _, err := cdr.AsExportRecord([]*config.CfgCdrField{cfgCdrFld}, 0, 0, "UTC", false, 0, "", nil); err == nil {
t.Error("Should give error here, got none.")
}
}
示例13: SetDerivedChargers
func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *string) (err error) {
if len(attrs.DerivedChargers) == 0 {
return utils.NewErrMandatoryIeMissing("DerivedChargers")
}
if len(attrs.Direction) == 0 {
attrs.Direction = utils.OUT
}
if len(attrs.Tenant) == 0 {
attrs.Tenant = utils.ANY
}
if len(attrs.Category) == 0 {
attrs.Category = utils.ANY
}
if len(attrs.Account) == 0 {
attrs.Account = utils.ANY
}
if len(attrs.Subject) == 0 {
attrs.Subject = utils.ANY
}
for _, dc := range attrs.DerivedChargers {
if _, err = utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db
return fmt.Errorf("%s:%s", utils.ErrParserError.Error(), err.Error())
}
}
dcKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject)
if !attrs.Overwrite {
if exists, err := self.RatingDb.HasData(utils.DERIVEDCHARGERS_PREFIX, dcKey); err != nil {
return utils.NewErrServerError(err)
} else if exists {
return utils.ErrExists
}
}
dstIds := strings.Split(attrs.DestinationIds, utils.INFIELD_SEP)
dcs := &utils.DerivedChargers{DestinationIDs: utils.NewStringMap(dstIds...), Chargers: attrs.DerivedChargers}
if err := self.RatingDb.SetDerivedChargers(dcKey, dcs); err != nil {
return utils.NewErrServerError(err)
}
if err := self.RatingDb.CacheRatingPrefixValues(map[string][]string{
utils.DERIVEDCHARGERS_PREFIX: []string{utils.DERIVEDCHARGERS_PREFIX + dcKey},
}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
示例14: SetDerivedChargers
func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *string) (err error) {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Category", "Direction", "Account", "Subject", "DerivedChargers"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
for _, dc := range attrs.DerivedChargers {
if _, err = utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db
return fmt.Errorf("%s:%s", utils.ERR_PARSER_ERROR, err.Error())
}
}
dcKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject)
if err := self.AccountDb.SetDerivedChargers(dcKey, attrs.DerivedChargers); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
if err := self.AccountDb.CacheAccounting([]string{}, []string{}, []string{}, []string{engine.DERIVEDCHARGERS_PREFIX + dcKey}); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
*reply = utils.OK
return nil
}
示例15: loadFromJsonCfg
func (self *DARequestProcessor) loadFromJsonCfg(jsnCfg *DARequestProcessorJsnCfg) error {
if jsnCfg == nil {
return nil
}
if jsnCfg.Id != nil {
self.Id = *jsnCfg.Id
}
if jsnCfg.Dry_run != nil {
self.DryRun = *jsnCfg.Dry_run
}
if jsnCfg.Publish_event != nil {
self.PublishEvent = *jsnCfg.Publish_event
}
var err error
if jsnCfg.Request_filter != nil {
if self.RequestFilter, err = utils.ParseRSRFields(*jsnCfg.Request_filter, utils.INFIELD_SEP); err != nil {
return err
}
}
if jsnCfg.Flags != nil {
self.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
}
if jsnCfg.Continue_on_success != nil {
self.ContinueOnSuccess = *jsnCfg.Continue_on_success
}
if jsnCfg.Append_cca != nil {
self.AppendCCA = *jsnCfg.Append_cca
}
if jsnCfg.CCR_fields != nil {
if self.CCRFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.CCR_fields); err != nil {
return err
}
}
if jsnCfg.CCA_fields != nil {
if self.CCAFields, err = CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.CCA_fields); err != nil {
return err
}
}
return nil
}