nagios-http-json icon indicating copy to clipboard operation
nagios-http-json copied to clipboard

key with brackets ()

Open oca-s opened this issue 3 years ago • 3 comments

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 ")"?

oca-s avatar May 23 '22 11:05 oca-s

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 :thinking: any ideas are welcome.

martialblog avatar Sep 09 '22 15:09 martialblog

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 avatar Mar 20 '24 15:03 martialblog

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.

martialblog avatar Mar 22 '24 15:03 martialblog