grokability / kandji2snipe

MIT License
27 stars 15 forks source link

TypeErrors when mapping Kandji data to custom fields #22

Closed stephenprohaska closed 1 month ago

stephenprohaska commented 2 months ago

I'm working on setting up the Kandji2Snipe integration for my org's hosted SnipeIT instance, and I'm running into issues when using the api mapping function

I have the following options set-up in my config file:

timezone = US/Central
manufacturer_id = 1
defaultStatus = 2
mac_model_category_id = 2
iphone_model_category_id = 5
ipad_model_category_id = 6
appletv_model_category_id = 7
mac_custom_fieldset_id = 2
iphone_custom_fieldset_id = 3
ipad_custom_fieldset_id = 4
appletv_custom_fieldset_id = 5

[asset-tag]
use_custom_pattern = no

[mac-api-mapping]
_snipeit_wifi_mac_address_3 = network mac_address
_snipeit_ssd_capacity_7 = volumes capacity
_snipeit_ram_11 = hardware_overview memory
_snipeit_cpu_cores_15 = hardware_overview total_number_of_cores
_snipeit_processor_name_17 = hardware_overview processor_name
_snipeit_macos_version_18 = general system_version

[iphone-api-mapping]
_snipeit_wifi_mac_address_3 = network mac_address

[ipad-api-mapping]
_snipeit_wifi_mac_address_3 = network mac_address

[appletv-api-mapping]
_snipeit_wifi_mac_address_3 = network mac_address

I'm running the script with the following arguments: ./kandji2snipe --mac --auto_incrementing --do_not_update_kandji --ratelimited

Things will go fine until it actually goes to write any of the selected values back to SnipeIT, at which time it will error out with the following info:

2024-08-01 14:19:42 - DEBUG - No asset tag found in Kandji, checking settings.conf for custom asset tag patterns.
2024-08-01 14:19:42 - DEBUG - No custom asset tag patterns found in settings.conf, using default.
2024-08-01 14:19:42 - DEBUG - Payload is being made.
2024-08-01 14:19:42 - DEBUG - network is not an integer
2024-08-01 14:19:42 - DEBUG - mac_address is not an integer
2024-08-01 14:19:42 - DEBUG - volumes is not an integer
2024-08-01 14:19:42 - DEBUG - capacity is not an integer
Traceback (most recent call last):
  File "./kandji2snipe", line 861, in <module>
    kandji_value = kandji_value[item]
                   ~~~~~~~~~~~~^^^^^^
TypeError: list indices must be integers or slices, not str

When I run the script with the --dryrun argument, it does not indicate that there are any issues. The errors only occur when it attempts to write data back to SnipeIT. Any advice or recommendations are appreciated

uberbrady commented 2 months ago

The "not an integer" errors are a bit of a red herring - it's just debugging that output because when it seems an integer there it treats it differently than when it's a string.

I suspect the volumes capacity thing might be giving you trouble here - looking at their sample output, that seems like it's returning an array of two objects, and not something you can necessarily dig into and pluck just one value out.

To start with, I'd consider removing that specific mapping - and if everything works once you do that, we can see about possibly putting it back in.

You could try volumes 0 capacity but I'm not necessarily convinced that would work - even though, like I said, we are doing some integer business in there.

stephenprohaska commented 2 months ago

That looks like it was correct! Removing that mapping resolved that error.

I did try volumes 0 capacity and was not met with much luck unfortunately

stephenprohaska commented 1 month ago

After testing again, volumes 0 capacity did appear to work! Marking this closed