-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_jamf_device.py
75 lines (61 loc) · 2.62 KB
/
update_jamf_device.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
#!/usr/bin/env python3
# Jason Satti
import argparse
import requests
import jamf_info
class JamfConnect(object):
"""Connect to Jamf Instance and update a user's device information."""
def __init__(self, resource_url, api_user, api_pw):
self.resource_url = resource_url
self.api_user = api_user
self.api_pw = api_pw
def update_jamf_device(self, last_name, status):
"""Update device information on Jamf.
:param status: Status of device to append end of name
:param last_name: last name of target user
"""
headers = {'Accept': "application/json",
'Content-Type': "application/xml"}
r = requests.get(F'{self.resource_url}match/%2A{last_name}',
auth=(self.api_user, self.api_pw),
headers=headers)
r.raise_for_status()
devices = r.json()['computers']
if devices:
for device in devices:
device_id = device.get('id')
device_name = device.get('name')
# <id>5</id> is the ID of extension attribute
payload = F"""<computer>
<general>
<name>{device_name}-{status}</name>
</general>
<extension_attributes>
<extension_attribute>
<id>5</id>
<value>Yes</value>
</extension_attribute>
</extension_attributes>
</computer>"""
r = requests.put(F'{self.resource_url}id/{str(device_id)}',
auth=(self.api_user, self.api_pw),
headers=headers,
data=payload)
r.raise_for_status()
def main():
"""Update a user's device information in Jamf.
:last_name: Required CLI Input
:status: Required CLI Input
"""
parser = argparse.ArgumentParser(description='Update user device '
'information on Jamf')
parser.add_argument('-l', '--last_name', required=True, type=str,
help='Last name of user for device to update')
parser.add_argument('-s', '--status', required=True, type=str,
help='Device status to append name with.')
args = parser.parse_args()
jss_connect = JamfConnect(jamf_info.resource_url, jamf_info.api_user,
jamf_info.api_pw)
jss_connect.update_jamf_device(args.last_name, args.status)
if __name__ == '__main__':
main()