Skip to content
Snippets Groups Projects
Verified Commit 42d56c1e authored by Varac's avatar Varac
Browse files

Catch exception

parent bc9f12b9
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,9 @@ def get_alerts(url, password, port=443, user="admin"): ...@@ -27,7 +27,9 @@ def get_alerts(url, password, port=443, user="admin"):
state = "unknown" state = "unknown"
try: try:
req = requests.get(api_url, auth=(user, password), params=query) print(f"{api_url}")
# req = requests.get(api_url, auth=(user, password), params=query)
with requests.get(api_url, auth=(user, password), params=query) as req:
alerts_json = req.json() alerts_json = req.json()
for alert in alerts_json: for alert in alerts_json:
# pp = pprint.PrettyPrinter(indent=2) # pp = pprint.PrettyPrinter(indent=2)
...@@ -52,9 +54,11 @@ def get_alerts(url, password, port=443, user="admin"): ...@@ -52,9 +54,11 @@ def get_alerts(url, password, port=443, user="admin"):
state = "ok" state = "ok"
summary = f"{count} alerts" summary = f"{count} alerts"
except Exception as e: except (requests.exceptions.HTTPError,
print(f"The error is: {e}") requests.exceptions.ConnectionError,
traceback.print_exc() requests.exceptions.Timeout) as err:
print ("Exception catched: ",err)
# traceback.print_exc()
summary = "Cant connect" summary = "Cant connect"
state = "warning" state = "warning"
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment