diff --git a/honeypot/store/postgres.go b/honeypot/store/postgres.go index 2a3e053..e0e7e46 100644 --- a/honeypot/store/postgres.go +++ b/honeypot/store/postgres.go @@ -127,5 +127,37 @@ func (s *PostgresStore) Stats(statType LoginStats, limit int) ([]StatsResult, er } func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { - return nil, nil + uniquePasswordStmt := `select count(*) from (select distinct password from login_attempts) as temp` + uniqueUsernameStmt := `select count(*) from (select distinct username from login_attempts) as temp` + uniqueIPStmt := `select count(*) from (select distinct remote_ip from login_attempts) as temp` + uniqueCountryStmt := `select count(*) from (select distinct country from login_attempts) as temp` + attemptsCountStmt := `select count(1) from login_attempts` + + var uniquePasswordsCount int + if err := s.db.QueryRow(uniquePasswordStmt).Scan(&uniquePasswordsCount); err != nil { + return nil, err + } + var uniqueUsernameCount int + if err := s.db.QueryRow(uniqueUsernameStmt).Scan(&uniqueUsernameCount); err != nil { + return nil, err + } + var uniqueIPCount int + if err := s.db.QueryRow(uniqueIPStmt).Scan(&uniqueIPCount); err != nil { + return nil, err + } + var uniqueCountryCount int + if err := s.db.QueryRow(uniqueCountryStmt).Scan(&uniqueCountryCount); err != nil { + return nil, err + } + var attemptsCount int + if err := s.db.QueryRow(attemptsCountStmt).Scan(&attemptsCount); err != nil { + return nil, err + } + return []StatsResult{ + {Name: "UniquePasswords", Count: uniquePasswordsCount}, + {Name: "UniqueUsernames", Count: uniqueUsernameCount}, + {Name: "UniqueIPs", Count: uniqueIPCount}, + {Name: "UniqueCountries", Count: uniqueCountryCount}, + {Name: "TotalLoginAttempts", Count: attemptsCount}, + }, nil }