From 426bd0fe4a6a396ab9549aaba20a423fb8052de4 Mon Sep 17 00:00:00 2001 From: Maciej Sawicki Date: Fri, 23 May 2014 01:39:56 +0200 Subject: [PATCH 1/2] 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. --- check_http_json.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check_http_json.py b/check_http_json.py index 2db2fd1..cb98427 100755 --- a/check_http_json.py +++ b/check_http_json.py @@ -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) \ No newline at end of file + exit(nagios.code) From 0241480494653c38878092869b4de61defffc6ec Mon Sep 17 00:00:00 2001 From: Maciej Sawicki Date: Fri, 23 May 2014 02:33:22 +0200 Subject: [PATCH 2/2] Update check_http_json.py --- check_http_json.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/check_http_json.py b/check_http_json.py index cb98427..7bc4daf 100755 --- a/check_http_json.py +++ b/check_http_json.py @@ -11,6 +11,8 @@ import httplib, urllib, urllib2 import json import argparse from pprint import pprint +from urllib2 import HTTPError +from urllib2 import URLError class NagiosHelper: