jpt
has some practical applications for the Jamf admin
Sanitizing Jamf Reports
Let’s say you’ve exported an Advanced Search, it’s got some interesting data you’d like to share, however there is personal data in it. Rather than re-running the report, why not blank out or remove those fields?
Here’s a sample file: advancedcomputersearch-2-raw.json
This an excerpt from one of the computer record:
{
"name": "Deathquark",
"udid": "2ca8977b-05a1-4cf0-9e06-24c4aa8115bc",
"Managed": "Managed",
"id": 2,
"Computer_Name": "Deathquark",
"Last_Inventory_Update": "2020-11-04 22:01:09",
"Total_Number_of_Cores": "8",
"Username": "Professor Frink",
"FileVault_2_Status": "Encrypted",
"JSS_Computer_ID": "2",
"Number_of_Available_Updates": "1",
"Model_Identifier": "MacBookPro16,1",
"Operating_System": "Mac OS X 10.15.7",
"Model": "MacBook Pro (16-inch, 2019)",
"MAC_Address": "12:34:56:78:9A:BC",
"Serial_Number": "C02K2ND8CMF1",
"Email_Address": "frink@hoyvin-glavin.com",
"IP_Address": "10.0.1.42",
"FileVault_Status": "1/1",
"Processor_Type": "Intel Core i9",
"Processor_Speed_MHz": "2457",
"Total_RAM_MB": "65536"
}
Now let’s say the privacy standards for this place is GDPR on steroids and all personally identifiable information must be removed, including serials, IPs, UUIDs, almost everything (but you don’t want to run the report again because it took ages to get the output)!
Here’s what that command would look like: jpt -o replace -v '"REDACTED"' -p '$["advanced_computer_search"]["computers"][*]["name","udid","Username","Computer_Name","MAC_Address","Serial_Number","Email_Address","IP_Address"]'
./advancedcomputersearch-2-raw.json
Here’s what that same computer looks like in the resulting output (as well as all others in the document):
{
"name": "REDACTED",
"udid": "REDACTED",
"Managed": "Managed",
"id": 2,
"Computer_Name": "REDACTED",
"Architecture_Type": "i386",
"Make": "Apple",
"Service_Pack": "",
"Last_Inventory_Update": "2020-11-04 22:01:09",
"Active_Directory_Status": "Not Bound",
"Total_Number_of_Cores": "8",
"Username": "REDACTED",
"FileVault_2_Status": "Encrypted",
"JSS_Computer_ID": "254",
"Number_of_Available_Updates": "1",
"Model_Identifier": "MacBookPro16,1",
"Operating_System": "Mac OS X 10.15.7",
"Model": "MacBook Pro (16-inch, 2019)",
"MAC_Address": "REDACTED",
"Serial_Number": "REDACTED",
"Email_Address": "REDACTED",
"IP_Address": "REDACTED",
"FileVault_Status": "1/1",
"Processor_Type": "Intel Core i9",
"Processor_Speed_MHz": "2457",
"Total_RAM_MB": "65536"
}
What we did was use the -o
replace
operation with a -v <value>
of the JSON string "REDACTED"
to all the paths matched by the JSONPath union expression (the comma separated property names in brackets) of the -p
option. JSON Pointer can only act on one value at a time, this is where JSONPath can save you time and really shines.
jpt
is fast because WebKit’s JavascriptCore engine is fast, for instance there is a larger version of that search that has 15,999 computers, it took only 11 seconds to redact every record.
jpt -l $.advanced_computer_search.computers ./advancedcomputersearch.json
15999
time jpt -o replace -v '"REDACTED"' -p '$.advanced_computer_search.computers[*]["name","udid","Username","Computer_Name","MAC_Address","Serial_Number","Email_Address","IP_Address"]' ./advancedcomputersearch.json > /dev/null
11.14s user 0.35s system 104% cpu 11.030 total
Put Smart Computer Groups on a diet
When you download Smart Groups via the API, you will also get an array of all the computers objects that match at that moment in time. If you just want to back up the logic or upload to another system, you don’t want all those computers in there.
Sample file: smartgroup-1-raw.json
{
"computer_group": {
"id": 12,
"name": "All 10.15.x Macs",
"is_smart": true,
"site": {
"id": -1,
"name": "None"
},
"criteria": [
{
"name": "Operating System Version",
"priority": 0,
"and_or": "and",
"search_type": "like",
"value": "10.15",
"opening_paren": false,
"closing_paren": false
}
],
"computers": [
{
"id": 1,
"name": "mac1",
"mac_address": "12:34:56:78:9A:BC",
"alt_mac_address": "12:34:56:78:9A:BD",
"serial_number": "Z18D132XJTQD"
},
{
"id": 2,
"name": "mac2",
"mac_address": "12:34:56:78:9A:BE",
"alt_mac_address": "12:34:56:78:9A:BF",
"serial_number": "Z39VM86X01MZ"
}
]
}
}
Lets’ remove those computers with jpt
and the JSON Patch remove operartion:
jpt -o remove -p '$.computer_group.computers' ./smartgroup-1-raw.json
Since the target is a single property name, JSON Pointer can also be used:
jpt -o remove -p /computer_group/computers ./smartgroup-1-raw.json
{
"computer_group": {
"id": 12,
"name": "All 10.15.x Macs",
"is_smart": true,
"site": {
"id": -1,
"name": "None"
},
"criteria": [
{
"name": "Operating System Version",
"priority": 0,
"and_or": "and",
"search_type": "like",
"value": "10.15",
"opening_paren": false,
"closing_paren": false
}
]
}
}
Further Uses
Using only JSON Patch replace and remove operations this JSON could have its id
removed to prep it for an API POST on another JSS to create a new group or the name and value could be modified in a looping script to create multiple JSON files for every macOS version. The jpt
is flexible enough to handle most anything you throw at it, whether you are using the standalone version or have embedded it in your scripts.
Stop by the jpt GitHub page to get your copy