What is the best way to check that a login is possible to a database in PostgreSQL

We know that we can put the plugin mk_postgres.py under /usr/lib/check_mk_agent/plugins on a host so that the checkmk-agent can fetch information about the PostgreSQL service and create servicess in Checkmk automatically.

What we like to know is what’s the easiest way to check that a login is possible to a certain database in PostgreSQL?

Method 1. Setup - Services - HTTP, TCP, Email, … - Check SQL Database - Add rule
then choose: PostgreSQL, port, user, password, Query or SQL statement
according to this info from Checkmk:

Are we supposes to write a query that gives the result in the form:
state name metrics where:
state is 0, 1, 2 or 3
name is service name
metrics is optional

This seems a bit cumbersome but maybe we misunderstand something.
Also a python-module seems to be required on the host so that check_sql works.

We just want to use the GUI to make a simple login-check against a PostgreSQL database.
Then if a login is possible and you for example can run SELECT version(); the service shows OK, otherwise Critical.

Method 2. Just make a shell-script that uses psql to log in to the database and execute SELECT version(); then depending on the result of the command the script outputs:
“0 check-name - Login is possible to database dbname”
or
“3 check-name - Can’t login to database dbname”

Method 3. Suggestions?

Best Regards
Bjorn.A

You could do something like a classical active check which does these sort of connectivity tests (Check postgres) or perform a simple query against your database which will also confirm that connectivity is there and the basic select works.
Regarding the formatting of the performance data this would be a good help Unable to get performance metrics from check_sql - #3 by lravelo

Maybe robotmk to check it using the webinterface if available.

If it should be a UI based login, I think Robotmk/Robot Framework is the only way to do it.

Thanks for the answers, we will try them and see which way that fits our purpose best.

Best Regards
Björn Ahlman

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.