Improve logging

This commit is contained in:
Torjus Håkestad 2021-04-10 11:59:10 +02:00
parent 76de4ad82c
commit a60190e6ac
3 changed files with 5 additions and 2 deletions

View File

@ -10,14 +10,16 @@ import (
//go:embed Geoacumen-Country.mmdb //go:embed Geoacumen-Country.mmdb
var mmdb []byte var mmdb []byte
func LookupCountry(ip net.IP) string { func (s *HoneypotServer) LookupCountry(ip net.IP) string {
db, err := geoip2.FromBytes(mmdb) db, err := geoip2.FromBytes(mmdb)
if err != nil { if err != nil {
s.Logger.Warnw("Error opening geoip database", "error", err)
return "??" return "??"
} }
country, err := db.Country(ip) country, err := db.Country(ip)
if err != nil { if err != nil {
s.Logger.Warnw("Error doing geoip lookup", "error", err)
return "??" return "??"
} }
return country.Country.IsoCode return country.Country.IsoCode

View File

@ -87,7 +87,7 @@ func (hs *HoneypotServer) passwordHandler(ctx ssh.Context, password string) bool
SSHClientVersion: ctx.ClientVersion(), SSHClientVersion: ctx.ClientVersion(),
ConnectionUUID: sessUUID, ConnectionUUID: sessUUID,
} }
country := LookupCountry(la.RemoteIP) country := hs.LookupCountry(la.RemoteIP)
la.Country = country la.Country = country
hs.Logger.Infow("Login attempt", hs.Logger.Infow("Login attempt",
"remote_ip", la.RemoteIP.String(), "remote_ip", la.RemoteIP.String(),

View File

@ -195,6 +195,7 @@ func (s *Server) HandlerStats(w http.ResponseWriter, r *http.Request) {
stats, err := s.store.Stats(statType, limit) stats, err := s.store.Stats(statType, limit)
if err != nil { if err != nil {
s.ServerLogger.Warnw("Error fetching stats", "error", err)
s.WriteAPIError(w, r, http.StatusInternalServerError, "Error fetching stats") s.WriteAPIError(w, r, http.StatusInternalServerError, "Error fetching stats")
return return
} }