![]() ![]() We continue to use the JSON module to pretty print the entire data structure. So we’ll have to use the appropriate label here when we ask for the number of sub-items. While we may search the mobiledevices space, the root node of the results is labeled mobile_devices. The JPS API gets a little odd here, so hang with me for a second. response_json = json.loads(response.read()) Displaying the results Reading the payload of the response involves using the JSON module to organize an easily parse-able data structure. ![]() Response = urllib2.urlopen(request) Handling the results Request.add_header('Authorization', 'Basic ' + base64.b64encode(jss_user + ':' + jss_pwrd)) Request.add_header('Accept', 'application/json') # build the request we'll send to the JSS ![]() If your production environment allows you to install it, I suggest taking a look at it. Other developers find the Requests module easier to use. This module is included in the standard library of Python. I pass the search_url to the JPS using the urllib2 module. Search_url = jss_base_url + '/' + jss_device_space + '/match/*' + jss_search_term + '*' # entering a blank string will return everything # assemble search space url, wildcarding the search string Jss_base_url = ' + jss_host + ':8443/JSSResource' # assemble root API url to your Jamf pro server Removing the asterisks will search only for instances of that specific search term. Note that hitting return in the script on the JSS search string? prompt will match everything, since it will be an empty wildcard. This will return any record that includes with search term within any of the supported fields. The search can be wildcarded by wrapping the search team with asterisks ( * ). The search_url is constructed by combining the base API URL with the jss_device_space (computer or mobiledevice), with the API call ( match ) and the jss_search_term . The jss_base_url is built using the jss_host string the user enters at the beginning of script. I’ll assemble the search URL in two stages for ease of reading, the base API URL and the full search URL. The following table shows slightly different fields each device categories search encompasses, there are also the fields returned with each match: Here’s an example of Tugboat’s search function is action:Įach type of device has a similar GET method for searching inside its space: The core activity of the application is maintaining the User and Location area of the Inventory pane for each computer in the JPS. ![]() Since that post was written the small experiment turned into a cross-platform, automated, text- and GUI-based application that talks to our JPS, campus LDAP as well as multiple MySQL databases. The inspiration for this series of articles came from internal inventory application that began as an experiment I described in a previous post: Using GIF images in Python GUI scripts. We’ll discuss searching for specific data within the JPS. This post builds on the other articles in the series: Fetching Data From the JSS using API calls & Python and Publishing information to the Jamf Pro server using API calls and Python. This allows an enterprise to customize specific areas of the JPS as needed. Jamf Software’s Jamf Pro server (JPS) provides an Application Programming Interface, or API, to interact with the JPS database. Like a loyal droid, your Jamf Pro server wants to help! (Episode III) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |