Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sendWebhookMessage function #29

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions Setup-Your-Mac-via-Dialog.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# - A "raw" unsorted listing of departments — with possible duplicates — is converted to a sorted, unique, JSON-compatible `departmentList` variable (Addresses [Issue No. 23](https://github.com/dan-snelson/Setup-Your-Mac/issues/23); thanks @rougegoat!)
# - The selected Configuration now displays in `helpmessage` (Addresses [Issue No. 17](https://github.com/dan-snelson/Setup-Your-Mac/issues/17); thanks for the idea, @master-vodawagner!)
# - Disable the so-called "Failure" dialog by setting the new `failureDialog` variable to `false` (Addresses [Issue No. 25](https://github.com/dan-snelson/Setup-Your-Mac/issues/25); thanks for the idea, @DevliegereM!)
#
# - Added function to send a message to Microsoft Teams
####################################################################################################


Expand All @@ -57,6 +57,7 @@ welcomeDialog="${6:-"userInput"}"
completionActionOption="${7:-"Restart Attended"}" # Parameter 7: Completion Action [ wait | sleep (with seconds) | Shut Down | Shut Down Attended | Shut Down Confirm | Restart | Restart Attended (default) | Restart Confirm | Log Out | Log Out Attended | Log Out Confirm ]
requiredMinimumBuild="${8:-"disabled"}" # Parameter 8: Required Minimum Build [ disabled (default) | 22E ] (i.e., Your organization's required minimum build of macOS to allow users to proceed; use "22E" for macOS 13.3)
outdatedOsAction="${9:-"/System/Library/CoreServices/Software Update.app"}" # Parameter 9: Outdated OS Action [ /System/Library/CoreServices/Software Update.app (default) | jamfselfservice://content?entity=policy&id=117&action=view ] (i.e., Jamf Pro Self Service policy ID for operating system ugprades)
sendWebhookMessage="${10:-"false"}" # Parameter 10: Send Webhook Message [ true | false (default) ] Can be used to send a success or failure message to Microsoft Teams via Webhook. Function could be modified to include other communication tools that support functionality.



Expand Down Expand Up @@ -383,6 +384,56 @@ else
updateScriptLog "PRE-FLIGHT CHECK: swiftDialog version $(/usr/local/bin/dialog --version) found; proceeding..."
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Microsoft Teams Message Function
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

function webHookMessage() {

# Modify this section to match your Microsoft Teams webhook URL
webhookURL="https://company.webhook.office.com/webhookb2/645f8aec-53c4-47da-a2f1-395798f37cef@59762c14-4b58-806e-f6cc47d75b19/IncomingWebhook/df0b0dc7fd6345f7ac0a7b493da5c9fd/521df584-45be-7b73b2c17905"
# Jamf Pro URL
jamfProURL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)
# URL to an image to add to your notification
activityImage="https://creazilla-store.fra1.digitaloceanspaces.com/cliparts/78010/old-mac-computer-clipart-md.png"

data=$(cat <<EOF
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "E4002B",
"summary": "New Mac Enrollment: '${status}'",
"sections": [{
"activityTitle": "New Mac Enrollment: '${status}'",
"activitySubtitle": '${jamfProURL}',
"activityImage": '${activityImage}',
"facts": [{
"name": "Mac Serial",
"value": '${serialNumber}'
}, {
"name": "Timestamp",
"value": '${timestamp}'
}, {
"name": "User",
"value": '${loggedInUser}'
}, {
"name": "Operating System Version",
"value": '${osVersion}'
}],
"markdown": true
}]
}
EOF
)

# Send the message to Microsoft Teams
curl --request POST \
--url ${webhookURL} \
--header 'Content-Type: application/json' \
--data "${data}"
}

updateScriptLog "PRE-FLIGHT CHECK: Send Webhook Message set to ${sendWebhookMessage}"


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -1397,6 +1448,11 @@ function finalise(){

outputLineNumberInVerboseDebugMode
updateScriptLog "Failed polcies detected …"
if [[ "${sendWebhookMessage}" == "true" ]]; then
updateScriptLog "Display Failure dialog: Sending webhook message"
status="Failures detected"
webHookMessage
fi

if [[ "${failureDialog}" == "true" ]]; then

Expand All @@ -1410,6 +1466,7 @@ function finalise(){
dialogUpdateSetupYourMac "button1text: Continue …"
dialogUpdateSetupYourMac "button1: enable"
dialogUpdateSetupYourMac "progress: reset"


# Wait for user-acknowledgment due to detected failure
wait
Expand Down Expand Up @@ -1459,6 +1516,11 @@ function finalise(){

outputLineNumberInVerboseDebugMode
updateScriptLog "All polcies executed successfully"
if [[ "${sendWebhookMessage}" == "true" ]]; then
status="Successful"
updateScriptLog "Sending success webhook message"
webHookMessage
fi

dialogUpdateSetupYourMac "title: ${loggedInUserFirstname}‘s ${modelName} is ready!"
dialogUpdateSetupYourMac "icon: SF=checkmark.circle.fill,weight=bold,colour1=#00ff44,colour2=#075c1e"
Expand Down Expand Up @@ -2676,4 +2738,4 @@ done

outputLineNumberInVerboseDebugMode

finalise
finalise