|
@@ -24,6 +24,7 @@ import (
|
|
"github.com/google/gopacket/layers"
|
|
"github.com/google/gopacket/layers"
|
|
"github.com/google/gopacket/pcap"
|
|
"github.com/google/gopacket/pcap"
|
|
"github.com/hpcloud/tail"
|
|
"github.com/hpcloud/tail"
|
|
|
|
+ "github.com/kr/pretty"
|
|
"github.com/nats-io/nats"
|
|
"github.com/nats-io/nats"
|
|
"github.com/nats-io/nats/encoders/protobuf"
|
|
"github.com/nats-io/nats/encoders/protobuf"
|
|
"github.com/satyrius/gonx"
|
|
"github.com/satyrius/gonx"
|
|
@@ -269,6 +270,9 @@ func nginxLogCapture(logfile, format string) {
|
|
reqRegexp := regexp.MustCompile(`^([A-Z]+)\s+(.+?)\s+(HTTP/\d+\.\d+)$`)
|
|
reqRegexp := regexp.MustCompile(`^([A-Z]+)\s+(.+?)\s+(HTTP/\d+\.\d+)$`)
|
|
|
|
|
|
for line := range t.Lines {
|
|
for line := range t.Lines {
|
|
|
|
+ var remote string
|
|
|
|
+ var err error
|
|
|
|
+
|
|
l := line.Text
|
|
l := line.Text
|
|
|
|
|
|
logEntry, err := p.ParseString(l)
|
|
logEntry, err := p.ParseString(l)
|
|
@@ -277,12 +281,30 @@ func nginxLogCapture(logfile, format string) {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
- remote, err := logEntry.Field("remote_addr")
|
|
|
|
|
|
+ if config.Trace {
|
|
|
|
+ pretty.Println(logEntry)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ remote, err = logEntry.Field("remote_addr")
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println(err)
|
|
log.Println(err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ xff, err := logEntry.Field("http_x_forwarded_for")
|
|
|
|
+ if err != nil && xff != "" {
|
|
|
|
+ if config.Trace {
|
|
|
|
+ log.Printf("Using XFF: %s\n", xff)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ remote = xff
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if remote == "" {
|
|
|
|
+ log.Println("remote is empty: ignoring request.")
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
// only use the first host in case there are multiple hosts in the log
|
|
// only use the first host in case there are multiple hosts in the log
|
|
if cidx := strings.Index(remote, ","); cidx >= 0 {
|
|
if cidx := strings.Index(remote, ","); cidx >= 0 {
|
|
remote = remote[0:cidx]
|
|
remote = remote[0:cidx]
|
|
@@ -575,7 +597,7 @@ func apacheLogCapture(logfile string) {
|
|
}
|
|
}
|
|
|
|
|
|
remote := logEntry.Host
|
|
remote := logEntry.Host
|
|
- if *useXForwardedAsSource && logEntry.ForwardedFor != "" {
|
|
|
|
|
|
+ if config.UseXForwardedAsSource && logEntry.ForwardedFor != "" {
|
|
remote = logEntry.ForwardedFor
|
|
remote = logEntry.ForwardedFor
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1078,7 +1100,7 @@ func loadConfig() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// version outputs build information
|
|
|
|
|
|
+// version outputs build information...
|
|
func version() {
|
|
func version() {
|
|
fmt.Printf("munchclient %s, built on %s\n", Version, BuildDate)
|
|
fmt.Printf("munchclient %s, built on %s\n", Version, BuildDate)
|
|
}
|
|
}
|