-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config_Exceptions_Mobile_Devices.sh
74 lines (54 loc) · 2.63 KB
/
Config_Exceptions_Mobile_Devices.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# Print report of exclusions for every mobile device configuration profile
# pip install requests if not already done
import requests
import json
from datetime import datetime
############################
# Editable variables
# Jamf credentials
username = "xxxxxx"
password = "xxxxxx"
jamfurl = "https://xxxxxx.jamfcloud.com"
############################
# definition for fetching API token
def fetchtoken():
response = requests.post(url=jamfurl + "/api/v1/auth/token", headers={'Accept': 'application/json'}, auth=(username, password))
print("new token fetched")
return response.json()['token'], datetime.strptime(response.json()['expires'], '%Y-%m-%dT%H:%M:%S.%fZ')
# definition for invalidating API token
def invalidatetoken():
response = requests.post(url=jamfurl + "/api/v1/auth/invalidate-token", headers={'Authorization': 'Bearer ' + token})
############################
# get initial token
token,tokenexpiration = fetchtoken()
# import data from API as a dictionary
response = requests.get(url=jamfurl + "/JSSResource/mobiledeviceconfigurationprofiles", headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
# iterate through imported data to get IDs
profilelist=[]
for profile in json.loads(response.text)['configuration_profiles']:
profilelist.append(profile['id'])
# iterate through device IDs
print (str(len(profilelist)) + " configuration profiles")
print()
print("ALL EXCEPTIONS:")
print()
response = requests.get(url=jamfurl + "/JSSResource/mobiledeviceconfigurationprofiles/id/81", headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
possibleexclusions = ["mobile_devices","buildings","departments","mobile_device_groups","users","user_groups","network_segments","ibeacons","jss_users","jss_user_groups"]
for index,profileID in enumerate(profilelist,start=1):
#get info for the user into a dictionary
responseurl = jamfurl + "/JSSResource/mobiledeviceconfigurationprofiles/id/" + str(profileID)
response = requests.get(url=responseurl, headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
profiledictionary=json.loads(response.text)
print(str(profiledictionary["configuration_profile"]["general"]["name"]) + ":")
for i in possibleexclusions:
exclusionlist = profiledictionary["configuration_profile"]["scope"]["exclusions"][i]
for entry in exclusionlist:
print(" " + i + ": " + str(entry["name"]))
print()
# if less than 5 minutes left, invalidate token and get a new one
if index % 25 == 0:
if (tokenexpiration-datetime.utcnow()).total_seconds() < 600:
invalidatetoken()
token,tokenexpiration = fetchtoken()
invalidatetoken()