Update check_http_json.py

casting compared values to floats instead of strings. String comparison uses lexicographical ordering: https://docs.python.org/2/tutorial/datastructures.html#comparing-sequences-and-other-types. It could cause unexpected behaviours.
This commit is contained in:
Maciej Sawicki 2014-05-23 01:39:56 +02:00
parent a322e17c63
commit 426bd0fe4a

View File

@ -44,8 +44,8 @@ class JsonHelper:
self.data = json_data
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 str(self.get(key)) <= value
def gte(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)
def gte(self, key, value): return self.exists(key) and float(self.get(key)) >= float(value)
def exists(self, key): return (self.get(key) != (None, 'not_found'))
def get(self, key, temp_data=''):
"""Can navigate nested json keys with a dot format (Element.Key.NestedKey). Returns (None, 'not_found') if not found"""
@ -205,4 +205,4 @@ if __name__ == "__main__":
# Print Nagios specific string and exit appropriately
print nagios.getMessage()
exit(nagios.code)
exit(nagios.code)