checkmk icon indicating copy to clipboard operation
checkmk copied to clipboard

add PGHOST variable to env files so mk_postgres can use type local co…

Open robertdahlem opened this issue 10 months ago • 5 comments

General information

This adds an optional PGHOST variable to the .env file of mk_postgres.py

It answers my own question at the Checkmk forum.

This is useful when connecting to databases that only LISTEN on a socket and not on a TCP port. Set PGHOST to a directory where the socket .s.PGSQL.$PGPORT is located and you can use connections that are configured in pg_hba.conf as type local.

In theory you could also set PGHOST to the name of a remote host where a database resides. This might be useful in cases where you are not allowed to install a Checkmk agent on a database machine.

here is an example for monitoring a GitLab PostgreSQL instance:

postgres.sql:

DBUSER=gitlab-psql
PG_BINARY_PATH=/opt/gitlab/embedded/postgresql/14/bin/psql
INSTANCE=/etc/check_mk/gitlabhq_production.env:gitlab-psql::

gitlabhq_production.env:

PGDATABASE=gitlabhq_production
PGPORT=5432
PGHOST=/var/opt/gitlab/postgresql

Also I deleted the mentioning of export in the description of .env files. It created the false appearance that you could export environment variables to mk_postgres.py.

robertdahlem avatar Feb 17 '25 17:02 robertdahlem

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Feb 17 '25 17:02 github-actions[bot]

I have read the CLA Document and I hereby sign the CLA or my organization already has a signed CLA.

robertdahlem avatar Feb 17 '25 17:02 robertdahlem

@mo-ki I see failing tests here. Do I need to change/add something?

robertdahlem avatar Feb 19 '25 14:02 robertdahlem

For transparency: I so far only identified the colleague responsible for this area; I made no further assessment of this PR.

What I can say: You changed the function to return a 4-tuple instead of a 3-tuple, which means you will have to adjust the type hint in line 1218. I think it should be # type: (str) -> tuple[str, str, str | None, str] now.

mo-ki avatar Feb 20 '25 07:02 mo-ki

What I can say: You changed the function to return a 4-tuple instead of a 3-tuple, which means you will have to adjust the type hint in line 1218. I think it should be # type: (str) -> tuple[str, str, str | None, str] now.

Done.

robertdahlem avatar Feb 20 '25 17:02 robertdahlem