From aa3f9ccaefa7f5314e911ffe9657e3fc46c89e92 Mon Sep 17 00:00:00 2001 From: cscaglioned42 Date: Thu, 12 Aug 2021 22:52:55 +0000 Subject: [PATCH] DQR-4292 - JAMF integration issues Changed back to use the bulk devices endpoint and fixed it so that it now works. --- device42.py | 13 +++++++------ starter.py | 21 +++------------------ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/device42.py b/device42.py index 07bef60..dc4cbb5 100644 --- a/device42.py +++ b/device42.py @@ -12,11 +12,12 @@ def __init__(self, config, options): self.dry_run = options['dry_run'] def _poster(self, data, url): + payload = data headers = { 'Authorization': 'Basic ' + base64.b64encode(self.username + ':' + self.password) } - r = requests.post(url, data, headers=headers, verify=False) + r = requests.post(url, json=payload, headers=headers, verify=False) if self.debug: msg1 = unicode(data) msg2 = 'Status code: %s' % str(r.status_code) @@ -85,10 +86,10 @@ def delete(self, identity, name): print msg return self._deleter(url).json() - # POST - def post(self, data, name): - url = 'https://%s/api/1.0/%s/' % (self.host, name) - msg = '\tPost request to %s ' % url + # BULK + def bulk(self, data): + url = 'https://%s/api/1.0/devices/bulk/' % self.host + msg = '\tBulk request to %s ' % url if not self.dry_run: print msg - return self._poster(data, url).json() + return self._poster({'payload': data}, url).text diff --git a/starter.py b/starter.py index a1823b6..1b9eae5 100644 --- a/starter.py +++ b/starter.py @@ -78,41 +78,35 @@ def get_computers(self): def get_device_network(general): macs = [] ips = [] - device_name = general['name'] if general['mac_address']: macs.append({ 'macaddress': general['mac_address'], - 'device': device_name }) if general['alt_mac_address']: macs.append({ 'macaddress': general['alt_mac_address'], - 'device': device_name }) if general['ip_address']: ips.append({ 'ipaddress': general['ip_address'], - 'device': device_name }) if general['last_reported_ip']: ips.append({ 'ipaddress': general['last_reported_ip'], - 'device': device_name }) return macs, ips @staticmethod - def get_device_software(applications, device_name): + def get_device_software(applications): software = [] for item in applications['applications']: software.append({ 'software': item['name'], 'version': item['version'], - 'device': device_name }) return software @@ -127,7 +121,7 @@ def main(): } for device in devices: macs, ips = integration.get_device_network(device['general']) - software = integration.get_device_software(device['software'], device['general']['name']) + software = integration.get_device_software(device['software']) if options['no_ips']: ips = [] @@ -145,14 +139,5 @@ def main(): if __name__ == '__main__': elements = main() for element in elements['devices']: - print device42_api.post(element['device'], 'devices') - - for mac in element['macs']: - print device42_api.post(mac, 'macs') - - for ip in element['ips']: - print device42_api.post(ip, 'ips') - - for software in element['software']: - print device42_api.post(software, 'software_details') + print device42_api.bulk(element) print '\n Finished'