Score:1

Using Zabbix to record JSON output from REST api? is it possible

us flag

I'm trying to use Zabbix (5.0) to capture the response from a REST API.

If I paste the following into a webbrowser (or wget / curl etc)

http://{username}:{password}@10.1.2.3:8443/api/metadata/

I get the response I expect:

{"items":[{"name":"this_is_my_name"}]}

I am trying to capture the value of name into zabbix.

I have set up a web scenario against my template, and in the steps section I have:

Name: test_name
URL: http://{username}:{password}@10.1.2.3:8443/api/metadata/
Raw Data
Retrieve Mode: Body
Timeout: 15s
Required String: $.items:["name"]
Required Status Code: 200

Then looking at the latest data for it I see I have a response conde of 200, but an error of:

required pattern "$.items:["name"]" was not found on http://{username}:{password}@10.1.2.3:8443/api/metadata/

I have tried all manner of variations in the Required String field, and always the same result.

Have I missed something, or misunderstood something. Does Zabbix even do what I am trying to do?

us flag
Shouldn’t items be accessed as a list?
Score:3
in flag

A web scenario can't evaluate JSON, it can only check plain text with a regular expression.

You could set Required string to this_is_my_name, but that would just check if the string occurs in the answer from the server, no matter where. Depending on the rest of your result and your use case this might work, or it might not.

If you want to get a specific field from the JSON you have to configure an item of the type HTTP agent:

enter image description here

Do NOT check Convert to JSON, it might be tempting, but it is meant to convert non-JSON answers to JSON. You already have JSON, so you don't need it.

Next, add a prepocessing step of the type JSONPath. The correct path for your example would be:

$.items[:1].name

enter image description here

The result from JSON will be ["this_is_my_name"], not just this_is_my_name, so you need the regular expression \["(.+)"\] to retrieve the plain value from the result.

You can test it directly:

enter image description here

Store your item as Text, and then you can add a trigger to it.

IGGt avatar
us flag
Perfect. It seems I had completely misunderstood, and was going in completely the wrong direction. This is exactly what I needed. cheers.
Reyan Chougle avatar
br flag
Complete answer. Thanks for your efforts. Another good article is here on official Zabbix website - https://www.zabbix.com/documentation/5.0/en/manual/config/items/itemtypes/http
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.