grokability / jamf2snipe

Import and sync assets from a JAMFPro instance to Snipe-IT asset management.
MIT License
108 stars 55 forks source link

Not updating assets #27

Closed jarrodCoombes closed 4 years ago

jarrodCoombes commented 4 years ago

I am running:

jamf2snipe -c

Initial run works perfectly, created all the records with the right category, manufacturer, fieldsets etc.

Subsequent runs do not update the records with the info specified in the settings.conf file. There are no errors given. The account that was used to create the API token has been confirmed as able to edit any of the assets.

Debug output of from one item from Jamf: INFO:root:Processing entry 14 out of 14 - JAMFID: 34 - NAME: <ComputerName> DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): <JSS URL> DEBUG:urllib3.connectionpool:https://<JSS UR>:8443 "GET /JSSResource/computers/id/34 HTTP/1.1" 200 26860 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: <snip - All JAMF info, looks correct> DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): <SNIPE-IT URL> DEBUG:urllib3.connectionpool:https://<SNIPE-IT URL>:443 "GET /api/v1/hardware/byserial/<Mac Serial Number> HTTP/1.1" 200 1469

Computer settings in the settings.conf file:

[computers-api-mapping] name = general name _snipeit_mac_address_1 = general mac_address _snipeit_os_version_6 = hardware os_version _snipeit_cpu_8 = hardware processor_type _snipeit_ram_9 = hardware total_ram

Checked and double checked, the custom field IDs are correct as well as the JSS side of things is also correct.

Running it on an Ubuntu 18.04 server (the snipe-it server) with Python 3.6

ParadoxGuitarist commented 4 years ago

I think most of this section should be passing messages in debug mode.

You should see either: "DEBUG:The payload for the snipe update is:" or "DEBUG:Skipping the payload, because it already exits." or "DEBUG:Skipping the payload, because it already exists, or the Snipe key we're mapping to doesn't." or "DEBUG: Found the field, and the value needs to be updated from {} to {}"

I don't see any of these in the log snipits you posted. Can you try searching for them and paste the relevent bits when you run it with jamf2snipe -d ?

jarrodCoombes commented 4 years ago

None of that shows up at all for the asset records. I was actively looking for some indication of it attempting to update in Snipe. What I pasted is a complete start to finish for each identified asset, all 14 of them have the exact same lines.

That said, I will give it another go and report back.

jarrodCoombes commented 4 years ago

Bizarrely I just ran it, and it actually did pull and sync the data, but only for 2 out of the 14 macbooks I am working with.

jarrodCoombes commented 4 years ago

The word "payload" does not appear in the debug output at all.

Here is the complete output, sanitised. There are now 15 computers as we enrolled another this morning. The new one was created in Snipe, but like the others, none of the fields are being updated.

$ ./jamf2snipe -c -d

INFO:root:Searching for a valid settings.conf file. DEBUG:root:Checking for a settings.conf in /opt/jamf2snipe ... INFO:root:Great, we found a settings file. Let's get started by parsing all fo the settings. INFO:root:The configured JAMFPro base url is: https://:8443 INFO:root:The configured JAMFPro username we'll be connecting with is: DEBUG:root:The configured password to access the API is: INFO:root:The configured Snipe-IT base url is: https:// DEBUG:root:The API key you provided for Snipe is: INFO:root:The default status we'll be setting updated computer to is: 2 (I sure hope this is a number or something is probably wrong) INFO:root:The configured JAMFPro base url is: 3 (Pretty sure this needs to be a number too) INFO:root:Creating the headers we'll need for API calls DEBUG:root:Request headers for JamfPro will be: {'Accept': 'application/json'} Request headers for Snipe will be: {'Authorization': 'Bearer ', 'Accept': 'application/json', 'Content-Type': 'application/json'} DEBUG:root:Checking the settings.conf file for valid JAMF subsets of the JAMF API so mapping can occur properly. INFO:root:Found subset general: Acceptable INFO:root:Found subset general: Acceptable INFO:root:Found subset hardware: Acceptable INFO:root:Found subset hardware: Acceptable INFO:root:Found subset hardware: Acceptable INFO:root:SSL Verification is set to: True INFO:root:Running tests to see if hosts are up. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET / HTTP/1.1" 302 366 DEBUG:urllib3.connectionpool:https://:443 "GET /login HTTP/1.1" 200 1335 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET / HTTP/1.1" 401 None INFO:root:We were able to get a good response from your Snipe-IT instance. INFO:root:We were able to get a good response from your JAMFPro instance. INFO:root:Finished running our tests. INFO:root:Getting a list of computer models that snipe knows about. DEBUG:root:Calling against: https:///api/v1/models DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/models HTTP/1.1" 200 None DEBUG:root:Got a valid response that should have 14 models. DEBUG:root:Parsing the 14 model results for models with model numbers. DEBUG:root:The model, AP230, did not have a model number. Skipping. DEBUG:root:The model, AP350, did not have a model number. Skipping. INFO:root:Our list of models has 12 entries. DEBUG:root:Here's the list of the 12 models and their id's that we were able to collect: {'CN65': 213, 'XE500C12': 212, 'C423': 211, 'C202SA': 209, 'C740': 210, 'C204': 208, 'MacBookPro15,2': 207, 'MacBookAir8,2': 206, 'MacBookPro16,1': 205, 'MacBookAir8,1': 204, 'WS-C2960X-24PD-L': 203, 'WS-C2960X-48FPD-L': 202} DEBUG:root:Calling for JAMF computers against: https://:8443/JSSResource/computers The username, passwords, and headers for this GET requestcan be found near the beginning of the output. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers HTTP/1.1" 200 491 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Calling for JAMF mobiles against: https://:8443/JSSResource/mobiledevices The username, passwords, and headers for this GET requestcan be found near the beginning of the output. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/mobiledevices HTTP/1.1" 200 1110720 DEBUG:root:Got back a valid 200 response code. INFO:root:Received a list of JAMF assets that had 15 entries.

