forked from device42/jamf_to_device42_sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarter.py
149 lines (117 loc) · 4.46 KB
/
starter.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import yaml
from jamf import JamfApi
from device42 import Device42Api
with open('config.yaml', 'r') as cfg:
config = yaml.load(cfg.read())
device42 = config['device42']
jamf = config['jamf']
options = config['options']
jamf_api = JamfApi(jamf, options)
device42_api = Device42Api(device42, options)
class Integration:
def __init__(self):
self.computers = jamf_api.get_list('computers')
def get_computers(self):
devices = []
for computer in self.computers['computers']:
device = {}
computer_data = jamf_api.get_item('computers', computer['id'])['computer']
general = computer_data['general']
hardware = computer_data['hardware']
software = computer_data['software']
purchase = computer_data['purchasing']
storage = hardware['storage']
if general['name']:
hdd_count = 0
hdd_size = 0
if storage:
for disk in storage:
if int(disk['drive_capacity_mb']) > 0:
hdd_count += 1
hdd_size += int(disk['drive_capacity_mb'])
if hdd_size > 0:
hdd_size = 1.0 * hdd_size / 1000 # convert to Gb
device.update({
'name': general['name'],
'new_name': general['name'],
'type': 'physical',
'manufacturer': 'Apple Inc.',
'hddcount': hdd_count,
'hddsize': hdd_size,
'uuid': general['udid'] if general['udid'] else None,
'hardware': hardware['model'] if hardware['model'] else None,
'os': hardware['os_name'] if hardware['os_name'] else None,
'osver': hardware['os_version'] if hardware['os_version'] else None,
'memory': hardware['total_ram_mb'] if hardware['total_ram_mb'] else None,
'cpucount': hardware['number_processors'] if hardware['number_processors'] else None,
'tags': general['asset_tag'] if general['asset_tag'] else None
})
if general['serial_number']:
device['serial_no'] = general['serial_number']
if hardware['processor_speed_mhz']:
device['cpupower'] = hardware['processor_speed_mhz']
if hardware['number_cores']:
device['cpucore'] = hardware['number_cores']
devices.append({
'device': {k: v for (k, v) in device.items() if str(v) != str(-1)},
'general': general,
'software': software,
'purchase': purchase
})
return devices
@staticmethod
def get_device_network(general):
macs = []
ips = []
if general['mac_address']:
macs.append({
'macaddress': general['mac_address'],
})
if general['alt_mac_address']:
macs.append({
'macaddress': general['alt_mac_address'],
})
if general['ip_address']:
ips.append({
'ipaddress': general['ip_address'],
})
if general['last_reported_ip']:
ips.append({
'ipaddress': general['last_reported_ip'],
})
return macs, ips
@staticmethod
def get_device_software(applications):
software = []
for item in applications['applications']:
software.append({
'software': item['name'],
'version': item['version'],
})
return software
def main():
integration = Integration()
devices = integration.get_computers()
data = {
'devices': []
}
for device in devices:
macs, ips = integration.get_device_network(device['general'])
software = integration.get_device_software(device['software'])
if options['no_ips']:
ips = []
data['devices'].append({
'device': device['device'],
'macs': macs,
'ips': ips,
'software': software
})
return data
if __name__ == '__main__':
elements = main()
for element in elements['devices']:
print device42_api.bulk(element)
print '\n Finished'