Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
# jamfexplore
Script to sync JAMF to Device42 (http://www.device42.com)
This script was tested with JSS v9.97.1483031164 and Device42 v12.

# Requirements
Take the file `config.yaml.example` and rename it to `config.yaml`. Then change the settings to correct ones.
Please install requirements `pip install -r requirements.txt`

# Run
Puppet :
```
python starter.py
```

# Specification
Current script version migrate `devices, ips, macs and software data`. If you have any requests\improvements, feel free to contact us.
MOVED TO BITBUCKET ON 2021-01-10. DM ME FOR ACCESS. -MW
59 changes: 57 additions & 2 deletions config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,69 @@
device42:
host: 192.168.0.1
username: admin
password: pass
password: adm!nd42

jamf:
host: __subdomain__.jamfcloud.com
host: tryitout.jamfcloud.com
username: admin
password: pass

options:
debug: True
dry_run: False
no_ips: False

custom_fields:
"mobile_device":
[
{
"dict": "general",
"key" : "last_inventory_update",
"type": "text",
"related_field_name":
},
{
"dict": "general",
"key" : "phone_number",
"type": "text",
"related_field_name":
},
{
"dict": "location",
"key" : "username",
"type": "related_field",
"related_field_name": "endusers"
}
]

"computer":
[
{
"dict": "location",
"key" : "username",
"type": "related_field",
"related_field_name": "endusers"
}
]

"enduser":
[
{
"dict": "location",
"key" : "real_name",
"type": "text",
"related_field_name":
},
{
"dict": "location",
"key" : "position",
"type": "text",
"related_field_name":
},
{
"dict": "location",
"key" : "department",
"type": "text",
"related_field_name":
}
]
41 changes: 41 additions & 0 deletions device42.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ def _poster(self, data, url):

return r

def _put(self, data, url):
payload = data
headers = {
'Authorization': 'Basic ' + base64.b64encode(self.username + ':' + self.password)
}

r = requests.put(url=url, data=payload, headers=headers, verify=False)

if self.debug:
msg1 = unicode(payload)
msg2 = 'Status code: %s' % str(r.status_code)
msg3 = str(r.text)

print '\n\t----------- PUT FUNCTION -----------'
print '\t' + msg1
print '\t' + msg2
print '\t' + msg3
print '\t------- END OF PUT FUNCTION -------\n'

return r

def _getter(self, data, url):
params = data
headers = {
Expand Down Expand Up @@ -94,4 +115,24 @@ def bulk(self, data):
print msg
return self._poster({'payload': json.dumps(data)}, url).json()

# POST - END USER
def post_enduser(self, data):
url ='https://%s/api/1.0/endusers/' %self.host
return self._poster(data, url).json()

# POST - BUILDING
def post_building(self, data):
url ='https://%s/api/1.0/buildings/' %self.host
return self._poster(data, url).json()

# PUT - END USER CUSTOM FIELDS
def put_enduserCF(self, data):
url ='https://%s/api/1.0/custom_fields/endusers/' %self.host
return self._put(data, url).json()

# PUT - DEVICE CUSTOM FIELDS
def put_deviceCF(self, data):
url ='https://%s/api/1.0/device/custom_field/' %self.host
return self._put(data, url).json()


18 changes: 12 additions & 6 deletions jamf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import requests

import json

class JamfApi:

Expand All @@ -9,13 +9,19 @@ def __init__(self, config, options):
self.debug = options['debug']
self.headers = {
'Content-Type': 'text/xml',
'Accept': 'application/json'
'accept': 'application/json'
}

def get_list(self, name):
return requests.get('https://%s/JSSResource/%s' % (self.host, name),
auth=self.auth, headers=self.headers).json()
return requests.get('https://%s/JSSResource/%s' % (self.host, name),
auth = self.auth,
headers=self.headers
#verify = False
).json()

def get_item(self, name, pk):
return requests.get('https://%s/JSSResource/%s/id/%s' % (self.host, name, pk),
auth=self.auth, headers=self.headers).json()
return requests.get('https://%s/JSSResource/%s/id/%s' % (self.host, name, pk),
auth = self.auth,
headers=self.headers
#verify = False
).json()
Loading