Add --base64 option to decode base64-encoded JSON responses
- Introduced the --base64 argument to the CLI.
- When specified, the plugin decodes the HTTP response body from base64 before parsing it as JSON.
- Maintains existing behavior if --base64 is not used.
Example usage with Passwork:
./check_http_json.py -vv -H passwork.intranet -p api/v1/app/health-check -X POST \
--header '{"Accept": "application/json", "Content-Type": "application/json"}' \
--data '{"token": "0123456789ABCD"}' --ssl --base64
Passwork responds with:
{
"format": "base64",
"content": "eyJzdGF0ZXMiOnsibW9uZ29kYiI6Im9rIiwidGFza3MiOiJvayJ9LCJlcnJvcnMiOltdfQ=="
}
The script decodes the 'content' field and parses the resulting JSON.
# ./check_http_json.py -vv -H passwork.intranet -p api/v1/app/health-check -X POST --header '{"Accept": "application/json", "Content-Type": "application/json"}' --data '{"token": "0123456789ABCD"}' --ssl --base64 content -Q states.mongodb,ok states.tasks,ok errors,[]
{
"states": {
"mongodb": "ok",
"tasks": "ok"
},
"errors": []
}
OK: Status OK.
- Before we only had a boolean debug flag, good for debugging errors.
The verbose flag can be used more precisely (`-v -vvv`) to specify when
something should be printed. This is useful for adding more output whilst avoiding
full debug output that contains secrets.
- I refactored the Nagios helper a bit to integrate this functionality a bit simpler.
Before we had distinct methods on the helper that added warn,crit,unko message, now
there's a general method that takes an int as parameter.
This way we avoid if-else structures for the new functionality.
The parameter --data is handled as type string, but the method urlopen() only accepts the datatype byte.
Before this fix you will get: "TypeError: POST data should be bytes, an iterable of bytes, or a filer object. It cannot be of type str."
This PR solves this.