diff --git a/honeypot/ssh/store/cache.go b/honeypot/ssh/store/cache.go index 71b2d19..c087c6c 100644 --- a/honeypot/ssh/store/cache.go +++ b/honeypot/ssh/store/cache.go @@ -108,3 +108,7 @@ func (s *CachingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) return attempts, err } + +func (s *CachingStore) IsHealthy() bool { + return s.backend.IsHealthy() +} diff --git a/honeypot/ssh/store/memory.go b/honeypot/ssh/store/memory.go index 9440b4a..66faf20 100644 --- a/honeypot/ssh/store/memory.go +++ b/honeypot/ssh/store/memory.go @@ -142,6 +142,10 @@ func (ms *MemoryStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) return results, nil } +func (s *MemoryStore) IsHealthy() bool { + return true +} + func toResults(m map[string]int) []StatsResult { var results []StatsResult diff --git a/honeypot/ssh/store/metrics.go b/honeypot/ssh/store/metrics.go index 374898d..5e3a3a2 100644 --- a/honeypot/ssh/store/metrics.go +++ b/honeypot/ssh/store/metrics.go @@ -120,3 +120,7 @@ func (s *MetricsCollectingStore) Stats(statType LoginStats, limit int) ([]StatsR func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) { return s.store.Query(query) } + +func (s *MetricsCollectingStore) IsHealthy() bool { + return s.IsHealthy() +} diff --git a/honeypot/ssh/store/postgres.go b/honeypot/ssh/store/postgres.go index 4a33e4c..6f054e2 100644 --- a/honeypot/ssh/store/postgres.go +++ b/honeypot/ssh/store/postgres.go @@ -126,6 +126,10 @@ func (s *PostgresStore) Stats(statType LoginStats, limit int) ([]StatsResult, er return results, nil } +func (s *PostgresStore) IsHealthy() bool { + return s.db.Ping() == nil +} + func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { uniquePasswordStmt := `select count(*) from (select distinct password from login_attempts) as temp` uniqueUsernameStmt := `select count(*) from (select distinct username from login_attempts) as temp` diff --git a/honeypot/ssh/store/store.go b/honeypot/ssh/store/store.go index eb2f71e..bc54aa8 100644 --- a/honeypot/ssh/store/store.go +++ b/honeypot/ssh/store/store.go @@ -35,4 +35,9 @@ type LoginAttemptStore interface { All() ([]models.LoginAttempt, error) Stats(statType LoginStats, limit int) ([]StatsResult, error) Query(query AttemptQuery) ([]models.LoginAttempt, error) + HealthCheker +} + +type HealthCheker interface { + IsHealthy() bool }