nagios-http-json
nagios-http-json copied to clipboard
key with brackets ()
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 ")"?
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.
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.
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.