grokability / jamf2snipe

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

Make script more resilient to errors? #58

Closed graffaelli closed 2 years ago

graffaelli commented 3 years ago

Hello! I was wondering if there is a way to make the script run even if it encounters and error. I have had a couple of issues with machines in Jamf updating their hardware info and when this happens, the jamf2snipe script run will fail out with a 'NoneType' error. With a debug run, I get this message:

{
    "messages": {
        "name": [
            "The name field is required."
        ]
    },
    "payload": null,
    "status": "error"
}

After message appears, the script run just fails out and stops even though it's only about 25% of the way through.

Is there a way to "skip" a problem asset?

hidalgo67 commented 2 years ago

I got an issue with personally owned devices. They don‘t get a serial number in Jamf, so they won‘t be synced into snipe-it. It‘s ok because the device should not be part of company‘s asset. But the script stops with an error on that device. It should skip and go on.

ParadoxGuitarist commented 2 years ago

Please try this again with the recent merges. If it's still not working, we'll need some of the output (sanatized please) when running Jamf2Snipe with the --debug flag to figure it out.

ParadoxGuitarist commented 2 years ago

Ok, I think I got side tracked with a bunch of stuff and missed part of this. I'm not sure If I'll be able to add it, but I can probably add a --skip-broken flag to the runtime. I'll look at it later tonight for sure.

I've also been waiting to get a test instance from Jamf, but I guess I need to pester them again. :)

ParadoxGuitarist commented 2 years ago

@robcraigfl @graffaelli or @hidalgo67

I know you three seem to have come across this bug. Jamf also pulls the SN out for DEP devices that haven't checked in yet and lists the SN field with a string Not Available but I need to know what's in these personal mobile devices. Is it null? Some other string? Can you please throw this in debug and give me the pay load (sanitized) so we can get this fixed?

ParadoxGuitarist commented 2 years ago

@robcraigfl @graffaelli or @hidalgo67 - barring a payload you can try This branch and see if it catches the bad/missing/whatever SN with a warning.

robcraigfl commented 2 years ago

Hi Brian, With debug mode we only get this output:

INFO:root:Processing entry 189 out of 205 - JAMFID: 358 - NAME: xxxx xxx INFO:root:Processing entry 190 out of 205 - JAMFID: 359 - NAME: xxxx xxxx INFO:root:Processing entry 191 out of 205 - JAMFID: 360 - NAME: xxxxx MacBook Air INFO:root:Sucessfully updated name with: xxxxxx MacBook Air INFO:root:JAMF doesn't have the same asset tag as SNIPE so we'll update it because it should be authoritative. INFO:root:Device is a computer, updating computer record INFO:root:Processing entry 192 out of 205 - JAMFID: 9 - NAME: iPhone Traceback (most recent call last): File "/home/runner/work/jamf2snipe/jamf2snipe/jamf2snipe", line 703, in snipe = search_snipe_asset(jamf['general']['serial_number']) File "/home/runner/work/jamf2snipe/jamf2snipe/jamf2snipe", line 373, in search_snipe_asset if jsonresponse['total'] == 1: KeyError: 'total' Error: Process completed with exit code 1.

As a work around we are running the script now with to get around this.

-c, --computers Runs against the Jamf computers endpoint only.

Regards,

On Tue, 8 Mar 2022 at 05:18, Brian Monroe @.***> wrote:

@robcraigfl https://github.com/robcraigfl @graffaelli https://github.com/graffaelli or @hidalgo67 https://github.com/hidalgo67

I know you three seem to have come across this bug. Jamf also pulls the SN out for DEP devices that haven't checked in yet and lists the SN field with a string Not Available but I need to know what's in these personal mobile devices. Is it null? Some other string? Can you please throw this in debug and give me the pay load (sanitized) so we can get this fixed?

— Reply to this email directly, view it on GitHub https://github.com/ParadoxGuitarist/jamf2snipe/issues/58#issuecomment-1061389705, or unsubscribe https://github.com/notifications/unsubscribe-auth/AS3Q5LPHH6DRBF7TUYWY6SLU63IJTANCNFSM4XW5W7UA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

--

FutureLearn Limited is a company incorporated in England and Wales with registered number 8324083 whose registered address is 71 Queen Victoria Street London EC4V 4BE United Kingdom.

Confidentiality: This e-mail and its attachments may contain confidential, privileged, proprietary, or otherwise private information. If they have come to you in error you must not copy, disseminate, distribute or show them to anyone; please notify the sender immediately and delete the original. Although FutureLearn has taken reasonable precautions to ensure no viruses are present in this email, it cannot accept responsibility for any loss or damage arising from the use of this email or attachments.

ParadoxGuitarist commented 2 years ago

@robcraigfl I don't think you reloaded the script from the branch I linked to. The error and traceback you posted is line 703

This is the link to the branch: https://github.com/grokability/jamf2snipe/blob/7f22c3562847bb69aea187f176e29e5502827f03/jamf2snipe#L703 and that line is blank. so it makes me think you're not trying on that fixed version of the script. Can you double check that?

ParadoxGuitarist commented 2 years ago

We patched some code that was suppose to fix this, and at this point the issue seems stale on getting verification if it's working as intended or not, so I'll just mark it closed for now. If you want to re-open it, try the latest version and mention the version number that's listed with --version :) Thanks!