Last active
May 12, 2025 08:35
-
-
Save karthikeyan-mac/9f1403de005bf3225465db46e020c340 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Karthikeyan Marappan | |
| # Slack Notification from Jamf Pro Policy | |
| # Exit immediately on error | |
| set -e | |
| # --- Input Parameters --- | |
| SLACK_WEBHOOK_URL="<SLACKWEBHOOKURL>" | |
| # Confiure Script parameters in Jamf Policy to match with variable. | |
| SLACK_TITLE_TEXT="$4" | |
| SLACK_AUTHOR_NAME="$5" | |
| SLACK_COLOR="$6" | |
| SLACK_ATTACHMENT_TEXT="${7}" | |
| # --- Optional Pretext (can be modified if needed) --- | |
| SLACK_PRETEXT_TEXT="" | |
| # --- Author Icon URL (Optional) --- | |
| SLACK_AUTHOR_ICON_URL="" | |
| # --- Replace author name with Serial Number if instructed --- | |
| if [[ "$SLACK_AUTHOR_NAME" == *"SERIALNUMBER"* ]]; then | |
| SLACK_AUTHOR_NAME="$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F'"' '/IOPlatformSerialNumber/ { print $4; exit }')" | |
| fi | |
| # Refer Attachment options in Slack Docs | |
| # ----https://api.slack.com/reference/messaging/attachments----- | |
| # --- Send Slack Notification --- | |
| payload=$(cat <<EOF | |
| { | |
| "text": "$SLACK_TITLE_TEXT", | |
| "attachments": [ | |
| { | |
| "fallback": "Notification from Jamf", | |
| "color": "$SLACK_COLOR", | |
| "pretext": "$SLACK_PRETEXT_TEXT", | |
| "author_name": "$SLACK_AUTHOR_NAME", | |
| "author_icon": "$SLACK_AUTHOR_ICON_URL", | |
| "text": "$SLACK_ATTACHMENT_TEXT" | |
| } | |
| ] | |
| } | |
| EOF | |
| ) | |
| curl -s -X POST -H 'Content-type: application/json' --data "$payload" "$SLACK_WEBHOOK_URL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment