kc9wwh / logCollection

Script to upload client device logs to Jamf Pro
MIT License
111 stars 27 forks source link

The xpath in the EA is outdated #14

Open IACtech opened 1 year ago

IACtech commented 1 year ago

The xpath in the EA code (https://github.com/kc9wwh/logCollection/blob/master/EA-NumAttachments.sh) is wrong/out of date...

line 11 jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath "//computer/general/id/text()" )

line 14 numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )

Taking a cue from the mail logCollection.sh code, it needs to filter for macOS 12 or later to set the right xpath... something like...

starting line 10...

osMajor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}')
osMinor=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $2}')

## Determine Jamf Pro Device ID
if [[ "$osMajor" -ge 11 ]]; then
jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath -e "//computer/general/id/text()" )
elif [[ "$osMajor" -eq 10 && "$osMinor" -gt 12 ]]; then
jamfProID=$( curl -k -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/serialnumber/$mySerial/subset/general | xpath  "//computer/general/id/text()" )
fi

## API Lookup for how many attachments are attached to this device record
if [[ "$osMajor" -ge 11 ]]; then
numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath -e '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )
elif [[ "$osMajor" -eq 10 && "$osMinor" -gt 12 ]]; then
numAttachments=$( curl -u $jamfProUser:$jamfProPass $jamfProURL/JSSResource/computers/id/$jamfProID -X GET | xmllint -format - | xpath '/computer/purchasing/attachments' | grep "<id>" | wc -l | xargs )
fi
## Echo results for EA
echo "<result>$numAttachments</result>"
ryanasik commented 1 year ago

@kc9wwh I am also seeing issues with this EA not functioning. Is it possible to have a new version of the code uploaded?

Thanks, Ryan

dmote75 commented 1 year ago

@IACtech This worked great, thanks!