API script help - how to prevent overwrite of EA value if Jamf Pro not responding

donmontalvo
Esteemed Contributor III

We are using an API script to get the Site a computer is in. That works fine. When Jamf Pro is working.

What blob of code are you using in your script that exits out if Jamf Pro is not responding.

By "not responding" we don't mean using ping, we mean Jamf Pro is not responding.

healthCheck.html value doesn't seem to do the trick, since [] shows even if API calls fail.

Basically if API call is successful, populate EA, else leave EA value alone.

--
https://donmontalvo.com
5 REPLIES 5

alexjdale
Valued Contributor III

If the API call fails, what data is returned? If it's null, that's easy, just exit out.

I think it comes down to how you are parsing the API response.

mm2270
Legendary Contributor III

In my experience, simply exiting the EA script does not do the trick. The problem is in how the jamf binary gathers data during an inventory collection. I have some older EAs that I have deprecated but not deleted from my Jamf instance, and what I get is that the value gets blanked out. In the scripts themselves, there is an exit 0 right at the top, but the previous values don't remain, because when the jamf binary uploads it's data collection, it must put something in the value for each EA. If it doesn't get anything, it uploads a blank value, and overwrites what was there before with a null value.
So, I get where this post is going and the problem.

@donmontalvo What I would suggest is rewriting your EA to capture a value and send it to a local file or plist on each run (in addition to echoing it back in the result tags), if it came back with something. Within your EA script, if the JSS isn't responding, grab the value from the file/plist instead and use that within the <result></result> tags. So that way, if it can't grab an updated string, it uses the previously gotten value stored on disk.

Hope that helps.

donmontalvo
Esteemed Contributor III

@mm2270 that makes sense. So basically...

  1. API script > /tmp/apiTempFile.txt
  2. cat /tmp/apiTempFile.txt for the three possible values X|Y|Z
  3. If value matches one of the three, then overwrite the /Library/Company/APIscripts/apiResult.txt (which is what EA reads).

Testing...

--
https://donmontalvo.com

mm2270
Legendary Contributor III

Yeah, pretty much. Sounds like you're already writing info into a local file. Maybe it can just pick up that value if it has trouble pulling something via the API.

Taking a step back a moment though, it just occurred to me, in what situation are you seeing a case where the EA script can't connect to your Jamf Pro instance, but it's still running a recon? Or do you have a separate ongoing policy calling a script to get those values? I guess what I'm asking is, if your JSS isn't available, how would EAs even be run in the first place?

donmontalvo
Esteemed Contributor III

@mm2270 sorry for the late response. This can happen if the computer is in the DMZ (we cripple API).

--
https://donmontalvo.com