return more meaningful error message if parsing of data failed

This commit is contained in:
Ricardo Bartels 2019-05-09 15:06:52 +02:00
parent 8437c464e5
commit d98d0396b2

View File

@ -741,9 +741,13 @@ if __name__ == "__main__":
nagios.append_unknown(" HTTPError[%s], url:%s" % (str(e.code), url))
except URLError as e:
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:
jsondata = response.read()
data = json.loads(jsondata)
debugPrint(args.debug, 'json:')
debugPrint(args.debug, data, True)
# Apply rules to returned JSON data
@ -752,6 +756,9 @@ if __name__ == "__main__":
nagios.append_critical(processor.checkCritical())
nagios.append_metrics(processor.checkMetrics())
nagios.append_unknown(processor.checkUnknown())
# Print Nagios specific string and exit appropriately
print(nagios.getMessage())
exit(nagios.getCode())
#EOF