mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
[Config] Add new section "template"
This commit is contained in:
committed by
Dan Christian Bogos
parent
07e217fbd4
commit
76d7df0dce
@@ -60,7 +60,7 @@ func NewDiameterAgent(cgrCfg *config.CGRConfig, filterS *engine.FilterS,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
msgTemplates := da.cgrCfg.DiameterAgentCfg().Templates
|
||||
msgTemplates := da.cgrCfg.TemplateCfg()
|
||||
// Inflate *template field types
|
||||
for _, procsr := range da.cgrCfg.DiameterAgentCfg().RequestProcessors {
|
||||
if tpls, err := config.InflateTemplates(procsr.RequestFields, msgTemplates); err != nil {
|
||||
@@ -185,7 +185,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) {
|
||||
// build the negative error answer
|
||||
diamErr, err := diamErr(
|
||||
m, diam.UnableToComply, reqVars,
|
||||
da.cgrCfg.DiameterAgentCfg().Templates[utils.MetaErr],
|
||||
da.cgrCfg.TemplateCfg()[utils.MetaErr],
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone,
|
||||
da.filterS)
|
||||
@@ -518,7 +518,7 @@ func (da *DiameterAgent) sendASR(originID string, reply *string) (err error) {
|
||||
dmd.vars, nil, nil, nil, nil,
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone, da.filterS, nil, nil)
|
||||
if err = aReq.SetFields(da.cgrCfg.DiameterAgentCfg().Templates[da.cgrCfg.DiameterAgentCfg().ASRTemplate]); err != nil {
|
||||
if err = aReq.SetFields(da.cgrCfg.TemplateCfg()[da.cgrCfg.DiameterAgentCfg().ASRTemplate]); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> cannot disconnect session with OriginID: <%s>, err: %s",
|
||||
utils.DiameterAgent, originID, err.Error()))
|
||||
@@ -561,7 +561,7 @@ func (da *DiameterAgent) V1ReAuthorize(originID string, reply *string) (err erro
|
||||
dmd.vars, nil, nil, nil, nil,
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone, da.filterS, nil, nil)
|
||||
if err = aReq.SetFields(da.cgrCfg.DiameterAgentCfg().Templates[da.cgrCfg.DiameterAgentCfg().RARTemplate]); err != nil {
|
||||
if err = aReq.SetFields(da.cgrCfg.TemplateCfg()[da.cgrCfg.DiameterAgentCfg().RARTemplate]); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> cannot send RAR with OriginID: <%s>, err: %s",
|
||||
utils.DiameterAgent, originID, err.Error()))
|
||||
|
||||
@@ -138,6 +138,7 @@ func NewDefaultCGRConfig() (cfg *CGRConfig, err error) {
|
||||
cfg.MaxCallDuration = time.Duration(3) * time.Hour // Hardcoded for now
|
||||
|
||||
cfg.rpcConns = make(map[string]*RPCConn)
|
||||
cfg.templates = make(map[string][]*FCTemplate)
|
||||
cfg.generalCfg = new(GeneralCfg)
|
||||
cfg.generalCfg.NodeID = utils.UUIDSha1Prefix()
|
||||
cfg.dataDbCfg = new(DataDbCfg)
|
||||
@@ -272,6 +273,8 @@ type CGRConfig struct {
|
||||
|
||||
rpcConns map[string]*RPCConn
|
||||
|
||||
templates map[string][]*FCTemplate
|
||||
|
||||
generalCfg *GeneralCfg // General config
|
||||
dataDbCfg *DataDbCfg // Database config
|
||||
storDbCfg *StorDbCfg // StroreDb config
|
||||
@@ -361,7 +364,7 @@ func (cfg *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
// Load sections out of JSON config, stop on error
|
||||
for _, loadFunc := range []func(*CgrJsonCfg) error{
|
||||
cfg.loadRPCConns,
|
||||
cfg.loadGeneralCfg, cfg.loadCacheCfg, cfg.loadListenCfg,
|
||||
cfg.loadGeneralCfg, cfg.loadTemplateSCfg, cfg.loadCacheCfg, cfg.loadListenCfg,
|
||||
cfg.loadHTTPCfg, cfg.loadDataDBCfg, cfg.loadStorDBCfg,
|
||||
cfg.loadFilterSCfg, cfg.loadRalSCfg, cfg.loadSchedulerCfg,
|
||||
cfg.loadCdrsCfg, cfg.loadSessionSCfg,
|
||||
@@ -728,7 +731,7 @@ func (cfg *CGRConfig) loadErsCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
if jsnERsCfg, err = jsnCfg.ERsJsonCfg(); err != nil {
|
||||
return
|
||||
}
|
||||
return cfg.ersCfg.loadFromJsonCfg(jsnERsCfg, cfg.generalCfg.RSRSep, cfg.dfltEvRdr, cfg.generalCfg.RSRSep)
|
||||
return cfg.ersCfg.loadFromJsonCfg(jsnERsCfg, cfg.templates, cfg.generalCfg.RSRSep, cfg.dfltEvRdr, cfg.generalCfg.RSRSep)
|
||||
}
|
||||
|
||||
// loadEesCfg loads the Ees section of the configuration
|
||||
@@ -737,7 +740,7 @@ func (cfg *CGRConfig) loadEesCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
if jsnEEsCfg, err = jsnCfg.EEsJsonCfg(); err != nil {
|
||||
return
|
||||
}
|
||||
return cfg.eesCfg.loadFromJsonCfg(jsnEEsCfg, cfg.generalCfg.RSRSep, cfg.dfltEvExp, cfg.generalCfg.RSRSep)
|
||||
return cfg.eesCfg.loadFromJsonCfg(jsnEEsCfg, cfg.templates, cfg.generalCfg.RSRSep, cfg.dfltEvExp, cfg.generalCfg.RSRSep)
|
||||
}
|
||||
|
||||
// loadRateSCfg loads the rates section of the configuration
|
||||
@@ -758,6 +761,22 @@ func (cfg *CGRConfig) loadSIPAgentCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
return cfg.sipAgentCfg.loadFromJsonCfg(jsnSIPAgentCfg, cfg.generalCfg.RSRSep)
|
||||
}
|
||||
|
||||
// loadTemplateSCfg loads the Template section of the configuration
|
||||
func (cfg *CGRConfig) loadTemplateSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
var jsnTemplateCfg map[string][]*FcTemplateJsonCfg
|
||||
if jsnTemplateCfg, err = jsnCfg.TemplateSJsonCfg(); err != nil {
|
||||
return
|
||||
}
|
||||
if jsnTemplateCfg != nil {
|
||||
for k, val := range jsnTemplateCfg {
|
||||
if cfg.templates[k], err = FCTemplatesFromFCTemplatesJsonCfg(val, cfg.generalCfg.RSRSep); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SureTaxCfg use locking to retrieve the configuration, possibility later for runtime reload
|
||||
func (cfg *CGRConfig) SureTaxCfg() *SureTaxCfg {
|
||||
cfg.lks[SURETAX_JSON].Lock()
|
||||
@@ -1035,6 +1054,13 @@ func (cfg *CGRConfig) RPCConns() map[string]*RPCConn {
|
||||
return cfg.rpcConns
|
||||
}
|
||||
|
||||
// DiameterAgentCfg returns the config for Diameter Agent
|
||||
func (cfg *CGRConfig) TemplateCfg() map[string][]*FCTemplate {
|
||||
cfg.lks[TemplatesJson].Lock()
|
||||
defer cfg.lks[TemplatesJson].Unlock()
|
||||
return cfg.templates
|
||||
}
|
||||
|
||||
// GetReloadChan returns the reload chanel for the given section
|
||||
func (cfg *CGRConfig) GetReloadChan(sectID string) chan struct{} {
|
||||
return cfg.rldChans[sectID]
|
||||
@@ -1127,6 +1153,8 @@ func (cfg *CGRConfig) V1GetConfigSection(args *StringWithOpts, reply *map[string
|
||||
jsonString = utils.ToJSON(cfg.RPCConns())
|
||||
case SIPAgentJson:
|
||||
jsonString = utils.ToJSON(cfg.SIPAgentCfg())
|
||||
case TemplatesJson:
|
||||
jsonString = utils.ToJSON(cfg.TemplateCfg())
|
||||
default:
|
||||
return errors.New("Invalid section")
|
||||
}
|
||||
@@ -1253,6 +1281,7 @@ func (cfg *CGRConfig) getLoadFunctions() map[string]func(*CgrJsonCfg) error {
|
||||
RPCConnsJsonName: cfg.loadRPCConns,
|
||||
RateSJson: cfg.loadRateSCfg,
|
||||
SIPAgentJson: cfg.loadSIPAgentCfg,
|
||||
TemplatesJson: cfg.loadTemplateSCfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -325,7 +325,6 @@ const CGRATES_CFG_JSON = `
|
||||
|
||||
"ers": { // EventReaderService
|
||||
"enabled": false, // starts the EventReader service: <true|false>
|
||||
"templates":{}, // default templates for ERs
|
||||
"sessions_conns":["*internal"], // RPC Connections IDs
|
||||
"readers": [
|
||||
{
|
||||
@@ -368,7 +367,6 @@ const CGRATES_CFG_JSON = `
|
||||
"cache": {
|
||||
"*file_csv": {"limit": -1, "ttl": "5s", "static_ttl": false},
|
||||
},
|
||||
"templates":{}, // default templates for EEs
|
||||
"exporters": [
|
||||
{
|
||||
"id": "*default", // identifier of the EventReader profile
|
||||
@@ -497,62 +495,6 @@ const CGRATES_CFG_JSON = `
|
||||
"asr_template": "", // enable AbortSession message being sent to client on DisconnectSession
|
||||
"rar_template": "", // template used to build the Re-Auth-Request
|
||||
"forced_disconnect": "*none", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
|
||||
"templates":{ // default message templates
|
||||
"*err": [
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "*rep.Origin-Host", "type": "*variable",
|
||||
"value": "~*vars.OriginHost", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*rep.Origin-Realm", "type": "*variable",
|
||||
"value": "~*vars.OriginRealm", "mandatory": true},
|
||||
],
|
||||
"*cca": [
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "ResultCode", "path": "*rep.Result-Code", "type": "*constant",
|
||||
"value": "2001"},
|
||||
{"tag": "OriginHost", "path": "*rep.Origin-Host", "type": "*variable",
|
||||
"value": "~*vars.OriginHost", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*rep.Origin-Realm", "type": "*variable",
|
||||
"value": "~*vars.OriginRealm", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "*rep.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
{"tag": "CCRequestType", "path": "*rep.CC-Request-Type", "type": "*variable",
|
||||
"value": "~*req.CC-Request-Type", "mandatory": true},
|
||||
{"tag": "CCRequestNumber", "path": "*rep.CC-Request-Number", "type": "*variable",
|
||||
"value": "~*req.CC-Request-Number", "mandatory": true},
|
||||
],
|
||||
"*asr": [
|
||||
{"tag": "SessionId", "path": "*diamreq.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "*diamreq.Origin-Host", "type": "*variable",
|
||||
"value": "~*req.Destination-Host", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*diamreq.Origin-Realm", "type": "*variable",
|
||||
"value": "~*req.Destination-Realm", "mandatory": true},
|
||||
{"tag": "DestinationRealm", "path": "*diamreq.Destination-Realm", "type": "*variable",
|
||||
"value": "~*req.Origin-Realm", "mandatory": true},
|
||||
{"tag": "DestinationHost", "path": "*diamreq.Destination-Host", "type": "*variable",
|
||||
"value": "~*req.Origin-Host", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "*diamreq.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
],
|
||||
"*rar": [
|
||||
{"tag": "SessionId", "path": "*diamreq.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "*diamreq.Origin-Host", "type": "*variable",
|
||||
"value": "~*req.Destination-Host", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*diamreq.Origin-Realm", "type": "*variable",
|
||||
"value": "~*req.Destination-Realm", "mandatory": true},
|
||||
{"tag": "DestinationRealm", "path": "*diamreq.Destination-Realm", "type": "*variable",
|
||||
"value": "~*req.Origin-Realm", "mandatory": true},
|
||||
{"tag": "DestinationHost", "path": "*diamreq.Destination-Host", "type": "*variable",
|
||||
"value": "~*req.Origin-Host", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "*diamreq.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
{"tag": "ReAuthRequestType", "path": "*diamreq.Re-Auth-Request-Type", "type": "*constant",
|
||||
"value": "0"},
|
||||
]
|
||||
},
|
||||
"request_processors": [ // list of processors to be applied to diameter messages
|
||||
],
|
||||
},
|
||||
@@ -983,14 +925,69 @@ const CGRATES_CFG_JSON = `
|
||||
"sessions_conns": ["*internal"],
|
||||
"timezone": "", // timezone of the events if not specified <UTC|Local|$IANA_TZ_DB>
|
||||
"retransmission_timer": "1s", // the duration to wait to receive an ACK before resending the reply
|
||||
"templates":{ // default message templates
|
||||
"*err": [
|
||||
{"tag": "Request", "path": "*rep.Request", "type": "*constant",
|
||||
"value": "SIP/2.0 500 Internal Server Error", "mandatory": true},
|
||||
],
|
||||
},
|
||||
"request_processors": [ // request processors to be applied to SIP messages
|
||||
],
|
||||
},
|
||||
|
||||
"templates": {
|
||||
"*err": [
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "*rep.Origin-Host", "type": "*variable",
|
||||
"value": "~*vars.OriginHost", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*rep.Origin-Realm", "type": "*variable",
|
||||
"value": "~*vars.OriginRealm", "mandatory": true},
|
||||
],
|
||||
"*cca": [
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "ResultCode", "path": "*rep.Result-Code", "type": "*constant",
|
||||
"value": "2001"},
|
||||
{"tag": "OriginHost", "path": "*rep.Origin-Host", "type": "*variable",
|
||||
"value": "~*vars.OriginHost", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*rep.Origin-Realm", "type": "*variable",
|
||||
"value": "~*vars.OriginRealm", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "*rep.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
{"tag": "CCRequestType", "path": "*rep.CC-Request-Type", "type": "*variable",
|
||||
"value": "~*req.CC-Request-Type", "mandatory": true},
|
||||
{"tag": "CCRequestNumber", "path": "*rep.CC-Request-Number", "type": "*variable",
|
||||
"value": "~*req.CC-Request-Number", "mandatory": true},
|
||||
],
|
||||
"*asr": [
|
||||
{"tag": "SessionId", "path": "*diamreq.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "*diamreq.Origin-Host", "type": "*variable",
|
||||
"value": "~*req.Destination-Host", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*diamreq.Origin-Realm", "type": "*variable",
|
||||
"value": "~*req.Destination-Realm", "mandatory": true},
|
||||
{"tag": "DestinationRealm", "path": "*diamreq.Destination-Realm", "type": "*variable",
|
||||
"value": "~*req.Origin-Realm", "mandatory": true},
|
||||
{"tag": "DestinationHost", "path": "*diamreq.Destination-Host", "type": "*variable",
|
||||
"value": "~*req.Origin-Host", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "*diamreq.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
],
|
||||
"*rar": [
|
||||
{"tag": "SessionId", "path": "*diamreq.Session-Id", "type": "*variable",
|
||||
"value": "~*req.Session-Id", "mandatory": true},
|
||||
{"tag": "OriginHost", "path": "*diamreq.Origin-Host", "type": "*variable",
|
||||
"value": "~*req.Destination-Host", "mandatory": true},
|
||||
{"tag": "OriginRealm", "path": "*diamreq.Origin-Realm", "type": "*variable",
|
||||
"value": "~*req.Destination-Realm", "mandatory": true},
|
||||
{"tag": "DestinationRealm", "path": "*diamreq.Destination-Realm", "type": "*variable",
|
||||
"value": "~*req.Origin-Realm", "mandatory": true},
|
||||
{"tag": "DestinationHost", "path": "*diamreq.Destination-Host", "type": "*variable",
|
||||
"value": "~*req.Origin-Host", "mandatory": true},
|
||||
{"tag": "AuthApplicationId", "path": "*diamreq.Auth-Application-Id", "type": "*variable",
|
||||
"value": "~*vars.*appid", "mandatory": true},
|
||||
{"tag": "ReAuthRequestType", "path": "*diamreq.Re-Auth-Request-Type", "type": "*constant",
|
||||
"value": "0"},
|
||||
],
|
||||
"*errSip": [
|
||||
{"tag": "Request", "path": "*rep.Request", "type": "*constant",
|
||||
"value": "SIP/2.0 500 Internal Server Error", "mandatory": true},
|
||||
],
|
||||
},
|
||||
|
||||
}`
|
||||
|
||||
@@ -62,6 +62,7 @@ const (
|
||||
RateSJson = "rates"
|
||||
RPCConnsJsonName = "rpc_conns"
|
||||
SIPAgentJson = "sip_agent"
|
||||
TemplatesJson = "templates"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -69,7 +70,7 @@ var (
|
||||
CACHE_JSN, FilterSjsn, RALS_JSN, CDRS_JSN, ERsJson, SessionSJson, AsteriskAgentJSN, FreeSWITCHAgentJSN,
|
||||
KamailioAgentJSN, DA_JSN, RA_JSN, HttpAgentJson, DNSAgentJson, ATTRIBUTE_JSN, ChargerSCfgJson, RESOURCES_JSON, STATS_JSON,
|
||||
THRESHOLDS_JSON, RouteSJson, LoaderJson, MAILER_JSN, SURETAX_JSON, CgrLoaderCfgJson, CgrMigratorCfgJson, DispatcherSJson,
|
||||
AnalyzerCfgJson, ApierS, EEsJson, RateSJson, SIPAgentJson, DispatcherHJson}
|
||||
AnalyzerCfgJson, ApierS, EEsJson, RateSJson, SIPAgentJson, DispatcherHJson, TemplatesJson}
|
||||
)
|
||||
|
||||
// Loads the json config out of io.Reader, eg other sources than file, maybe over http
|
||||
@@ -531,3 +532,15 @@ func (self CgrJsonCfg) SIPAgentJsonCfg() (*SIPAgentJsonCfg, error) {
|
||||
}
|
||||
return sipAgnt, nil
|
||||
}
|
||||
|
||||
func (self CgrJsonCfg) TemplateSJsonCfg() (map[string][]*FcTemplateJsonCfg, error) {
|
||||
rawCfg, hasKey := self[TemplatesJson]
|
||||
if !hasKey {
|
||||
return nil, nil
|
||||
}
|
||||
cfg := make(map[string][]*FcTemplateJsonCfg)
|
||||
if err := json.Unmarshal(*rawCfg, &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -761,153 +761,7 @@ func TestDiameterAgentJsonCfg(t *testing.T) {
|
||||
Asr_template: utils.StringPointer(""),
|
||||
Rar_template: utils.StringPointer(""),
|
||||
Forced_disconnect: utils.StringPointer(utils.META_NONE),
|
||||
Templates: map[string][]*FcTemplateJsonCfg{
|
||||
utils.MetaErr: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginHost"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginRealm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaCCA: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("ResultCode"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Result-Code", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("2001")},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginHost"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginRealm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("AuthApplicationId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Auth-Application-Id", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.*appid"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("CCRequestType"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.CC-Request-Type", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.CC-Request-Type"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("CCRequestNumber"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.CC-Request-Number", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.CC-Request-Number"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaASR: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("AuthApplicationId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Auth-Application-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.*appid"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaRAR: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("AuthApplicationId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Auth-Application-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.*appid"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("ReAuthRequestType"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Re-Auth-Request-Type", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("0")},
|
||||
},
|
||||
},
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{},
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{},
|
||||
}
|
||||
if cfg, err := dfCgrJSONCfg.DiameterAgentJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
@@ -1850,7 +1704,6 @@ func TestDfEventReaderCfg(t *testing.T) {
|
||||
eCfg := &ERsJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Sessions_conns: &[]string{utils.MetaInternal},
|
||||
Templates: map[string][]*FcTemplateJsonCfg{},
|
||||
Readers: &[]*EventReaderJsonCfg{
|
||||
{
|
||||
Id: utils.StringPointer(utils.MetaDefault),
|
||||
@@ -1978,7 +1831,6 @@ func TestDfEventExporterCfg(t *testing.T) {
|
||||
Static_ttl: utils.BoolPointer(false),
|
||||
},
|
||||
},
|
||||
Templates: map[string][]*FcTemplateJsonCfg{},
|
||||
Exporters: &[]*EventExporterJsonCfg{
|
||||
{
|
||||
Id: utils.StringPointer(utils.MetaDefault),
|
||||
@@ -2024,3 +1876,165 @@ func TestDfRateSJsonCfg(t *testing.T) {
|
||||
t.Error("Received: ", utils.ToJSON(cfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDfTemplateSJsonCfg(t *testing.T) {
|
||||
eCfg := map[string][]*FcTemplateJsonCfg{
|
||||
"*errSip": {
|
||||
{
|
||||
Tag: utils.StringPointer("Request"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Request", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("SIP/2.0 500 Internal Server Error"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaErr: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginHost"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginRealm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaCCA: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("ResultCode"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Result-Code", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("2001")},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginHost"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.OriginRealm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("AuthApplicationId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Auth-Application-Id", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.*appid"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("CCRequestType"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.CC-Request-Type", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.CC-Request-Type"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("CCRequestNumber"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.CC-Request-Number", utils.MetaRep)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.CC-Request-Number"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaASR: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("AuthApplicationId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Auth-Application-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.*appid"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
},
|
||||
utils.MetaRAR: {
|
||||
{
|
||||
Tag: utils.StringPointer("SessionId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Session-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Session-Id"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("OriginRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Origin-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Destination-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationRealm"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Realm", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Realm"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("DestinationHost"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Destination-Host", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.Origin-Host"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("AuthApplicationId"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Auth-Application-Id", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*vars.*appid"),
|
||||
Mandatory: utils.BoolPointer(true)},
|
||||
{
|
||||
Tag: utils.StringPointer("ReAuthRequestType"),
|
||||
Path: utils.StringPointer(fmt.Sprintf("%s.Re-Auth-Request-Type", utils.MetaDiamreq)),
|
||||
Type: utils.StringPointer(utils.META_CONSTANT),
|
||||
Value: utils.StringPointer("0")},
|
||||
},
|
||||
}
|
||||
if cfg, err := dfCgrJSONCfg.TemplateSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eCfg, cfg) {
|
||||
t.Errorf("Expected: %+v \n,received: %+v", utils.ToJSON(eCfg), utils.ToJSON(cfg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1895,7 +1895,6 @@ func TestCgrCdfEventReader(t *testing.T) {
|
||||
eCfg := &ERsCfg{
|
||||
Enabled: false,
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS)},
|
||||
Templates: map[string][]*FCTemplate{},
|
||||
Readers: []*EventReaderCfg{
|
||||
{
|
||||
ID: utils.MetaDefault,
|
||||
@@ -1960,7 +1959,6 @@ func TestCgrCdfEventExporter(t *testing.T) {
|
||||
StaticTTL: false,
|
||||
},
|
||||
},
|
||||
Templates: map[string][]*FCTemplate{},
|
||||
Exporters: []*EventExporterCfg{
|
||||
{
|
||||
ID: utils.MetaDefault,
|
||||
@@ -2494,139 +2492,6 @@ func TestRpcConnsDefaults(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckConfigSanity(t *testing.T) {
|
||||
// Rater checks
|
||||
cfg, _ := NewDefaultCGRConfig()
|
||||
cfg.ralsCfg = &RalsCfg{
|
||||
Enabled: true,
|
||||
StatSConns: []string{utils.MetaInternal},
|
||||
}
|
||||
expected := "<StatS> not enabled but requested by <RALs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = true
|
||||
cfg.ralsCfg.ThresholdSConns = []string{utils.MetaInternal}
|
||||
func TestTemplateConnsDefaults(t *testing.T) {
|
||||
|
||||
expected = "<ThresholdS> not enabled but requested by <RALs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg = &RalsCfg{
|
||||
Enabled: false,
|
||||
StatSConns: []string{},
|
||||
ThresholdSConns: []string{},
|
||||
}
|
||||
// CDRServer checks
|
||||
cfg.thresholdSCfg.Enabled = true
|
||||
cfg.cdrsCfg = &CdrsCfg{
|
||||
Enabled: true,
|
||||
ChargerSConns: []string{utils.MetaInternal},
|
||||
}
|
||||
expected = "<ChargerS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.chargerSCfg.Enabled = true
|
||||
cfg.cdrsCfg.RaterConns = []string{utils.MetaInternal}
|
||||
|
||||
expected = "<RALs> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg.Enabled = true
|
||||
cfg.cdrsCfg.AttributeSConns = []string{utils.MetaInternal}
|
||||
expected = "<AttributeS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = false
|
||||
cfg.attributeSCfg.Enabled = true
|
||||
cfg.cdrsCfg.StatSConns = []string{utils.MetaInternal}
|
||||
expected = "<StatS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = true
|
||||
cfg.cdrsCfg.OnlineCDRExports = []string{"stringy"}
|
||||
expected = "<CDRs> cannot find exporter with ID: <stringy>"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.thresholdSCfg.Enabled = false
|
||||
cfg.cdrsCfg.OnlineCDRExports = []string{"stringx"}
|
||||
cfg.cdrsCfg.ThresholdSConns = []string{utils.MetaInternal}
|
||||
expected = "<ThresholdS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneralCfg(t *testing.T) {
|
||||
var gencfg GeneralCfg
|
||||
cfgJSONStr := `{
|
||||
"general": {
|
||||
"node_id": "",
|
||||
"logger":"*syslog",
|
||||
"log_level": 6,
|
||||
"http_skip_tls_verify": false,
|
||||
"rounding_decimals": 5,
|
||||
"dbdata_encoding": "*msgpack",
|
||||
"tpexport_dir": "/var/spool/cgrates/tpe",
|
||||
"poster_attempts": 3,
|
||||
"failed_posts_dir": "/var/spool/cgrates/failed_posts",
|
||||
"failed_posts_ttl": "5s",
|
||||
"default_request_type": "*rated",
|
||||
"default_category": "call",
|
||||
"default_tenant": "cgrates.org",
|
||||
"default_timezone": "Local",
|
||||
"default_caching":"*reload",
|
||||
"connect_attempts": 5,
|
||||
"reconnects": -1,
|
||||
"connect_timeout": "1s",
|
||||
"reply_timeout": "2s",
|
||||
"locking_timeout": "0",
|
||||
"digest_separator": ",",
|
||||
"digest_equal": ":",
|
||||
"rsr_separator": ";",
|
||||
"max_parallel_conns": 100,
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
"node_id": "",
|
||||
"logger": "*syslog",
|
||||
"log_level": 6,
|
||||
"http_skip_tls_verify": false,
|
||||
"rounding_decimals": 5,
|
||||
"dbdata_encoding": "*msgpack",
|
||||
"tpexport_dir": "/var/spool/cgrates/tpe",
|
||||
"poster_attempts": 3,
|
||||
"failed_posts_dir": "/var/spool/cgrates/failed_posts",
|
||||
"failed_posts_ttl": "5s",
|
||||
"default_request_type": "*rated",
|
||||
"default_category": "call",
|
||||
"default_tenant": "cgrates.org",
|
||||
"default_timezone": "Local",
|
||||
"default_caching": "*reload",
|
||||
"connect_attempts": 5,
|
||||
"reconnects": -1,
|
||||
"connect_timeout": "1s",
|
||||
"reply_timeout": "2s",
|
||||
"locking_timeout": "0",
|
||||
"digest_separator": ",",
|
||||
"digest_equal": ":",
|
||||
"rsr_separator": ";",
|
||||
"max_parallel_conns": 100,
|
||||
utils.ConcurrentRequestsCfg: 0,
|
||||
utils.ConcurrentStrategyCfg: utils.EmptyString,
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnGenCfg, err := jsnCfg.GeneralJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = gencfg.loadFromJsonCfg(jsnGenCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := gencfg.AsMapInterface(); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("Expected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DiameterAgent, connID)
|
||||
}
|
||||
}
|
||||
for prf, tmp := range cfg.diameterAgentCfg.Templates {
|
||||
for prf, tmp := range cfg.templates {
|
||||
for _, field := range tmp {
|
||||
if field.Type != utils.META_NONE && field.Path == utils.EmptyString {
|
||||
return fmt.Errorf("<%s> %s for template %s at %s", utils.DiameterAgent, utils.NewErrMandatoryIeMissing(utils.Path), prf, field.Tag)
|
||||
|
||||
@@ -874,3 +874,71 @@ func TestConfigSanityFilterS(t *testing.T) {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckConfigSanity(t *testing.T) {
|
||||
// Rater checks
|
||||
cfg, _ := NewDefaultCGRConfig()
|
||||
cfg.ralsCfg = &RalsCfg{
|
||||
Enabled: true,
|
||||
StatSConns: []string{utils.MetaInternal},
|
||||
}
|
||||
expected := "<StatS> not enabled but requested by <RALs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = true
|
||||
cfg.ralsCfg.ThresholdSConns = []string{utils.MetaInternal}
|
||||
|
||||
expected = "<ThresholdS> not enabled but requested by <RALs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg = &RalsCfg{
|
||||
Enabled: false,
|
||||
StatSConns: []string{},
|
||||
ThresholdSConns: []string{},
|
||||
}
|
||||
// CDRServer checks
|
||||
cfg.thresholdSCfg.Enabled = true
|
||||
cfg.cdrsCfg = &CdrsCfg{
|
||||
Enabled: true,
|
||||
ChargerSConns: []string{utils.MetaInternal},
|
||||
}
|
||||
expected = "<ChargerS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.chargerSCfg.Enabled = true
|
||||
cfg.cdrsCfg.RaterConns = []string{utils.MetaInternal}
|
||||
|
||||
expected = "<RALs> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg.Enabled = true
|
||||
cfg.cdrsCfg.AttributeSConns = []string{utils.MetaInternal}
|
||||
expected = "<AttributeS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = false
|
||||
cfg.attributeSCfg.Enabled = true
|
||||
cfg.cdrsCfg.StatSConns = []string{utils.MetaInternal}
|
||||
expected = "<StatS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = true
|
||||
cfg.cdrsCfg.OnlineCDRExports = []string{"stringy"}
|
||||
expected = "<CDRs> cannot find exporter with ID: <stringy>"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.thresholdSCfg.Enabled = false
|
||||
cfg.cdrsCfg.OnlineCDRExports = []string{"stringx"}
|
||||
cfg.cdrsCfg.ThresholdSConns = []string{utils.MetaInternal}
|
||||
expected = "<ThresholdS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ type DiameterAgentCfg struct {
|
||||
ASRTemplate string
|
||||
RARTemplate string
|
||||
ForcedDisconnect string
|
||||
Templates map[string][]*FCTemplate
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
@@ -97,16 +96,6 @@ func (da *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg, separa
|
||||
if jsnCfg.Forced_disconnect != nil {
|
||||
da.ForcedDisconnect = *jsnCfg.Forced_disconnect
|
||||
}
|
||||
if jsnCfg.Templates != nil {
|
||||
if da.Templates == nil {
|
||||
da.Templates = make(map[string][]*FCTemplate)
|
||||
}
|
||||
for k, jsnTpls := range jsnCfg.Templates {
|
||||
if da.Templates[k], err = FCTemplatesFromFCTemplatesJsonCfg(jsnTpls, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnCfg.Request_processors != nil {
|
||||
for _, reqProcJsn := range *jsnCfg.Request_processors {
|
||||
rp := new(RequestProcessor)
|
||||
@@ -130,16 +119,6 @@ func (da *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg, separa
|
||||
}
|
||||
|
||||
func (ds *DiameterAgentCfg) AsMapInterface(separator string) map[string]interface{} {
|
||||
templates := make(map[string][]map[string]interface{})
|
||||
for key, value := range ds.Templates {
|
||||
fcTemplate := make([]map[string]interface{}, len(value))
|
||||
for i, val := range value {
|
||||
fcTemplate[i] = val.AsMapInterface(separator)
|
||||
|
||||
}
|
||||
templates[key] = fcTemplate
|
||||
}
|
||||
|
||||
requestProcessors := make([]map[string]interface{}, len(ds.RequestProcessors))
|
||||
for i, item := range ds.RequestProcessors {
|
||||
requestProcessors[i] = item.AsMapInterface(separator)
|
||||
@@ -170,7 +149,6 @@ func (ds *DiameterAgentCfg) AsMapInterface(separator string) map[string]interfac
|
||||
utils.ASRTemplateCfg: ds.ASRTemplate,
|
||||
utils.RARTemplateCfg: ds.RARTemplate,
|
||||
utils.ForcedDisconnectCfg: ds.ForcedDisconnect,
|
||||
utils.TemplatesCfg: templates,
|
||||
utils.RequestProcessorsCfg: requestProcessors,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
VendorId: 0,
|
||||
ProductName: "CGRateS",
|
||||
SyncedConnReqs: true,
|
||||
Templates: make(map[string][]*FCTemplate),
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
@@ -105,7 +104,6 @@ func TestDiameterAgentCfgAsMapInterface(t *testing.T) {
|
||||
"sessions_conns": []string{"*internal"},
|
||||
"synced_conn_requests": true,
|
||||
"vendor_id": 0,
|
||||
"templates": map[string][]map[string]interface{}{},
|
||||
"request_processors": []map[string]interface{}{},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
|
||||
@@ -28,11 +28,10 @@ type EEsCfg struct {
|
||||
Enabled bool
|
||||
AttributeSConns []string
|
||||
Cache map[string]*CacheParamCfg
|
||||
Templates map[string][]*FCTemplate
|
||||
Exporters []*EventExporterCfg
|
||||
}
|
||||
|
||||
func (eeS *EEsCfg) loadFromJsonCfg(jsnCfg *EEsJsonCfg, sep string, dfltExpCfg *EventExporterCfg, separator string) (err error) {
|
||||
func (eeS *EEsCfg) loadFromJsonCfg(jsnCfg *EEsJsonCfg, msgTemplates map[string][]*FCTemplate, sep string, dfltExpCfg *EventExporterCfg, separator string) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
@@ -59,17 +58,7 @@ func (eeS *EEsCfg) loadFromJsonCfg(jsnCfg *EEsJsonCfg, sep string, dfltExpCfg *E
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnCfg.Templates != nil {
|
||||
if eeS.Templates == nil {
|
||||
eeS.Templates = make(map[string][]*FCTemplate)
|
||||
}
|
||||
for k, jsnTpls := range jsnCfg.Templates {
|
||||
if eeS.Templates[k], err = FCTemplatesFromFCTemplatesJsonCfg(jsnTpls, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return eeS.appendEEsExporters(jsnCfg.Exporters, eeS.Templates, sep, dfltExpCfg)
|
||||
return eeS.appendEEsExporters(jsnCfg.Exporters, msgTemplates, sep, dfltExpCfg)
|
||||
}
|
||||
|
||||
func (eeS *EEsCfg) appendEEsExporters(exporters *[]*EventExporterJsonCfg, msgTemplates map[string][]*FCTemplate, separator string, dfltExpCfg *EventExporterCfg) (err error) {
|
||||
|
||||
@@ -151,7 +151,6 @@ func TestEventExporterSameID(t *testing.T) {
|
||||
StaticTTL: false,
|
||||
},
|
||||
},
|
||||
Templates: map[string][]*FCTemplate{},
|
||||
Exporters: []*EventExporterCfg{
|
||||
&EventExporterCfg{
|
||||
ID: utils.MetaDefault,
|
||||
|
||||
@@ -28,11 +28,10 @@ import (
|
||||
type ERsCfg struct {
|
||||
Enabled bool
|
||||
SessionSConns []string
|
||||
Templates map[string][]*FCTemplate
|
||||
Readers []*EventReaderCfg
|
||||
}
|
||||
|
||||
func (erS *ERsCfg) loadFromJsonCfg(jsnCfg *ERsJsonCfg, sep string, dfltRdrCfg *EventReaderCfg, separator string) (err error) {
|
||||
func (erS *ERsCfg) loadFromJsonCfg(jsnCfg *ERsJsonCfg, msgTemplates map[string][]*FCTemplate, sep string, dfltRdrCfg *EventReaderCfg, separator string) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
@@ -50,17 +49,7 @@ func (erS *ERsCfg) loadFromJsonCfg(jsnCfg *ERsJsonCfg, sep string, dfltRdrCfg *E
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnCfg.Templates != nil {
|
||||
if erS.Templates == nil {
|
||||
erS.Templates = make(map[string][]*FCTemplate)
|
||||
}
|
||||
for k, jsnTpls := range jsnCfg.Templates {
|
||||
if erS.Templates[k], err = FCTemplatesFromFCTemplatesJsonCfg(jsnTpls, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return erS.appendERsReaders(jsnCfg.Readers, erS.Templates, sep, dfltRdrCfg)
|
||||
return erS.appendERsReaders(jsnCfg.Readers, msgTemplates, sep, dfltRdrCfg)
|
||||
}
|
||||
|
||||
func (ers *ERsCfg) appendERsReaders(jsnReaders *[]*EventReaderJsonCfg, msgTemplates map[string][]*FCTemplate, sep string,
|
||||
|
||||
@@ -103,7 +103,6 @@ func TestEventReaderLoadFromJSON(t *testing.T) {
|
||||
expectedERsCfg := &ERsCfg{
|
||||
Enabled: true,
|
||||
SessionSConns: []string{"conn1", "conn3"},
|
||||
Templates: map[string][]*FCTemplate{},
|
||||
Readers: []*EventReaderCfg{
|
||||
{
|
||||
ID: utils.MetaDefault,
|
||||
@@ -242,7 +241,6 @@ func TestEventReaderSameID(t *testing.T) {
|
||||
expectedERsCfg := &ERsCfg{
|
||||
Enabled: true,
|
||||
SessionSConns: []string{"conn1"},
|
||||
Templates: map[string][]*FCTemplate{},
|
||||
Readers: []*EventReaderCfg{
|
||||
{
|
||||
ID: utils.MetaDefault,
|
||||
|
||||
@@ -155,7 +155,6 @@ type CdrsJsonCfg struct {
|
||||
type ERsJsonCfg struct {
|
||||
Enabled *bool
|
||||
Sessions_conns *[]string
|
||||
Templates map[string][]*FcTemplateJsonCfg
|
||||
Readers *[]*EventReaderJsonCfg
|
||||
}
|
||||
|
||||
@@ -187,7 +186,6 @@ type EEsJsonCfg struct {
|
||||
Enabled *bool
|
||||
Attributes_conns *[]string
|
||||
Cache *map[string]*CacheParamJsonCfg
|
||||
Templates map[string][]*FcTemplateJsonCfg
|
||||
Exporters *[]*EventExporterJsonCfg
|
||||
}
|
||||
|
||||
@@ -345,7 +343,6 @@ type DiameterAgentJsonCfg struct {
|
||||
Asr_template *string
|
||||
Rar_template *string
|
||||
Forced_disconnect *string
|
||||
Templates map[string][]*FcTemplateJsonCfg
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium
|
||||
* [DispatcherH] Added DispatcherH subsystem
|
||||
* [ERs] Added support for *amqp_json_map type
|
||||
* [DataDB] Moved all specific DB options in opts
|
||||
* [Config] Add new section "template"
|
||||
|
||||
-- DanB <danb@cgrates.org> Wed, 19 Feb 2020 13:25:52 +0200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user