Posted on 03-20-2024 02:48 PM
Hello,
As an intro to myself and my level of Jamf/scripting - I am a 200 level tech who took the 300 and did not pass. lol
What I am trying to do is get notifications sent from Jamf connect when someone 'requests admin privileges' to be sent to a Microsoft Teams channel.
The Mac admin guru at my workplace set this up: https://snelson.us/2024/02/setup-your-mac-1-14-0-under-the-hood/ it is a way to auto setup a Mac and it also includes a Teams channel set up guide using Webhook (an app within teams) to notify us when someone has completed the "setup your Mac" portion of their first time set up.
I would like to do something similar to this but again just for when someone clicks on requesting to become an admin on Jamf connect. I have the script for setup your Mac but I think this will require an agent and obviously its own script. Is there anyone out their willing to help me out with this? I might need my hand held a lot through this process to be honest lol. Thanks in advance!
Posted on 03-20-2024 02:55 PM
to clarify when they click here - i want it go to my Teams channel as a notification kinda like this below:
Posted on 03-20-2024 04:00 PM
You would need to setup an event based trigger on the macOS client side that sends the Webhook to the teams channel. It would probably require writing a launchDaemon and a corresponding script to execute the Webhook post command with the adaptive card. SYM is a great starting point to learn how to write the webhook and adaptive card. Look here to start: https://github.com/setup-your-mac/Setup-Your-Mac/blob/084c8293115df89fd9db0343cacb45ec99b01631/Setup...
Posted on 03-22-2024 01:31 PM
so i created the webhook using an example from @hüseyinusta - but that is for when a Macbook enrolls - do you think yo can help me with an example script or point me in the direction of where or how I can manipulate a template for the times my users click on requesting to elevate to admin on jamf connect?
Posted on 03-22-2024 01:45 PM
ps this is kinda what i got now
#bin/bash!
webhookURL="${10:-""}" # Parameter 10: Microsoft Teams or Slack Webhook URL [ Leave blank to disable (default) |***I PUT MY WEBHOOKS URL HERE*** | https://hooks.slack.com/services/URL ] Can be used to send a success or failure message to Microsoft Teams or Slack via Webhook. (Function will automatically detect if Webhook URL is for Slack or Teams; can be modified to include other communication tools that support functionality.)
scriptVersion="1.13.0"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
scriptLog="${4:-"/var/log/org.churchofjesuschrist.log"}" # Parameter 4: Script Log Location [ /var/log/org.churchofjesuschrist.log ] (i.e., Your organization's default location for client-side logs)
debugMode="${5:-"verbose"}" # Parameter 5: Debug Mode [ verbose (default) | true | false ]
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)
presetConfiguration="${11:-""}" # Parameter 11: Specify a Configuration (i.e., `policyJSON`; NOTE: If set, `promptForConfiguration` will be automatically suppressed and the preselected configuration will be used instead)
swiftDialogMinimumRequiredVersion="2.3.2.4726" # This will be set and updated as dependancies on newer features change.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Webhook Message (Microsoft Teams or Slack) (thanks, @robjschroeder! and @idrewbs!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function webHookMessage() {
outputLineNumberInVerboseDebugMode
jamfProURL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)
# # Jamf Pro URL for on-prem, multi-node, clustered environments
# case ${jamfProURL} in
# *"beta"* ) jamfProURL="https://jamfpro-beta.internal.company.com/" ;;
# * ) jamfProURL="https://jamfpro-prod.internal.company.com/" ;;
# esac
jamfProComputerURL="${jamfProURL}computers.html?id=${computerID}&o=r"
# If there aren't any failures, use "None" for the value of `jamfProPolicyNameFailures`
if [[ -z "${jamfProPolicyNameFailures}" ]]; then
jamfProPolicyNameFailures="None"
fi
if [[ $webhookURL == *"slack"* ]]; then
updateScriptLog "Generating Slack Message …"
webHookdata=$(cat <<EOF
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "User Clicked Admin: '${webhookStatus}'",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Computer Name:*\n$( scutil --get ComputerName )"
},
{
"type": "mrkdwn",
"text": "*Serial:*\n${serialNumber}"
},
{
"type": "mrkdwn",
"text": "*Timestamp:*\n${timestamp}"
},
{
"type": "mrkdwn",
"text": "*Configuration:*\n${symConfiguration}"
},
{
"type": "mrkdwn",
"text": "*User:*\n${loggedInUser}"
},
{
"type": "mrkdwn",
"text": "*OS Version:*\n${osVersion}"
},
{
"type": "mrkdwn",
"text": "*Additional Comments:*\n${jamfProPolicyNameFailures}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View in Jamf Pro"
},
"style": "primary",
"url": "${jamfProComputerURL}"
}
]
}
]
}
EOF
)
# Send the message to Slack
updateScriptLog "Send the message to Slack …"
updateScriptLog "${webHookdata}"
# Submit the data to Slack
/usr/bin/curl -sSX POST -H 'Content-type: application/json' --data "${webHookdata}" $webhookURL 2>&1
webhookResult="$?"
updateScriptLog "Slack Webhook Result: ${webhookResult}"
else
updateScriptLog "Generating Microsoft Teams Message …"
# URL to an image to add to your notification
activityImage="https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.quora.com%2FIs-Chancellor-Palpatine-evil&psig=..."
webHookdata=$(cat <<EOF
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "E4002B",
"summary": "New Mac Enrollment: '${webhookStatus}'",
"sections": [{
"activityTitle": "New Mac Enrollment: ${webhookStatus}",
"activitySubtitle": "${jamfProURL}",
"activityImage": "${activityImage}",
"facts": [{
"name": "Mac Serial",
"value": "${serialNumber}"
}, {
"name": "Computer Name",
"value": "$( scutil --get ComputerName )"
}, {
"name": "Timestamp",
"value": "${timestamp}"
}, {
"name": "Configuration",
"value": "${symConfiguration}"
}, {
"name": "User",
"value": "${loggedInUser}"
}, {
"name": "Operating System Version",
"value": "${osVersion}"
}, {
"name": "Additional Comments",
"value": "${jamfProPolicyNameFailures}"
}],
"markdown": true,
"potentialAction": [{
"@type": "OpenUri",
"name": "View in Jamf Pro",
"targets": [{
"os": "default",
"uri": "${jamfProComputerURL}"
}]
}]
}]
}
EOF
)
# Send the message to Microsoft Teams
updateScriptLog "Send the message Microsoft Teams …"
updateScriptLog "${webHookdata}"
curl --request POST \
--url "${webhookURL}" \
--header 'Content-Type: application/json' \
--data "${webHookdata}"
webhookResult="$?"
updateScriptLog "Microsoft Teams Webhook Result: ${webhookResult}"
fi
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Quit Script (thanks, @bartreadon!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Posted on 03-21-2024 04:56 AM
Posted on 03-22-2024 01:25 PM
okay so i did this - now I need to learn how to do what @rqomsiya said, which is a daemon and manipulating this script to not report when a computer enrolls but instead when a user clicks on admin on jamf connect.
Posted on 03-22-2024 08:09 AM
thank you both, looking into both suggestions now.