Posgres plugin configuration

Hello All,

I wanted to know how you configure plugin for monitoring postgres databases.
In this plugin I should enter
DB username
path to .env file
instance username
path to .pgpass file

I tried use these env i pgpass files but without success
Could you put your “working” postgres.cfg .env and pgpass files please to check how these should looks

And mayby I should configure something else to working properly?

Hello kosiarka44,

in our case the agent plugin works out of the box as soon as it is deployed in the plugin dir of the agent on the Postgres host (thus it uses the default “postgres” user).

Did you have a look inside the plugin – esp. the function that parses the configuration file? Maybe that could help you get a clue why your config fails?
There is an example for Linux in the function’s docstring. Also, notice the different separator for Windows in the first if-statement of the function:

def parse_postgres_cfg(postgres_cfg):
    """
    Parser for Postgres config. x-Plattform compatible.

    Example for .cfg file:
    DBUSER=postgres
    INSTANCE=/home/postgres/db1.env:USER_NAME:/PATH/TO/.pgpass
    INSTANCE=/home/postgres/db2.env:USER_NAME:/PATH/TO/.pgpass
    """
    if IS_LINUX:
        conf_sep = ":"
    elif IS_WINDOWS:
        conf_sep = "|"
    else:
        raise NotImplementedError("The OS type(%s) is not yet implemented." % platform.system())
    dbuser = None
    instances = []
    for line in postgres_cfg:
        if line.startswith("#") or "=" not in line:
            continue
        line = line.strip()
        key, value = line.split("=")
        if key == "DBUSER":
            dbuser = value.rstrip()
        if key == "INSTANCE":
            env_file, pg_user, pg_passfile = value.split(conf_sep)
            env_file = env_file.strip()
            pg_database, pg_port = parse_env_file(env_file)
            instances.append({
                "name": env_file.split(os.sep)[-1].split(".")[0],
                "pg_user": pg_user.strip(),
                "pg_passfile": pg_passfile.strip(),
                "pg_database": pg_database,
                "pg_port": pg_port,
            })
    if dbuser is None:
        raise ValueError("DBUSER must be specified in postgres.cfg")
    return dbuser, instances

Thank you for this and if I understood my files should like below (my username for database is “pgsql”)

cat check_mk_posgres.env

PGDATABASE=database_name
PGPORT=5432

cat check_mk_postgres.pgpass

pgsql:pgsql_password

cat /etc/check_mk/postgres.cfg

DBUSER=pgsql
INSTANCE:/etc/check_mk/check_mk_posgres.env:pgsql:/etc/check_mk/check_mk_posgres.pgpass

Am I right or maybe wrong?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.