Skip to content

Commit

Permalink
added ability to reference array elements when the root element is an…
Browse files Browse the repository at this point in the history
… array
  • Loading branch information
drewkerrigan committed May 6, 2015
1 parent 9aa7ed5 commit 82f4eaa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion check_http_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def getSubArrayElement(self, key, data):
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)
Expand Down

0 comments on commit 82f4eaa

Please sign in to comment.