python script - Low iPad battery percentage monitoring

vhua
New Contributor

Each morning we have our helpdesk guy walking around our office to check 200+ iPads to make sure the ones with low battery are plugged in for charging. This is done manually and is not efficient.
Is there an existing python script that will query all the iPads' battery level? We would like to gather this info and then implement with Nagios to alert the NOC of any iPad batteries that are below a certain threshold (i.e. < 20%). I have no python experience so any help is appreciated. My attempted script is the following but I'm stuck at this point.

import json
import requests

print ("Fetching ipad record from JSS...")
print ("")
response = requests.get('https://myjss.com/JSSResource/mobiledevices', headers={'Accept': 'application/json'}, auth=('user', 'password'))

print (response.json())

"#print ('The current battery level is:' + ['mobile_device']['general']['battery_level'])"

1 REPLY 1

m_donovan
Contributor III

Have you tried a smart group or even an advanced search? Querying the API could be intensive. Either way the data is only as current as the devices last inventory.