Skip to content

Commit 5ebb1ea

Browse files
Add check for trailing / in settings conf.
1 parent 7ac796a commit 5ebb1ea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

jamf2snipe

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ if not 'user-mapping' in config and (user_args.users or user_args.users_force or
159159
logging.error("""You've chosen to check out assets to users in some capacity using a cmdline switch, but not specified how you want to
160160
search Snipe IT for the users from Jamf. Make sure you have a 'user-mapping' section in your settings.conf file.""")
161161
SETTINGS_CORRECT = False
162+
if snipe_base.endswith("/"):
163+
logging.error("""You have a trailing forward slash in the snipe url. Please remove it.""")
164+
SETTINGS_CORRECT = False
165+
if jamfpro_base.endswith("/"):
166+
logging.error("""You have a trailing forward slash in the JamfPro url. Please remove it.""")
167+
SETTINGS_CORRECT = False
168+
162169

163170
if not SETTINGS_CORRECT:
164171
raise SystemExit
@@ -845,6 +852,12 @@ for jamf_type in jamf_types:
845852
if new_snipe_asset[0] != "AssetCreated":
846853
continue
847854
if user_args.users or user_args.users_force or user_args.users_inverse:
855+
jamfsplit = config['user-mapping']['jamf_api_field'].split()
856+
if jamfsplit[1] not in jamf[jamfsplit[0]]:
857+
logging.info("Couldn't find {} for this device in {}, not checking it out.".format(jamfsplit[1], jamfsplit[0]))
858+
continue
859+
logging.info('Checking out new item {} to user {}'.format(jamf['general']['name'], jamf['{}'.format(jamfsplit[0])]['{}'.format(jamfsplit[1])]))
860+
checkout_snipe_asset(jamf['{}'.format(jamfsplit[0])]['{}'.format(jamfsplit[1])],new_snipe_asset[1].json()['payload']['id'], "NewAsset")
848861
# Log an error if there's an issue, or more than once match.
849862
elif snipe == 'MultiMatch':
850863
logging.warning("WARN: You need to resolve multiple assets with the same serial number in your inventory. If you can't find them in your inventory, you might need to purge your deleted records. You can find that in the Snipe Admin settings. Skipping serial number {} for now.".format(jamf['general']['serial_number']))

0 commit comments

Comments
 (0)