diff --git a/honeypot/ssh/store/cache.go b/honeypot/ssh/store/cache.go index c087c6c..75b02c3 100644 --- a/honeypot/ssh/store/cache.go +++ b/honeypot/ssh/store/cache.go @@ -109,6 +109,6 @@ func (s *CachingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) return attempts, err } -func (s *CachingStore) IsHealthy() bool { +func (s *CachingStore) IsHealthy() error { return s.backend.IsHealthy() } diff --git a/honeypot/ssh/store/memory.go b/honeypot/ssh/store/memory.go index 66faf20..20a3cfb 100644 --- a/honeypot/ssh/store/memory.go +++ b/honeypot/ssh/store/memory.go @@ -142,8 +142,8 @@ func (ms *MemoryStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) return results, nil } -func (s *MemoryStore) IsHealthy() bool { - return true +func (s *MemoryStore) IsHealthy() error { + return nil } func toResults(m map[string]int) []StatsResult { diff --git a/honeypot/ssh/store/metrics.go b/honeypot/ssh/store/metrics.go index 5e3a3a2..ac45619 100644 --- a/honeypot/ssh/store/metrics.go +++ b/honeypot/ssh/store/metrics.go @@ -121,6 +121,6 @@ func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttemp return s.store.Query(query) } -func (s *MetricsCollectingStore) IsHealthy() bool { - return s.IsHealthy() +func (s *MetricsCollectingStore) IsHealthy() error { + return s.store.IsHealthy() } diff --git a/honeypot/ssh/store/postgres.go b/honeypot/ssh/store/postgres.go index 6f054e2..d312780 100644 --- a/honeypot/ssh/store/postgres.go +++ b/honeypot/ssh/store/postgres.go @@ -126,8 +126,11 @@ 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) IsHealthy() error { + if err := s.db.Ping(); err != nil { + return ErrStoreUnhealthy + } + return nil } func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { diff --git a/honeypot/ssh/store/store.go b/honeypot/ssh/store/store.go index bc54aa8..08d61e7 100644 --- a/honeypot/ssh/store/store.go +++ b/honeypot/ssh/store/store.go @@ -1,6 +1,12 @@ package store -import "github.uio.no/torjus/apiary/models" +import ( + "errors" + + "github.uio.no/torjus/apiary/models" +) + +var ErrStoreUnhealthy = errors.New("store is unhealthy") type LoginStats string @@ -39,5 +45,5 @@ type LoginAttemptStore interface { } type HealthCheker interface { - IsHealthy() bool + IsHealthy() error }