Skip to content

Commit

Permalink
Postgres support: Corrected one typo, and added distinction between n…
Browse files Browse the repository at this point in the history
…o rights and no data
  • Loading branch information
blackandred committed Dec 1, 2019
1 parent 4c9ab72 commit 6d8c8cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion infracheck/checks/postgres-primary-streaming-status
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ from infracheck.infracheck.checklib.postgres import BasePostgreSQL

class PostgresReplicaCheck(BasePostgreSQL):
def main(self, expected_status: str, expected_user: str) -> tuple:
return self.validate_replication_row_exists('SELECT state, username FROM pg_stat_replication;',
return self.validate_replication_row_exists('SELECT state, usename FROM pg_stat_replication;',
expected_status=expected_status, expected_user=expected_user)


Expand Down
8 changes: 8 additions & 0 deletions infracheck/infracheck/checklib/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ def query(self, qstr: str):
def validate_replication_row_exists(self, sql: str, expected_status: str, expected_user: str):
out = self.query(sql)
active_replications = len(out)
has_no_access_to_at_least_one_row = False

for row in out:
status, conn_info = row

if conn_info is None:
has_no_access_to_at_least_one_row = True
continue

if status != expected_status and expected_user in conn_info:
return False, 'Expected "%s" status for conn_info="%s", got "%s"' % (
expected_status, conn_info, status
Expand All @@ -50,6 +55,9 @@ def validate_replication_row_exists(self, sql: str, expected_status: str, expect
)

if active_replications == 0:
if has_no_access_to_at_least_one_row:
return False, "no replications active: possibly connection user has no permissions to view this data"

return False, "no replications active"

return False, "%i replications active, but none found for user '%s'" % (active_replications, expected_user)

0 comments on commit 6d8c8cd

Please sign in to comment.