From e73cdd0c5ee7d808ccd5c01d0d6f243aafc50cac Mon Sep 17 00:00:00 2001 From: adragusin Date: Mon, 27 Jan 2020 14:16:42 +0200 Subject: [PATCH] Added RemoteCost field in *vars (in agents) --- agents/diamagent.go | 1 + agents/dnsagent.go | 1 + agents/httpagent.go | 4 +++- agents/radagent.go | 8 ++++++-- integration_test.sh | 15 ++++++++++++--- utils/consts.go | 1 + 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/agents/diamagent.go b/agents/diamagent.go index 494a985c2..19a91d76b 100644 --- a/agents/diamagent.go +++ b/agents/diamagent.go @@ -150,6 +150,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) { utils.MetaApp: dApp.Name, utils.MetaAppID: dApp.ID, utils.MetaCmd: dCmd.Short + "R", + utils.RemoteHost: c.RemoteAddr().String(), } // build the negative error answer diamErr, err := diamErr(m, diam.UnableToComply, reqVars, diff --git a/agents/dnsagent.go b/agents/dnsagent.go index 03beec96c..9bd9f7e56 100644 --- a/agents/dnsagent.go +++ b/agents/dnsagent.go @@ -111,6 +111,7 @@ func (da *DNSAgent) handleMessage(w dns.ResponseWriter, req *dns.Msg) { reqVars[E164Address] = e164 reqVars[DomainName] = domainNameFromNAPTR(req.Question[0].Name) } + reqVars[utils.RemoteHost] = w.RemoteAddr().String() cgrRplyNM := config.NewNavigableMap(nil) rplyNM := config.NewNavigableMap(nil) // share it among different processors var processed bool diff --git a/agents/httpagent.go b/agents/httpagent.go index b707c67cc..e46b094d3 100644 --- a/agents/httpagent.go +++ b/agents/httpagent.go @@ -56,6 +56,7 @@ type HTTPAgent struct { // ServeHTTP implements http.Handler interface func (ha *HTTPAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) { + reqVars := make(map[string]interface{}) dcdr, err := newHADataProvider(ha.reqPayload, req) // dcdr will provide information from request if err != nil { utils.Logger.Warning( @@ -65,8 +66,9 @@ func (ha *HTTPAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) { } cgrRplyNM := config.NewNavigableMap(nil) rplyNM := config.NewNavigableMap(nil) + reqVars[utils.RemoteHost] = req.RemoteAddr for _, reqProcessor := range ha.reqProcessors { - agReq := NewAgentRequest(dcdr, nil, cgrRplyNM, rplyNM, + agReq := NewAgentRequest(dcdr, reqVars, cgrRplyNM, rplyNM, reqProcessor.Tenant, ha.dfltTenant, utils.FirstNonEmpty(reqProcessor.Timezone, config.CgrConfig().GeneralCfg().DefaultTimezone), diff --git a/agents/radagent.go b/agents/radagent.go index 4e2018ce3..6ed84666d 100644 --- a/agents/radagent.go +++ b/agents/radagent.go @@ -70,6 +70,7 @@ type RadiusAgent struct { // handleAuth handles RADIUS Authorization request func (ra *RadiusAgent) handleAuth(req *radigo.Packet) (rpl *radigo.Packet, err error) { + reqVars := make(map[string]interface{}) req.SetAVPValues() // populate string values in AVPs dcdr := newRADataProvider(req) // dcdr will provide information from request rpl = req.Reply() @@ -77,8 +78,9 @@ func (ra *RadiusAgent) handleAuth(req *radigo.Packet) (rpl *radigo.Packet, err e cgrRplyNM := config.NewNavigableMap(nil) rplyNM := config.NewNavigableMap(nil) var processed bool + reqVars[utils.RemoteHost] = req.RemoteAddr().String() for _, reqProcessor := range ra.cgrCfg.RadiusAgentCfg().RequestProcessors { - agReq := NewAgentRequest(dcdr, nil, cgrRplyNM, rplyNM, + agReq := NewAgentRequest(dcdr, reqVars, cgrRplyNM, rplyNM, reqProcessor.Tenant, ra.cgrCfg.GeneralCfg().DefaultTenant, utils.FirstNonEmpty(reqProcessor.Timezone, config.CgrConfig().GeneralCfg().DefaultTimezone), @@ -107,6 +109,7 @@ func (ra *RadiusAgent) handleAuth(req *radigo.Packet) (rpl *radigo.Packet, err e // handleAcct handles RADIUS Accounting request // supports: Acct-Status-Type = Start, Interim-Update, Stop func (ra *RadiusAgent) handleAcct(req *radigo.Packet) (rpl *radigo.Packet, err error) { + reqVars := make(map[string]interface{}) req.SetAVPValues() // populate string values in AVPs dcdr := newRADataProvider(req) // dcdr will provide information from request rpl = req.Reply() @@ -114,8 +117,9 @@ func (ra *RadiusAgent) handleAcct(req *radigo.Packet) (rpl *radigo.Packet, err e cgrRplyNM := config.NewNavigableMap(nil) rplyNM := config.NewNavigableMap(nil) var processed bool + reqVars[utils.RemoteHost] = req.RemoteAddr().String() for _, reqProcessor := range ra.cgrCfg.RadiusAgentCfg().RequestProcessors { - agReq := NewAgentRequest(dcdr, nil, cgrRplyNM, rplyNM, + agReq := NewAgentRequest(dcdr, reqVars, cgrRplyNM, rplyNM, reqProcessor.Tenant, ra.cgrCfg.GeneralCfg().DefaultTenant, utils.FirstNonEmpty(reqProcessor.Timezone, config.CgrConfig().GeneralCfg().DefaultTimezone), diff --git a/integration_test.sh b/integration_test.sh index e856c8b81..d49e5407d 100755 --- a/integration_test.sh +++ b/integration_test.sh @@ -28,6 +28,9 @@ agts_internal=$? echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*internal' go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*internal smg_internal=$? +echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*internal' +go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*internal +dis_internal=$? # SQL echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*sql' go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*sql @@ -53,6 +56,9 @@ agts_sql=$? echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*sql' go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*sql smg_sql=$? +echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*sql' +go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*sql +dis_sql=$? # Mongo echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo' go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo @@ -78,6 +84,9 @@ agts_mongo=$? echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*mongo' go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*mongo smg_mongo=$? +echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*mongo' +go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*mongo +dis_mongo=$? # Postgres echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres' go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres @@ -103,6 +112,9 @@ agts_postgres=$? echo 'go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*postgres' go test github.com/cgrates/cgrates/sessions -tags=integration -dbtype=*postgres smg_postgres=$? +echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*postgres' +go test github.com/cgrates/cgrates/dispatchers -tags=integration -dbtype=*postgres +dis_postgres=$? echo 'go test github.com/cgrates/cgrates/config -tags=integration' go test github.com/cgrates/cgrates/config -tags=integration @@ -115,9 +127,6 @@ go test github.com/cgrates/cgrates/services -tags=integration srv=$? #All -echo 'go test github.com/cgrates/cgrates/dispatchers -tags=integration' -go test github.com/cgrates/cgrates/dispatchers -tags=integration -dis=$? echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline' go test github.com/cgrates/cgrates/apier/v1 -tags=offline offline=$? diff --git a/utils/consts.go b/utils/consts.go index b9d2765ff..c8adaf17b 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -543,6 +543,7 @@ const ( IdxEnd = "]" MetaLog = "*log" MetaRemoteHost = "*remote_host" + RemoteHost = "RemoteHost" Local = "local" TCP = "tcp" CGRDebitInterval = "CGRDebitInterval"