Commit dbba295c authored by Olav Morken's avatar Olav Morken

Log error from Zabbix on API request error.

parent 8404bad2
......@@ -48,7 +48,15 @@ def invoke(method, **kwargs):
'Content-Type': 'application/json-rpc',
}
r = requests.post(url, headers=headers, json=message)
r.raise_for_status()
try:
r.raise_for_status()
except requests.RequestException as e:
print('Error fetching {url}: {exception}'.format(url=url, exception=e), file=sys.stderr)
if e.response.text:
print('HTTP response body: {response}'.format(response=e.response.text), file=sys.stderr)
else:
print('No HTTP response body.', file=sys.stderr)
sys.exit(1)
response = r.json()
if not 'result' in response:
raise Exception('Invalid response from Zabbix: {response}'.format(response=repr(response)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment