Browse Source

config bugfix for X-Forwarded-For header when parsing logfiles

Tobias von Dewitz 6 years ago
parent
commit
5cc2d01372
2 changed files with 4 additions and 4 deletions
  1. 1 1
      Makefile
  2. 3 3
      main.go

+ 1 - 1
Makefile

@@ -3,4 +3,4 @@ BUILD=$(shell date +%FT%T%z)
 
 
 all:
-	go build -tags netgo -ldflags "-s -X main.Version=$(VERSION) -X main.BuildDate=$(BUILD)"
+	env GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags "-s -X main.Version=$(VERSION) -X main.BuildDate=$(BUILD)"

+ 3 - 3
main.go

@@ -278,9 +278,9 @@ func nginxLogCapture(logfile, format string) {
 			continue
 		}
 
-		if *useXForwardedAsSource {
+		if config.UseXForwardedAsSource {
 			xff, err := logEntry.Field("http_x_forwarded_for")
-			if err != nil {
+			if err != nil && xff != "" {
 				remote = xff
 			}
 		}
@@ -387,7 +387,7 @@ func apacheLogCapture(logfile string) {
 		}
 
 		remote := logEntry.Host
-		if *useXForwardedAsSource && logEntry.ForwardedFor != "" {
+		if config.UseXForwardedAsSource && logEntry.ForwardedFor != "" {
 			remote = logEntry.ForwardedFor
 		}