Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using the check_postgres.pl plugin for Nagios. I am trying to monitor how long since the last checkpoint has been run using the check_postgres_checkpoint option. When I run the command from CLI as root I am getting the output but I am not able to get the output in the Nagios web interface. The error which it shows is,

ERROR: pg_controldata could not read the given data directory: "/opt/PostgreSQL/9.1/data"

It is trying to access the pg_control file in the 'global' directory present beneath the data directory which has only read access to the postgres user.

Can anyone please suggest me how this can be resolved ?

Thanks.

share|improve this question

4 Answers 4

The best way to do this, in my opinion, is via sudo, as Khaled suggests.

Run 'visudo' and add a line like this:

nagios ALL=NOPASSWD:/path/to/check_postgres.pl

Then, change the command def to run the plugin through sudo. Oh, and be sure to make sure 'requiretty' isn't set (also via visudo), or it will fail.

Alternatively, you could make a new group containing nagios + postgres, and make /opt/PostgreSQL/9.1/data owned by postgres:postnag (or whatever), but you'd need to make sure that all new files are also group 'postnag' (via chmod g+s, for example). This is a much more complicated solution, but doesn't involve sudo (some people seem to dislike using sudo like this...?).

share|improve this answer
    
I run several Postgres and 3Ware host/service checks this (sudo) way. –  Kendall Dec 29 '11 at 1:00
  • Run your check script as the postgres user.

or

  • Run your check script as root

or

  • Run your check as one of the above users via cron, and have it write the data somewhere check_postgres can read it

or

  • …… I'm sure you can come up with more of these kinds of options on your own :-)
share|improve this answer

This can be solved by granting sudo right for nagios user to execute this plugin without requiring a password.

share|improve this answer

Give pg_controldata seutuid privileges. It is the easiest and safier than sudo mangling:

chmod u+s /usr/lib/postgresql/9.0/bin/pg_controldata
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.