forked from jamf/Jamf-Nation-Extension-Attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrashPlan PROe - Selected Files Size.xml
149 lines (125 loc) · 5.12 KB
/
CrashPlan PROe - Selected Files Size.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?xml version="1.0" encoding="UTF-8"?>
<extensionAttribute>
<displayName>CrashPlan PROe - Selected Files Size</displayName>
<displayInCategory>Backup</displayInCategory>
<description>This attribute displays the size of the files that CrashPlan PROe has selected to actively back up. This attribute applies to both Mac and Windows.</description>
<dataType>string</dataType>
<scriptContentsMac>
#!/bin/sh
# Modified 1/24/13
# Third-Part Product page for CrashPlan PROe - https://jamfnation.jamfsoftware.com/viewProduct.html?id=217
CP_ServerAddress="EditFromTemplate_CrashPlan_PROe_Server_Name_-_including_protocol_and_port"
CP_AdminUsername="EditFromTemplate_CrashPlan_PROe_Service_Account_Username"
CP_AdminPassword="EditFromTemplate_CrashPlan_PROe_Service_Account_Password"
if [ "$CP_ServerAddress" == "" ] || [ "$CP_AdminUsername" == "" ] || [ "$CP_AdminPassword" == "" ];then
echo "<result>Please ensure all variables are set in the extension attribute script.</result>"
elif [ -f /Library/Application\ Support/CrashPlan/.identity ];then
SERVER=`echo $CP_ServerAddress | sed 's|/$||'`
GUID=`cat /Library/Application\ Support/CrashPlan/.identity | sed -n 's/guid=//p'`
value=`curl -q -u "$CP_AdminUsername:$CP_AdminPassword" -k "$SERVER/api/Computer?guid=$GUID&incBackupUsage=1" | sed -n 's/.*selectedBytes": \([^,]*\).*/\1/p'`
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>"
fi
</scriptContentsMac>
<scriptTypeWindows>VBScript</scriptTypeWindows>
<scriptContentsWindows>
On Error Resume Next
'Declaration of Objects, Constants, Variables
Dim objFSO
Dim objTextFile
Dim strTextFile
Dim objHTTP
Dim arrResults
Dim strResult
Dim GUID
Dim CP_ServerAddress
Dim CP_AdminUsername
Dim CP_AdminPassword
Dim SERVER
'Set Variables
CP_ServerAddress = "EditFromTemplate_CrashPlan_PROe_Server_Name_-_including_protocol_and_port"
CP_AdminUsername = "EditFromTemplate_CrashPlan_PROe_Service_Account_Username"
CP_AdminPassword = "EditFromTemplate_CrashPlan_PROe_Service_Account_Password"
'Validate Variables Have Been Set
If CP_ServerAddress = "" Or CP_AdminUsername = "" Or CP_AdminPassword = "" Then
WScript.Echo "<result>Please ensure all variables are set in the extension attribute script.</result>"
Else
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
'Set Constants
Const WinHttpRequestOption_SslErrorIgnoreFlags = 4
Const WinHttpRequestOption_EnableHttpsToHttpRedirects = 12
'Read in CrashPlan GUID
Set objTextFile = objFSO.OpenTextFile("C:\ProgramData\CrashPlan\.identity")
strTextFile = objTextFile.ReadAll
objTextFile.Close
arrResults=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 if
Next
If GUID = "" Then
WScript.Echo "<result>Not installed</result>"
Else
If Right(CP_ServerAddress,1) = "/" Then
SERVER = Left(CP_ServerAddress, Len(CP_ServerAddress) -1)
Else
SERVER = CP_ServerAddress
End if
'Connect to the CrashPlan ProE Server Rest API
objHTTP.open "GET", SERVER & "/api/computers?guid=" & GUID & "&incBackupUsage=1", False
objHTTP.Option(WHttpRequestOption_SslErrorIgnoreFlags) = &H3300
objHTTP.Option(WinHttpRequestOption_EnableHttpsToHttpRedirects) = True
objHTTP.SetCredentials CP_AdminUsername, CP_AdminPassword, 0
objHTTP.send
'Parse the JSON Output
If objHTTP.Status = "200" Then
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, 2) & " bytes"
ElseIf mega < 1 then
strResult = Round(kilo, 2) & " KB"
ElseIf giga < 1 Then
strResult = Round(mega, 2) & " MB"
Else
strResult = Round(giga, 2) & " GB"
End If
WScript.Echo "<result>" & strResult & "</result>"
Else
WScript.Echo "<result>ERROR RETRIEVING DATA: " & objHTTP.Status & " - " & objHTTP.StatusText & "</result>"
End If
End If
End If
</scriptContentsWindows>
</extensionAttribute>