Closed blogh closed 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
yes but a nagos plugin shoud return a string like "UNKNOWN: click.exceptions.UsageError: Config File not found" and RC 3 in that case.
Why 3? This is ESRCH 3 No such process
. ENOENT 2 No such file or directory
seems more appropriate.
It's the norm they propose in the Nagios Plugins Development Guidelines.
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.
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
ha yes, mutch better. Th. I'll use that one instead.
This PR is for #61.
@dlax is there a better way to do this ?