Skip to content

Commit

Permalink
Merge pull request #10 from cscaglioned42/DQR-4292
Browse files Browse the repository at this point in the history
DQR-4292 - JAMF integration issues
  • Loading branch information
cscaglioned42 committed Aug 27, 2021
2 parents e03c79e + aa3f9cc commit 434a0a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
13 changes: 7 additions & 6 deletions device42.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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
21 changes: 3 additions & 18 deletions starter.py
Expand Up @@ -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
Expand All @@ -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 = []
Expand All @@ -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'

0 comments on commit 434a0a5

Please sign in to comment.