Improving Python Access To JAMF – A New Tool

At my current employer we use JAMF Pro to manage a medium sized fleet of Macs and that means talking to the back end JSS if we want data.

The tool to talk to your JSS from Python is Crag Shea’s python_jss. The big problem you then hit is that it returns XML. In the case of a computer record in tje JSS tha’s 2500 lines of ugly XML. I couldn’t find a parser that would correctly parse it so have to fall back to using Elementree to pick it apart piece by piece.

That leads to ugly code that’s hard to follow.

So I decided to write jss_tools, a set of functions that takes the XML and converts it to Python data structures and converts the XML data strings to Python types.

The other annoyance it removes is that JAMF doesn’t support a boolean type for extension attributes (EA). EAs are incredibly useful and can be thought of as custom fields in the computer record that can be written to either from yur Pythom code or by running a script on a client computer. To get over that my tools fake a boolean type. If you store `True`, `False`, `0` or `1` in a string EA I convert it to a boolean for you on the way in and convert it back to a string on the way out.

Let me show you an example of how all this simplifies code.

old_way

You can see how the logic of the code is hidden behind all those calls to extract the XML. The code also needs to loop through all the EAs to find the three that matter.

new_way

Now we do all the access stuff right at the top and it’s clear in the code what we are doing.

It’s now available GitHub and I’d love you to try it out and give me some feedback. I also have the Keynote presentation I gave at XWorld2018 last week here which includes some notes on what I’m up to next.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s