Posted on 03-30-2016 11:48 AM
I am looking for a way to pull a report via the JSS API to show all the Policies that are associated with a specific script. Looking through the API, I don't see any simple way of finding this information.
I have been able to accomplish this via a MySQL query similar to this:
SELECT
scripts.file_name,
scripts.script_id,
policies.name,
policies.policy_id
FROM policy_scripts
INNER JOIN scripts
ON scripts.script_id = policy_scripts.script_id
INNER JOIN policies
ON policies.policy_id = policy_scripts.policy_id
WHERE scripts.file_name = "Super Awesome Script";
This query would return the the data in the following format:
file_name script_id name policy_id
Super Awesome Script 165 Super Awesome Policy 1 1645
Super Awesome Script 165 Super Awesome Policy 2 2314
Super Awesome Script 165 Super Awesome Policy 3 2356
Is there anyway to achieve the same thing via the API that I am missing?
Solved! Go to Solution.
Posted on 03-30-2016 12:13 PM
I only wish this were easy. Unfortunately, there is no one single function that will get you this info from the API. That being said, I'm certain it can be scripted, but it will be somewhat ugly and will likely take time to generate your final report.
You can take a look at some of my Casper-API scripts posted to my github page for examples on how I've built some reporting around the API, to do other but similar things. Forewarning, its fairly clunky since you have no choice but to pull down an xml of each policy and scan the data for the specific script or package ID you're looking for and then add any it finds into an array or append it to a file, etc. Better than nothing, but I sincerely wish JAMF would beef up the API for this kind of stuff.
Posted on 03-30-2016 12:13 PM
I only wish this were easy. Unfortunately, there is no one single function that will get you this info from the API. That being said, I'm certain it can be scripted, but it will be somewhat ugly and will likely take time to generate your final report.
You can take a look at some of my Casper-API scripts posted to my github page for examples on how I've built some reporting around the API, to do other but similar things. Forewarning, its fairly clunky since you have no choice but to pull down an xml of each policy and scan the data for the specific script or package ID you're looking for and then add any it finds into an array or append it to a file, etc. Better than nothing, but I sincerely wish JAMF would beef up the API for this kind of stuff.
Posted on 03-30-2016 12:48 PM
Thanks @mm2270
That's what I was afraid of. I think I may just stick to MySQL Queries for simple reports for the time being. I discovered that even with the SQL Query, Casper Remote installs are lumped in as a Policy. I need to work on something to filter those results out.
I really just wanted a quick at-a-glance way of knowing if a script was actively associated with any Policies. JAMF leaves a lot to be desired in terms of good script organization right now. Same thing for Smart Groups, Static Groups, etc. Guess I will have to search the feature requests to see if I need to submit a new one or not. :)
Thanks again!
Posted on 03-30-2016 01:15 PM
I have a messy and slow script on my github repo
https://github.com/tmhoule/JSSReport/blob/master/cleanup.sh
It will output unused scripts and groups.
EDIT: Scripts used in configurations for imaging may show up as unused; not sure if I fixed that yet or not.
Posted on 04-04-2016 10:42 AM
Thanks @thoule
I will take a look at this.
Posted on 04-04-2016 11:09 AM
I really just wanted a quick at-a-glance way of knowing if a script was actively associated with any Policies.
@FritzsCorner When I want to see if a particular script/package is in use I just paste its name into the search box under Policies to see which policies it is in:
Obviously this doesn't scale well and is just for quick checks, but it is handy.