From aa90ecad657799af9bc013600cfd06e81469ecc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hunor=20Kova=CC=81cs?= Date: Tue, 5 May 2015 14:32:16 +0300 Subject: [PATCH] Changed from square brackets to normal paranthesis for arrays. Nagios doesn't like square brackets. (http://sourceforge.net/p/nagios/nrpe/ci/master/tree/SECURITY illegal metachars section) Fixed case when no dot after array (e.g. checks(0) wasn't working) Extract paranthesis characters in attribute. --- check_http_json.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/check_http_json.py b/check_http_json.py index 1491e22..c156248 100755 --- a/check_http_json.py +++ b/check_http_json.py @@ -45,6 +45,8 @@ class JsonHelper: def __init__(self, json_data, separator): self.data = json_data self.separator = separator + self.arrayOpener = '(' + self.arrayCloser = ')' def getSubElement(self, key, data): separatorIndex = key.find(self.separator) @@ -56,9 +58,12 @@ class JsonHelper: return (None, 'not_found') def getSubArrayElement(self, key, data): - subElemKey = key[:key.find('[')] - index = int(key[key.find('[') + 1:key.find(']')]) - remainingKey = key[key.find('].') + 2:] + subElemKey = key[:key.find(self.arrayOpener)] + index = int(key[key.find(self.arrayOpener) + 1:key.find(self.arrayCloser)]) + remainingKey = key[key.find(self.arrayCloser + self.separator) + 2:] + if key.find(self.arrayCloser + self.separator) == -1: + remainingKey = key[key.find(self.arrayCloser) + 1:] + if subElemKey in data: if index < len(data[subElemKey]): return self.get(remainingKey, data[subElemKey][index]) @@ -81,8 +86,8 @@ class JsonHelper: if len(key) <= 0: return data - if key.find(self.separator) != -1 and key.find('[') != -1 : - if key.find(self.separator) < key.find('[') : + if key.find(self.separator) != -1 and key.find(self.arrayOpener) != -1 : + if key.find(self.separator) < key.find(self.arrayOpener) : return self.getSubElement(key, data) else: return self.getSubArrayElement(key, data) @@ -90,7 +95,7 @@ class JsonHelper: if key.find(self.separator) != -1 : return self.getSubElement(key, data) else: - if key.find('[') != -1 : + if key.find(self.arrayOpener) != -1 : return self.getSubArrayElement(key, data) else: if key in data: