Skip to main content
Question

Druva inSync Current mac Active / Inactive status via Druva UAPI Computer Extension Attribute Script


akamenev47
Forum|alt.badge.img+10

This is something I have been wishing for a while and decided to put it together myself. It is ready to be used as a JSS Computer Extension Attribute if you want to automate Druva inSync re-install/re-activate via Smart Group or simply obtain a list of computers on which Druva inSync is currently Inactive.

 

Please note: the script is using jq JSON parser, which can be installed on each mac using only a script as I posted here: https://community.jamf.com/t5/jamf-pro/homebrew-and-js-deloyment-using-only-scripts/td-p/247472 

 

You can get the script here on my gist: https://gist.github.com/shurkin18/2c0a1e454f5dbac8b91cfca5893e7722 

Or from below:

 

 

 

 

 

 

#!/bin/bash ########################################################################################################################################################################## ########################################################################################################################################################################## # 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 # # Please note: this script requires jq JSON parser to be installed on the mac, otherwise the script won't work # If you are using JAMF JSS, you can read how jq can be pushed via homebrew using only scripts: # https://community.jamf.com/t5/jamf-pro/homebrew-and-js-deloyment-using-only-scripts/td-p/247472 # # 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# #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

 

 

 

 

 

 

 

2 replies

markopolo
Forum|alt.badge.img+8
  • Contributor
  • 57 replies
  • November 14, 2022

Thanks for sharing this script! I'm getting this on output, any idea what I'm doing wrong?

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 176 100 136 100 40 218 64 --:--:-- --:--:-- --:--:-- 285 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 1 1161k 1 18582 0 0 5749 0 0:03:26 0:00:03 0:03:23 5761 curl: (23) Failure writing output to destination inSync activation status: /Users/testuser/Downloads/EA_Test.sh: line 57: [: ==: unary operator expected <result>Not Activated</result>

akamenev47
Forum|alt.badge.img+10
  • Author
  • Valued Contributor
  • 80 replies
  • November 14, 2022
markopolo wrote:

Thanks for sharing this script! I'm getting this on output, any idea what I'm doing wrong?

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 176 100 136 100 40 218 64 --:--:-- --:--:-- --:--:-- 285 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 1 1161k 1 18582 0 0 5749 0 0:03:26 0:00:03 0:03:23 5761 curl: (23) Failure writing output to destination inSync activation status: /Users/testuser/Downloads/EA_Test.sh: line 57: [: ==: unary operator expected <result>Not Activated</result>

Hmm, 

curl: (23) Failure writing output to destination

This is pretty generic, often I saw this simply due to minor mistakes in code, like miss-types and such, make sure your DRUVA API URL is correct and you are able to run a simple GET API call with it on the Druva API end.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings