mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 22:58:44 +05:00
Individual configuration in sm/freeswitch for capturing extra fields
This commit is contained in:
@@ -40,6 +40,8 @@ type Event interface {
|
||||
GetAnswerTime(string) (time.Time, error)
|
||||
GetEndTime() (time.Time, error)
|
||||
GetDuration(string) (time.Duration, error)
|
||||
GetOriginatorIP(string) string
|
||||
GetExtraFields() map[string]string
|
||||
MissingParameter() bool
|
||||
ParseEventValue(*utils.RSRField) string
|
||||
PassesFieldFilter(*utils.RSRField) (bool, string)
|
||||
|
||||
@@ -627,3 +627,14 @@ func TestFsEvAsStoredCdr(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eStoredCdr, storedCdr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsEvGetExtraFields(t *testing.T) {
|
||||
cfg, _ = config.NewDefaultCGRConfig()
|
||||
cfg.FSCdrExtraFields = []*utils.RSRField{&utils.RSRField{Id: "Channel-Read-Codec-Name"}, &utils.RSRField{Id: "Channel-Write-Codec-Name"}, &utils.RSRField{Id: "NonExistingHeader"}}
|
||||
config.SetCgrConfig(cfg)
|
||||
ev := new(FSEvent).New(hangupEv)
|
||||
expectedExtraFields := map[string]string{"Channel-Read-Codec-Name": "G722", "Channel-Write-Codec-Name": "G722", "NonExistingHeader": ""}
|
||||
if extraFields := ev.GetExtraFields(); !reflect.DeepEqual(extraFields, extraFields) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedExtraFields, extraFields)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,12 @@ func (osipsev *OsipsEvent) GetDuration(fieldName string) (time.Duration, error)
|
||||
}
|
||||
return utils.ParseDurationWithSecs(durStr)
|
||||
}
|
||||
func (osipsEv *OsipsEvent) GetOriginatorIP(fieldName string) string {
|
||||
if osipsEv.osipsEvent == nil || osipsEv.osipsEvent.OriginatorAddress == nil {
|
||||
return ""
|
||||
}
|
||||
return osipsEv.osipsEvent.OriginatorAddress.IP.String()
|
||||
}
|
||||
func (osipsev *OsipsEvent) MissingParameter() bool {
|
||||
return len(osipsev.GetUUID()) == 0 ||
|
||||
len(osipsev.GetAccount(utils.META_DEFAULT)) == 0 ||
|
||||
@@ -184,18 +190,13 @@ func (osipsev *OsipsEvent) GetExtraFields() map[string]string {
|
||||
}
|
||||
return extraFields
|
||||
}
|
||||
func (osipsEv *OsipsEvent) GetOriginatorIP() string {
|
||||
if osipsEv.osipsEvent == nil || osipsEv.osipsEvent.OriginatorAddress == nil {
|
||||
return ""
|
||||
}
|
||||
return osipsEv.osipsEvent.OriginatorAddress.IP.String()
|
||||
}
|
||||
|
||||
func (osipsEv *OsipsEvent) AsStoredCdr() *utils.StoredCdr {
|
||||
storCdr := new(utils.StoredCdr)
|
||||
storCdr.CgrId = osipsEv.GetCgrId()
|
||||
storCdr.TOR = utils.VOICE
|
||||
storCdr.AccId = osipsEv.GetUUID()
|
||||
storCdr.CdrHost = osipsEv.GetOriginatorIP()
|
||||
storCdr.CdrHost = osipsEv.GetOriginatorIP(utils.META_DEFAULT)
|
||||
storCdr.CdrSource = "OSIPS_" + osipsEv.GetName()
|
||||
storCdr.ReqType = osipsEv.GetReqType(utils.META_DEFAULT)
|
||||
storCdr.Direction = osipsEv.GetDirection(utils.META_DEFAULT)
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestOsipsEventGetValues(t *testing.T) {
|
||||
!answerTime.Equal(eAnswerTime) ||
|
||||
!endTime.Equal(eAnswerTime.Add(dur)) ||
|
||||
dur != time.Duration(20*time.Second) ||
|
||||
osipsEv.GetOriginatorIP() != "172.16.254.77" {
|
||||
osipsEv.GetOriginatorIP(utils.META_DEFAULT) != "172.16.254.77" {
|
||||
t.Error("GetValues not matching: ", osipsEv.GetName() != "E_ACC_CDR",
|
||||
osipsEv.GetCgrId() != utils.Sha1("ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ"+";"+"eb082607"+";"+"4ea9687f", setupTime.UTC().String()),
|
||||
osipsEv.GetUUID() != "ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ;eb082607;4ea9687f",
|
||||
@@ -107,7 +107,7 @@ func TestOsipsEventGetValues(t *testing.T) {
|
||||
!answerTime.Equal(time.Date(2014, 7, 26, 12, 28, 19, 0, time.Local)),
|
||||
!endTime.Equal(time.Date(2014, 7, 26, 12, 28, 39, 0, time.Local)),
|
||||
dur != time.Duration(20*time.Second),
|
||||
osipsEv.GetOriginatorIP() != "172.16.254.77",
|
||||
osipsEv.GetOriginatorIP(utils.META_DEFAULT) != "172.16.254.77",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user