Posted on 07-23-2019 12:22 PM
Working on a script right now to export JAMF info to an ITAM solution.
So far I no issue pulling in any hardware info, since each has a unique name. I can't, however, figure out a way to grab the software.
Here's the meat of the script:
CI_type = 'Computer'
TAGS_CORRELATIONS = { 'serial_number': 'CI Name', 'name': 'Hostname', 'model_identifier': 'Model', 'building': 'JAMF Location',
'model': 'Description',
'total_ram': 'Total Memory',
'username': 'Last Logged User',
'os_name': 'OS',
'os_version': 'OS Version',
'make': 'Manufacturer',
'mac_address': 'Primary MAC Address',
'alt_mac_address': 'Secondary MAC Address',
'????': 'Software_Info',
}
JAMF_CREDENTIALS = base64.b64encode(bytes(JAMF_USENAME ':' JAMF_PASSWORD, 'utf-8')).decode('utf-8')
jamf_headers = {
"authorization": "Basic " + JAMF_CREDENTIALS,
"accept": "application/json"
}
errors = []
def xml_wrapper(func): def wrapper(args, kwargs): result = func(args, kwargs) reparsed = minidom.parseString(result) xml_string = reparsed.toxml(encoding='UTF-8').decode('UTF-8') print('XML sent to MEngine: ', reparsed.toprettyxml(indent=' ')) return xml_string return wrapper
def fetch_computer_by_id(session, computer_id): response = session.get( '{url}/JSSResource/computers/id/{id_n}'.format(url=JAMF_PRO_URL, id_n=str(computer_id)), headers={**jamf_headers, 'accept': 'application/xml'} ) return response.text
def set_parameter(record, name, value): parameter = ET.SubElement(record, 'parameter') p_name = ET.SubElement(parameter, 'name') p_value = ET.SubElement(parameter, 'value') p_name.text = name p_value.text = value