This article helps explain how to configure PostgreSQL with Checkmk via the Agent Bakery.
LAST TESTED ON CHECKMK 2.1.0P1
Deploy Plugin to PostgreSQL-Server
Single instance
Create a .env file for instance-settings (name should always be the same as the instance)
root@myhost:~# vi /etc/check_mk/main.env
.
Supply the following- PGDATABASE
- PGPORT
- PGVERSION
e.g.,
/etc/check_mk/main.envPGDATABASE=postgres PGPORT=5432 PGVERSION=15
.
Create a .pgpass file with the password of the User configured in the .env-file (PGDATABASE)
root@myhost:~# vi /etc/check_mk/main.pgpass
.
Example .pgpass file/etc/check_mk/main.pgpasshostname:port:database:username:password
.
Besides the password, you can use wildcards ("*") for every option.
The agent looks for all databases, so create a line for every database in your instance or use * instead of a database name.
e.g.,/etc/check_mk/main.pgpass*:*:*:*:password
.
.pgpass-file should only have read/write rights for the root user: no group or others.
.
Configure the GUI
Setup → Agents → Windows, Linux, Solaris, AIX → Agent rules → PostgreSQL database and sessions (Linux, Windows) → Add rule
.Provide the following- DB username
- Path to .env file
- Instance username
- Path to .pgpass file
.
- Click Save
. - Activate changes
. - Bake and sign agents
Multiple Instances
Create a .env file for instance-settings
root@myhost:~# vi /etc/check_mk/main.env
The name should always be the same as the instance.
.
Supply the following- PGDATABASE
- PGPORT
- PGVERSION
e.g.,
/etc/check_mk/main.envPGDATABASE=postgres PGPORT=5432 PGVERSION=15
.
Create a .env file for any additional instances
root@myhost:~# vi /etc/check_mk/secondinst.env
.
Supply the following- PGDATABASE
- PGPORT
- PGVERSION
e.g.,
/etc/check_mk/secondinst.envPGDATABASE=postgres_second PGPORT=5433 PGVERSION=15
Ensure that the port numbers and names are unique for each instance.
.
Create a .pgpass file with the password of the User configured in the .env-file (PGDATABASE) for each instance
root@myhost:~# vi /etc/check_mk/main.pgpass root@myhost:~# vi /etc/check_mk/secondinst.pgpass
Example .pgpass file/etc/check_mk/main.pgpasshostname:port:database:username:password
.
Besides the password, you can use wildcards ("*") for every option.
The agent looks for all databases, so create a line for every database in your instance or use * instead of a database name.
e.g.,/etc/check_mk/main.pgpass*:*:*:*:password
.
.pgpass-file should only have read/write rights for the root user: no group or others.
.
Configure the GUI
Setup → Agents → Windows, Linux, Solaris, AIX → Agent rules → PostgreSQL database and sessions (Linux, Windows) → Add rule
.Provide the following for each instance- DB username
- Path to .env file
- Instance username
- Path to .pgpass file
.
- Click Save
. - Activate changes
. - Bake and sign agents
Debugging
A simple test if the connection is up (The Script is using your settings, saved in /etc/check_mk/postgres.cfg):
Linuxroot@myhost:~# /usr/lib/check_mk_agent/plugins/mk_postgres.py -t
WindowsC:\ProgramData\checkmk\agent\modules\python-3\.venv\Scripts\python.exe C:\ProgramData\checkmk\agent\plugins\mk_postgres.py -t
.
Only the first one is tested if you have configured more than one instance.
.
Run /usr/lib/check_mk_agent/plugins/mk_postgres.py on Agent Host
/usr/lib/check_mk_agent/plugins/mk_postgres.pyroot@myhost:~# /usr/lib/check_mk_agent/plugins/mk_postgres.py -vv
WindowsC:\ProgramData\checkmk\agent\modules\python-3\.venv\Scripts\python.exe C:\ProgramData\checkmk\agent\plugins\mk_postgres.py -vv
.
ErrorsErrors are in the first lines before the output.
You will get a DEBUG-Message if paths to conf, .env, or .pgpass-file are wrong or access to files isn't possible.
psql-errors are displayed even without verbose-option. e.g.:
- connection to server on socket " failed: No such file or directory" → if the wrong port is configured or port is not accessible
- connection to server on socket " failed: FATAL: database does not exist" → if the wrong User is configured
Related articles