Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON path depth in apps::protocols::http::mode::collection #5118

Open
acelor opened this issue Jul 27, 2024 · 1 comment
Open

JSON path depth in apps::protocols::http::mode::collection #5118

acelor opened this issue Jul 27, 2024 · 1 comment

Comments

@acelor
Copy link

acelor commented Jul 27, 2024

Quick description

HTTP collection is currently not capable traversing JSON path deeper then 2 nodes. The issue is discussed here: https://thewatch.centreon.com/data-collection-6/http-data-collection-path-depth-3639

How to reproduce

it should be reproducible on any JSON api with relatively deep paths. If you try to parse $.node1.content it will work fine, whereas $.node2.subnode.content will not. The reason is the hash handling in sub parse_structure, currently arround line 447. The code used to split the $_->{id} in key and value look like this:
if($_->{id} =~ /^(.+?)\.(.*)$/){ if (!defined($value->{$1}->{$2})) { $entry->{ $_->{id} } = ''; #...
The problem is that the first group of the regex is non-greedy. For the examples above, it will mean $value->{node1}->{content} #works and $value->{node2}->{subnode.content} #not defined, should be $value->{node2}->{subnode}->{content}.

In my post on thewatch, I suggested an additional sub to traverse arbitary depth JSON (or in Perl: hashes). I've tested it and it work for me. As I'm not this deep into Perl and Github as I should be, but feel free to adapt the code provided in my post to your coding standard and use it. Or find another clever solution

Expected result

Return the values that are actually contained in deep json

Actual result

The values of deep json are empty

@lucie-dubrunfaut
Copy link
Contributor

Hello :)

Thank you for this feedback and your contribution. I'll put this information in a dev ticket and we'll look at estimating and resolving it as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants