Check For JSON Response

Hello everybody,

does anyone happen to know a plugin to check a JSON response?

I have already tested several, but all fail because of the 404 message when calling the Url.

To be tested is a Url: https://test.de/api/daten/load/1234

The Response of the Url is:

Whitelabel Error Page
This application has no explicit mapping for / error, so you are seeing this as a fallback.

Wed Jun 19 14:10:43 CEST 2019
There is an unexpected error (type = Not Found, status = 404).
{“error”: {“status”: 404, “title”: “NOT_FOUND_EXCEPTION”, “description”: “Code does not exists.”, “type”: “NOT_FOUND_EXCEPTION”, “metadata”: {“ID”: " 1234 “,” RESOURCE “:” CodeEntity "}}}

The “description” section: “Code does not exists.” must be present, then the service is running. If anything else is here, the check should go to Critical.

Python 2.7 is available

Thanks to all

Are you handy with Python at all? The requests module for it is super handy for writing quick checks like these, and raising a 404 isn’t going to raise an exception unless you tell it to. It can pull json objects into dictionaries to parse through.

https://2.python-requests.org/en/master/

2 Likes

+1 for Python requests!

It will be much nicer to implement your own plugin with that, than to go with something pre-made. Even for a python beginner, this module makes it super easy to write a nice check script.

Cheers,
George

1 Like

If have build some Shell Script like this:

curl -s --insecure https://test.de/api/daten/load/1234 | grep “Code does not exists.”

if it’s true, then the Check is OK - When the Query is empty, the Check is Critical

This Script is not so fine for Icinga 2.

Take a look at jq and jo, both are awesome CLI tools for handling JSON.

1 Like