forked from jamf/Jamf-Nation-Extension-Attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrashPlan - Alert Status.xml
95 lines (86 loc) · 3.82 KB
/
CrashPlan - Alert Status.xml
1
<?xml version="1.0" encoding="UTF-8"?><extensionAttribute> <displayName>CrashPlan - Alert Status</displayName> <displayInCategory>Backup</displayInCategory> <description>This attribute displays the CrashPlan alert status of the computer. "OK" if the computer has backed up within defined days, "WARN" if computer has exceeded "warning" threshold, "ALERT" if computer has exceeded "alert" threshold. 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` echo "<result>`/usr/bin/curl -u "$CP_AdminUsername":"$CP_AdminPassword" -k https://"$CP_ServerAddress":"$CP_ServerPort"/rest/computers?guid="$GUID" | grep -w alertStates | awk '{print $2}' | sed s/,//g | sed 's/..\(.*\)/\1/' | sed 's/\(.*\)../\1/'`</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 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), "alertStates") > 0 Then strResult = Replace (arrResults(i), chr(34) & "alertStates" & chr(34) & ": [" & chr(34), "") strResult = Replace (strResult, chr(34) & "]", "") strResult = Replace (strResult, chr(10), "") strResult = Replace (strResult, chr(32), "") Exit for End if Next WScript.Echo "<result>" & strResult & "</result>"End IfEnd If</scriptContentsWindows></extensionAttribute>