sensu-plugins / sensu-plugins-postgres

This plugin provides native PostgreSQL instrumentation for monitoring and metrics collection, including: service health, database connectivity, database locks, replication status, database size, `pg_stat_bgwriter` metrics, and more.
http://sensu-plugins.io
MIT License
16 stars 43 forks source link

Multiple-line pgpass file doesn't work #54

Open pkaeding opened 6 years ago

pkaeding commented 6 years ago

If I have a .pgpass file with multiple lines, it seems only the first line is used.

I think this is due to the [0] in https://github.com/sensu-plugins/sensu-plugins-postgres/blob/1653c8b88f4fe3f7c3844352bc0ef27814403ee0/lib/sensu-plugins-postgres/pgpass.rb#L4 (but I may be wrong there).

Given the postgres docs on the pgpass file format, I expected this to work the same way.

pkaeding commented 6 years ago

Oh, I just noticed that https://github.com/sensu-plugins/sensu-plugins-postgres#pgpass-file does document this issue, so I guess it is my fault for missing that initially. I suspect that this module is not really supporting the pgpass format in general, though, as wildcards in fields other than the database (eg the host or port) would be misinterpreted?

I'm also curious why this module needs to parse the pgpass file itself-- won't the pg gem use that file if it finds it? https://stackoverflow.com/a/18282613/4257 says it will, but I have not verified that.

majormoses commented 5 years ago

@pkaeding honestly I am not too sure as I dont really use much postgres I can try to take a closer look, @phumpal do you have any insight before I try diving in? You touched this recently in #104 so figure you might have more context.

phumpal commented 5 years ago

@majormoses I don't see any mention of libpq in either the original issue (#9) or the PR (#36) which added pgpass support.

I'm also curious why this module needs to parse the pgpass file itself.

As am I however I suspect this is a shortcoming of the pg gem and not libpq or sensu-plugins-postgres intentionally.

I suspect I should review the C library.

this module is not really supporting the pgpass format

The module supports a single line pgpass file w/multiple leading comments.

wildcards in fields other than the database (eg the host or port) would be misinterpreted?

According to https://www.postgresql.org/docs/11/libpq-pgpass.html all fields except password can be wildcards.

Coming full circle I'm not 100% certain what the issue is.

I'm happy to take this on but I'm not sure how to scope the work.