added ability to reference array elements when the root element is an array

This commit is contained in:
drewkerrigan 2015-05-06 12:17:00 -04:00
parent 9aa7ed57aa
commit 82f4eaa48a
2 changed files with 18 additions and 1 deletions

View File

@ -97,6 +97,20 @@ optional arguments:
Access a specific JSON field by following this syntax: `alpha.beta.gamma(3).theta.omega(0)`
Dots are field separators (changeable), parantheses are for entering arrays.
If the root of the JSON data is itself an array like the following:
```
[
{ "gauges": { "jvm.buffers.direct.capacity": {"value1": 215415}}}
]
```
The beginning of the key should start with ($index) as in this example:
```
./check_http_json.py -H localhost:8081 -p metrics --key_exists "(0)_gauges_jvm.buffers.direct.capacity_value" -f _
```
More info about Nagios Range format and Units of Measure can be found at [https://nagios-plugins.org/doc/guidelines.html](https://nagios-plugins.org/doc/guidelines.html).
### Docker Info Example Plugin

View File

@ -70,7 +70,10 @@ class JsonHelper:
else:
return (None, 'not_found')
else:
return (None, 'not_found')
if not subElemKey:
return self.get(remainingKey, data[index])
else:
return (None, 'not_found')
def equals(self, key, value): return self.exists(key) and str(self.get(key)) == value
def lte(self, key, value): return self.exists(key) and float(self.get(key)) <= float(value)