Skip to content

Commit e03c79e

Browse files
Merge pull request #7 from cscaglioned42/DQR-4111
GitHub JAMF script generates errors when using it with D42 17.02.
2 parents 0bfd9c5 + 537c161 commit e03c79e

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

device42.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ def __init__(self, config, options):
1212
self.dry_run = options['dry_run']
1313

1414
def _poster(self, data, url):
15-
payload = data
1615
headers = {
1716
'Authorization': 'Basic ' + base64.b64encode(self.username + ':' + self.password)
1817
}
1918

20-
r = requests.post(url, payload, headers=headers, verify=False)
19+
r = requests.post(url, data, headers=headers, verify=False)
2120
if self.debug:
22-
msg1 = unicode(payload)
21+
msg1 = unicode(data)
2322
msg2 = 'Status code: %s' % str(r.status_code)
2423
msg3 = str(r.text)
2524

@@ -86,12 +85,10 @@ def delete(self, identity, name):
8685
print msg
8786
return self._deleter(url).json()
8887

89-
# BULK
90-
def bulk(self, data):
91-
url = 'https://%s/api/1.0/devices/bulk/' % self.host
92-
msg = '\tBulk request to %s ' % url
88+
# POST
89+
def post(self, data, name):
90+
url = 'https://%s/api/1.0/%s/' % (self.host, name)
91+
msg = '\tPost request to %s ' % url
9392
if not self.dry_run:
9493
print msg
95-
return self._poster({'payload': json.dumps(data)}, url).json()
96-
97-
94+
return self._poster(data, url).json()

starter.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,41 @@ def get_computers(self):
7878
def get_device_network(general):
7979
macs = []
8080
ips = []
81+
device_name = general['name']
8182
if general['mac_address']:
8283
macs.append({
8384
'macaddress': general['mac_address'],
85+
'device': device_name
8486
})
8587

8688
if general['alt_mac_address']:
8789
macs.append({
8890
'macaddress': general['alt_mac_address'],
91+
'device': device_name
8992
})
9093

9194
if general['ip_address']:
9295
ips.append({
9396
'ipaddress': general['ip_address'],
97+
'device': device_name
9498
})
9599

96100
if general['last_reported_ip']:
97101
ips.append({
98102
'ipaddress': general['last_reported_ip'],
103+
'device': device_name
99104
})
100105

101106
return macs, ips
102107

103108
@staticmethod
104-
def get_device_software(applications):
109+
def get_device_software(applications, device_name):
105110
software = []
106111
for item in applications['applications']:
107112
software.append({
108113
'software': item['name'],
109114
'version': item['version'],
115+
'device': device_name
110116
})
111117

112118
return software
@@ -121,7 +127,7 @@ def main():
121127
}
122128
for device in devices:
123129
macs, ips = integration.get_device_network(device['general'])
124-
software = integration.get_device_software(device['software'])
130+
software = integration.get_device_software(device['software'], device['general']['name'])
125131

126132
if options['no_ips']:
127133
ips = []
@@ -139,5 +145,14 @@ def main():
139145
if __name__ == '__main__':
140146
elements = main()
141147
for element in elements['devices']:
142-
print device42_api.bulk(element)
148+
print device42_api.post(element['device'], 'devices')
149+
150+
for mac in element['macs']:
151+
print device42_api.post(mac, 'macs')
152+
153+
for ip in element['ips']:
154+
print device42_api.post(ip, 'ips')
155+
156+
for software in element['software']:
157+
print device42_api.post(software, 'software_details')
143158
print '\n Finished'

0 commit comments

Comments
 (0)