mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding ability to specify ids for subsystems directly from agent flags
This commit is contained in:
committed by
Dan Christian Bogos
parent
d99d229295
commit
5c14688366
@@ -156,7 +156,7 @@ func (smaEv *SMAsteriskEvent) Supplier() string {
|
||||
}
|
||||
|
||||
func (smaEv *SMAsteriskEvent) Subsystems() string {
|
||||
return smaEv.cachedFields[utils.CGRSubsystems]
|
||||
return smaEv.cachedFields[utils.CGRFlags]
|
||||
}
|
||||
|
||||
func (smaEv *SMAsteriskEvent) OriginHost() string {
|
||||
@@ -281,24 +281,46 @@ func (smaEv *SMAsteriskEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs)
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
if smaEv.Subsystems() == utils.EmptyString {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> cgr_subsystems variable is not set",
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> cgr_flags variable is not set",
|
||||
utils.AsteriskAgent))
|
||||
return
|
||||
}
|
||||
args.GetMaxUsage = strings.Index(smaEv.Subsystems(), utils.MetaAccounts) != -1
|
||||
args.AuthorizeResources = strings.Index(smaEv.Subsystems(), utils.MetaResources) != -1
|
||||
args.GetSuppliers = strings.Index(smaEv.Subsystems(), utils.MetaSuppliers) != -1
|
||||
args.SuppliersIgnoreErrors = strings.Index(smaEv.Subsystems(), utils.MetaSuppliersIgnoreErrors) != -1
|
||||
if strings.Index(smaEv.Subsystems(), utils.MetaSuppliersEventCost) != -1 {
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
for _, subsystem := range strings.Split(smaEv.Subsystems(), utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.GetMaxUsage = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AuthorizeResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
case subsystem == utils.MetaSuppliers:
|
||||
args.GetSuppliers = true
|
||||
case subsystem == utils.MetaSuppliersIgnoreErrors:
|
||||
args.SuppliersIgnoreErrors = true
|
||||
case subsystem == utils.MetaSuppliersEventCost:
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
args.GetAttributes = strings.Index(smaEv.Subsystems(), utils.MetaAttributes) != -1
|
||||
args.ProcessThresholds = strings.Index(smaEv.Subsystems(), utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(smaEv.Subsystems(), utils.MetaStats) != -1
|
||||
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(smaEv.Subsystems(), utils.MetaDispatchers) != -1, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
return
|
||||
}
|
||||
|
||||
@@ -307,18 +329,41 @@ func (smaEv *SMAsteriskEvent) V1InitSessionArgs(cgrEvDisp utils.CGREventWithArgD
|
||||
InitSession: true,
|
||||
CGREvent: cgrEvDisp.CGREvent,
|
||||
}
|
||||
subsystems, err := cgrEvDisp.CGREvent.FieldAsString(utils.CGRSubsystems)
|
||||
subsystems, err := cgrEvDisp.CGREvent.FieldAsString(utils.CGRFlags)
|
||||
if err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> event: %s don't have cgr_subsystems variable",
|
||||
utils.AsteriskAgent, utils.ToJSON(cgrEvDisp.CGREvent)))
|
||||
return
|
||||
}
|
||||
args.InitSession = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.AllocateResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.GetAttributes = strings.Index(subsystems, utils.MetaAttributes) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
args.ArgDispatcher = cgrEvDisp.ArgDispatcher
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.InitSession = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AllocateResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEvDisp.ConsumeArgs(true, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -327,16 +372,34 @@ func (smaEv *SMAsteriskEvent) V1TerminateSessionArgs(cgrEvDisp utils.CGREventWit
|
||||
TerminateSession: true,
|
||||
CGREvent: cgrEvDisp.CGREvent,
|
||||
}
|
||||
subsystems, err := cgrEvDisp.CGREvent.FieldAsString(utils.CGRSubsystems)
|
||||
subsystems, err := cgrEvDisp.CGREvent.FieldAsString(utils.CGRFlags)
|
||||
if err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> event: %s don't have cgr_subsystems variable",
|
||||
utils.AsteriskAgent, utils.ToJSON(cgrEvDisp.CGREvent)))
|
||||
return
|
||||
}
|
||||
args.TerminateSession = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.ReleaseResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
args.ArgDispatcher = cgrEvDisp.ArgDispatcher
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.TerminateSession = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.ReleaseResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEvDisp.ConsumeArgs(true, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ func TestSMAEventV1AuthorizeArgs(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp.GetMaxUsage, rcv.GetMaxUsage)
|
||||
}
|
||||
|
||||
stasisStart2 := `{"type":"StasisStart","timestamp":"2018-11-25T05:03:26.464-0500","args":["cgr_reqtype=*prepaid","cgr_supplier=supplier1","cgr_subsystems=*accounts*attributes*resources*stats*suppliers*thresholds"],"channel":{"id":"1543140206.0","dialplan":{"context":"internal","exten":"1002","priority":4},"caller":{"name":"","number":"1001"},"name":"PJSIP/1001-00000000","state":"Ring","connected":{"name":"","number":""},"language":"en","accountcode":"","creationtime":"2018-11-25T05:03:26.463-0500"},"asterisk_id":"08:00:27:b7:b8:1f","application":"cgrates_auth"}`
|
||||
stasisStart2 := `{"type":"StasisStart","timestamp":"2018-11-25T05:03:26.464-0500","args":["cgr_reqtype=*prepaid","cgr_supplier=supplier1","cgr_flags=*accounts,*attributes,*resources,*stats,*suppliers,*thresholds"],"channel":{"id":"1543140206.0","dialplan":{"context":"internal","exten":"1002","priority":4},"caller":{"name":"","number":"1001"},"name":"PJSIP/1001-00000000","state":"Ring","connected":{"name":"","number":""},"language":"en","accountcode":"","creationtime":"2018-11-25T05:03:26.463-0500"},"asterisk_id":"08:00:27:b7:b8:1f","application":"cgrates_auth"}`
|
||||
var ev2 map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(stasisStart2), &ev2); err != nil {
|
||||
t.Error(err)
|
||||
@@ -410,7 +410,7 @@ func TestSMAEventV1InitSessionArgs(t *testing.T) {
|
||||
InitSession: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
cgrEv.Event[utils.CGRSubsystems] = "*resources*accounts*attributes"
|
||||
cgrEv.Event[utils.CGRFlags] = "*resources,*accounts,*attributes"
|
||||
if rcv := smaEv.V1InitSessionArgs(utils.CGREventWithArgDispatcher{CGREvent: cgrEv}); !reflect.DeepEqual(exp2, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp2), utils.ToJSON(rcv))
|
||||
}
|
||||
@@ -443,7 +443,7 @@ func TestSMAEventV1TerminateSessionArgs(t *testing.T) {
|
||||
ProcessStats: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
cgrEv.Event[utils.CGRSubsystems] = "*resources*accounts*stats"
|
||||
cgrEv.Event[utils.CGRFlags] = "*resources,*accounts,*stats"
|
||||
if rcv := smaEv.V1TerminateSessionArgs(utils.CGREventWithArgDispatcher{CGREvent: cgrEv}); !reflect.DeepEqual(exp2, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp2), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func (sm *FSsessions) onChannelHangupComplete(fsev FSEvent, connIdx int) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(fsev[VarCGRSubsystems], utils.MetaDispatchers) != -1, false)
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(fsev[VarCGRFlags], utils.MetaDispatchers) != -1, false)
|
||||
if err := sm.sS.Call(utils.SessionSv1ProcessCDR,
|
||||
&utils.CGREventWithArgDispatcher{CGREvent: cgrEv, ArgDispatcher: cgrArgs.ArgDispatcher}, &reply); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> Failed processing CGREvent: %s, error: <%s>",
|
||||
|
||||
@@ -65,7 +65,7 @@ const (
|
||||
PDD_NOMEDIA_MS = "variable_progressmsec"
|
||||
IGNOREPARK = "variable_cgr_ignorepark"
|
||||
FS_VARPREFIX = "variable_"
|
||||
VarCGRSubsystems = "variable_" + utils.CGRSubsystems
|
||||
VarCGRFlags = "variable_" + utils.CGRFlags
|
||||
CGRResourceAllocation = "cgr_resource_allocation"
|
||||
VAR_CGR_DISCONNECT_CAUSE = "variable_" + utils.CGR_DISCONNECT_CAUSE
|
||||
VAR_CGR_CMPUTELCR = "variable_" + utils.CGR_COMPUTELCR
|
||||
@@ -415,23 +415,46 @@ func (fsev FSEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) {
|
||||
GetMaxUsage: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := fsev[VarCGRSubsystems]
|
||||
subsystems, has := fsev[VarCGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.GetMaxUsage = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.AuthorizeResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.GetSuppliers = strings.Index(subsystems, utils.MetaSuppliers) != -1
|
||||
args.SuppliersIgnoreErrors = strings.Index(subsystems, utils.MetaSuppliersIgnoreErrors) != -1
|
||||
if strings.Index(subsystems, utils.MetaSuppliersEventCost) != -1 {
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.GetMaxUsage = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AuthorizeResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
case subsystem == utils.MetaSuppliers:
|
||||
args.GetSuppliers = true
|
||||
case subsystem == utils.MetaSuppliersIgnoreErrors:
|
||||
args.SuppliersIgnoreErrors = true
|
||||
case subsystem == utils.MetaSuppliersEventCost:
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
args.GetAttributes = strings.Index(subsystems, utils.MetaAttributes) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
return
|
||||
}
|
||||
|
||||
@@ -445,17 +468,39 @@ func (fsev FSEvent) V1InitSessionArgs() (args *sessions.V1InitSessionArgs) {
|
||||
InitSession: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := fsev[VarCGRSubsystems]
|
||||
subsystems, has := fsev[VarCGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.InitSession = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.AllocateResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.GetAttributes = strings.Index(subsystems, utils.MetaAttributes) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.InitSession = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AllocateResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -469,16 +514,33 @@ func (fsev FSEvent) V1TerminateSessionArgs() (args *sessions.V1TerminateSessionA
|
||||
TerminateSession: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := fsev[VarCGRSubsystems]
|
||||
subsystems, has := fsev[VarCGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.TerminateSession = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.ReleaseResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.TerminateSession = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.ReleaseResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ variable_rtp_audio_out_dtmf_packet_count: 0
|
||||
variable_rtp_audio_out_cng_packet_count: 0
|
||||
variable_rtp_audio_rtcp_packet_count: 1450
|
||||
variable_rtp_audio_rtcp_octet_count: 45940
|
||||
variable_cgr_subsystems: *resources%3B*attributes%3B*sessions%3B*suppliers_event_cost%3B*suppliers_ignore_errors%3B*accounts`
|
||||
variable_cgr_flags: *resources,*attributes,*sessions,*suppliers,*suppliers_event_cost,*suppliers_ignore_errors,*accounts`
|
||||
|
||||
func TestEventCreation(t *testing.T) {
|
||||
body := `Event-Name: RE_SCHEDULE
|
||||
|
||||
@@ -219,12 +219,12 @@ func (ka *KamailioAgent) onCallEnd(evData []byte, connIdx int) {
|
||||
utils.KamailioAgent, kev[utils.OriginID], err.Error()))
|
||||
// no return here since we want CDR anyhow
|
||||
}
|
||||
if ka.cfg.CreateCdr || strings.Index(kev[utils.CGRSubsystems], utils.MetaCDRs) != -1 {
|
||||
if ka.cfg.CreateCdr || strings.Index(kev[utils.CGRFlags], utils.MetaCDRs) != -1 {
|
||||
cgrEv, err := kev.AsCGREvent(ka.timezone) // FixMe: do we need to create the event once again?
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(kev[utils.CGRSubsystems], utils.MetaDispatchers) != -1, false)
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(kev[utils.CGRFlags], utils.MetaDispatchers) != -1, false)
|
||||
if err := ka.sessionS.Call(utils.SessionSv1ProcessCDR,
|
||||
&utils.CGREventWithArgDispatcher{CGREvent: cgrEv, ArgDispatcher: cgrArgs.ArgDispatcher}, &reply); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("%s> failed processing CGREvent: %s, error: %s",
|
||||
@@ -277,7 +277,7 @@ func (ka *KamailioAgent) onCgrProcessEvent(evData []byte, connIdx int) {
|
||||
|
||||
//in case that we don't reveice cgr_subsystems from kamailio
|
||||
//we consider this as ping-pong event
|
||||
if _, has := kev[utils.CGRSubsystems]; !has {
|
||||
if _, has := kev[utils.CGRFlags]; !has {
|
||||
if err = ka.conns[connIdx].Send(kev.AsKamProcessEventEmptyReply().String()); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> failed sending empty process event reply for event: %s, error %s",
|
||||
utils.KamailioAgent, kev[utils.OriginID], err.Error()))
|
||||
|
||||
@@ -47,7 +47,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
kamReservedEventFields = []string{EVENT, KamTRIndex, KamTRLabel, utils.CGRSubsystems, KamReplyRoute}
|
||||
kamReservedEventFields = []string{EVENT, KamTRIndex, KamTRLabel, utils.CGRFlags, KamReplyRoute}
|
||||
kamReservedCDRFields = append(kamReservedEventFields, KamHashEntry, KamHashID) // HashEntry and id are needed in events for disconnects
|
||||
)
|
||||
|
||||
@@ -110,7 +110,7 @@ func (kev KamEvent) MissingParameter() bool {
|
||||
case CGR_PROCESS_EVENT:
|
||||
// TRIndex and TRLabel must exist in order to know where to send back the response
|
||||
mndPrm := []string{kev[KamTRIndex], kev[KamTRLabel]}
|
||||
_, has := kev[utils.CGRSubsystems]
|
||||
_, has := kev[utils.CGRFlags]
|
||||
// in case that the user populate cgr_subsystems we treat it like a ProcessEvent
|
||||
// and expect to have the required fields
|
||||
if has {
|
||||
@@ -208,23 +208,46 @@ func (kev KamEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) {
|
||||
GetMaxUsage: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := kev[utils.CGRSubsystems]
|
||||
subsystems, has := kev[utils.CGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.GetMaxUsage = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.AuthorizeResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.GetSuppliers = strings.Index(subsystems, utils.MetaSuppliers) != -1
|
||||
args.SuppliersIgnoreErrors = strings.Index(subsystems, utils.MetaSuppliersIgnoreErrors) != -1
|
||||
if strings.Index(subsystems, utils.MetaSuppliersEventCost) != -1 {
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.GetMaxUsage = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AuthorizeResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
case subsystem == utils.MetaSuppliers:
|
||||
args.GetSuppliers = true
|
||||
case subsystem == utils.MetaSuppliersIgnoreErrors:
|
||||
args.SuppliersIgnoreErrors = true
|
||||
case subsystem == utils.MetaSuppliersEventCost:
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
tdIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &tdIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
args.GetAttributes = strings.Index(subsystems, utils.MetaAttributes) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
return
|
||||
}
|
||||
|
||||
@@ -279,17 +302,39 @@ func (kev KamEvent) V1InitSessionArgs() (args *sessions.V1InitSessionArgs) {
|
||||
InitSession: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := kev[utils.CGRSubsystems]
|
||||
subsystems, has := kev[utils.CGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.InitSession = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.AllocateResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.GetAttributes = strings.Index(subsystems, utils.MetaAttributes) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.InitSession = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AllocateResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -302,23 +347,46 @@ func (kev KamEvent) V1ProcessEventArgs() (args *sessions.V1ProcessEventArgs) {
|
||||
args = &sessions.V1ProcessEventArgs{ // defaults
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := kev[utils.CGRSubsystems]
|
||||
subsystems, has := kev[utils.CGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.GetAttributes = strings.Index(subsystems, utils.MetaAttributes) != -1
|
||||
args.AllocateResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.Debit = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
args.GetSuppliers = strings.Index(subsystems, utils.MetaSuppliers) != -1
|
||||
args.SuppliersIgnoreErrors = strings.Index(subsystems, utils.MetaSuppliersIgnoreErrors) != -1
|
||||
if strings.Index(subsystems, utils.MetaSuppliersEventCost) != -1 {
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.Debit = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AllocateResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
case subsystem == utils.MetaSuppliers:
|
||||
args.GetSuppliers = true
|
||||
case subsystem == utils.MetaSuppliersIgnoreErrors:
|
||||
args.SuppliersIgnoreErrors = true
|
||||
case subsystem == utils.MetaSuppliersEventCost:
|
||||
args.SuppliersMaxCost = utils.MetaEventCost
|
||||
case strings.Index(subsystem, utils.MetaAttributes) != -1:
|
||||
args.GetAttributes = true
|
||||
if attrWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(attrWithIDs) > 1 {
|
||||
attrIDs := strings.Split(attrWithIDs[1], utils.INFIELD_SEP)
|
||||
args.AttributeIDs = &attrIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
tdIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &tdIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, true)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
args.Paginator = *cgrArgs.SupplierPaginator
|
||||
return
|
||||
}
|
||||
|
||||
@@ -331,7 +399,7 @@ func (kev KamEvent) V1ProcessCDRArgs() (args *utils.CGREventWithArgDispatcher) {
|
||||
args = &utils.CGREventWithArgDispatcher{ // defaults
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := kev[utils.CGRSubsystems]
|
||||
subsystems, has := kev[utils.CGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
@@ -421,16 +489,33 @@ func (kev KamEvent) V1TerminateSessionArgs() (args *sessions.V1TerminateSessionA
|
||||
TerminateSession: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := kev[utils.CGRSubsystems]
|
||||
subsystems, has := kev[utils.CGRFlags]
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
args.TerminateSession = strings.Index(subsystems, utils.MetaAccounts) != -1
|
||||
args.ReleaseResources = strings.Index(subsystems, utils.MetaResources) != -1
|
||||
args.ProcessThresholds = strings.Index(subsystems, utils.MetaThresholds) != -1
|
||||
args.ProcessStats = strings.Index(subsystems, utils.MetaStats) != -1
|
||||
cgrArgs := cgrEv.ConsumeArgs(strings.Index(subsystems, utils.MetaDispatchers) != -1, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
for _, subsystem := range strings.Split(subsystems, utils.FIELDS_SEP) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.TerminateSession = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.ReleaseResources = true
|
||||
case subsystem == utils.MetaDispatchers:
|
||||
cgrArgs := cgrEv.ConsumeArgs(true, false)
|
||||
args.ArgDispatcher = cgrArgs.ArgDispatcher
|
||||
case strings.Index(subsystem, utils.MetaThresholds) != -1:
|
||||
args.ProcessThresholds = true
|
||||
if thdWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(thdWithIDs) > 1 {
|
||||
thIDs := strings.Split(thdWithIDs[1], utils.INFIELD_SEP)
|
||||
args.ThresholdIDs = &thIDs
|
||||
}
|
||||
case strings.Index(subsystem, utils.MetaStats) != -1:
|
||||
args.ProcessStats = true
|
||||
if stsWithIDs := strings.Split(subsystem, utils.InInFieldSep); len(stsWithIDs) > 1 {
|
||||
stsIDs := strings.Split(stsWithIDs[1], utils.INFIELD_SEP)
|
||||
args.StatIDs = &stsIDs
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestKamEvV1AuthorizeArgs(t *testing.T) {
|
||||
"cgr_duration": "3", "cgr_pdd": "4",
|
||||
utils.CGR_SUPPLIER: "supplier2",
|
||||
utils.CGR_DISCONNECT_CAUSE: "200",
|
||||
utils.CGRSubsystems: "*accounts;**suppliers_event_cost;*suppliers_ignore_errors"}
|
||||
utils.CGRFlags: "*accounts,*suppliers,*suppliers_event_cost,*suppliers_ignore_errors"}
|
||||
sTime, err := utils.ParseTimeDetectLayout(kamEv[utils.AnswerTime], timezone)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -560,7 +560,6 @@ const (
|
||||
MetaErr = "*err"
|
||||
OriginRealm = "OriginRealm"
|
||||
ProductName = "ProductName"
|
||||
CGRSubsystems = "cgr_subsystems"
|
||||
IdxStart = "["
|
||||
IdxEnd = "]"
|
||||
MetaLog = "*log"
|
||||
|
||||
Reference in New Issue
Block a user