Posted on 02-23-2016 07:35 AM
I'm wondering if anyone out there has had to deal with something like this-
We have specific requirements for the contents of all our client Macs ARD Computer Info fields, that I'm hoping to populate dynamically from the User and Location info for each system in our JSS (which is derived from LDAP via a daily policy) - and seeing as we have a thousand or so systems to populate, I'm interested in automating this as much as possible. I know that the binary has the
setARDFields
command as well as kickstarter's
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -set1 -1 "some text"
Moreover, once these are set the first time for our site, if this works, little or no time need be spent updating those ARD fields when a new user is assigned to a system.
So:
ARD Computer 1 = User full name (as listed for that system in the JSS -User and Location info)
ARD Computer 2 = username ("")
ARD Computer 3 - = Department ("")
ARDComputer 4 – Building / floor number ("")
And in my research thus far I haven't seen anything about writing from the JSS info to the fields - https://jamfnation.jamfsoftware.com/discussion.html?id=13233
any advice deeply appreciated!
Posted on 02-23-2016 09:01 AM
The info you're looking for can be obtained with the JSS API.
You'd need a script, possibly run from a once per computer policy that would use the API to grab the already assigned user data from the JSS' computer record and then use those as variables with the "jamf setARDFields" command.
Here's a quick example of getting the data from the API.
#!/bin/sh
## API user info and JSS URL. Adjust as needed
apiuser="apiuser"
apipass="apipass"
jssurl="https://jss-server.address:8443"
## Get the computer's serial number (for locating the record in the API)
Serial_Num=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
## Generate variable containing "location" information on the computer record
Comp_Location_Data=$(curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers/serialnumber/${Serial_Num}/subset/location" | xmllint --format - 2>/dev/null)
## Extract items from the above variable
Full_Name=$(echo "$Comp_Location_Data" | awk -F'>|<' '/<real_name/{print $3}')
User_Name=$(echo "$Comp_Location_Data" | awk -F'>|<' '/<username/{print $3}')
Department=$(echo "$Comp_Location_Data" | awk -F'>|<' '/<department/{print $3}')
Building=$(echo "$Comp_Location_Data" | awk -F'>|<' '/<building/{print $3}')
## Print back what was found
echo "Full Name: $Full_Name
Username: $User_Name
Department: $Department
Building: $Building"
You can then use the above variables, like $Full_Name, $User_Name, etc. in a jamf setARDFields
command on the Mac, which will set those local attributes on the Mac itself.
Hope that helps. Let me know if you have any other questions.
Posted on 02-23-2016 09:07 AM
PERFECT!
Thank you!
Posted on 02-23-2016 12:31 PM
Just because I wanted to do this using Python for practice:
#!/usr/bin/env python
import urllib
import xml.etree.ElementTree as ET
import subprocess
jssAPIuser = 'apiuser'
jssAPIpass = 'apipass'
jssURL = 'https://' + jssAPIuser + ':' + jssAPIpass +
'@jss.server.com:8443'
serial = subprocess.Popen("system_profiler SPHardwareDataType |grep -v tray
| awk '/Serial/ {print $4}'", shell=True, stdout=subprocess.PIPE).
communicate()[0].strip()
url = jssURL +
'/JSSResource/computers/serialnumber/' + serial
uh = urllib.urlopen(url)
data = uh.read()
tree = ET.fromstring(data)
location = tree.findall('location')
full_name = location[0].find('real_name').text
user_name = location[0].find('username').text
building = location[0].find('building').text
updateARD = subprocess.check_output(['/usr/local/bin/jamf', 'setARDFields', '-1', full_name, '-2', user_name, '-3', building])
Posted on 02-23-2016 01:41 PM
Updated the script to work with older versions of the JSS that do not have the jamf binary in /usr/local/bin:
#!/usr/bin/env python
# Name: updateARDinfo.py
# Date: 23 February 2016
# Purpose: used to pull location data out of the JSS and use it to update
# the ARD fields on a computer.
# This will pull Real Name, User name, and Building from JSS via API. Change the
# variables to pull different information and push to the ARD Fields.
import urllib
import subprocess
import os.path
import xml.etree.ElementTree as ET
jssAPIuser = 'apiuser'
jssAPIpass = 'apipass'
jssURL = 'https://' + jssAPIuser + ':' + jssAPIpass +
'@jss.server.com:8443'
def jamf_check():
if os.path.exists('/usr/sbin/jamf'):
jamfbin = '/usr/sbin/jamf'
elif os.path.exists('/usr/local/bin/jamf'):
jamfbin = '/usr/local/bin/jamf'
return jamfbin
serial = subprocess.Popen("system_profiler SPHardwareDataType |grep -v tray
| awk '/Serial/ {print $4}'", shell=True, stdout=subprocess.PIPE).
communicate()[0].strip()
url = jssURL +
'/JSSResource/computers/serialnumber/' + serial
uh = urllib.urlopen(url)
data = uh.read()
tree = ET.fromstring(data)
location = tree.findall('location')
full_name = location[0].find('real_name').text
user_name = location[0].find('username').text
building = location[0].find('building').text
updateARD = subprocess.check_output([jamf_check(), 'setARDFields', '-1', full_name, '-2', user_name, '-3', building])
Posted on 10-04-2018 08:37 AM
that worked fine for me, thank you! :-)