Unable to connect to postgres database for monitoring

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
RIDS_I2MP
Posts: 751
Joined: Thu Mar 13, 2014 9:25 am

Re: Unable to connect to postgres database for monitoring

Post by RIDS_I2MP »

Hi Team,

We are able to login to the postgres database server from our nagios server, refer below command output:

"[nagios@eu1papu002 ~]$ psql -h <DB host IP> -p 5432 -d <DB Name> -U <username>
Password for user nagios:
psql (8.4.20, server 9.2.6.17)
WARNING: psql version 8.4, server version 9.2.
Some psql features might not work.
Type "help" for help.

DB Name=> \q
[nagios@eu1papu002 ~]$"

But when we try to monitor postgres database using below command on same server we receive below message:

COMMAND: /usr/local/nagios/libexec/check_postgres.pl -H <DB host IP> --port=5432 --dbuser=<username> --dbname=<DB Name> --dbpass=<passwd> --action=connection
OUTPUT: POSTGRES_CONNECTION UNKNOWN: DB "<DB Name>" (host:<DB host IP>) Invalid query returned: EnterpriseDB 9.2.6.17 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit\n | time=0.01

Kindly let us know, what changes we need to make?
Thanks & Regards,
I2MP Team.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Unable to connect to postgres database for monitoring

Post by tgriep »

Try running the command in verbose mode like the example below and see if you can get a more detailed error message.

Code: Select all

/usr/local/nagios/libexec/check_postgres.pl -H <DB host IP> --port=5432 --dbuser=<username> --dbname=<DB Name> --dbpass=<passwd> --action=connection -v -v -v
Be sure to check out our Knowledgebase for helpful articles and solutions!
RIDS_I2MP
Posts: 751
Joined: Thu Mar 13, 2014 9:25 am

Re: Unable to connect to postgres database for monitoring

Post by RIDS_I2MP »

Hi Team,

Below is the output:

Code: Select all

[nagios@eu1papu002 libexec]$ ./check_postgres.pl -H <DB Host IP> --port=5432 --dbuser=<DB user> --dbname=<DB name> --dbpass=<DB passwd> --action=connection -v -v -v
$POSTGRES1 = {
               "verbose" => 3,
               "test" => 0,
               "transform" => "",
               "dbpass" => [
                             "<DB passwd>"
                           ],
               "showperf" => 1,
               "port" => [
                           5432
                         ],
               "defaultport" => 5432,
               "dbname" => [
                             "<DB name>"
                           ],
               "host" => [
                           "<DB Host IP>"
                         ],
               "defaultuser" => "postgres",
               "dbuser" => [
                             "<DB user>"
                           ],
               "showtime" => 1,
               "timeout" => 30,
               "action" => "connection"
             };
psql=/usr/bin/psql version=8.4
Starting run_command with: SELECT version()
Created temporary pgpass file /tmp/dExO02hbHd/check_postgres.hcvy7lEz.tmp
$POSTGRES1 = [
               "-q",
               "-t",
               "-d",
               "<DB name>",
               "-U",
               "<DB user>",
               "-p",
               5432,
               "-h",
               "<DB Host IP>",
               "-o",
               "/tmp/dExO02hbHd/check_postgres_psql.4gkymg9.tmp",
               "-c",
               "BEGIN;SET statement_timeout=30000;COMMIT;SELECT version()"
             ];
$POSTGRES1 = {
               "hosts" => 1,
               "db" => [
                         {
                           "dbpass" => "<DB passwd>",
                           "dbservice" => "",
                           "port" => 5432,
                           "dbname" => "<DB name>",
                           "host" => "<DB Host IP>",
                           "ok" => 1,
                           "dbuser" => "<DB name>",
                           "totaltime" => "0.01",
                           "slurp" => " EnterpriseDB 9.2.6.17 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit\n\n",
                           "pname" => "port=5432 host=<DB Host IP> db=<DB name> user=<DB name>"
                         }
                       ],
               "command" => "SELECT version()"
             };
POSTGRES_CONNECTION UNKNOWN: DB "<DB name>" (host:<DB Host IP>) Invalid query returned:  EnterpriseDB 9.2.6.17 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit\n  | time=0.01
[nagios@eu1papu002 libexec]$
Last edited by tmcdonald on Mon Sep 12, 2016 10:02 am, edited 1 time in total.
Reason: Please use [code][/code] tags around code output
Thanks & Regards,
I2MP Team.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Unable to connect to postgres database for monitoring

Post by tgriep »

It looks like the plugin is having problems returning the version number and I found this known bug in the developers web site.
https://github.com/bucardo/check_postgres/issues/71
Try and add the fix and see if it works for you, if not, you may have to contact the developer.
Be sure to check out our Knowledgebase for helpful articles and solutions!
RIDS_I2MP
Posts: 751
Joined: Thu Mar 13, 2014 9:25 am

Re: Unable to connect to postgres database for monitoring

Post by RIDS_I2MP »

Hi Team,

Kindly can you suggest us any script which can monitor postgres database "EnterpriseDB 9.2.6.17 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2
20080704 (Red Hat 4.1.2-52), 64-bit", which we can implement in our environment.
Thanks & Regards,
I2MP Team.
RIDS_I2MP
Posts: 751
Joined: Thu Mar 13, 2014 9:25 am

Re: Unable to connect to postgres database for monitoring

Post by RIDS_I2MP »

Hi Team,

As per your below suggestion and our understanding we have replace the string "server_version" to "server_version_num", but still we are receiving "(Return code of 255 is out of bounds)" error message, kindly let us know if our understanding was wrong and if any other changes need to done in the script.
tgriep wrote:It looks like the plugin is having problems returning the version number and I found this known bug in the developers web site.
https://github.com/bucardo/check_postgres/issues/71
Try and add the fix and see if it works for you, if not, you may have to contact the developer.
Also let us know if our understanding was right and it didn't work of us, then how to contact the developer?

Kindly can you suggest us any script which can monitor postgres database "EnterpriseDB 9.2.6.17 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2
20080704 (Red Hat 4.1.2-52), 64-bit" ? which we can implement in our environment.
Thanks & Regards,
I2MP Team.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Unable to connect to postgres database for monitoring

Post by tgriep »

No, changing "server_version" to "server_version_num" is correct.
First question, did you upgrade to the latest version of the plugin?
If so, then you would have to edit line 2981 and change it from

Code: Select all

$SQL = q{SELECT setting FROM pg_settings WHERE name = 'server_version'};
to

Code: Select all

$SQL = q{SELECT setting FROM pg_settings WHERE name = 'server_version_num'};
Here is the link to download the latest script and you could use that to contact the author.
https://github.com/bucardo/check_postgr ... ostgres.pl

Another alternative plugin you could try is this one. Take a look and see if that would meet your needs.
https://exchange.nagios.org/directory/P ... ty/details
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked