mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2025-05-10 18:03:45 +02:00
Parse JSON if HTTPError is greater than 500
This commit is contained in:
parent
357c2240ba
commit
e01c44629a
@ -22,6 +22,7 @@ OK_CODE = 0
|
|||||||
WARNING_CODE = 1
|
WARNING_CODE = 1
|
||||||
CRITICAL_CODE = 2
|
CRITICAL_CODE = 2
|
||||||
UNKNOWN_CODE = 3
|
UNKNOWN_CODE = 3
|
||||||
|
value_tested = 0
|
||||||
|
|
||||||
class NagiosHelper:
|
class NagiosHelper:
|
||||||
"""Help with Nagios specific status string formatting."""
|
"""Help with Nagios specific status string formatting."""
|
||||||
@ -424,6 +425,25 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
response = urllib2.urlopen(req)
|
response = urllib2.urlopen(req)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
|
if e.code >= 500:
|
||||||
|
jsondata = e.read()
|
||||||
|
data = json.loads(jsondata)
|
||||||
|
debugPrint(args.debug, 'json:')
|
||||||
|
debugPrint(args.debug, data, True)
|
||||||
|
# Apply rules to returned JSON data
|
||||||
|
processor = JsonRuleProcessor(data, args)
|
||||||
|
nagios.append_warning(processor.checkWarning())
|
||||||
|
nagios.append_critical(processor.checkCritical())
|
||||||
|
nagios.append_metrics(processor.checkMetrics())
|
||||||
|
# If JSON test passed:
|
||||||
|
LstRules = (processor.rules.key_threshold_warning, processor.rules.key_value_list, processor.rules.key_list, processor.rules.key_threshold_critical, processor.rules.key_value_list_critical, processor.rules.key_list_critical, processor.rules.metric_list)
|
||||||
|
is_tested = 0
|
||||||
|
for i in LstRules:
|
||||||
|
if i:
|
||||||
|
is_tested = 1
|
||||||
|
if is_tested == 0:
|
||||||
|
nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
|
||||||
|
else:
|
||||||
nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
|
nagios.append_unknown("HTTPError[%s], url:%s" % (str(e.code), url))
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
nagios.append_critical("URLError[%s], url:%s" % (str(e.reason), url))
|
nagios.append_critical("URLError[%s], url:%s" % (str(e.reason), url))
|
||||||
|
Loading…
Reference in New Issue
Block a user