Updating an Extension Attribute via Policy

Iwamoto
New Contributor

Hi Folks,

I'm trying to find a way to update our extension attribute every 5 minutes, but only one specific, so i don't want to mess with the inventory collection.

I figured my best bet is to create a script that does the same as it does now for the EA, but instead of just doing a <results> echo, writing it directly using the API

I still need to redo my JAMF 400 since i found the whole API thing so confusing, but i think i have the idea down.
would this be effective/would you do it differently?

-credentials
-grab serial number from system profiler
-use serial to grab the computer ID using the API (so 

"https://***.jamfcloud.com/JSSResource/computers/serialnumber/$serial_number")
-execute the script (in this case, it checks the IP for a specific interface)
-writes the value using the API by using the previously fetched ID (i think this should go via the computer then, not clear if there's a better way?)

as you might be able to tell, i kind of know what to do but still feel lost, tips/hints would be greatly appreciated.
1 ACCEPTED SOLUTION

Ismere
Contributor

We are writing some EAs trough the API. But instead of using the Serial and the API to get the JAMF-ID of a Computer we are using the UDID of each Computer.
I posted some parts of the script:

 

#Grab UDID
computerUDID=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID:/ { print $3 }')

# Construct the API data for writing
apiData="<computer><extension_attributes><extension_attribute><name>${eaName}</name><value>${eaValue}</value></extension_attribute></extension_attributes></computer>"

# Writing API-Data (Classic Auth, Tokenauth is prototyped for the moment)
apiPut=`curl -H "Content-Type: text/xml" -sfu ${apiUsername}:${apiPassword} ${apiURL}/JSSResource/computers/udid/${computerUDID} -d "${apiData}" -X PUT` 

 If someone wants to use the ID they will have to ether get it trough the API with the help of the Serial Number or running a full inventory trough a script once grep the ID and Save it in a local file to read whenever it is needed....

If you want this every 5 Minutes then as @jamf-42 wrote you should create a launchdaemon running the script locally.
What we normally do for this is creating the script and launchdaemon. Packaging them together. Scripts are going into the opt folder in our case. Postinstall script bootstraping the Daemon. Then sending this package to every Computer ,we want this to be run on, as a policy once per Computer.

View solution in original post

3 REPLIES 3

jamf-42
Valued Contributor II

While still using the same setup with API write etc, but simply run locally on the users device?

Ismere
Contributor

We are writing some EAs trough the API. But instead of using the Serial and the API to get the JAMF-ID of a Computer we are using the UDID of each Computer.
I posted some parts of the script:

 

#Grab UDID
computerUDID=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID:/ { print $3 }')

# Construct the API data for writing
apiData="<computer><extension_attributes><extension_attribute><name>${eaName}</name><value>${eaValue}</value></extension_attribute></extension_attributes></computer>"

# Writing API-Data (Classic Auth, Tokenauth is prototyped for the moment)
apiPut=`curl -H "Content-Type: text/xml" -sfu ${apiUsername}:${apiPassword} ${apiURL}/JSSResource/computers/udid/${computerUDID} -d "${apiData}" -X PUT` 

 If someone wants to use the ID they will have to ether get it trough the API with the help of the Serial Number or running a full inventory trough a script once grep the ID and Save it in a local file to read whenever it is needed....

If you want this every 5 Minutes then as @jamf-42 wrote you should create a launchdaemon running the script locally.
What we normally do for this is creating the script and launchdaemon. Packaging them together. Scripts are going into the opt folder in our case. Postinstall script bootstraping the Daemon. Then sending this package to every Computer ,we want this to be run on, as a policy once per Computer.