-
Notifications
You must be signed in to change notification settings - Fork 0
/
jssEnrollment.py
34 lines (26 loc) · 1.2 KB
/
jssEnrollment.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
import requests, json, datetime
from os.path import expanduser
home = expanduser("~")
lWeek = datetime.datetime.today() - datetime.timedelta(days = 7)
last = lWeek.strftime('%m/%d/%Y')
cResp = requests.get(<jssURL>, auth = (<username>, <password>), headers={'Accept': 'application/json'})
comp = cResp.json()['computers']
compID = []
for c in comp:
compID.append(json.dumps(c['id']))
compCheck = []
for c in compID:
iResp = requests.get(<jssURL> + '{0}'.format(c), auth = (<username>, <password>), headers = {'Accept': 'application/json'})
info = iResp.json()['computer']
date = datetime.datetime.strptime(info['general']['initial_entry_date'], '%Y-%m-%d')
if date >= lWeek:
compCheck.append('System: ' + json.dumps(info['general']['name']))
compCheck.append('UserID: ' + json.dumps(info['location']['username']))
compCheck.append('User Name: ' + json.dumps(info['location']['real_name']))
compCheck.append('Enrolled: ' + json.dumps(info['general']['initial_entry_date']))
MSG = """ Here is a list of computers that have been enrolled in the last week:
%s
"""" % ('\n'.join(compCheck), last)
f = open(home + "\Desktop\enrollment.txt", "w")
f.write(MSG)
f.close()