I am trying to extract the success/failure of a recently called Jamf policy to be used in a script for the next steps. However, I am unable to gather from the end-user system and the Jamf Dashboard if the recently called Jamf Policy was successful. I know that if the policy has a script within, the exit code ( exit code 0) would provide whether it was executed successfully. But more importantly, the policy logs provide a STATUS. This status shows "Completed" or "Failed". That is what I am trying to extract as a condition for the script to either proceed or notify the end-user of the failure.
Has anyone been able to find a way to extract the status of a recently executed policy, no matter what it contains within (a package, a script, a UNIX command, etc..)?
You'll have to do this with an API call. I'm not sure there's any other way to get policy status. The local Jamf log doesn't yield too much information other than that a policy ran and the time.
In case you do want to explore this with the API, the resource path you're looking for is called "computerhistory", so it would be something like this:
curl -H "Accept: application/xml" -su "username:password" "https://your.jamf.url/JSSResource/computerhistory/udid/<UDID>/subset/policy_logs"
You can send it through xmllint to get it formatted and maybe easier to parse, or if you know how to, use xpath to drill down to the specific policy log and status you're interested in.
Hope that helps, and post back if you need more guidance.