mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 18:33:49 +01:00
return more meaningful error message if parsing of data failed
This commit is contained in:
parent
8437c464e5
commit
d98d0396b2
@ -741,9 +741,13 @@ if __name__ == "__main__":
|
|||||||
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))
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = json.loads(response.read())
|
||||||
|
except ValueError as e:
|
||||||
|
nagios.append_unknown(" Parser error: %s" % str(e))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
jsondata = response.read()
|
|
||||||
data = json.loads(jsondata)
|
|
||||||
debugPrint(args.debug, 'json:')
|
debugPrint(args.debug, 'json:')
|
||||||
debugPrint(args.debug, data, True)
|
debugPrint(args.debug, data, True)
|
||||||
# Apply rules to returned JSON data
|
# Apply rules to returned JSON data
|
||||||
@ -752,6 +756,9 @@ if __name__ == "__main__":
|
|||||||
nagios.append_critical(processor.checkCritical())
|
nagios.append_critical(processor.checkCritical())
|
||||||
nagios.append_metrics(processor.checkMetrics())
|
nagios.append_metrics(processor.checkMetrics())
|
||||||
nagios.append_unknown(processor.checkUnknown())
|
nagios.append_unknown(processor.checkUnknown())
|
||||||
|
|
||||||
# Print Nagios specific string and exit appropriately
|
# Print Nagios specific string and exit appropriately
|
||||||
print(nagios.getMessage())
|
print(nagios.getMessage())
|
||||||
exit(nagios.getCode())
|
exit(nagios.getCode())
|
||||||
|
|
||||||
|
#EOF
|
||||||
|
Loading…
Reference in New Issue
Block a user