Set Computer Name to DNS reverse lookup - Any Suggestions?

alanmcseveney
New Contributor

I would like to set a computer record's name in the JSS and on the computer to it's DNS name. Doing the computer itself is easy, using scutil or jamfhelper. Getting the change up to the JSS is harder. I can run jamf recon, but that takes forever. Ideally I would like this option in Casper Imaging and in Prestage Imaging, so that all policies are using the correct name from the beginning, like joining the domain, etc.

Does anyone else use DNS as their authority for names, and if so, how do you go about getting the JSS to use those names?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Use the JSS API.

Get the Mac's name from DNS and drop that into a variable and export it out to an xml file that would change just the computer name, then upload that back up to the JSS with curl using the Mac's MAC address for en0 or its JSS ID, if that's known, using a PUT command, so it only updates the record.

It will be loads faster than using recon.

View solution in original post

10 REPLIES 10

PeterClarke
Contributor II

Yes I do this too - for our LAB Machines, but currently not for Staff Machines..

Sadly, I too rely on recon to get the info into the JSS..
Very slow as you say..

That's why I too would prefer a better method - such as a custom recon verb..
just for this operation..

JAMF, How about creating a new command: recon -computerName ??
( where as currently as alanmcseveney says - we presently have to do a full recon scan to pick this up)

Another way, to resolve this - would be to write directly to the SQL database from the client machine.. using the Casper API.. But I haven't look at that more complex option yet..

Ideally, a Casper verb extension to recon as first suggested above ( recon -computerName ) would be the best 'future' solution..
- but that could only be added in a new release of Casper.. Should JAMF consider it worthwhile.

mm2270
Legendary Contributor III

Use the JSS API.

Get the Mac's name from DNS and drop that into a variable and export it out to an xml file that would change just the computer name, then upload that back up to the JSS with curl using the Mac's MAC address for en0 or its JSS ID, if that's known, using a PUT command, so it only updates the record.

It will be loads faster than using recon.

PeterClarke
Contributor II

Yes - that's what I thought. - But I haven't actually tried yet, since I've been busy on other things...
- That method would work "right now"...

The other idea: for JAMF to introduce a new option: recon -computerName, would be a 'nice to have' for future use
and would be an 'easy to use' for most folks.. So is a development I would recommend to JAMF.

The API method is rather more complex, but not so difficult... However it's a method in the "advanced use" category..
-- This being perhaps the simplest such use of that technique..
(And requires a separate SQL read-write account, to be setup for the curl statement to use.)

mm2270
Legendary Contributor III

I can't say for sure whether JAMF would want to include a special verb for just pulling the computer name. Perhaps to make it worth their while to implement, there would need to be a few other common items that could be pulled and updated at the same time. So meaning they could consider implementing a verb like sudo jamf recon -basicInfo** that would pull only the most basic information from a Mac - Computer Name, IP, Serial #, & a few other items and upload those, skipping pulling stuff like Applications and whatnot.

But as you know from this Feature Request here: https://jamfnation.jamfsoftware.com/featureRequest.html?id=78, it appears JAMF is kind of against not pulling all data at the same time, so I don't know if they'll even want to do that.

For now, the API is a viable method and doesn't involve a high level of effort once a person wraps their head around how it works. The major issue with the API I run into is that it doesn't work when Macs report in from the outside if you have a Limited Access JSS cluster set up. For the OP's request though that may not be relevant since it seems he was looking for a way to do this post imaging. I'd assume a Mac right out of imaging wouldn't be sitting in the DMZ, but, you never know?

alanmcseveney
New Contributor

In my opinion, jamf -ComputerName -name $myvariable should talk to both scutil AND the JSS (if available) immediately. I can't think of any scenario where it would be desirable for their to be a <24 hour naming disparity between computer and JSS record.

This would be a close second to having the option to name a machine by DNS in Casper Imaging and Prestage Imaging.

mm2270
Legendary Contributor III

You make a valid point, and I would agree. If you set out to rename a Mac using the jamf binary, it should feed that name change back up to the JSS' record immediately after. Yes, there is always stringing that command with a jamf recon after, but as mentioned, that takes some time and eats up resources on the host system unnecessarily. I'm all for reducing any footprint the jamf binary and its ancillary processes take as much as possible, so a full recon just to feed back the Comp name change seems gratuitous to me.
If the name change occurs outside of the jamf framework, like a user going into Sharing and changing the name, then all bets are off, but if the jamf binary is doing the renaming, it should be able to feed that back upstream right away (if available)

alanmcseveney
New Contributor

mm2270,

Does this sound like a reasonable approach to you?

Create Prestage image and use computer serial number as name;
On enrollment, computer queries JSS for JSS ID of computer with matching serial number, then update the record for the JSS ID.

Do you have an example of how to GET and PUT in a scenario like this?

Many thanks.

mm2270
Legendary Contributor III

Yeah, that sounds like it should work.
Are you on some version of JSS 9.x? I ask because I believe in version 8, the serial number as a query back to the JSS API wasn't a valid item. You can only use name, MAC address, or JSS ID if I'm not mistaken. JSS version 9 opened up several more ways to locate and update a Mac's record in the JSS, including the serial number.

Assuming you're on version 9, something like this should work although I did not test this at all, so you need to test it carefully.

#!/bin/sh

apiuser="apiuser"
apipass="apipass"
jssURL="https://your.casper.server.com:8443"
apiURL="JSSResource/computers/serialnumber"

## Get the Mac's serial number using ioreg
Serial=$( ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{ print $4 }' )

## Get the Mac's name from scutil
COMPNAME=$( scutil --get ComputerName )

## Create the xml file for later upload to the JSS
echo "<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<computer>
<general>
<name>${COMPNAME}</name>
</general>
</computer>" > /tmp/${COMPNAME}.xml

## Upload xml to the JSS via API
curl -fsku "${apiuser}:${apipass}" "${jssURL}/${apiURL}/${Serial} -T /tmp/${COMPNAME}.xml -X PUT

## Check the exit status of the curl upload
if [ "$?" == "0" ]; then
    echo "Upload successful"
    rm -f /tmp/${COMPNAME}.xml
    exit 0
else
    echo "Upload to JSS failed"
    rm -f /tmp/${COMPNAME}.xml
    exit 1
fi

Change the variables up top for the API account and JSS address to match your environment.

alanmcseveney
New Contributor

Apart from a missing close-quotes in line 23, I'd say I owe you a beer. Thank you so much. :)

mm2270
Legendary Contributor III

Heh. See, I said I didn't test it. :D

Glad it helped you (I assume)