forked from jamf/Jamf-Nation-Extension-Attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrashPlan - Backup Percent Complete.xml
113 lines (100 loc) · 4.3 KB
/
CrashPlan - Backup Percent Complete.xml
1
<?xml version="1.0" encoding="UTF-8"?><extensionAttribute> <displayName>CrashPlan - Backup Percent Complete</displayName> <displayInCategory>Backup</displayInCategory> <description>This attribute displays the backup percent complete based on the total size of selected files and the total size of files that CrashPlan has yet to back up. This attribute applies to both Mac and Windows.</description> <dataType>integer</dataType> <scriptContentsMac>#!/bin/shCP_ServerAddress="EditFromTemplate_CrashPlan_Server_Name"CP_ServerPort="4285"CP_AdminUsername="EditFromTemplate_CrashPlan_Service_Account_Username"CP_AdminPassword="EditFromTemplate_CrashPlan_Service_Account_Password"if [ "$CP_ServerAddress" == "" ] || [ "$CP_ServerPort" == "" ] || [ "$CP_AdminUsername" == "" ] || [ "$CP_AdminPassword" == "" ];thenecho "<result>Please ensure all variables are set in the extension attribute script.</result>"elseif [ -f /Library/Application\ Support/CrashPlan/.identity ];then GUID=`/bin/cat /Library/Application\ Support/CrashPlan/.identity | grep guid | sed s/guid\=//g` totalSize=`/usr/bin/curl -u "$CP_AdminUsername":"$CP_AdminPassword" -k https://"$CP_ServerAddress":"$CP_ServerPort"/rest/computerUsage?sourceGuid="$GUID" 2>&1 | grep -w selectedBytes | awk '{print $2}' | sed s/,//g` todo=`/usr/bin/curl -u "$CP_AdminUsername":"$CP_AdminPassword" -k https://"$CP_ServerAddress":"$CP_ServerPort"/rest/computerUsage?sourceGuid="$GUID" | grep -w todoBytes | awk '{print $2}' | sed s/,//g` done=`expr "$totalSize" - "$todo"` result=$( echo "scale=4; ($done / $totalSize) * 100" | bc | sed 's/\(.*\)../\1/' ) echo "<result>$result</result>"else echo "<result>Not installed</result>"fifi </scriptContentsMac> <scriptTypeWindows>VBScript</scriptTypeWindows> <scriptContentsWindows>On Error Resume Next'Declaration of Objects, Constants, VariablesDim objFSODim objTextFileDim strTextFileDim objHTTPDim arrResultsDim strResultDim inttoDoDim intTotalSizeDim GUIDDim CP_ServerAddressDim CP_ServerPortDim CP_AdminUsernameDim CP_AdminPassword'Set VariablesCP_ServerAddress = "EditFromTemplate_CrashPlan_Server_Name"CP_ServerPort = "4285"CP_AdminUsername = "EditFromTemplate_CrashPlan_Service_Account_Username"CP_AdminPassword = "EditFromTemplate_CrashPlan_Service_Account_Password"'Validate Variables Have Been SetIf CP_ServerAddress = "" Or CP_ServerPort = "" Or CP_AdminUsername = "" Or CP_AdminPassword = "" ThenWScript.Echo "<result>Please ensure all variables are set in the extension attribute script.</result>"Else'Set ObjectsSet objFSO = CreateObject("Scripting.FileSystemObject")Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")'Set ConstantsConst WinHttpRequestOption_SslErrorIgnoreFlags = 4'Read in CrashPlan GUIDSet objTextFile = objFSO.OpenTextFile("C:\ProgramData\CrashPlan\.identity")strTextFile = objTextFile.ReadAllobjTextFile.ClosearrResults=Split(strTextFile, Chr(13))For i = 0 to ubound(arrResults) If inStr(arrResults(i), "guid") > 0 Then strResult = Replace(arrResults(i), "guid=", "") GUID = strResult strResult = "" Exit for End ifNextIf GUID = "" Then WScript.Echo "<result>Not installed</result>"Else 'Connect to the CrashPlan Pro Server Rest API objHTTP.open "GET", "https://" & CP_ServerAddress & ":" & CP_ServerPort & "/rest/computerUsage?sourceGuid=" & GUID & "", False objHTTP.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300 objHTTP.SetCredentials CP_AdminUsername, CP_AdminPassword, 0 objHTTP.send 'Parse the JSON Output arrResults=Split(objHTTP.ResponseText, ",") For i = 0 to ubound(arrResults) If inStr(arrResults(i), "selectedBytes") > 0 Then intTotalSize = Replace (arrResults(i), chr(34) & "selectedBytes" & chr(34) & ": ", "") intTotalSize = CInt(Trim(intTotalSize)) Exit for End if Next For i = 0 to ubound(arrResults) If inStr(arrResults(i), "todoBytes") > 0 Then inttoDo = Replace (arrResults(i), chr(34) & "todoBytes" & chr(34) & ": ", "") inttoDo = CInt(Trim(inttoDo)) Exit for End if Nextintdone = intTotalSize - inttoDostrResult = Round(intdone / intTotalSize * 100) WScript.Echo "<result>" & strResult & "</result>"End IfEnd If </scriptContentsWindows></extensionAttribute>