forked from jamf/Jamf-Nation-Extension-Attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrashPlan - Selected Files Size.xml
130 lines (115 loc) · 4.35 KB
/
CrashPlan - Selected Files Size.xml
1
<?xml version="1.0" encoding="UTF-8"?><extensionAttribute> <displayName>CrashPlan - Selected Files Size</displayName> <displayInCategory>Backup</displayInCategory> <description>This attribute displays the size of the files that CrashPlan has selected to actively back up. This attribute applies to both Mac and Windows.</description> <dataType>string</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` value=`/usr/bin/curl -u "$CP_AdminUsername":"$CP_AdminPassword" -k https://"$CP_ServerAddress":"$CP_ServerPort"/rest/computerUsage?sourceGuid="$GUID" | grep -w selectedBytes | awk '{print $2}' | sed s/,//g` kilo=$( echo "scale=2; $value / 1024" | bc ) kiloint=$( echo "$value / 1024" | bc ) mega=$( echo "scale=2; $kilo / 1024" | bc ) megaint=$( echo "$kilo / 1024" | bc ) giga=$( echo "scale=2; $mega / 1024" | bc ) gigaint=$( echo "$mega / 1024" | bc ) if [ $kiloint -lt 1 ] ; then result="$value bytes" elif [ $megaint -lt 1 ] ; then result="${kilo} KB" elif [ $gigaint -lt 1 ] ; then result="${mega} MB" else result="${giga} GB" fi 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 kilo = intTotalSize / 1024 mega = kilo / 1024 giga = mega / 1024 If kilo < 1 then strResult = Round(intTotalSize) & " bytes" ElseIf mega < 1 then strResult = Round(kilo) & " KB" ElseIf giga < 1 Then strResult = Round(mega) & " MB" Else strResult = Round(giga) & " GB" End If WScript.Echo "<result>" & strResult & "</result>"End IfEnd If </scriptContentsWindows></extensionAttribute>