Extention Attribute for logCollection not working

DouglasWard-IA
New Contributor III

What is the best way to try and debug an EA script? I’ve implemented logCollection https://github.com/kc9wwh/logCollection/wiki , and that works fine, but I’m trying to make a smart group that reports on Macs that have an attachment. The EA from https://github.com/kc9wwh/logCollection/wiki/Reporting doesn’t seem do anything. https://github.com/kc9wwh/logCollection/blob/master/EA-NumAttachments.sh shows... "jamfProURL="https://jamfpro.acme.net:8443"

I've tried that format, plus...
https://jamfpro.acme.net
https://jamfpro.acme.net/

...and none of those work (of course I'm using my own JPro instance address). Is there a log I can check to see where this is failing? Also, I know the api_user works, because that is the same user + creds that runs logCollection in the first place, and adds the attachment to the Mac.

1 ACCEPTED SOLUTION

Notice the -e after xpath in OS > 11.

This should work.  Replaces lines 10-14 from the original script. (Haven't tested)

 

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

 

View solution in original post

4 REPLIES 4

DBrowning
Valued Contributor II

Take a look at the xpath parts on the EA.  its only setup to work on older OS.  If you look at the xpath on the script that uploads the logs, you can see the difference in xpath scheme for older and newer OS.

DouglasWard-IA
New Contributor III

hmmm, so the EA code is out of date. I tried change the xpath code from...

xpath '/computer/purchasing/attachments'


to

xpath "//computer/general/id/text()"

but now it just produces "parser error"s. 

Notice the -e after xpath in OS > 11.

This should work.  Replaces lines 10-14 from the original script. (Haven't tested)

 

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

 

DouglasWard-IA
New Contributor III

That totally worked. I appreciate the assistance.