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

key with brackets () #76

Open
oca-s opened this issue May 23, 2022 · 3 comments
Open

key with brackets () #76

oca-s opened this issue May 23, 2022 · 3 comments
Labels

Comments

@oca-s
Copy link

oca-s commented May 23, 2022

We have a status, which contains a key like
"last data received (minutes)", i.e. the key string contains round brackets.

If i try to address this key, the array-selection mechanism kicks in. Can i somehow quote "(" and ")"?

@martialblog
Copy link
Collaborator

Yeah I think that's might not be possible at the moment.

curl -q http://localhost:8000/bracket.json                                          
[
  {
  "foobar": 123
  },
  {
  "foo bar (foobar)": 123
  }
]
 ./check_http_json.py -H localhost:8000 -p bracket.json -q "(0).foobar,123"            
OK: Status OK.

./check_http_json.py -H localhost:8000 -p bracket.json -q "(1).foo bar (foobar),123"
Traceback (most recent call last):
....
  File "nagios-http-json/./check_http_json.py", line 111, in getSubArrayElement
    index = int(key[key.find(self.arrayOpener) +
ValueError: invalid literal for int() with base 10: 'foobar'

Like you said it's the array detection, not sure if and how to fix that yet 🤔 any ideas are welcome.

@martialblog martialblog added the bug label Sep 9, 2022
@martialblog
Copy link
Collaborator

I might have something for this: https://github.com/drewkerrigan/nagios-http-json/tree/fix/array-in-key

Not 100% sure yet but the tests seem OK.

@martialblog
Copy link
Collaborator

Tested it a bit more, but I wouldn't call it a real solution just a workaround. Unittests are green but I don't wanna merge it yet.
If anyone needs this: Test the provided code and let me know.

Switching to jsonpath would really be the longterm way to fix issues like these.

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

No branches or pull requests

2 participants