grokability / jamf2snipe

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

Jamf sent a malformed timestamp #112

Closed KV-CS closed 1 year ago

KV-CS commented 1 year ago

Hi,

When I run jamf2snipe I get the following error:

ERROR:root:Jamf sent a malformed timestamp: 2023-07-11T19:10:53.822Z
 Please feel free to complain to Jamf support.
Unable to grok Jamf Timestamp - Exiting

I know it asks me to complain to Jamf, but that timestamp looks OK. If I should complain, what format should I request of them?

Thanks!

jerm commented 1 year ago

That's very strange, as we handle jamf-specific date goofiness here: https://github.com/grokability/jamf2snipe/blob/87d9a3ea8bad80fd5eac03ca2936b2756cd47a87/jamf2snipe#L213-L221

and that date/time string seems to be covered by our logic -- I can make it work locally (just running the basic functions)

What version of Python are you using? It works on 3.7->3.11 for me, but 3.6 doesn't have fromisoformat in datetime.datetime, so if you're using 3.6, that's likely the issue, and your only solution is to upgrade or use a local-install of a newer version

If you're using a modern python, read on...

I'm very interested in what the actual error is come from datetime.fromisoformat... would you mind commenting-out the surrounding try/except code and de-denting the conversions so we can see the raw error? It should look something like this when you're done:


        # So we have our token and Expires time. Set the expires time globably so we can reset later.
#        try:
        expires_time = datetime.datetime.fromisoformat(jsonresponse['expires'].replace("Z", "+00:00"))
        expires_time = datetime.datetime.fromisoformat(jsonresponse['expires'].replace("Z", "0+00:00"))
#        except:
#            # APIs are awful and Jamf doesn't always send enough ms digits. UGH.
#            try:
#                expires_time = datetime.datetime.fromisoformat(jsonresponse['expires'].replace("Z", "0+00:00"))
#            except:
#                logging.error("Jamf sent a malformed timestamp: {}\n Please feel free to complain to Jamf support.".format(jsonresponse['expires']))
#                raise SystemExit("Unable to grok Jamf Timestamp - Exiting")
        logging.debug("Token expires in: {}".format(expires_time - datetime.datetime.now(datetime.timezone.utc)))

For you to see that error, both of those conversions would have had to have failed.. in which case it should fail on the first one... but just in case that one works, we also include the second.  

Let me know. 
jerm commented 1 year ago

In the meantime, I'll update the requirements section of the README

KV-CS commented 1 year ago

Got it. I'm running 3.6.9 on an on Ubuntu 18.04.06 LTS server.... I'll upgrade python.

jerm commented 1 year ago

Sounds good. Sorry it broke for you, and that our docs were out of date, but glad it's an easy enough fix :)