Esempio n. 1
0
// Extracts data out of CCR into a SMGenericEvent based on the configured template
func (self *CCR) AsSMGenericEvent(cfgFlds []*config.CfgCdrField) (sessionmanager.SMGenericEvent, error) {
	outMap := make(map[string]string) // work with it so we can append values to keys
	outMap[utils.EVENT_NAME] = DIAMETER_CCR
	for _, cfgFld := range cfgFlds {
		var outVal string
		var err error
		switch cfgFld.Type {
		case utils.META_FILLER:
			outVal = cfgFld.Value.Id()
			cfgFld.Padding = "right"
		case utils.META_CONSTANT:
			outVal = cfgFld.Value.Id()
		case utils.META_HANDLER:
			outVal, err = self.metaHandler(cfgFld.HandlerId, cfgFld.Layout)
			if err != nil {
				utils.Logger.Warning(fmt.Sprintf("<Diameter> Ignoring processing of metafunction: %s, error: %s", cfgFld.HandlerId, err.Error()))
			}
		case utils.META_COMPOSED:
			outVal = self.eventFieldValue(cfgFld.Value)
		}
		fmtOut := outVal
		if fmtOut, err = utils.FmtFieldWidth(outVal, cfgFld.Width, cfgFld.Strip, cfgFld.Padding, cfgFld.Mandatory); err != nil {
			utils.Logger.Warning(fmt.Sprintf("<Diameter> Error when processing field template with tag: %s, error: %s", cfgFld.Tag, err.Error()))
			return nil, err
		}
		if _, hasKey := outMap[cfgFld.FieldId]; !hasKey {
			outMap[cfgFld.FieldId] = fmtOut
		} else { // If already there, postpend
			outMap[cfgFld.FieldId] += fmtOut
		}
	}
	return sessionmanager.SMGenericEvent(utils.ConvertMapValStrIf(outMap)), nil
}
Esempio n. 2
0
// Extracts data out of CCR into a SMGenericEvent based on the configured template
func (self *CCR) AsSMGenericEvent(cfgFlds []*config.CfgCdrField) (sessionmanager.SMGenericEvent, error) {
	outMap := make(map[string]string) // work with it so we can append values to keys
	outMap[utils.EVENT_NAME] = DIAMETER_CCR
	for _, cfgFld := range cfgFlds {
		fmtOut, err := fieldOutVal(self.diamMessage, cfgFld, self.debitInterval)
		if err != nil {
			if err == ErrFilterNotPassing {
				continue // Do nothing in case of Filter not passing
			}
			return nil, err
		}
		if _, hasKey := outMap[cfgFld.FieldId]; hasKey && cfgFld.Append {
			outMap[cfgFld.FieldId] += fmtOut
		} else {
			outMap[cfgFld.FieldId] = fmtOut

		}
	}
	return sessionmanager.SMGenericEvent(utils.ConvertMapValStrIf(outMap)), nil
}