Skip to content

Commit 3679290

Browse files
authored
Merge pull request #102 from tanyayeu/search_snipe_asset_fix
Update search_snipe_asset to handle no asset found
2 parents e37a598 + 7e85350 commit 3679290

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

jamf2snipe

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,18 @@ def search_snipe_asset(serial):
444444
if response.status_code == 200:
445445
jsonresponse = response.json()
446446
# Check to make sure there's actually a result
447-
if jsonresponse['total'] == 1:
448-
return jsonresponse
449-
elif jsonresponse['total'] == 0:
447+
if "total" in jsonresponse:
448+
if jsonresponse['total'] == 1:
449+
return jsonresponse
450+
elif jsonresponse['total'] == 0:
451+
logging.info("No assets match {}".format(serial))
452+
return "NoMatch"
453+
else:
454+
logging.warning('FOUND {} matching assets while searching for: {}'.format(jsonresponse['total'], serial))
455+
return "MultiMatch"
456+
else:
450457
logging.info("No assets match {}".format(serial))
451458
return "NoMatch"
452-
else:
453-
logging.warning('FOUND {} matching assets while searching for: {}'.format(jsonresponse['total'], serial))
454-
return "MultiMatch"
455459
else:
456460
logging.warning('Snipe-IT responded with error code:{} when we tried to look up: {}'.format(response.text, serial))
457461
logging.debug('{} - {}'.format(response.status_code, response.content))

0 commit comments

Comments
 (0)