Fix psql check for new configs

This commit is contained in:
Joshua Boniface 2023-12-01 03:58:21 -05:00
parent 6315a068d1
commit 915a84ee3c
1 changed files with 15 additions and 15 deletions

View File

@ -67,8 +67,8 @@ class MonitoringPluginScript(MonitoringPlugin):
# Run any imports first # Run any imports first
from psycopg2 import connect from psycopg2 import connect
conn_metadata = None conn_api = None
cur_metadata = None cur_api = None
conn_dns = None conn_dns = None
cur_dns = None cur_dns = None
@ -79,25 +79,25 @@ class MonitoringPluginScript(MonitoringPlugin):
# Check the Metadata database (primary) # Check the Metadata database (primary)
try: try:
conn_metadata = connect( conn_api = connect(
host=self.this_node.name, host=self.this_node.name,
port=self.config["metadata_postgresql_port"], port=self.config["api_postgresql_port"],
dbname=self.config["metadata_postgresql_dbname"], dbname=self.config["api_postgresql_dbname"],
user=self.config["metadata_postgresql_user"], user=self.config["api_postgresql_user"],
password=self.config["metadata_postgresql_password"], password=self.config["api_postgresql_password"],
) )
cur_metadata = conn_metadata.cursor() cur_api = conn_api.cursor()
cur_metadata.execute("""SELECT * FROM alembic_version""") cur_api.execute("""SELECT * FROM alembic_version""")
data = cur_metadata.fetchone() data = cur_api.fetchone()
except Exception as e: except Exception as e:
health_delta = 50 health_delta = 50
err = str(e).split('\n')[0] err = str(e).split('\n')[0]
message = f"Failed to connect to PostgreSQL database {self.config['metadata_postgresql_dbname']}: {err}" message = f"Failed to connect to PostgreSQL database {self.config['api_postgresql_dbname']}: {err}"
finally: finally:
if cur_metadata is not None: if cur_api is not None:
cur_metadata.close() cur_api.close()
if conn_metadata is not None: if conn_api is not None:
conn_metadata.close() conn_api.close()
if health_delta == 0: if health_delta == 0:
# Check the PowerDNS database (secondary) # Check the PowerDNS database (secondary)