dalibo / check_patroni

A nagios plugin for patroni.
PostgreSQL License
7 stars 3 forks source link

Handle inexistant config file #64

Closed blogh closed 11 months ago

blogh commented 11 months ago

This PR is for #61.

@dlax is there a better way to do this ?

dlax commented 11 months ago

Did you try using a click.File() argument type? According to its documentation, click will try to open the file early enough to report I/O errors to the user:

$ check_patroni --config no-such-file
Usage: check_patroni [OPTIONS] COMMAND [ARGS]...
Try 'check_patroni --help' for help.

Error: Invalid value for '--config': 'no-such-file': No such file or directory
blogh commented 11 months ago

yes but a nagos plugin shoud return a string like "UNKNOWN: click.exceptions.UsageError: Config File not found" and RC 3 in that case.

dlax commented 11 months ago

Why 3? This is ESRCH 3 No such process. ENOENT 2 No such file or directory seems more appropriate.

blogh commented 11 months ago

It's the norm they propose in the Nagios Plugins Development Guidelines.

https://nagios-plugins.org/doc/guidelines.html#AEN78

dlax commented 11 months ago

I have pushed a better implementation, in branch "fix_configfile_error" on the main repo: https://github.com/dalibo/check_patroni/compare/fix_configfile_error (based on your commit).

The idea is to only handle IO errors in the configure() callback, and then possibly exit (with rc 3) from there.

dlax commented 11 months ago

WIth the version posted above:

$ check_patroni --config no-such-file
failed to read configuration: [Errno 2] No such file or directory: 'no-such-file'
$ echo $?
3
$ check_patroni --config /etc/postgresql/16/main/pg_hba.conf 
failed to read configuration: [Errno 13] Permission denied: '/etc/postgresql/16/main/pg_hba.conf'
$ echo $?
3
blogh commented 11 months ago

ha yes, mutch better. Th. I'll use that one instead.