Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres #68

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions operator/scripts/postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/env python
import pexpect
import sys
import os
import re
from pexpect import pxssh

def remove_ansi_escape_sequences(string):
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
return ansi_escape.sub('', string)

def remove_cr(string):
r = re.compile(r'\r')
return r.sub('', string)

hostname=os.environ['HOSTNAME']
username=os.environ['USERNAME']
password=os.environ['PASSWORD']

s = pxssh.pxssh(options={"StrictHostKeyChecking": "no", "UserKnownHostsFile": "/dev/null"})
s.force_password = True
s.login (hostname, username, password)

# If any rows return 'Y' then we are good.
s.sendline('''echo "select count(*) from data where data_col = 'Y'" | psql -t argus_demo | xargs''')
s.prompt()
output=s.before.decode('utf-8').split('\n')
line=remove_ansi_escape_sequences(output[1].strip())
line=remove_cr(line)
count=int(line)

if count > 0:
sys.exit(0)
else:
sys.exit(1)
Loading