setup-your-mac / Setup-Your-Mac

Setup Your Mac aims to simplify initial device configuration by leveraging swiftDialog and Jamf Pro Policy Custom Events to allow end-users to self-complete Mac setup post-enrollment.
https://snelson.us/sym
MIT License
244 stars 55 forks source link

Feature request: Policy retry at least 3 times. #9

Closed mani2care closed 1 year ago

mani2care commented 1 year ago

Hi Dan , it a new idea about the policy event if in case failed the policy can we do retry at least 3 times it may some time failed due to internet or some internal issues so here the example logical to retry the policy if possible it will help some how failed counts


#!/bin/bash

# Define the policy and event to run
policy="Sudo JAMF policy"
event="setup"

# Define the number of times to retry if the policy fails
retry_count=3

# Loop through the retries
for (( i=1; i<=${retry_count}; i++ ))
do
    # Run the policy
    jamf policy -event "${event}"

    # Extract the success or failure message for the last run of the policy
    log_message=$(grep -A 1 "${policy}" /var/log/jamf.log | grep -A 1 "${event}" | tail -n 1)

    # Check the JAMF log for success or failure
    if echo "${log_message}" | grep -q "Policy succeeded"; then
        echo "Policy ran successfully"
        break
    elif echo "${log_message}" | grep -q "Policy failed"; then
        echo "Policy failed (retry ${i}/${retry_count})"
    else
        echo "Unknown error occurred (retry ${i}/${retry_count})"
    fi
done
dan-snelson commented 1 year ago

@mani2care:

For me, this is a solution in search of a problem: I manage a few thousand Macs for a worldwide organization, receive alerts for each policy failure and we don't (currently) have a need to retry policies as part of SYM. (The so-called "Failure" dialog informs users which policies to re-try if something went sideways during the initial run.)

I'm going to close this FR as "not planned" and you're welcome to submit a feature-complete Pull Request.

Thanks.

masonc73 commented 1 year ago

This would be helpful for security apps that you wouldn't want to rely on the user going to SS to install

dan-snelson commented 12 months ago

Well, @mani2care, this finally happened to me today:

Tue Aug 29 10:55:46 Dan's Laptop jamf[5236]: Could not connect to the JSS. Looking for cached policies...

Tue Aug 29 10:47:34 Dan's Laptop jamf[4388]: Checking for policies triggered by "sophosEndpoint" for user "dan"...
Tue Aug 29 10:47:37 Dan's Laptop jamf[4388]: Executing Policy Sophos Endpoint: Workforce (1.0.4)
Tue Aug 29 10:50:31 Dan's Laptop jamf[4836]: Checking for policies triggered by "globalProtect" for user "dan"...
Tue Aug 29 10:50:34 Dan's Laptop jamf[4836]: Executing Policy Enrollment: Palo Alto GlobalProtect (5.2.10-6)
Tue Aug 29 10:50:36 Dan's Laptop jamf[4836]: Verifying package integrity...
Tue Aug 29 10:50:36 Dan's Laptop jamf[4836]: Installing GlobalProtect-5.2.10-6.pkg...
Tue Aug 29 10:50:42 Dan's Laptop jamf[4836]: Successfully installed GlobalProtect-5.2.10-6.pkg.
Tue Aug 29 10:50:45 Dan's Laptop jamf[5236]: Checking for policies triggered by "microsoftOffice365" for user "dan"...
Tue Aug 29 10:55:46 Dan's Laptop jamf[5236]: Could not connect to the JSS. Looking for cached policies...
Tue Aug 29 10:55:49 Dan's Laptop jamf[5337]: Checking for policies triggered by "symvMicrosoftOffice365" for user "dan"...
Tue Aug 29 10:55:54 Dan's Laptop jamf[5337]: Executing Policy Setup Your Mac Validation: Microsoft Office 365 (0.0.2)