Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit 348dcb5

Browse files
andronachedanbogos
authored andcommitted
Default requestType in agents
1 parent db672ba commit 348dcb5

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

agents/asterisk_event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (smaEv *SMAsteriskEvent) Destination() string {
144144
}
145145

146146
func (smaEv *SMAsteriskEvent) RequestType() string {
147-
return smaEv.cachedFields[utils.CGRReqType]
147+
return utils.FirstNonEmpty(smaEv.cachedFields[utils.CGRReqType], config.CgrConfig().GeneralCfg().DefaultReqType)
148148
}
149149

150150
func (smaEv *SMAsteriskEvent) Tenant() string {

agents/asterisk_event_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func TestSMAEventRequestType(t *testing.T) {
211211
}
212212
ev = make(map[string]interface{}) // Clear previous data
213213
smaEv = NewSMAsteriskEvent(ev, "127.0.0.1", "")
214-
if smaEv.RequestType() != "" {
214+
if smaEv.RequestType() != config.CgrConfig().GeneralCfg().DefaultReqType {
215215
t.Error("Received:", smaEv.RequestType())
216216
}
217217
}
@@ -459,3 +459,19 @@ func TestSMAEventV1TerminateSessionArgs(t *testing.T) {
459459
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp2), utils.ToJSON(rcv))
460460
}
461461
}
462+
463+
func TestRequestType(t *testing.T) {
464+
var ev map[string]interface{}
465+
if err := json.Unmarshal([]byte(stasisStart), &ev); err != nil {
466+
t.Error(err)
467+
}
468+
smaEv := NewSMAsteriskEvent(ev, "127.0.0.1", "")
469+
if smaEv.RequestType() != "*prepaid" {
470+
t.Error("Received:", smaEv.RequestType())
471+
}
472+
ev = make(map[string]interface{}) // Clear previous data
473+
smaEv = NewSMAsteriskEvent(ev, "127.0.0.1", "")
474+
if smaEv.RequestType() != config.CgrConfig().GeneralCfg().DefaultReqType {
475+
t.Error("Received:", smaEv.RequestType())
476+
}
477+
}

agents/kamevent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ func (kev KamEvent) AsMapStringInterface() (mp map[string]interface{}) {
147147
if _, has := mp[utils.Source]; !has {
148148
mp[utils.Source] = utils.KamailioAgent
149149
}
150+
if _, has := mp[utils.RequestType]; !has {
151+
mp[utils.RequestType] = config.CgrConfig().GeneralCfg().DefaultReqType
152+
}
150153
return
151154
}
152155

agents/kamevent_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func TestKamEvAsMapStringInterface(t *testing.T) {
102102
expMp["from_tag"] = "bf71ad59"
103103
expMp["to_tag"] = "7351fecf"
104104
expMp["cgr_reqtype"] = utils.MetaPostpaid
105+
expMp[utils.RequestType] = utils.MetaRated
105106
expMp[utils.Source] = utils.KamailioAgent
106107
rcv := kamEv.AsMapStringInterface()
107108
if !reflect.DeepEqual(expMp, rcv) {

data/ansible/calls/asterisk/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
# Install and config CGRateS
7575
- name: Install and config CGRateS
7676
include: cgrates.yaml
77-
77+
7878
# Configure Asterisk
7979
- name: Download Asterisk
8080
become: yes

0 commit comments

Comments
 (0)