Exemple #1
0
func (self SMGenericEvent) AsLcrRequest() *engine.LcrRequest {
	setupTimeStr, _ := utils.ConvertIfaceToString(self[utils.SETUP_TIME])
	usageStr, _ := utils.ConvertIfaceToString(self[utils.USAGE])
	return &engine.LcrRequest{
		Direction:   self.GetDirection(utils.META_DEFAULT),
		Tenant:      self.GetTenant(utils.META_DEFAULT),
		Category:    self.GetCategory(utils.META_DEFAULT),
		Account:     self.GetAccount(utils.META_DEFAULT),
		Subject:     self.GetSubject(utils.META_DEFAULT),
		Destination: self.GetDestination(utils.META_DEFAULT),
		SetupTime:   utils.FirstNonEmpty(setupTimeStr),
		Duration:    usageStr,
	}
}
Exemple #2
0
func (self SMGenericEvent) GetAnswerTime(fieldName, timezone string) (time.Time, error) {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.ANSWER_TIME
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return utils.ParseTimeDetectLayout(result, timezone)
}
Exemple #3
0
func (self SMGenericEvent) GetOriginatorIP(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.CDRHOST
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #4
0
func (self SMGenericEvent) GetDestination(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.DESTINATION
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #5
0
func (self SMGenericEvent) GetCategory(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.CATEGORY
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #6
0
func (self SMGenericEvent) GetAccount(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.ACCOUNT
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #7
0
func (self SMGenericEvent) GetSubject(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.SUBJECT
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #8
0
func (self SMGenericEvent) GetDisconnectCause(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.DISCONNECT_CAUSE
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #9
0
func (self SMGenericEvent) GetReqType(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.REQTYPE
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #10
0
func (self SMGenericEvent) GetSupplier(fieldName string) string {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.SUPPLIER
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return result
}
Exemple #11
0
func (self SMGenericEvent) GetPdd(fieldName string) (time.Duration, error) {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.PDD
	}
	result, _ := utils.ConvertIfaceToString(self[fieldName])
	return utils.ParseDurationWithSecs(result)
}
Exemple #12
0
func (self SMGenericEvent) GetLastUsed(fieldName string) (time.Duration, error) {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.LastUsed
	}
	valStr, hasVal := self[fieldName]
	if !hasVal {
		return nilDuration, utils.ErrNotFound
	}
	result, _ := utils.ConvertIfaceToString(valStr)
	return utils.ParseDurationWithSecs(result)
}
Exemple #13
0
func (self SMGenericEvent) GetFieldAsString(fieldName string) (string, error) {
	valIf, hasVal := self[fieldName]
	if !hasVal {
		return "", utils.ErrNotFound
	}
	result, converted := utils.ConvertIfaceToString(valIf)
	if !converted {
		return "", utils.ErrNotConvertible
	}
	return result, nil
}
Exemple #14
0
func (self SMGenericEvent) GetMaxUsage(fieldName string, cfgMaxUsage time.Duration) (time.Duration, error) {
	if fieldName == utils.META_DEFAULT {
		fieldName = utils.USAGE
	}
	maxUsageStr, hasIt := self[fieldName]
	if !hasIt {
		return cfgMaxUsage, nil
	}
	result, _ := utils.ConvertIfaceToString(maxUsageStr)
	return utils.ParseDurationWithSecs(result)
}
Exemple #15
0
func (self SMGenericEvent) ParseEventValue(rsrFld *utils.RSRField, timezone string) string {
	switch rsrFld.Id {
	case utils.CGRID:
		return rsrFld.ParseValue(self.GetCgrId(timezone))
	case utils.TOR:
		return rsrFld.ParseValue(utils.VOICE)
	case utils.ACCID:
		return rsrFld.ParseValue(self.GetUUID())
	case utils.CDRHOST:
		return rsrFld.ParseValue(self.GetOriginatorIP(utils.META_DEFAULT))
	case utils.CDRSOURCE:
		return rsrFld.ParseValue(self.GetName())
	case utils.REQTYPE:
		return rsrFld.ParseValue(self.GetReqType(utils.META_DEFAULT))
	case utils.DIRECTION:
		return rsrFld.ParseValue(self.GetDirection(utils.META_DEFAULT))
	case utils.TENANT:
		return rsrFld.ParseValue(self.GetTenant(utils.META_DEFAULT))
	case utils.CATEGORY:
		return rsrFld.ParseValue(self.GetCategory(utils.META_DEFAULT))
	case utils.ACCOUNT:
		return rsrFld.ParseValue(self.GetAccount(utils.META_DEFAULT))
	case utils.SUBJECT:
		return rsrFld.ParseValue(self.GetSubject(utils.META_DEFAULT))
	case utils.DESTINATION:
		return rsrFld.ParseValue(self.GetDestination(utils.META_DEFAULT))
	case utils.SETUP_TIME:
		st, _ := self.GetSetupTime(utils.META_DEFAULT, timezone)
		return rsrFld.ParseValue(st.String())
	case utils.ANSWER_TIME:
		at, _ := self.GetAnswerTime(utils.META_DEFAULT, timezone)
		return rsrFld.ParseValue(at.String())
	case utils.USAGE:
		dur, _ := self.GetUsage(utils.META_DEFAULT)
		return rsrFld.ParseValue(strconv.FormatInt(dur.Nanoseconds(), 10))
	case utils.PDD:
		pdd, _ := self.GetPdd(utils.META_DEFAULT)
		return rsrFld.ParseValue(strconv.FormatFloat(pdd.Seconds(), 'f', -1, 64))
	case utils.SUPPLIER:
		return rsrFld.ParseValue(self.GetSupplier(utils.META_DEFAULT))
	case utils.DISCONNECT_CAUSE:
		return rsrFld.ParseValue(self.GetDisconnectCause(utils.META_DEFAULT))
	case utils.MEDI_RUNID:
		return rsrFld.ParseValue(utils.META_DEFAULT)
	case utils.COST:
		return rsrFld.ParseValue(strconv.FormatFloat(-1, 'f', -1, 64)) // Recommended to use FormatCost
	default:
		strVal, _ := utils.ConvertIfaceToString(self[rsrFld.Id])
		val := rsrFld.ParseValue(strVal)
		return val
	}
	return ""
}
Exemple #16
0
func (self SMGenericEvent) GetExtraFields() map[string]string {
	extraFields := make(map[string]string)
	for key, val := range self {
		primaryFields := append(utils.PrimaryCdrFields, utils.EVENT_NAME)
		if utils.IsSliceMember(primaryFields, key) {
			continue
		}
		result, _ := utils.ConvertIfaceToString(val)
		extraFields[key] = result
	}
	return extraFields
}
Exemple #17
0
// GetSessionTTL retrieves SessionTTL setting out of SMGenericEvent
func (self SMGenericEvent) GetSessionTTL() time.Duration {
	valIf, hasVal := self[utils.SessionTTL]
	if !hasVal {
		return time.Duration(0)
	}
	ttlStr, converted := utils.ConvertIfaceToString(valIf)
	if !converted {
		return time.Duration(0)
	}
	ttl, _ := utils.ParseDurationWithSecs(ttlStr)
	return ttl
}
Exemple #18
0
// GetSessionTTLUsage retrieves SessionTTLUsage setting out of SMGenericEvent
func (self SMGenericEvent) GetSessionTTLUsage() *time.Duration {
	valIf, hasVal := self[utils.SessionTTLUsage]
	if !hasVal {
		return nil
	}
	ttlStr, converted := utils.ConvertIfaceToString(valIf)
	if !converted {
		return nil
	}
	if ttl, err := utils.ParseDurationWithSecs(ttlStr); err != nil {
		return nil
	} else {
		return &ttl
	}
}
Exemple #19
0
func (self SMGenericEvent) GetUUID() string {
	result, _ := utils.ConvertIfaceToString(self[utils.ACCID])
	return result
}
Exemple #20
0
func (self SMGenericEvent) GetName() string {
	result, _ := utils.ConvertIfaceToString(self[utils.EVENT_NAME])
	return result
}