pgstef / check_pgbackrest

pgBackRest backup check plugin for Nagios
PostgreSQL License
35 stars 14 forks source link

Failed to decode json when there's a WARNING for the pgbackrest #32

Closed manute closed 2 years ago

manute commented 2 years ago

Hey @pgstef ,

Thank you for creating this project! It 's very useful!

One thing I noticed is that if the pgbackrest info is throwing a WARNING before the results the decode json fails (I think is the line 540), ie:

# check_pgbackrest -c /home/appuser/conf -S an -s retention -Ojson
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "WARN: configuration ...") at /usr/bin/check_pgbackrest line 540.
# pgbackrest info --stanza=an --output=json --log-level-console=error --config=/home/appuser/conf
WARN: configuration file contains invalid option 'repo1-s3-key-role
[{"archive":[{"database":{"id":1,"repo-key":1},"rest of the json string....}]
pgstef commented 2 years ago

Hi,

That's weird. What version are you using? In the current one, --log-level-console=error is passed to pgbackrest info so warnings shouldn't be returned by pgBackRest.

Could you try adding --debug to see exactly what pgbackrest info command is used by check_pgbackrest?

manute commented 2 years ago

Yeah, the versions are :

> check_pgbackrest --version
check_pgbackrest version 2.2, Perl 5.30.0

> pgbackrest version
pgBackRest 2.38

And the issue is when the pgbackrest.conf contains an invalid option, so it seems that the WARNING appears even if the --log-level-console=error is passed:

 > check_pgbackrest -c /home/appuser/bad.conf -S an -s retention -Ojson  --debug
DEBUG: pgBackRest info command was : 'pgbackrest info --stanza=an --output=json --log-level-console=error --config=/home/appuser/bad.conf'
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "WARN: configuration ...") at /usr/bin/check_pgbackrest line 540.

Executing the actual pgbackrest info cmd from the above msg:

> pgbackrest info --stanza=an --output=json --log-level-console=error --config=/home/appuser/bad.conf
WARN: configuration file contains invalid option 'repo1-s3-key-role'
[{"archive":[{"database":{"id":1,"repo-key":1},"id":"..... rest of the json"}]

Thanks!

pgstef commented 2 years ago

That behavior comes from pgBackRest itself to make sure config file warnings will be output.

We removed the "WARN" filtering previously because of various reported issues. So I'd prefer not to bring it back.

I kinda have mixed feelings about this "issue". I believe the best answer would be: please, fix your pgBackRest configuration. In the sense that ignoring configuration errors might lead to point to inaccurate data without you knowing...

That being said, I agree the error message should be improved. Would it make sense to have this kind of output ?

DEBUG: pgBackRest info command was : 'pgbackrest info --stanza=mycluster --output=json --log-level-console=error'
pgBackRest output was not valid JSON.
HINT: does your configuration file contain invalid option?

Kind Regards

manute commented 2 years ago

Oh yeah, that would be awesome! Because the main issue is that the check_pgbackrest cmd was not showing the real error so that will fix it. Thanks!

pgstef commented 2 years ago

I just pushed an update to catch the invalid json problem and display the HINT message.

You can directly try the dev release using the main branch script.

Hope this helps, Kind Regards

pgstef commented 2 years ago

This comment change has been implemented in 2.3, which has just been released.

Don't hesitate to try it and re-open this issue if needed.

Kind Regards