Commit e9c766d7 authored by Matthew Smith's avatar Matthew Smith
Browse files

error handling for netbox

parent a2ea5e6a
......@@ -168,7 +168,6 @@ class Netbox:
else:
print("Found no device's or vm's that match")
self.ip = nb_ip
if nb_ip:
self.ip = nb_ip
self.ip_url = "{}/{}/".format(NETBOXBASE + NETBOXPATHIPS, nb_ip['id'])
......@@ -177,12 +176,19 @@ class Netbox:
headers = {'Accept': 'application/json'}
if NETBOXTOKEN:
headers.update({'Authorization': 'Token ' + NETBOXTOKEN})
response = requests.get(url, headers=headers)
try:
response = requests.get(url, headers=headers)
result = response.json()
if DEBUG:
print("Netbox response: ")
print(response)
except Exception as e:
print("Error getting netbox data from {} with error {}".format(url, e))
result = {'count': 0}
if DEBUG:
print("Netbox response: ")
print(response)
print(response.json())
return response.json()
print("Netbox result: ")
print(result)
return result
def searchNetboxData(self, url):
result = self.getNetboxData(url)
......
Supports Markdown
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