[ZBX-16453] Can't discover JSON from top level Created: 2019 Aug 02 Updated: 2020 Jun 08 Resolved: 2020 Jun 08 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Server (S) |
Affects Version/s: | 4.2.5 |
Fix Version/s: | None |
Type: | Problem report | Priority: | Trivial |
Reporter: | Craig Hopkins | Assignee: | Edgars Melveris |
Resolution: | Fixed | Votes: | 2 |
Labels: | json, jsonpath | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Attachments: |
![]() ![]() ![]() ![]() |
||||||||||||||||
Issue Links: |
|
Description |
Given the attached JSON, I want to be able to create a {#LIGHTID} for the top level IDs, and then {#LIGHTNAME} for *.name. When I pass LLD the link to the JSON, with pre-processing set to JSON, and the parameters set to $, I would expect it to return all the JSON, but the error I get is Preprocessing failed for: {"1":{"state":{"on":false,"bri":254,"hue":8597,"sat":121,"effect":"none","xy":[0.4452,0.4068],"ct... 1. Failed: cannot extract value from json by path "$": unsupported character in json path starting with: "" I don't know if Zabbix can descend in to the arrays during discovery to give me *.name, but at the very least it should be able to take in the entire block of JSON so that I can get the IDs using $.*~ Why is "$" not accepted by pre-processing? |
Comments |
Comment by DaneT [ 2019 Aug 06 ] |
Thank you for reporting the issue. I found a similar case registered under ZBXNEXT-968 with suggestions how to process multiline, so we will close this ticket and continue the discussion there. Feel free to follow the original case and vote for it. |
Comment by Glebs Ivanovskis [ 2019 Aug 06 ] |
Dear mbuhholcs, how can these two issues be related? |
Comment by Edgars Melveris [ 2019 Aug 06 ] |
Thanks cyclone, I guess there was a mixup of regexp and JSONSPath. |
Comment by Craig Hopkins [ 2019 Aug 06 ] |
Screenshots uploaded |
Comment by Glebs Ivanovskis [ 2019 Aug 06 ] |
Dear craigmcfly, what do you want to achieve? JSONPath "$" will extract the whole JSON, i.e. it's useless as a preprocessing step since it does not alter the value in any way. Dear zux, I guess at very least error message
should be replaced with more understandable
|
Comment by Craig Hopkins [ 2019 Aug 06 ] |
I want to create a macro that extracts the IDs, i.e. $.*~ so then I can query the API for each individual object and get all the extended information. Ideally, I'd love to be able to get the name, too, but I don't think you can extract two sets of information like that. |
Comment by Edgars Melveris [ 2019 Aug 06 ] |
Hello cyclone, the problem is, that I tried to set this up the way I understand from the report, but wasn't able to see the same error. |
Comment by Craig Hopkins [ 2019 Aug 14 ] |
This has a state of "Need Info" but I don't know what you're awaiting. Please can you elaborate? |
Comment by Edgars Melveris [ 2019 Aug 23 ] |
There where actually some changes in latest release, please take a look: Sorry for the maybe dumb question, but what do you expect the "~" symbol to do here? |
Comment by Craig Hopkins [ 2019 Aug 23 ] |
Based on the example in your documentation, $.*~ would return [ "books", "services", "filters", "closed message", "tags" ] http://jsonpath.com is a good tool for debugging JSONPath. |
Comment by Edgars Melveris [ 2019 Aug 23 ] |
I don't see the symbol "~" in our documentation, that's why I'm asking, what do you expect it to do? cannot extract value from json by path "$.*~": unsupported construct in jsonpath starting with: "~" Zabbix has it's own implementation of JSONpath, so external tools might not work exactly the same way. There are some improvements in recent versions: |
Comment by Craig Hopkins [ 2019 Aug 23 ] |
Yes, but what it should do based on the JSONPath spec is give the top level item names. I don't understand why that doesn't work. i.e. it seems to have been missed during the updates to JSONPath in 4.2 |
Comment by Craig Hopkins [ 2019 Aug 23 ] |
I suppose my question is, simply, how do I get the top level items for building discovery? |
Comment by Craig Hopkins [ 2019 Aug 23 ] |
This topic was raised in 4502:
Roberto Cremasco added a comment - 2019 Jun 04 14:11 - edited
Supporting paths like "$.*~" would allow to create any number of dependent items.
|
Comment by Fernando Chaves [ 2019 Sep 09 ] |
The official examples at https://www.zabbix.com/documentation/4.2/manual/appendix/items/jsonpath stated as "supported" does not work. For example: $.books[?(@.id == 2 || @.id == 4)].title sets the item as "not supported" with error:
Failed: cannot extract value from json by path "$.books[?(@.id == 2 || @.id == 4)].title": unsupported character in json path starting with: "[?(@.id == 2 || @.id == 4)].title" in Zabbix 4.2.6
|
Comment by Edgars Melveris [ 2019 Dec 05 ] |
Can you give more precise examples? { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } }, "expensive": 10 } JSONpath: $.store.book[?(@.price > 2 || @.price < 20)].title Result: [ "Sayings of the Century", "Sword of Honour", "Moby Dick", "The Lord of the Rings" ] |
Comment by Craig Hopkins [ 2019 Dec 06 ] |
The thread seems to have moved on to problems with json search. Please can I have a response to my question on the support for "$.*~" ? |
Comment by Edgars Melveris [ 2019 Dec 09 ] |
It seems to work on some online evaluators, not on others. And on some that it does work, the results are different. So I'm not sure how is this suppose to work. I'll consult with the development team about it. |
Comment by Andrejs Tumilovics [ 2019 Dec 19 ] |
zux |
Comment by Edgars Melveris [ 2019 Dec 20 ] |
There already is a |
Comment by Craig Hopkins [ 2019 Dec 20 ] |
Yeah, close it off. I'll watch the new task with interest |