Skip to content

Instantly share code, notes, and snippets.

@shurkin18
Last active October 3, 2023 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shurkin18/2c0a1e454f5dbac8b91cfca5893e7722 to your computer and use it in GitHub Desktop.
Save shurkin18/2c0a1e454f5dbac8b91cfca5893e7722 to your computer and use it in GitHub Desktop.
Checks if Druva inSync client is Active using UAPI and returns the status which can be used as JSS Computer Extension Attribute
#!/bin/bash
##########################################################################################################################################################################
##########################################################################################################################################################################
# Please note: this script requires jq JSON parser to be installed on the mac, otherwise the script won't work
# You can install jq JSON parser using brew by running this script, which will install brew and jq automatically (non-interactive):
# https://gist.github.com/shurkin18/62ec34967794a32f9d63615db881ab5c
#
# There is also an alternative way of running jq JSON parser, without installing the whole brew suite
# You can download the jq binary here: https://techstoreon.com/files/jq-osx-amd64
# Pre-load it to each mac via the policy and store it somewhere (in /var for example) and just point your script to it
# every time jq needs to be used > jq="/usr/local/jq/jq-osx-amd64" and simply use jq as $jq
#
# NOTE: Can add a check if jq is present to the top of the script and then download/install it with a policy to ensure the script will work
# if [ ! -f "$jq" ]; then
# <<<DOWNLOAD/INSTALL WITH THE POLICY jq BINARY>>
##########################################################################################################################################################################
# This is a UAPI script which checks for Druva inSync client activation status based on the current mac name
# You need to first add Druva API credentials for this script, you can check that documentation here: https://developer.druva.com/docs/introduction
#
# It can be used on JSS as an Extension Attribute
#
# Created by Aleksandr Kamenev / shurkin18@gmail.com
##########################################################################################################################################################################
##########################################################################################################################################################################
#Druva API credentials
druvaApiURL="https://apis.druva.com"
usernameclientID="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
passwordsecretKEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
################################################################
# DO NOT TOUCH BELOW UNLESS YOU KNOW WHAT YOU ARE DOING! #######
################################################################
# created base64-encoded credentials
encodedCredentials=$( printf "$usernameclientID:$passwordsecretKEY" | /usr/bin/iconv -t ISO-8859-1 | /usr/bin/base64 -i - )
# generate an auth token
authToken=$( /usr/bin/curl -X POST -H "authorization: Basic $encodedCredentials" -d "grant_type=client_credentials&scope=read" $druvaApiURL/token )
# parse authToken for token, omit expiration
token=$( /usr/bin/awk -F \" '{ print $4 }' <<< "$authToken" | /usr/bin/xargs )
#Debugging
#echo "encodedCredentials are: $encodedCredentials"
#echo "authToken is: $authToken"
#echo "token is: $token"
#///////////////////////
#Start the UAPI scripts#
# Check if js JSON parser is present on the mac and if not - exit out of the script immediately
if [ -z $(which jq) ]; then
echo "jq JSON parser is not installed on the machine, unable to run the script, please install it using brew or any other method."
exit 1
fi
#Current machine name
currentmacname=$(hostname)
#echo $currentmacname
#Obtain the current device status based on the current machine name
insyncactivationstatus=`curl --request GET \
--url "$druvaApiURL/insync/endpoints/v1/devices" \
--header "Accept: application/json" \
--header "Authorization: Bearer $token" | jq | grep '"deviceName": "'$currentmacname'"' -A 20 | grep "deviceMarkedInactive" | awk -F '"' '{ print $3 }' | sed 's/://g' | head -n 1`
echo "inSync activation status: $insyncactivationstatus"
#Check if Druva is activated and if so provide <result> for JSS extension attribute
if [ $insyncactivationstatus == "false" ];then
echo "<result>Activated</result>"
else
echo "<result>Not Activated</result>"
fi
#End of the UAPI scripts#
#\\\\\\\\\\\\\\\\\\\\\
exit 0
@TheRossRoss
Copy link

@shurkin18 what would be the best way to reach out to you about this and some issues were facing getting this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment