@@ -39,17 +39,17 @@ type Network struct {
3939 api.TransformNetwork
4040}
4141
42- func (n * Network ) Transform (inputEntries []config.GenericMap ) []config.GenericMap {
42+ func (n * Network ) Transform (input []config.GenericMap ) []config.GenericMap {
4343 outputEntries := make ([]config.GenericMap , 0 )
44- for _ , entry := range inputEntries {
44+ for _ , entry := range input {
4545 outputEntry := n .TransformEntry (entry )
4646 outputEntries = append (outputEntries , outputEntry )
4747 }
4848 return outputEntries
4949}
5050
5151func (n * Network ) TransformEntry (inputEntry config.GenericMap ) config.GenericMap {
52- outputEntries := inputEntry
52+ outputEntry := inputEntry . Copy ()
5353
5454 for _ , rule := range n .Rules {
5555 switch rule .Type {
@@ -59,28 +59,28 @@ func (n *Network) TransformEntry(inputEntry config.GenericMap) config.GenericMap
5959 panic (err )
6060 }
6161 buf := & bytes.Buffer {}
62- err = template .Execute (buf , outputEntries )
62+ err = template .Execute (buf , outputEntry )
6363 if err != nil {
6464 panic (err )
6565 }
6666 FlowIDFieldsAsString := buf .String ()
6767 isNew := connection_tracking .CT .AddFlow (FlowIDFieldsAsString )
6868 if isNew {
6969 if rule .Parameters != "" {
70- outputEntries [rule .Output ] = rule .Parameters
70+ outputEntry [rule .Output ] = rule .Parameters
7171 } else {
72- outputEntries [rule .Output ] = true
72+ outputEntry [rule .Output ] = true
7373 }
7474 }
7575
7676 case api .TransformNetworkOperationName ("AddRegExIf" ):
77- matched , err := regexp .MatchString (rule .Parameters , fmt .Sprintf ("%s" , outputEntries [rule .Input ]))
77+ matched , err := regexp .MatchString (rule .Parameters , fmt .Sprintf ("%s" , outputEntry [rule .Input ]))
7878 if err != nil {
7979 continue
8080 }
8181 if matched {
82- outputEntries [rule .Output ] = outputEntries [rule .Input ]
83- outputEntries [rule .Output + "_Matched" ] = true
82+ outputEntry [rule .Output ] = outputEntry [rule .Input ]
83+ outputEntry [rule .Output + "_Matched" ] = true
8484 }
8585 case api .TransformNetworkOperationName ("AddIf" ):
8686 expressionString := fmt .Sprintf ("val %s" , rule .Parameters )
@@ -89,81 +89,81 @@ func (n *Network) TransformEntry(inputEntry config.GenericMap) config.GenericMap
8989 log .Errorf ("Can't evaluate AddIf rule: %+v expression: %v. err %v" , rule , expressionString , err )
9090 continue
9191 }
92- result , evaluateErr := expression .Evaluate (map [string ]interface {}{"val" : outputEntries [rule .Input ]})
92+ result , evaluateErr := expression .Evaluate (map [string ]interface {}{"val" : outputEntry [rule .Input ]})
9393 if evaluateErr == nil && result .(bool ) {
94- outputEntries [rule .Output ] = outputEntries [rule .Input ]
95- outputEntries [rule .Output + "_Evaluate" ] = true
94+ outputEntry [rule .Output ] = outputEntry [rule .Input ]
95+ outputEntry [rule .Output + "_Evaluate" ] = true
9696 }
9797 case api .TransformNetworkOperationName ("AddSubnet" ):
98- _ , ipv4Net , err := net .ParseCIDR (fmt .Sprintf ("%v%s" , outputEntries [rule .Input ], rule .Parameters ))
98+ _ , ipv4Net , err := net .ParseCIDR (fmt .Sprintf ("%v%s" , outputEntry [rule .Input ], rule .Parameters ))
9999 if err != nil {
100- log .Errorf ("Can't find subnet for IP %v and prefix length %s - err %v" , outputEntries [rule .Input ], rule .Parameters , err )
100+ log .Errorf ("Can't find subnet for IP %v and prefix length %s - err %v" , outputEntry [rule .Input ], rule .Parameters , err )
101101 continue
102102 }
103- outputEntries [rule .Output ] = ipv4Net .String ()
103+ outputEntry [rule .Output ] = ipv4Net .String ()
104104 case api .TransformNetworkOperationName ("AddLocation" ):
105105 var locationInfo * location.Info
106- err , locationInfo := location .GetLocation (fmt .Sprintf ("%s" , outputEntries [rule .Input ]))
106+ err , locationInfo := location .GetLocation (fmt .Sprintf ("%s" , outputEntry [rule .Input ]))
107107 if err != nil {
108- log .Errorf ("Can't find location for IP %v err %v" , outputEntries [rule .Input ], err )
108+ log .Errorf ("Can't find location for IP %v err %v" , outputEntry [rule .Input ], err )
109109 continue
110110 }
111- outputEntries [rule .Output + "_CountryName" ] = locationInfo .CountryName
112- outputEntries [rule .Output + "_CountryLongName" ] = locationInfo .CountryLongName
113- outputEntries [rule .Output + "_RegionName" ] = locationInfo .RegionName
114- outputEntries [rule .Output + "_CityName" ] = locationInfo .CityName
115- outputEntries [rule .Output + "_Latitude" ] = locationInfo .Latitude
116- outputEntries [rule .Output + "_Longitude" ] = locationInfo .Longitude
111+ outputEntry [rule .Output + "_CountryName" ] = locationInfo .CountryName
112+ outputEntry [rule .Output + "_CountryLongName" ] = locationInfo .CountryLongName
113+ outputEntry [rule .Output + "_RegionName" ] = locationInfo .RegionName
114+ outputEntry [rule .Output + "_CityName" ] = locationInfo .CityName
115+ outputEntry [rule .Output + "_Latitude" ] = locationInfo .Latitude
116+ outputEntry [rule .Output + "_Longitude" ] = locationInfo .Longitude
117117 case api .TransformNetworkOperationName ("AddService" ):
118- protocol := fmt .Sprintf ("%v" , outputEntries [rule .Parameters ])
119- portNumber , err := strconv .Atoi (fmt .Sprintf ("%v" , outputEntries [rule .Input ]))
118+ protocol := fmt .Sprintf ("%v" , outputEntry [rule .Parameters ])
119+ portNumber , err := strconv .Atoi (fmt .Sprintf ("%v" , outputEntry [rule .Input ]))
120120 if err != nil {
121- log .Errorf ("Can't convert port to int: Port %v - err %v" , outputEntries [rule .Input ], err )
121+ log .Errorf ("Can't convert port to int: Port %v - err %v" , outputEntry [rule .Input ], err )
122122 continue
123123 }
124124 service := netdb .GetServByPort (portNumber , netdb .GetProtoByName (protocol ))
125125 if service == nil {
126126 protocolAsNumber , err := strconv .Atoi (fmt .Sprintf ("%v" , protocol ))
127127 if err != nil {
128- log .Infof ("Can't find service name for Port %v and protocol %v - err %v" , outputEntries [rule .Input ], protocol , err )
128+ log .Infof ("Can't find service name for Port %v and protocol %v - err %v" , outputEntry [rule .Input ], protocol , err )
129129 continue
130130 }
131131 service = netdb .GetServByPort (portNumber , netdb .GetProtoByNumber (protocolAsNumber ))
132132 if service == nil {
133- log .Infof ("Can't find service name for Port %v and protocol %v - err %v" , outputEntries [rule .Input ], protocol , err )
133+ log .Infof ("Can't find service name for Port %v and protocol %v - err %v" , outputEntry [rule .Input ], protocol , err )
134134 continue
135135 }
136136 }
137- outputEntries [rule .Output ] = service .Name
137+ outputEntry [rule .Output ] = service .Name
138138 case api .TransformNetworkOperationName ("AddKubernetes" ):
139139 var kubeInfo * kubernetes.Info
140- kubeInfo , err := kubernetes .Data .GetInfo (fmt .Sprintf ("%s" , outputEntries [rule .Input ]))
140+ kubeInfo , err := kubernetes .Data .GetInfo (fmt .Sprintf ("%s" , outputEntry [rule .Input ]))
141141 if err != nil {
142- log .Debugf ("Can't find kubernetes info for IP %v err %v" , outputEntries [rule .Input ], err )
142+ log .Debugf ("Can't find kubernetes info for IP %v err %v" , outputEntry [rule .Input ], err )
143143 continue
144144 }
145- outputEntries [rule .Output + "_Namespace" ] = kubeInfo .Namespace
146- outputEntries [rule .Output + "_Name" ] = kubeInfo .Name
147- outputEntries [rule .Output + "_Type" ] = kubeInfo .Type
148- outputEntries [rule .Output + "_OwnerName" ] = kubeInfo .Owner .Name
149- outputEntries [rule .Output + "_OwnerType" ] = kubeInfo .Owner .Type
145+ outputEntry [rule .Output + "_Namespace" ] = kubeInfo .Namespace
146+ outputEntry [rule .Output + "_Name" ] = kubeInfo .Name
147+ outputEntry [rule .Output + "_Type" ] = kubeInfo .Type
148+ outputEntry [rule .Output + "_OwnerName" ] = kubeInfo .Owner .Name
149+ outputEntry [rule .Output + "_OwnerType" ] = kubeInfo .Owner .Type
150150 if rule .Parameters != "" {
151151 for labelKey , labelValue := range kubeInfo .Labels {
152- outputEntries [rule .Parameters + "_" + labelKey ] = labelValue
152+ outputEntry [rule .Parameters + "_" + labelKey ] = labelValue
153153 }
154154 }
155155 if kubeInfo .HostIP != "" {
156- outputEntries [rule .Output + "_HostIP" ] = kubeInfo .HostIP
156+ outputEntry [rule .Output + "_HostIP" ] = kubeInfo .HostIP
157157 if kubeInfo .HostName != "" {
158- outputEntries [rule .Output + "_HostName" ] = kubeInfo .HostName
158+ outputEntry [rule .Output + "_HostName" ] = kubeInfo .HostName
159159 }
160160 }
161161 default :
162162 log .Panicf ("unknown type %s for transform.Network rule: %v" , rule .Type , rule )
163163 }
164164 }
165165
166- return outputEntries
166+ return outputEntry
167167}
168168
169169// NewTransformNetwork create a new transform
0 commit comments