From a60190e6ac152fc9cbdef32077a6faf6b5448eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 10 Apr 2021 11:59:10 +0200 Subject: [PATCH] Improve logging --- honeypot/geolocate.go | 4 +++- honeypot/server.go | 2 +- web/server.go | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/honeypot/geolocate.go b/honeypot/geolocate.go index f3969b0..e18c9d7 100644 --- a/honeypot/geolocate.go +++ b/honeypot/geolocate.go @@ -10,14 +10,16 @@ import ( //go:embed Geoacumen-Country.mmdb var mmdb []byte -func LookupCountry(ip net.IP) string { +func (s *HoneypotServer) LookupCountry(ip net.IP) string { db, err := geoip2.FromBytes(mmdb) if err != nil { + s.Logger.Warnw("Error opening geoip database", "error", err) return "??" } country, err := db.Country(ip) if err != nil { + s.Logger.Warnw("Error doing geoip lookup", "error", err) return "??" } return country.Country.IsoCode diff --git a/honeypot/server.go b/honeypot/server.go index a068147..35f9bd0 100644 --- a/honeypot/server.go +++ b/honeypot/server.go @@ -87,7 +87,7 @@ func (hs *HoneypotServer) passwordHandler(ctx ssh.Context, password string) bool SSHClientVersion: ctx.ClientVersion(), ConnectionUUID: sessUUID, } - country := LookupCountry(la.RemoteIP) + country := hs.LookupCountry(la.RemoteIP) la.Country = country hs.Logger.Infow("Login attempt", "remote_ip", la.RemoteIP.String(), diff --git a/web/server.go b/web/server.go index 56f20fc..93ef00f 100644 --- a/web/server.go +++ b/web/server.go @@ -195,6 +195,7 @@ func (s *Server) HandlerStats(w http.ResponseWriter, r *http.Request) { stats, err := s.store.Stats(statType, limit) if err != nil { + s.ServerLogger.Warnw("Error fetching stats", "error", err) s.WriteAPIError(w, r, http.StatusInternalServerError, "Error fetching stats") return }