INFO:root:Starting to Update Inventory

INFO:root:Processing entry 1 out of 15 - JAMFID: 6 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/6 HTTP/1.1" 200 27472 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1670

INFO:root:Processing entry 2 out of 15 - JAMFID: 15 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/15 HTTP/1.1" 200 28769 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1519

INFO:root:Processing entry 3 out of 15 - JAMFID: 16 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/16 HTTP/1.1" 200 32471 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1661

INFO:root:Processing entry 4 out of 15 - JAMFID: 17 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/17 HTTP/1.1" 200 28916 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 5 out of 15 - JAMFID: 21 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/21 HTTP/1.1" 200 26389 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 6 out of 15 - JAMFID: 23 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/23 HTTP/1.1" 200 24113 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 7 out of 15 - JAMFID: 26 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/26 HTTP/1.1" 200 28265 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 8 out of 15 - JAMFID: 27 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/27 HTTP/1.1" 200 31543 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 9 out of 15 - JAMFID: 28 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/28 HTTP/1.1" 200 29049 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 10 out of 15 - JAMFID: 30 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/30 HTTP/1.1" 200 24642 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 11 out of 15 - JAMFID: 31 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/31 HTTP/1.1" 200 25326 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 12 out of 15 - JAMFID: 32 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/32 HTTP/1.1" 200 27579 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1477

INFO:root:Processing entry 13 out of 15 - JAMFID: 33 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/33 HTTP/1.1" 200 22152 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

INFO:root:Processing entry 14 out of 15 - JAMFID: 34 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/34 HTTP/1.1" 200 26860 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1668

INFO:root:Processing entry 15 out of 15 - JAMFID: 35 - NAME: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:8443 "GET /JSSResource/computers/id/35 HTTP/1.1" 200 26567 DEBUG:root:Got back a valid 200 response code. DEBUG:root:Returning: DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): DEBUG:urllib3.connectionpool:https://:443 "GET /api/v1/hardware/byserial/ HTTP/1.1" 200 1476

$ _

ParadoxGuitarist commented 4 years ago

From this line you should have also had some addtional text in your output that I'm not seeing here either. Does that line exist in your local copy?

jarrodCoombes commented 4 years ago

Yes, it is in there, same line number and everything. I downloaded the script by just curling: https://raw.githubusercontent.com/ParadoxGuitarist/jamf2snipe/34b740d1178d855111b1f88fa814407f7e04ad9d/jamf2snipe

So i am 99.9999% sure I have the right script and version.

I also just checked, the Jamf server and Snipe server both have the same local time, not sure if that is relevant, but since that line deals with time stamps I figured it was worth checking.

jarrodCoombes commented 4 years ago

Hang on a second. Reading this code, that section compares the update time in Jamf to the update time in Snipe, and if you have a device that has not checked in for some time with Jamf, then that date will almost certainly be older than the update date in Snipe if you are adding the asset way after it was deployed.

So I ran the script for the first time on say April 20th, but the last time the computer checked in and update was say April 10th, then it will always fail that check, since April 10 is older than April 20th.

Have I got that right?

This could explain why I now have three random devices that have those fields imported.

jarrodCoombes commented 4 years ago

Got it. If I force an inventory update on the computer, it changes the last inventory date in the JSS, which is then newer than the modified date in Snipe, and therefore it pulls and syncs the data.

I would suggest a few things around this, and I will submit them as feature requests:

  1. If the referenced field in the settings.conf field is empty in the Snipe, then it should pull that from the JSS regardless of the date codes.
  2. There should be an info message if/when that check returns false. Something like INFO:root:Jamf check in date is older than Snipe modification date so there is nothing to sync, force an inventory update to rectify if this is incorrect or something like that.