-
Notifications
You must be signed in to change notification settings - Fork 0
/
Report_Models_by_OS.py
104 lines (83 loc) · 3.23 KB
/
Report_Models_by_OS.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
# Report of all computer or mobile device models by OS version installed
# pip install requests if not already done
import json
import requests
############################
# Editable variables
# Jamf credentials
username="xxxxxx"
password="xxxxxx"
jamfurl="https://xxxxxx.jamfcloud.com"
# searching for computers or mobile devices? if iscomputer=True then computers, if =False then mobile devices
iscomputer=False
############################
# fetch API token
response = requests.post(url=jamfurl + "/api/v1/auth/token", headers={'Accept': 'application/json'}, auth=(username, password))
token = response.json()['token']
# variables for computer v. mobile device
if iscomputer:
devicetype="computers"
devicetypejson="computers"
devicetypejsonsingular="computer"
devicesubset="hardware"
deviceostype="os_name"
else:
devicetype="mobiledevices"
devicetypejson="mobile_devices"
devicetypejsonsingular="mobile_device"
devicesubset="general"
deviceostype="os_type"
# import data from API as a dictionary
response = requests.get(url=jamfurl + "/JSSResource/" + devicetype, headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
# iterate through imported data to get IDs
devicelist=[]
for device in json.loads(response.text)[devicetypejson]:
devicelist.append(device['id'])
# wildcard logic class
class Wildcard:
def __eq__(self, anything):
return True
# create applist
oslist=[]
# iterate through device IDs
print (str(len(devicelist)) + " devices:")
print
for index,deviceID in enumerate(devicelist,start=1):
responseurl=jamfurl + "/JSSResource/" + devicetype + "/id/" + str(deviceID) + "/subset/" + devicesubset
response = requests.get(url=responseurl, headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
devicedictionary=json.loads(response.text)
# pull needed variables from devicedictionary
model=devicedictionary[devicetypejsonsingular][devicesubset]['model']
ostype=devicedictionary[devicetypejsonsingular][devicesubset][deviceostype]
osversion=devicedictionary[devicetypejsonsingular][devicesubset]['os_version']
# if device/OS version combo new to list, add it to OSlist
if oslist.count([model,ostype + " " + osversion,Wildcard()]) == 0:
oslist.append([model,ostype + " " + osversion,1])
# otherwise update the number of minutes
else:
oslist[oslist.index([model,ostype + " " + osversion,Wildcard()])][2]+=1
#print status every 10
if index % 10 == 0:
print (str(index) + " / " + str(len(devicelist)))
# print final status (if not already printed)
if len(devicelist) % 10 != 0:
print (str(len(devicelist)) + " / " + str(len(devicelist)))
print()
# sort oslist by number of devices high to low
oslist.sort(key=lambda x : x[2], reverse=True)
# grab all models and dedup -- list/set command is doing the deduping
allmodels=list(set([item[0] for item in oslist]))
allmodels.sort()
# iterate through every model
for thismodel in allmodels:
print(thismodel + ":")
# iterate through oslist finding sublists that are from this model and printing them
for os in oslist:
if thismodel == os[0]:
#if blank OS print not reported, otherwise print OS
if os[1] == " ":
print (" not reported: " + str(os[2]))
else:
print(" " + os[1] + ": " + str(os[2]))
print()