Skip to content

Commit 0434962

Browse files
authored
Merge pull request #97 from bondurantdt/fixAssetCreation
Fix asset creation
2 parents 8da3c99 + b22a9f0 commit 0434962

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

jamf2snipe

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,16 @@ for jamf_type in jamf_types:
790790
try:
791791
jamf_asset_tag = jamf['{}'.format(tag_split[0])]['{}'.format(tag_split[1])]
792792
except:
793-
raise SystemError('No such attribute {} in the jamf payload. Please check your settings.conf file'.format(tag_split))
793+
if jamf_type == 'mobile_devices':
794+
jamf_asset_tag = 'jamfid-m-{}'.format(jamf['general']['id'])
795+
elif jamf_type == 'computers':
796+
jamf_asset_tag = 'jamfid-{}'.format(jamf['general']['id'])
797+
else:
798+
logging.error("Could not generate an asset tag for this device. Skipping")
799+
# Dump the object for debugging.
800+
logging.verbose(jamf)
801+
continue
802+
#raise SystemError('No such attribute {} in the jamf payload. Please check your settings.conf file'.format(tag_split))
794803
if jamf_asset_tag == None or jamf_asset_tag == '':
795804
logging.debug('No custom configuration found in settings.conf for asset tag name upon asset creation.')
796805
if jamf_type == 'mobile_devices':
@@ -804,9 +813,12 @@ for jamf_type in jamf_types:
804813
if jamf_type == 'mobile_devices':
805814
logging.debug("Payload is being made for a mobile device")
806815
newasset = {'asset_tag': jamf_asset_tag, 'model_id': modelnumbers['{}'.format(jamf['general']['model_identifier'])], 'name': jamf['general']['name'], 'status_id': defaultStatus,'serial': jamf['general']['serial_number']}
816+
logging.debug(newasset)
817+
new_snipe_asset = create_snipe_asset(newasset)
807818
elif jamf_type == 'computers':
808819
logging.debug("Payload is being made for a computer")
809820
newasset = {'asset_tag': jamf_asset_tag,'model_id': modelnumbers['{}'.format(jamf['hardware']['model_identifier'])], 'name': jamf['general']['name'], 'status_id': defaultStatus,'serial': jamf['general']['serial_number']}
821+
new_snipe_asset = create_snipe_asset(newasset)
810822
else:
811823
for snipekey in config['{}-api-mapping'.format(jamf_type)]:
812824
jamfsplit = config['{}-api-mapping'.format(jamf_type)][snipekey].split()
@@ -829,12 +841,13 @@ for jamf_type in jamf_types:
829841
except KeyError:
830842
continue
831843
# Reset the payload without the asset_tag if auto_incrementing flag is set.
832-
if user_args.auto_incrementing:
833-
newasset.pop('asset_tag', None)
844+
if user_args.auto_incrementing:
845+
newasset.pop('asset_tag', None)
834846
new_snipe_asset = create_snipe_asset(newasset)
847+
logging.debug(new_snipe_asset)
835848
if new_snipe_asset[0] != "AssetCreated":
836849
continue
837-
if user_args.users or user_args.users_force or user_args.users_inverse:
850+
if user_args.users or user_args.users_force or user_args.users_inverse:
838851
jamfsplit = config['user-mapping']['jamf_api_field'].split()
839852
if jamfsplit[1] not in jamf[jamfsplit[0]]:
840853
logging.info("Couldn't find {} for this device in {}, not checking it out.".format(jamfsplit[1], jamfsplit[0]))
@@ -935,4 +948,4 @@ for jamf_type in jamf_types:
935948
update_jamf_mobiledevice_asset_tag("{}".format(jamf['general']['id']), '{}'.format(snipe['rows'][0]['asset_tag']))
936949
logging.info("Device is a mobile device, updating the mobile device record")
937950

938-
logging.debug('Total amount of API calls made: {}'.format(api_count))
951+
logging.debug('Total amount of API calls made: {}'.format(api_count))

0 commit comments

Comments
 (0)