NAME
Monitoring::Sneck::Checks::http_json - checks values in a JSON response
VERSION
Version 0.0.1
SYNOPSIS
api_health|perl:http_json -u https://api.example.org/health -J status=ok -J checks.db.status=ok
queue|perl:http_json -H 192.0.2.30 -p 8080 -u /stats -V queue.depth -W 100 -C 500
first_node|perl:http_json -u https://cluster.example.org/nodes -J nodes.0.healthy=true
DESCRIPTION
Fetches a URL the same as Monitoring::Sneck::Checks::http, taking all of its options, then checks values in the JSON it gets back. Content that is not JSON, or a value that is not there or not what it should be, is CRITICAL.
Paths are keys split by dots, with numbers indexing arrays, so nodes.0.name is the name of the first node. -1 is the last. Keys with dots in them can not be reached.
true, false, and null are compared as those words.
OPTIONS
These are on top of the options of Monitoring::Sneck::Checks::http.
- -J, --json :: "path=value", a value that must be there, or "path", something that must be there. May be given more than once.
- -V, --value :: The path to a number to check with --value-warning and --value-critical, and add to the perfdata.
- -W, --value-warning :: Range for --value.
- -C, --value-critical :: Range for --value.
One of --json or --value must be given. --value-warning and --value-critical need --value.
METHODS
content_problems
Checks the content as http does, then as --json and --value say.
json_path
Finds a path in decoded JSON, as said under "DESCRIPTION".
- data :: The decoded JSON.
- path :: The path, such as nodes.0.name.
Returns 1 and the value if it is there, else 0.
my ( $there, $value ) = $check->json_path( { nodes => [ { name => 'a' } ] }, 'nodes.0.name' );
# ( 1, 'a' )