From b0fc13896d8479fdf70baba404566634a1b8b032 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 17 Jun 2025 17:32:42 +0300 Subject: [PATCH] cfg: add stats/thresholds_conns to http_agent --- config/config_test.go | 2 +- config/configsanity.go | 18 ++ config/{httpagntcfg.go => httpagent.go} | 128 ++++----- ...{httpagntcfg_test.go => httpagent_test.go} | 270 ++++++++++-------- 4 files changed, 238 insertions(+), 180 deletions(-) rename config/{httpagntcfg.go => httpagent.go} (64%) rename config/{httpagntcfg_test.go => httpagent_test.go} (74%) diff --git a/config/config_test.go b/config/config_test.go index c9b7c397a..7fa03c3d5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1117,7 +1117,7 @@ func TestLoadHttpAgentCfgError(t *testing.T) { }, ], }` - expected := "json: cannot unmarshal array into Go struct field HttpAgentJsonCfg.Id of type string" + expected := "json: cannot unmarshal array into Go struct field HttpAgentJsonCfg.id of type string" cgrConfig := NewDefaultCGRConfig() if cgrCfgJSON, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil { t.Error(err) diff --git a/config/configsanity.go b/config/configsanity.go index a5e95376a..8848867e5 100644 --- a/config/configsanity.go +++ b/config/configsanity.go @@ -493,6 +493,24 @@ func (cfg *CGRConfig) checkConfigSanity() error { return fmt.Errorf("<%s> template with ID <%s> has connection with id: <%s> not defined", utils.HTTPAgent, httpAgentCfg.ID, connID) } } + for _, connID := range httpAgentCfg.StatSConns { + isInternal := strings.HasPrefix(connID, utils.MetaInternal) + if isInternal && !cfg.statsCfg.Enabled { + return fmt.Errorf("<%s> not enabled but requested by <%s> HTTPAgent Template", utils.StatS, httpAgentCfg.ID) + } + if _, has := cfg.rpcConns[connID]; !has && !isInternal { + return fmt.Errorf("<%s> template with ID <%s> has connection with id: <%s> not defined", utils.HTTPAgent, httpAgentCfg.ID, connID) + } + } + for _, connID := range httpAgentCfg.ThresholdSConns { + isInternal := strings.HasPrefix(connID, utils.MetaInternal) + if isInternal && !cfg.thresholdSCfg.Enabled { + return fmt.Errorf("<%s> not enabled but requested by <%s> HTTPAgent Template", utils.ThresholdS, httpAgentCfg.ID) + } + if _, has := cfg.rpcConns[connID]; !has && !isInternal { + return fmt.Errorf("<%s> template with ID <%s> has connection with id: <%s> not defined", utils.HTTPAgent, httpAgentCfg.ID, connID) + } + } if !slices.Contains([]string{utils.MetaUrl, utils.MetaXml}, httpAgentCfg.RequestPayload) { return fmt.Errorf("<%s> unsupported request payload %s", utils.HTTPAgent, httpAgentCfg.RequestPayload) } diff --git a/config/httpagntcfg.go b/config/httpagent.go similarity index 64% rename from config/httpagntcfg.go rename to config/httpagent.go index 6ec331a28..405e51cfd 100644 --- a/config/httpagntcfg.go +++ b/config/httpagent.go @@ -23,7 +23,6 @@ import ( "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // HTTPAgentCfgs the config section for HTTP Agent @@ -44,9 +43,9 @@ func (hcfgs *HTTPAgentCfgs) loadFromJSONCfg(jsnHTTPAgntCfg *[]*HttpAgentJsonCfg) for _, jsnCfg := range *jsnHTTPAgntCfg { hac := new(HTTPAgentCfg) var haveID bool - if jsnCfg.Id != nil { + if jsnCfg.ID != nil { for _, val := range *hcfgs { - if val.ID == *jsnCfg.Id { + if val.ID == *jsnCfg.ID { hac = val haveID = true break @@ -90,6 +89,8 @@ type HTTPAgentCfg struct { ID string // identifier for the agent, so we can update it's processors URL string SessionSConns []string + StatSConns []string + ThresholdSConns []string RequestPayload string ReplyPayload string RequestProcessors []*RequestProcessor @@ -99,89 +100,79 @@ func (ha *HTTPAgentCfg) loadFromJSONCfg(jsnCfg *HttpAgentJsonCfg) (err error) { if jsnCfg == nil { return nil } - if jsnCfg.Id != nil { - ha.ID = *jsnCfg.Id + if jsnCfg.ID != nil { + ha.ID = *jsnCfg.ID } - if jsnCfg.Url != nil { - ha.URL = *jsnCfg.Url + if jsnCfg.URL != nil { + ha.URL = *jsnCfg.URL } - if jsnCfg.Sessions_conns != nil { - ha.SessionSConns = make([]string, len(*jsnCfg.Sessions_conns)) - for idx, connID := range *jsnCfg.Sessions_conns { - // if we have the connection internal we change the name so we can have internal rpc for each subsystem - ha.SessionSConns[idx] = connID - if connID == utils.MetaInternal || - connID == rpcclient.BiRPCInternal { - ha.SessionSConns[idx] = utils.ConcatenatedKey(connID, utils.MetaSessionS) - } - } + if jsnCfg.SessionSConns != nil { + ha.SessionSConns = tagInternalConns(*jsnCfg.SessionSConns, utils.MetaSessionS) } - if jsnCfg.Request_payload != nil { - ha.RequestPayload = *jsnCfg.Request_payload + if jsnCfg.StatSConns != nil { + ha.StatSConns = tagInternalConns(*jsnCfg.StatSConns, utils.MetaStats) } - if jsnCfg.Reply_payload != nil { - ha.ReplyPayload = *jsnCfg.Reply_payload + if jsnCfg.ThresholdSConns != nil { + ha.ThresholdSConns = tagInternalConns(*jsnCfg.ThresholdSConns, utils.MetaThresholds) } - ha.RequestProcessors, err = appendRequestProcessors(ha.RequestProcessors, jsnCfg.Request_processors) + + if jsnCfg.RequestPayload != nil { + ha.RequestPayload = *jsnCfg.RequestPayload + } + if jsnCfg.ReplyPayload != nil { + ha.ReplyPayload = *jsnCfg.ReplyPayload + } + ha.RequestProcessors, err = appendRequestProcessors(ha.RequestProcessors, jsnCfg.RequestProcessors) return } // AsMapInterface returns the config as a map[string]any -func (ha *HTTPAgentCfg) AsMapInterface() (initialMP map[string]any) { - initialMP = map[string]any{ - utils.IDCfg: ha.ID, - utils.URLCfg: ha.URL, - utils.RequestPayloadCfg: ha.RequestPayload, - utils.ReplyPayloadCfg: ha.ReplyPayload, - } - - if ha.SessionSConns != nil { - sessionSConns := make([]string, len(ha.SessionSConns)) - for i, item := range ha.SessionSConns { - sessionSConns[i] = item - if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) { - sessionSConns[i] = utils.MetaInternal - } else if item == utils.ConcatenatedKey(rpcclient.BiRPCInternal, utils.MetaSessionS) { - sessionSConns[i] = rpcclient.BiRPCInternal - } - } - initialMP[utils.SessionSConnsCfg] = sessionSConns - } +func (ha *HTTPAgentCfg) AsMapInterface() map[string]any { requestProcessors := make([]map[string]any, len(ha.RequestProcessors)) for i, item := range ha.RequestProcessors { requestProcessors[i] = item.AsMapInterface() } - initialMP[utils.RequestProcessorsCfg] = requestProcessors - return + m := map[string]any{ + utils.IDCfg: ha.ID, + utils.URLCfg: ha.URL, + utils.SessionSConnsCfg: stripInternalConns(ha.SessionSConns), + utils.StatSConnsCfg: stripInternalConns(ha.StatSConns), + utils.ThresholdSConnsCfg: stripInternalConns(ha.ThresholdSConns), + utils.RequestPayloadCfg: ha.RequestPayload, + utils.ReplyPayloadCfg: ha.ReplyPayload, + utils.RequestProcessorsCfg: requestProcessors, + } + return m } // Clone returns a deep copy of HTTPAgentCfg -func (ha HTTPAgentCfg) Clone() (cln *HTTPAgentCfg) { - cln = &HTTPAgentCfg{ +func (ha HTTPAgentCfg) Clone() *HTTPAgentCfg { + clone := &HTTPAgentCfg{ ID: ha.ID, URL: ha.URL, + SessionSConns: slices.Clone(ha.SessionSConns), + StatSConns: slices.Clone(ha.StatSConns), + ThresholdSConns: slices.Clone(ha.ThresholdSConns), RequestPayload: ha.RequestPayload, ReplyPayload: ha.ReplyPayload, RequestProcessors: make([]*RequestProcessor, len(ha.RequestProcessors)), } - if ha.SessionSConns != nil { - cln.SessionSConns = make([]string, len(ha.SessionSConns)) - copy(cln.SessionSConns, ha.SessionSConns) - } for i, req := range ha.RequestProcessors { - cln.RequestProcessors[i] = req.Clone() + clone.RequestProcessors[i] = req.Clone() } - return + return clone } // Conecto Agent configuration section type HttpAgentJsonCfg struct { - Id *string - Url *string - Sessions_conns *[]string - Request_payload *string - Reply_payload *string - Request_processors *[]*ReqProcessorJsnCfg + ID *string `json:"id"` + URL *string `json:"url"` + SessionSConns *[]string `json:"sessions_conns"` + StatSConns *[]string `json:"stats_conns"` + ThresholdSConns *[]string `json:"thresholds_conns"` + RequestPayload *string `json:"request_payload"` + ReplyPayload *string `json:"reply_payload"` + RequestProcessors *[]*ReqProcessorJsnCfg `json:"request_processors"` } func diffHttpAgentJsonCfg(d *HttpAgentJsonCfg, v1, v2 *HTTPAgentCfg) *HttpAgentJsonCfg { @@ -189,22 +180,27 @@ func diffHttpAgentJsonCfg(d *HttpAgentJsonCfg, v1, v2 *HTTPAgentCfg) *HttpAgentJ d = new(HttpAgentJsonCfg) } if v1.ID != v2.ID { - d.Id = utils.StringPointer(v2.ID) + d.ID = utils.StringPointer(v2.ID) } if v1.URL != v2.URL { - d.Url = utils.StringPointer(v2.URL) + d.URL = utils.StringPointer(v2.URL) } if v1.RequestPayload != v2.RequestPayload { - d.Request_payload = utils.StringPointer(v2.RequestPayload) + d.RequestPayload = utils.StringPointer(v2.RequestPayload) } if v1.ReplyPayload != v2.ReplyPayload { - d.Reply_payload = utils.StringPointer(v2.ReplyPayload) + d.ReplyPayload = utils.StringPointer(v2.ReplyPayload) } if !slices.Equal(v1.SessionSConns, v2.SessionSConns) { - d.Sessions_conns = utils.SliceStringPointer(stripInternalConns(v2.SessionSConns)) + d.SessionSConns = utils.SliceStringPointer(stripInternalConns(v2.SessionSConns)) } - - d.Request_processors = diffReqProcessorsJsnCfg(d.Request_processors, v1.RequestProcessors, v2.RequestProcessors) + if !slices.Equal(v1.StatSConns, v2.StatSConns) { + d.StatSConns = utils.SliceStringPointer(stripInternalConns(v2.StatSConns)) + } + if !slices.Equal(v1.ThresholdSConns, v2.ThresholdSConns) { + d.ThresholdSConns = utils.SliceStringPointer(stripInternalConns(v2.ThresholdSConns)) + } + d.RequestProcessors = diffReqProcessorsJsnCfg(d.RequestProcessors, v1.RequestProcessors, v2.RequestProcessors) return d } @@ -227,7 +223,7 @@ func equalsHTTPAgentCfgs(v1, v2 HTTPAgentCfgs) bool { func getHttpAgentJsonCfg(d []*HttpAgentJsonCfg, id string) (*HttpAgentJsonCfg, int) { for i, v := range d { - if v.Id != nil && *v.Id == id { + if v.ID != nil && *v.ID == id { return v, i } } diff --git a/config/httpagntcfg_test.go b/config/httpagent_test.go similarity index 74% rename from config/httpagntcfg_test.go rename to config/httpagent_test.go index af9900f18..5fca0fe77 100644 --- a/config/httpagntcfg_test.go +++ b/config/httpagent_test.go @@ -29,12 +29,14 @@ import ( func TestHttpAgentCfgsloadFromJsonCfgCase1(t *testing.T) { cfgJSON := &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("RandomID"), - Url: utils.StringPointer("/randomURL"), - Sessions_conns: &[]string{"*internal"}, - Reply_payload: utils.StringPointer(utils.MetaXml), - Request_payload: utils.StringPointer(utils.MetaUrl), - Request_processors: &[]*ReqProcessorJsnCfg{ + ID: utils.StringPointer("RandomID"), + URL: utils.StringPointer("/randomURL"), + SessionSConns: &[]string{"*internal"}, + StatSConns: &[]string{"*internal"}, + ThresholdSConns: &[]string{"*internal"}, + ReplyPayload: utils.StringPointer(utils.MetaXml), + RequestPayload: utils.StringPointer(utils.MetaUrl), + RequestProcessors: &[]*ReqProcessorJsnCfg{ { ID: utils.StringPointer("OutboundAUTHDryRun"), Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"}, @@ -57,11 +59,13 @@ func TestHttpAgentCfgsloadFromJsonCfgCase1(t *testing.T) { } expected := HTTPAgentCfgs{ { - ID: "RandomID", - URL: "/randomURL", - SessionSConns: []string{"*internal:*sessions"}, - RequestPayload: "*url", - ReplyPayload: "*xml", + ID: "RandomID", + URL: "/randomURL", + SessionSConns: []string{"*internal:*sessions"}, + StatSConns: []string{"*internal:*stats"}, + ThresholdSConns: []string{"*internal:*thresholds"}, + RequestPayload: "*url", + ReplyPayload: "*xml", RequestProcessors: []*RequestProcessor{{ ID: "OutboundAUTHDryRun", Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"}, @@ -91,12 +95,14 @@ func TestHttpAgentCfgsloadFromJsonCfgCase1(t *testing.T) { func TestHttpAgentCfgsloadFromJsonCfgCase2(t *testing.T) { cfgJSON := &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("conecto1"), - Url: utils.StringPointer("/conecto"), - Sessions_conns: &[]string{utils.MetaLocalHost}, - Request_payload: utils.StringPointer(utils.MetaUrl), - Reply_payload: utils.StringPointer(utils.MetaXml), - Request_processors: &[]*ReqProcessorJsnCfg{ + ID: utils.StringPointer("conecto1"), + URL: utils.StringPointer("/conecto"), + SessionSConns: &[]string{utils.MetaLocalHost}, + StatSConns: &[]string{utils.MetaLocalHost}, + ThresholdSConns: &[]string{utils.MetaLocalHost}, + RequestPayload: utils.StringPointer(utils.MetaUrl), + ReplyPayload: utils.StringPointer(utils.MetaXml), + RequestProcessors: &[]*ReqProcessorJsnCfg{ { ID: utils.StringPointer("OutboundAUTHDryRun"), Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"}, @@ -142,12 +148,14 @@ func TestHttpAgentCfgsloadFromJsonCfgCase2(t *testing.T) { }}, }, { - Id: utils.StringPointer("conecto_xml"), - Url: utils.StringPointer("/conecto_xml"), - Sessions_conns: &[]string{utils.MetaLocalHost}, - Request_payload: utils.StringPointer("*xml"), - Reply_payload: utils.StringPointer("*xml"), - Request_processors: &[]*ReqProcessorJsnCfg{ + ID: utils.StringPointer("conecto_xml"), + URL: utils.StringPointer("/conecto_xml"), + SessionSConns: &[]string{utils.MetaLocalHost}, + StatSConns: &[]string{utils.MetaLocalHost}, + ThresholdSConns: &[]string{utils.MetaLocalHost}, + RequestPayload: utils.StringPointer("*xml"), + ReplyPayload: utils.StringPointer("*xml"), + RequestProcessors: &[]*ReqProcessorJsnCfg{ { ID: utils.StringPointer("cdr_from_xml"), Tenant: utils.StringPointer("cgrates.org"), @@ -160,11 +168,13 @@ func TestHttpAgentCfgsloadFromJsonCfgCase2(t *testing.T) { } expected := HTTPAgentCfgs{ &HTTPAgentCfg{ - ID: "conecto1", - URL: "/conecto", - SessionSConns: []string{utils.MetaLocalHost}, - RequestPayload: utils.MetaUrl, - ReplyPayload: utils.MetaXml, + ID: "conecto1", + URL: "/conecto", + SessionSConns: []string{utils.MetaLocalHost}, + StatSConns: []string{utils.MetaLocalHost}, + ThresholdSConns: []string{utils.MetaLocalHost}, + RequestPayload: utils.MetaUrl, + ReplyPayload: utils.MetaXml, RequestProcessors: []*RequestProcessor{ { ID: "OutboundAUTHDryRun", @@ -204,11 +214,13 @@ func TestHttpAgentCfgsloadFromJsonCfgCase2(t *testing.T) { }}, }}, }, &HTTPAgentCfg{ - ID: "conecto_xml", - URL: "/conecto_xml", - SessionSConns: []string{utils.MetaLocalHost}, - RequestPayload: utils.MetaXml, - ReplyPayload: utils.MetaXml, + ID: "conecto_xml", + URL: "/conecto_xml", + SessionSConns: []string{utils.MetaLocalHost}, + StatSConns: []string{utils.MetaLocalHost}, + ThresholdSConns: []string{utils.MetaLocalHost}, + RequestPayload: utils.MetaXml, + ReplyPayload: utils.MetaXml, RequestProcessors: []*RequestProcessor{{ ID: "cdr_from_xml", Tenant: utils.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), @@ -230,12 +242,12 @@ func TestHttpAgentCfgsloadFromJsonCfgCase2(t *testing.T) { func TestHttpAgentCfgloadFromJsonCfgCase3(t *testing.T) { jsnhttpCfg := &HttpAgentJsonCfg{ - Id: utils.StringPointer("conecto1"), - Url: utils.StringPointer("/conecto"), - Sessions_conns: &[]string{utils.MetaLocalHost}, - Request_payload: utils.StringPointer("*url"), - Reply_payload: utils.StringPointer("*xml"), - Request_processors: &[]*ReqProcessorJsnCfg{ + ID: utils.StringPointer("conecto1"), + URL: utils.StringPointer("/conecto"), + SessionSConns: &[]string{utils.MetaLocalHost}, + RequestPayload: utils.StringPointer("*url"), + ReplyPayload: utils.StringPointer("*xml"), + RequestProcessors: &[]*ReqProcessorJsnCfg{ { ID: utils.StringPointer("OutboundAUTHDryRun"), Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"}, @@ -272,12 +284,12 @@ func TestHttpAgentCfgloadFromJsonCfgCase3(t *testing.T) { func TestHttpAgentCfgloadFromJsonCfgCase4(t *testing.T) { cfgJSON := &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("conecto1"), - Url: utils.StringPointer("/conecto"), - Sessions_conns: &[]string{utils.MetaLocalHost}, - Request_payload: utils.StringPointer(utils.MetaUrl), - Reply_payload: utils.StringPointer(utils.MetaXml), - Request_processors: &[]*ReqProcessorJsnCfg{ + ID: utils.StringPointer("conecto1"), + URL: utils.StringPointer("/conecto"), + SessionSConns: &[]string{utils.MetaLocalHost}, + RequestPayload: utils.StringPointer(utils.MetaUrl), + ReplyPayload: utils.StringPointer(utils.MetaXml), + RequestProcessors: &[]*ReqProcessorJsnCfg{ { ID: utils.StringPointer("OutboundAUTHDryRun"), Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"}, @@ -323,12 +335,12 @@ func TestHttpAgentCfgloadFromJsonCfgCase4(t *testing.T) { }}, }, { - Id: utils.StringPointer("conecto_xml"), - Url: utils.StringPointer("/conecto_xml"), - Sessions_conns: &[]string{utils.MetaLocalHost}, - Request_payload: utils.StringPointer("*xml"), - Reply_payload: utils.StringPointer("*xml"), - Request_processors: &[]*ReqProcessorJsnCfg{ + ID: utils.StringPointer("conecto_xml"), + URL: utils.StringPointer("/conecto_xml"), + SessionSConns: &[]string{utils.MetaLocalHost}, + RequestPayload: utils.StringPointer("*xml"), + ReplyPayload: utils.StringPointer("*xml"), + RequestProcessors: &[]*ReqProcessorJsnCfg{ { ID: utils.StringPointer("cdr_from_xml"), Tenant: utils.StringPointer("a{*"), @@ -349,7 +361,7 @@ func TestHttpAgentCfgloadFromJsonCfgCase4(t *testing.T) { func TestHttpAgentCfgloadFromJsonCfgCase5(t *testing.T) { cfgJSON := &[]*HttpAgentJsonCfg{ { - Request_processors: nil, + RequestProcessors: nil, }, } jsonCfg := NewDefaultCGRConfig() @@ -376,7 +388,7 @@ func TestHttpAgentCfgloadFromJsonCfgCase7(t *testing.T) { }` cfgJSON := &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("RandomID"), + ID: utils.StringPointer("RandomID"), }, } expected := HTTPAgentCfgs{ @@ -405,7 +417,9 @@ func TestHttpAgentCfgAsMapInterface(t *testing.T) { { "id": "conecto1", "url": "/conecto", - "sessions_conns": ["*birpc_internal", "*localhost","*internal"], + "sessions_conns": ["*birpc_internal", "*localhost","conn1"], + "stats_conns": ["*birpc_internal", "*localhost","conn1"], + "thresholds_conns": ["*birpc_internal", "*localhost","conn1"], "request_payload": "*url", "reply_payload": "*xml", "request_processors": [ @@ -435,11 +449,13 @@ func TestHttpAgentCfgAsMapInterface(t *testing.T) { }` eMap := []map[string]any{ { - utils.IDCfg: "conecto1", - utils.URLCfg: "/conecto", - utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal, "*localhost", "*internal"}, - utils.RequestPayloadCfg: "*url", - utils.ReplyPayloadCfg: "*xml", + utils.IDCfg: "conecto1", + utils.URLCfg: "/conecto", + utils.SessionSConnsCfg: []string{rpcclient.BiRPCInternal, "*localhost", "conn1"}, + utils.StatSConnsCfg: []string{rpcclient.BiRPCInternal, "*localhost", "conn1"}, + utils.ThresholdSConnsCfg: []string{rpcclient.BiRPCInternal, "*localhost", "conn1"}, + utils.RequestPayloadCfg: "*url", + utils.ReplyPayloadCfg: "*xml", utils.RequestProcessorsCfg: []map[string]any{ { utils.IDCfg: "OutboundAUTHDryRun", @@ -469,11 +485,13 @@ func TestHttpAgentCfgAsMapInterface(t *testing.T) { func TestHTTPAgentCfgsClone(t *testing.T) { ban := HTTPAgentCfgs{ { - ID: "RandomID", - URL: "/randomURL", - SessionSConns: []string{"*internal:*sessions", "*conn1"}, - RequestPayload: "*url", - ReplyPayload: "*xml", + ID: "RandomID", + URL: "/randomURL", + SessionSConns: []string{"*internal:*sessions", "*conn1"}, + StatSConns: []string{"*internal:*stats", "*conn1"}, + ThresholdSConns: []string{"*internal:*thresholds", "*conn1"}, + RequestPayload: "*url", + ReplyPayload: "*xml", RequestProcessors: []*RequestProcessor{{ ID: "OutboundAUTHDryRun", Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"}, @@ -498,6 +516,12 @@ func TestHTTPAgentCfgsClone(t *testing.T) { if (*rcv)[0].SessionSConns[1] = ""; ban[0].SessionSConns[1] != "*conn1" { t.Errorf("Expected clone to not modify the cloned") } + if (*rcv)[0].StatSConns[1] = ""; ban[0].StatSConns[1] != "*conn1" { + t.Errorf("Expected clone to not modify the cloned") + } + if (*rcv)[0].ThresholdSConns[1] = ""; ban[0].ThresholdSConns[1] != "*conn1" { + t.Errorf("Expected clone to not modify the cloned") + } if (*rcv)[0].RequestProcessors[0].ID = ""; ban[0].RequestProcessors[0].ID != "OutboundAUTHDryRun" { t.Errorf("Expected clone to not modify the cloned") } @@ -506,11 +530,13 @@ func TestHTTPAgentCfgsClone(t *testing.T) { func TestEqualsHTTPAgentCfgs(t *testing.T) { v1 := HTTPAgentCfgs{ { - ID: "RANDOM_ID", - URL: "/url", - SessionSConns: []string{"*localhost"}, - RequestPayload: "*url", - ReplyPayload: "*xml", + ID: "RANDOM_ID", + URL: "/url", + SessionSConns: []string{"*localhost"}, + StatSConns: []string{"*localhost"}, + ThresholdSConns: []string{"*localhost"}, + RequestPayload: "*url", + ReplyPayload: "*xml", RequestProcessors: []*RequestProcessor{ { ID: "OutboundAUTHDryRun", @@ -535,11 +561,13 @@ func TestEqualsHTTPAgentCfgs(t *testing.T) { v2 := HTTPAgentCfgs{ { - ID: "RANDOM_ID2", - URL: "/url", - SessionSConns: []string{"*localhost"}, - RequestPayload: "*url", - ReplyPayload: "*xml", + ID: "RANDOM_ID2", + URL: "/url", + SessionSConns: []string{"*localhost"}, + StatSConns: []string{"*localhost"}, + ThresholdSConns: []string{"*localhost"}, + RequestPayload: "*url", + ReplyPayload: "*xml", RequestProcessors: []*RequestProcessor{ { ID: "OutboundAUTHDryRun", @@ -581,16 +609,16 @@ func TestEqualsHTTPAgentCfgs(t *testing.T) { func TestGetHttpAgentJsonCfg(t *testing.T) { d := []*HttpAgentJsonCfg{ { - Id: utils.StringPointer("ID_1"), - Url: utils.StringPointer("/url"), - Sessions_conns: &[]string{"*localhost"}, + ID: utils.StringPointer("ID_1"), + URL: utils.StringPointer("/url"), + SessionSConns: &[]string{"*localhost"}, }, } expected := &HttpAgentJsonCfg{ - Id: utils.StringPointer("ID_1"), - Url: utils.StringPointer("/url"), - Sessions_conns: &[]string{"*localhost"}, + ID: utils.StringPointer("ID_1"), + URL: utils.StringPointer("/url"), + SessionSConns: &[]string{"*localhost"}, } rcv, idx := getHttpAgentJsonCfg(d, "ID_1") @@ -639,11 +667,13 @@ func TestDiffHttpAgentJson(t *testing.T) { var d *HttpAgentJsonCfg v1 := &HTTPAgentCfg{ - ID: "http_agent", - URL: "http_url", - SessionSConns: []string{"*localhost"}, - RequestPayload: "request_payload", - ReplyPayload: "reply_payload", + ID: "http_agent", + URL: "http_url", + SessionSConns: []string{"*localhost"}, + StatSConns: []string{"*localhost"}, + ThresholdSConns: []string{"*localhost"}, + RequestPayload: "request_payload", + ReplyPayload: "reply_payload", RequestProcessors: []*RequestProcessor{ { ID: "req_processors", @@ -654,19 +684,23 @@ func TestDiffHttpAgentJson(t *testing.T) { v2 := &HTTPAgentCfg{ ID: "http_agent2", URL: "http_url2", - SessionSConns: []string{"*birpc"}, + SessionSConns: []string{"*internal"}, + StatSConns: []string{"*internal"}, + ThresholdSConns: []string{"*internal"}, RequestPayload: "request_payload2", ReplyPayload: "reply_payload2", RequestProcessors: []*RequestProcessor{}, } expected := &HttpAgentJsonCfg{ - Id: utils.StringPointer("http_agent2"), - Url: utils.StringPointer("http_url2"), - Sessions_conns: &[]string{"*birpc"}, - Request_payload: utils.StringPointer("request_payload2"), - Reply_payload: utils.StringPointer("reply_payload2"), - Request_processors: &[]*ReqProcessorJsnCfg{}, + ID: utils.StringPointer("http_agent2"), + URL: utils.StringPointer("http_url2"), + SessionSConns: &[]string{"*internal"}, + StatSConns: &[]string{"*internal"}, + ThresholdSConns: &[]string{"*internal"}, + RequestPayload: utils.StringPointer("request_payload2"), + ReplyPayload: utils.StringPointer("reply_payload2"), + RequestProcessors: &[]*ReqProcessorJsnCfg{}, } rcv := diffHttpAgentJsonCfg(d, v1, v2) @@ -676,7 +710,7 @@ func TestDiffHttpAgentJson(t *testing.T) { v1 = v2 expected = &HttpAgentJsonCfg{ - Request_processors: &[]*ReqProcessorJsnCfg{}, + RequestProcessors: &[]*ReqProcessorJsnCfg{}, } rcv = diffHttpAgentJsonCfg(d, v1, v2) if !reflect.DeepEqual(rcv, expected) { @@ -689,11 +723,13 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) { v1 := HTTPAgentCfgs{ { - ID: "http_agent", - URL: "http_url", - SessionSConns: []string{"*localhost"}, - RequestPayload: "request_payload", - ReplyPayload: "reply_payload", + ID: "http_agent", + URL: "http_url", + SessionSConns: []string{"*localhost"}, + StatSConns: []string{"*localhost"}, + ThresholdSConns: []string{"*localhost"}, + RequestPayload: "request_payload", + ReplyPayload: "reply_payload", RequestProcessors: []*RequestProcessor{ { ID: "req_processors", @@ -706,7 +742,9 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) { { ID: "http_agent2", URL: "http_url2", - SessionSConns: []string{"*birpc"}, + SessionSConns: []string{"*internal"}, + StatSConns: []string{"*internal"}, + ThresholdSConns: []string{"*internal"}, RequestPayload: "request_payload2", ReplyPayload: "reply_payload2", RequestProcessors: []*RequestProcessor{}, @@ -715,12 +753,14 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) { expected := &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("http_agent2"), - Url: utils.StringPointer("http_url2"), - Sessions_conns: &[]string{"*birpc"}, - Request_payload: utils.StringPointer("request_payload2"), - Reply_payload: utils.StringPointer("reply_payload2"), - Request_processors: &[]*ReqProcessorJsnCfg{}, + ID: utils.StringPointer("http_agent2"), + URL: utils.StringPointer("http_url2"), + SessionSConns: &[]string{"*internal"}, + StatSConns: &[]string{"*internal"}, + ThresholdSConns: &[]string{"*internal"}, + RequestPayload: utils.StringPointer("request_payload2"), + ReplyPayload: utils.StringPointer("reply_payload2"), + RequestProcessors: &[]*ReqProcessorJsnCfg{}, }, } @@ -731,7 +771,7 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) { d = &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("http_agent2"), + ID: utils.StringPointer("http_agent2"), }, } @@ -742,14 +782,14 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) { d = &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("http_agent2"), + ID: utils.StringPointer("http_agent2"), }, } v1 = v2 expected = &[]*HttpAgentJsonCfg{ { - Id: utils.StringPointer("http_agent2"), + ID: utils.StringPointer("http_agent2"), }, } rcv = diffHttpAgentsJsonCfg(d, v1, v2) @@ -761,11 +801,13 @@ func TestDiffHttpAgentsJsonCfg(t *testing.T) { func TestHttpAgentCloneSection(t *testing.T) { httpCfg := HTTPAgentCfgs{ { - ID: "http_agent", - URL: "http_url", - SessionSConns: []string{"*localhost"}, - RequestPayload: "request_payload", - ReplyPayload: "reply_payload", + ID: "http_agent", + URL: "http_url", + SessionSConns: []string{"*localhost"}, + StatSConns: []string{"*localhost"}, + ThresholdSConns: []string{"*localhost"}, + RequestPayload: "request_payload", + ReplyPayload: "reply_payload", }, } @@ -774,6 +816,8 @@ func TestHttpAgentCloneSection(t *testing.T) { ID: "http_agent", URL: "http_url", SessionSConns: []string{"*localhost"}, + StatSConns: []string{"*localhost"}, + ThresholdSConns: []string{"*localhost"}, RequestPayload: "request_payload", ReplyPayload: "reply_payload", RequestProcessors: []*RequestProcessor{},