mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Individual configuration in sm/freeswitch for capturing extra fields
This commit is contained in:
@@ -127,6 +127,7 @@ type CGRConfig struct {
|
||||
FSLowBalanceAnnFile string // File to be played when low balance is reached
|
||||
FSEmptyBalanceContext string // If defined, call will be transfered to this context on empty balance
|
||||
FSEmptyBalanceAnnFile string // File to be played before disconnecting prepaid calls (applies only if no context defined)
|
||||
FSCdrExtraFields []*utils.RSRField // Extra fields to store in CDRs in case of processing them
|
||||
OsipsListenUdp string // Address where to listen for event datagrams coming from OpenSIPS
|
||||
OsipsMiAddr string // Adress where to reach OpenSIPS mi_datagram module
|
||||
OsipsEvSubscInterval time.Duration // Refresh event subscription at this interval
|
||||
@@ -229,6 +230,7 @@ func (self *CGRConfig) setDefaults() error {
|
||||
self.FSLowBalanceAnnFile = ""
|
||||
self.FSEmptyBalanceContext = ""
|
||||
self.FSEmptyBalanceAnnFile = ""
|
||||
self.FSCdrExtraFields = []*utils.RSRField{}
|
||||
self.OsipsListenUdp = "127.0.0.1:2020"
|
||||
self.OsipsMiAddr = "127.0.0.1:8020"
|
||||
self.OsipsEvSubscInterval = time.Duration(60) * time.Second
|
||||
@@ -599,6 +601,14 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
|
||||
if hasOpt = c.HasOption("freeswitch", "empty_balance_ann_file"); hasOpt {
|
||||
cfg.FSEmptyBalanceAnnFile, _ = c.GetString("freeswitch", "empty_balance_ann_file")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "cdr_extra_fields"); hasOpt {
|
||||
extraFieldsStr, _ := c.GetString("freeswitch", "cdr_extra_fields")
|
||||
if extraFields, err := utils.ParseRSRFields(extraFieldsStr, utils.FIELDS_SEP); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cfg.FSCdrExtraFields = extraFields
|
||||
}
|
||||
}
|
||||
if hasOpt = c.HasOption("opensips", "listen_udp"); hasOpt {
|
||||
cfg.OsipsListenUdp, _ = c.GetString("opensips", "listen_udp")
|
||||
}
|
||||
|
||||
@@ -129,6 +129,7 @@ func TestDefaults(t *testing.T) {
|
||||
eCfg.FSLowBalanceAnnFile = ""
|
||||
eCfg.FSEmptyBalanceContext = ""
|
||||
eCfg.FSEmptyBalanceAnnFile = ""
|
||||
eCfg.FSCdrExtraFields = []*utils.RSRField{}
|
||||
eCfg.OsipsListenUdp = "127.0.0.1:2020"
|
||||
eCfg.OsipsMiAddr = "127.0.0.1:8020"
|
||||
eCfg.OsipsEvSubscInterval = time.Duration(60) * time.Second
|
||||
@@ -286,6 +287,7 @@ func TestConfigFromFile(t *testing.T) {
|
||||
eCfg.FSLowBalanceAnnFile = "test"
|
||||
eCfg.FSEmptyBalanceContext = "test"
|
||||
eCfg.FSEmptyBalanceAnnFile = "test"
|
||||
eCfg.FSCdrExtraFields = []*utils.RSRField{&utils.RSRField{Id: "test"}}
|
||||
eCfg.OsipsListenUdp = "test"
|
||||
eCfg.OsipsMiAddr = "test"
|
||||
eCfg.OsipsEvSubscInterval = time.Duration(99) * time.Second
|
||||
|
||||
@@ -129,6 +129,7 @@ min_dur_low_balance = 99 # Threshold which will trigger low balance warnin
|
||||
low_balance_ann_file = test # File to be played when low balance is reached
|
||||
empty_balance_context = test # If defined, call will be transfered to this context on empty balance
|
||||
empty_balance_ann_file = test # File to be played before disconnecting prepaid calls (applies only if no context defined)
|
||||
cdr_extra_fields = test # Extra fields to store in CDRs in case of processing them
|
||||
|
||||
[opensips]
|
||||
listen_udp = test # Address where to listen for event datagrams coming from OpenSIPS
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
# low_balance_ann_file = # File to be played when low balance is reached for prepaid calls
|
||||
# empty_balance_context = # If defined, prepaid calls will be transfered to this context on empty balance
|
||||
# empty_balance_ann_file = # File to be played before disconnecting prepaid calls on empty balance (applies only if no context defined)
|
||||
# cdr_extra_fields = # Extra fields to store in CDRs in case of processing them
|
||||
|
||||
[opensips]
|
||||
# listen_udp = 127.0.0.1:2020 # Address where to listen for datagram events coming from OpenSIPS
|
||||
|
||||
@@ -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