Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel
borderColorblack
bgColor#f8f8f8
titleTable of Contents

Table of Contents



Deploy Plugin to PostgreSQL-Server


Single instance

  1. Create a .env file for instance-settings (name should always be the same as the instance)

    Code Block
    languagebash
    themeRDark
    root@myhost:~# vi /etc/check_mk/main.env

    .

    Panel
    borderColorblack
    bgColor#F8F8F8
    titleSupply the following
    • PGDATABASE
    • PGPORT
    • PGVERSION

    e.g.,

    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/main.env
    PGDATABASE=postgres
    PGPORT=5432
    PGVERSION=15


    .

  2. Create a .pgpass file with the password of the User configured in the .env-file (PGDATABASE)

    Code Block
    languagebash
    themeRDark
    root@myhost:~# vi /etc/check_mk/main.pgpass

    .

    Panel
    borderColorblack
    bgColor#f8f8f8
    titleExample .pgpass file


    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/main.pgpass
    hostname:port:database:username:password

    .

    Tip

    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.,

    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/main.pgpass
    *:*:*:*:password


    .

    Note

    .pgpass-file should only have read/write rights for the root user: no group or others.

    .

  3. Configure the GUI

    Setup → Agents → Windows, Linux, Solaris, AIX → Agent rules → PostgreSQL database and sessions (Linux, Windows) → Add rule
    Screenshot of new rule added for PostgresSQL.
    .

    Panel
    borderColorblack
    bgColor#f8f8f8
    titleProvide the following
    • DB username
    • Path to .env file
    • Instance username
    • Path to .pgpass file

    .

  4. Click Save
    .
  5. Activate changes
    .
  6. Bake and sign agents

Multiple Instances

  1. Create a .env file for instance-settings 

    Code Block
    languagebash
    themeRDark
    root@myhost:~# vi /etc/check_mk/main.env


    Tip

    The name should always be the same as the instance.

    .

    Panel
    borderColorblack
    bgColor#f8f8f8
    titleSupply the following
    • PGDATABASE
    • PGPORT
    • PGVERSION

    e.g.,

    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/main.env
    PGDATABASE=postgres
    PGPORT=5432
    PGVERSION=15


    .

  2. Create a .env file for any additional instances

    Code Block
    languagebash
    themeRDark
    root@myhost:~# vi /etc/check_mk/secondinst.env

    .

    Panel
    borderColorblack
    bgColor#f8f8f8
    titleSupply the following
    • PGDATABASE
    • PGPORT
    • PGVERSION

    e.g.,

    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/secondinst.env
    PGDATABASE=postgres_second
    PGPORT=5433
    PGVERSION=15


    Note

    Ensure that the port numbers and names are unique for each instance.


    .

  3. Create a .pgpass file with the password of the User configured in the .env-file (PGDATABASE) for each instance

    Code Block
    languagebash
    themeRDark
    root@myhost:~# vi /etc/check_mk/main.pgpass
    
    root@myhost:~# vi /etc/check_mk/secondinst.pgpass


    Panel
    borderColorblack
    bgColor#f8f8f8
    titleExample .pgpass file


    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/main.pgpass
    hostname:port:database:username:password

    .

    Tip

    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.,

    Code Block
    languagebash
    themeRDark
    title/etc/check_mk/main.pgpass
    *:*:*:*:password

    .

    Note

    .pgpass-file should only have read/write rights for the root user: no group or others.


    .

  4. Configure the GUI

    Setup → Agents → Windows, Linux, Solaris, AIX → Agent rules → PostgreSQL database and sessions (Linux, Windows) → Add rule
    Screenshot of new rule added for PostgresSQL.
    .

    Panel
    borderColorblack
    bgColor#f8f8f8
    titleProvide the following for each instance
    • DB username
    • Path to .env file
    • Instance username
    • Path to .pgpass file

    .

  5. Click Save
    .
  6. Activate changes
    .
  7. 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):

    Code Block
    languagebash
    themeRDark
    titleLinux
    root@myhost:~# /usr/lib/check_mk_agent/plugins/mk_postgres.py -t


    Code Block
    languagebash
    themeRDark
    titleWindows
    C:\ProgramData\checkmk\agent\modules\python-3\.venv\Scripts\python.exe C:\ProgramData\checkmk\agent\plugins\mk_postgres.py -t

    .

    Info

    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

    Code Block
    languagebash
    themeRDark
    title/usr/lib/check_mk_agent/plugins/mk_postgres.py
    root@myhost:~# /usr/lib/check_mk_agent/plugins/mk_postgres.py -vv


    Code Block
    languagebash
    themeRDark
    titleWindows
    C:\ProgramData\checkmk\agent\modules\python-3\.venv\Scripts\python.exe C:\ProgramData\checkmk\agent\plugins\mk_postgres.py -vv

    .

    Panel
    borderColorblack
    bgColor#f8f8f8
    titleErrors

    Errors 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


Filter by label (Content by label)
showLabelsfalse
max5
spacesKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ( "kb-how-to-article" , "postgres" ) and type = "page" and space = "KB"
labelskb-how-to-article

...