func (kev KamEvent) AsStoredCdr(timezone string) *engine.StoredCdr { storCdr := new(engine.StoredCdr) storCdr.CgrId = kev.GetCgrId(timezone) storCdr.TOR = utils.VOICE storCdr.AccId = kev.GetUUID() storCdr.CdrHost = kev.GetOriginatorIP(utils.META_DEFAULT) storCdr.CdrSource = kev.GetCdrSource() storCdr.ReqType = kev.GetReqType(utils.META_DEFAULT) storCdr.Direction = kev.GetDirection(utils.META_DEFAULT) storCdr.Tenant = kev.GetTenant(utils.META_DEFAULT) storCdr.Category = kev.GetCategory(utils.META_DEFAULT) storCdr.Account = kev.GetAccount(utils.META_DEFAULT) storCdr.Subject = kev.GetSubject(utils.META_DEFAULT) storCdr.Destination = kev.GetDestination(utils.META_DEFAULT) storCdr.SetupTime, _ = kev.GetSetupTime(utils.META_DEFAULT, timezone) storCdr.AnswerTime, _ = kev.GetAnswerTime(utils.META_DEFAULT, timezone) storCdr.Usage, _ = kev.GetDuration(utils.META_DEFAULT) storCdr.Pdd, _ = kev.GetPdd(utils.META_DEFAULT) storCdr.Supplier = kev.GetSupplier(utils.META_DEFAULT) storCdr.DisconnectCause = kev.GetDisconnectCause(utils.META_DEFAULT) storCdr.ExtraFields = kev.GetExtraFields() storCdr.Cost = -1 return storCdr }
// Populates the func populateStoredCdrField(cdr *engine.StoredCdr, fieldId, fieldVal, timezone string) error { var err error switch fieldId { case utils.TOR: cdr.TOR += fieldVal case utils.ACCID: cdr.AccId += fieldVal case utils.REQTYPE: cdr.ReqType += fieldVal case utils.DIRECTION: cdr.Direction += fieldVal case utils.TENANT: cdr.Tenant += fieldVal case utils.CATEGORY: cdr.Category += fieldVal case utils.ACCOUNT: cdr.Account += fieldVal case utils.SUBJECT: cdr.Subject += fieldVal case utils.DESTINATION: cdr.Destination += fieldVal case utils.RATED_FLD: cdr.Rated, _ = strconv.ParseBool(fieldVal) case utils.SETUP_TIME: if cdr.SetupTime, err = utils.ParseTimeDetectLayout(fieldVal, timezone); err != nil { return fmt.Errorf("Cannot parse answer time field with value: %s, err: %s", fieldVal, err.Error()) } case utils.PDD: if cdr.Pdd, err = utils.ParseDurationWithSecs(fieldVal); err != nil { return fmt.Errorf("Cannot parse answer time field with value: %s, err: %s", fieldVal, err.Error()) } case utils.ANSWER_TIME: if cdr.AnswerTime, err = utils.ParseTimeDetectLayout(fieldVal, timezone); err != nil { return fmt.Errorf("Cannot parse answer time field with value: %s, err: %s", fieldVal, err.Error()) } case utils.USAGE: if cdr.Usage, err = utils.ParseDurationWithSecs(fieldVal); err != nil { return fmt.Errorf("Cannot parse duration field with value: %s, err: %s", fieldVal, err.Error()) } case utils.SUPPLIER: cdr.Supplier += fieldVal case utils.DISCONNECT_CAUSE: cdr.DisconnectCause += fieldVal case utils.COST: if cdr.Cost, err = strconv.ParseFloat(fieldVal, 64); err != nil { return fmt.Errorf("Cannot parse cost field with value: %s, err: %s", fieldVal, err.Error()) } default: // Extra fields will not match predefined so they all show up here cdr.ExtraFields[fieldId] += fieldVal } return nil }