def updateMobileDeviceInventory(mobileSearch, username, password):
    print "Running refactored updateMobileDeviceInventory...\n"
    print 'Issuing Update Inventory command for mobile device ' + mobileSearch + ' ...'
    mobile_id = mobiledevice_core.getMobileDeviceId(mobileSearch, username,
                                                    password)
    if str(mobile_id) == '-1':
        print 'Mobile device ' + mobileSearch + ' not found, please try again.'
        return -1
    elif str(mobile_id) == '-2':
        print 'More than one mobile device matching search string ' + str(
            mobileSearch) + ', please try again.'
        return -1

    #postStr = jss_api_base_url + '/mobiledevicecommands/command/UpdateInventory/id/' + mobile_id
    postStr = jss_api_base_url + '/mobiledevicecommands/command/UpdateInventory'

    postXML = "<mobile_device_command><command>UpdateInventory</command><mobile_devices><mobile_device><id>" + mobile_id + "</id></mobile_device></mobile_devices></mobile_device_command>"
    #print postStr
    #print postXML
    #return

    response = apirequests.sendAPIRequest(postStr, username, password, 'POST',
                                          postXML)

    if response == -1:
        print 'Failed to issued update inventory command for device ' + mobileSearch
        return -1
    else:
        print 'Successfully issued update inventory command for device ' + mobileSearch
        return 1
def getAllComputersBasic(username, password, sn=False):
	''' Query Jamf API for all Computers using the Basic Subset query to return limited details on each, create dictionary, return dict for iteration in other methods '''

	reqStr = jss_api_base_url + '/computers/subset/basic'
	compsBasicDict = {}

	r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

	if r == -1:
		return

	baseXml = r.read()
	# print baseXml
	responseXml = etree.fromstring(baseXml)

	# computers = responseXml.find('computers')

	if sn:
		for comp in responseXml.findall('computer'):
			serial = comp.find('serial_number').text
			jssID = comp.find('id').text
			compsBasicDict.update({jssID: serial})

	else:
		for comp in responseXml.findall('computer'):
			compname = comp.find('name').text
			jssID = comp.find('id').text
			compsBasicDict.update({jssID: compname})

	return compsBasicDict
def getComputerId(computerSearch, username, password):
	print 'Running refactored getComputerId...\n'
	computerSearch_normalized = urllib2.quote(computerSearch)

	reqStr = jss_api_base_url + '/computers/match/' + computerSearch_normalized

	r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

	if r == -1:
		return -1

	#responseCode = r.code
	baseXml = r.read()
	#print baseXml
	responseXml = etree.fromstring(baseXml)

	response_size = responseXml.find('size').text

	if response_size == '0':
		#print 'Mobile Device not found, please search again.'
		return -1
	elif response_size == '1':
		return responseXml.find('computer/id').text
	else:
		#print 'Too many results, narrow your search paramaters.'
		return -2
def clearMobileDevicePasscode(mobileSearch, username, password):
    print "Running refactored clearMobileDevicePasscode...\n"
    print 'Issuing Clear Passcode command for mobile device ' + mobileSearch + ' ...'
    mobile_id = mobiledevice_core.getMobileDeviceId(mobileSearch, username,
                                                    password)
    if str(mobile_id) == '-1':
        print 'Mobile device ' + mobileSearch + ' not found, please try again.'
        return -1
    elif str(mobile_id) == '-2':
        print 'More than one mobile device matching search string ' + str(
            mobileSearch) + ', please try again.'
        return -1

    postStr = jss_api_base_url + '/mobiledevicecommands/command/ClearPasscode'

    postXML = "<mobile_device_command><command>ClearPasscode</command><mobile_devices><mobile_device><id>" + mobile_id + "</id></mobile_device></mobile_devices></mobile_device_command>"

    response = apirequests.sendAPIRequest(postStr, username, password, 'POST',
                                          postXML)

    if response == -1:
        print 'Failed to issued clear passcode command for device ' + mobileSearch
        return -1
    else:
        print 'Successfully issued clear passcode command for device ' + mobileSearch
        return 1
def updateMobileAssetTag(mobileSearch, asset_tag, username, password):
    print "Running refactored updateMobileAssetTag...\n"
    print 'Updating asset tag for mobile device ' + mobileSearch + ' with asset tag ' + asset_tag + '...'
    mobile_id = mobiledevice_core.getMobileDeviceId(mobileSearch, username,
                                                    password)
    if str(mobile_id) == '-1':
        print 'Mobile device ' + mobileSearch + ' not found, please try again.'
        return
    elif str(mobile_id) == '-2':
        print 'More than one mobile device matching search string ' + str(
            mobileSearch) + ', please try again.'
        return

    putStr = jss_api_base_url + '/mobiledevices/id/' + mobile_id
    #print putStr

    putXML = "<mobile_device><general><asset_tag>" + asset_tag + "</asset_tag></general></mobile_device>"
    response = apirequests.sendAPIRequest(putStr, username, password, 'PUT',
                                          putXML)

    if response == -1:
        print 'Failed to update asset tag for mobile device ' + mobileSearch + ', see error above.'
        return
    else:
        print 'Successfully updated asset tag for mobile device ' + mobileSearch + '.'
Exemple #6
0
def getSupervisedMobileDeviceId(mobileDeviceName, username, password):
    print "Running refactored getSupervisedMobileDeviceId...\n"
    mobileDeviceName_normalized = urllib2.quote(mobileDeviceName)

    mobile_device_id = getMobileDeviceId(mobileDeviceName, username, password)

    if mobile_device_id == '-1' or mobile_device_id == '-2':
        print 'Please refine your search.'
        return -1
    else:
        reqStr = jss_api_base_url + '/mobiledevices/id/' + mobile_device_id
        r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')
        if r == -1:
            return -1

        #responseCode = r.code
        baseXml = r.read()
        #print baseXml
        responseXml = etree.fromstring(baseXml)
        #print prettify(responseXml)
        #raise SystemExit

        supervised = responseXml.find('general/supervised').text
        if supervised == 'false':
            return -3
        else:
            return mobile_device_id
def removeMobileDeviceFromGroup(mobile_device, mobile_device_group, username, password):
    print "Running refactored removeMobileDeviceFromGroup...\n"
    # Find mobile device JSS ID
    mobile_device_id = mobiledevice_core.getMobileDeviceId(mobile_device, username, password)
    if str(mobile_device_id) == '-1':
        print 'Mobile device ' + mobile_device + ' not found, please try again.'
        return
    elif str(mobile_device_id) == '-2':
        print 'More than one mobile device matching search string ' + mobile_device + ', please try again.'
        return

    # Find mobile device group ID
    mobile_device_group_id = getMobileDeviceGroup(mobile_device_group, username, password)
    if str(mobile_device_group_id) == '-1':
        print 'Mobile device group ' + mobile_device_group + ' not found, please try again.'
        return

    print 'Removing mobile device id ' + str(mobile_device_id) + ' from group id ' + str(mobile_device_group_id)

    putStr = jss_api_base_url + '/mobiledevicegroups/id/' + str(mobile_device_group_id)
    putXML = '<mobile_device_group><mobile_device_deletions><mobile_device><id>' + str(mobile_device_id) + '</id></mobile_device></mobile_device_deletions></mobile_device_group>'

    #print putStr
    #print putXML
    #return

    response = apirequests.sendAPIRequest(putStr, username, password, 'PUT', putXML)

    if response == -1:
        print 'Failed to remove mobile device ' + mobile_device + ' to group, see error above.'
        return
    else:
        print 'Successfully remove mobile device ' + mobile_device + ' to group ' + mobile_device_group + '.'
Exemple #8
0
def getMobileDeviceId(mobileDeviceName, username, password):
    print "Running refactored getMobileDeviceByID...\n"
    try:
        mobileDeviceName_normalized = urllib2.quote(mobileDeviceName)
        reqStr = jss_api_base_url + '/mobiledevices/match/' + mobileDeviceName_normalized

        r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

        if r == -1:
            return -1

        #responseCode = r.code
        baseXml = r.read()
        #print baseXml
        responseXml = etree.fromstring(baseXml)

        response_size = responseXml.find('size').text

        if response_size == '0':
            #print 'Mobile Device not found, please search again.'
            return -1
        elif response_size == '1':
            return responseXml.find('mobile_device/id').text
        else:
            #print 'Too many results, narrow your search paramaters.'
            return -2
    except KeyError as error:
        print 'Problem parsing device name. Possibly an invalid character'
        print error
def getCompEAbyEAname(compID, searchStr, username, password):
    ''' Returns specific details for an Extension Attribute based upon that computer's
    JSS ID and the EA's JSS ID as arguments '''

    print "Running Refactored getCompEAbyEAID...\n"
    reqStr = jss_api_base_url + '/computers/id/' + compID

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    baseXml = r.read()
    responseXml = etree.fromstring(baseXml)
    extension_attributes = responseXml.find('extension_attributes')
    eaInfo = []

    for ea in extension_attributes.findall('extension_attribute'):
        eaID = ea.find('id').text
        eaName = ea.find('name').text
        eaValue = ea.find('value').text
        # print eaName
        if searchStr in eaName:
            eaInfo.append('EA ID: ' + str(eaID) + ' --- ' + str(eaName) +
                          ': ' + str(eaValue))

    if eaInfo:
        print '\n\n'.join(sorted(eaInfo))
    else:
        print 'No Extension Attribute was found containing: {}.  Try using another search string instead.\n'.format(
            searchStr)
Exemple #10
0
def getMobileDevice(mobileDeviceName, username, password, detail):
    print "Running refactored getMobileDevice...\n"

    mobileDeviceName_normalized = urllib2.quote(mobileDeviceName)
    reqStr = jss_api_base_url + '/mobiledevices/match/' + mobileDeviceName_normalized
    #print reqStr
    #print detail

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    #responseCode = r.code
    baseXml = r.read()
    #print baseXml
    responseXml = etree.fromstring(baseXml)

    print 'All mobile devices with ' + mobileDeviceName + ' as part of the device information:\n'

    for mobile_device in responseXml.findall('mobile_device'):
        name = mobile_device.find('name').text
        sn = mobile_device.find('serial_number').text
        mac_addr = mobile_device.find('mac_address').text
        jssID = mobile_device.find('id').text

        if detail == 'yes':
            getMobileDeviceByID(jssID, username, password)
        else:
            print 'Mobile Device Name: ' + name
            print 'Serial Number: ' + sn
            print 'Mac Address: ' + str(mac_addr)
            print 'JSS Mobile Device ID: ' + jssID + '\n'
def getCompEAsbyCompID(compID, username, password):
    ''' List all Extension Attributes for computer in JSS to screen -
    including Extension Attribute's ID value for reference and additional lookup '''

    print "We're Refactored!  Getting All Computer Extension Attributes..."
    reqStr = jss_api_base_url + '/computers/id/' + compID

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    baseXml = r.read()
    responseXml = etree.fromstring(baseXml)
    extension_attributes = responseXml.find('extension_attributes')
    eas = []

    print '\nEXTENSION ATTRIBUTES:'

    for ea in extension_attributes.findall('extension_attribute'):
        eaID = ea.find('id').text
        eaName = ea.find('name').text
        eaValue = ea.find('value').text
        eaInfo = '(EA ID:  ' + str(eaID) + ') --- ' + str(eaName) + ': ' + str(
            eaValue)
        eas += [eaInfo]

    print '\n'.join(sorted(eas))
def removeComputerFromGroup(computer, computer_group, username, password):
	print 'Running refactored removeComputerFromGroup...\n'
	# Find computer JSS ID
	computer_id = getComputerId(computer, username, password)

	if str(computer_id) == '-1':
		print 'Computer ' + computer + ' not found, please try again.'
		return
	elif str(computer_id) == '-2':
		print 'More than one computer found matching search string ' + computer + ', please try again.'
		return

	# Find computer group JSS ID
	computer_group_id = computergroups.getComputerGroupId(computer_group, username, password)
	if str(computer_group_id) == '-1':
		print 'Computer group ' + computer_group + ' not found, please try again.'
		return

	print 'Removing computer id ' + str(computer_id) + ' from computer group id ' + str(computer_group_id)

	putStr = jss_api_base_url + '/computergroups/id/' + str(computer_group_id)
	putXML = '<computer_group><computer_deletions><computer><id>' + str(computer_id) + '</id></computer></computer_deletions></computer_group>'

	#print putStr
	#print putXML
	#return

	response = apirequests.sendAPIRequest(putStr, username, password, 'PUT', putXML)

	if response == -1:
		print 'Failed to remove computer ' + computer + ' from group, see error above.'
		return
	else:
		print 'Successfully removed computer ' + computer + ' from group ' + computer_group + '.'
def getCompEAbyEAID(compID, extattribID, username, password):
    ''' Returns specific details for an Extension Attribute based upon that computer's
    JSS ID and the EA's JSS ID as arguments - for use within other functions '''

    print "Running Refactored getCompEAbyEAID...\n"
    reqStr = jss_api_base_url + '/computers/id/' + compID

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    baseXml = r.read()
    responseXml = etree.fromstring(baseXml)
    extension_attributes = responseXml.find('extension_attributes')

    for ea in extension_attributes.findall('extension_attribute'):
        eaID = ea.find('id').text
        eaName = ea.find('name').text
        eaValue = ea.find('value').text
        # print eaID
        if eaID == extattribID:
            eaInfo = 'EA ID:  ' + str(eaID) + ' --- ' + str(
                eaName) + ': ' + str(eaValue)
            print '\nFound the following extension attribute:  ' + eaInfo + '\n'
            continueRun = raw_input(
                'If this is correct, press ENTER to continue...')
            if continueRun != None:
                # print eaID
                return eaID
            else:
                print 'Extension Attribute with ID: {} not found in JSS.  Check the Extension Attribute ID again.\n'.format(
                    extattribID)
def getAllComputerGroups(username, password):
    ''' Lists all computer groups in JSS to screen, returning ID, name, and type '''
    print 'Running refactored getAllComputerGroups...\n'

    print "Getting All JAMF Computer Groups...\n"
    reqStr = jss_api_base_url + '/computergroups'

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    baseXml = r.read()
    responseXml = etree.fromstring(baseXml)
    groupCount = 0
    smartCount = 0
    staticCount = 0

    for group in responseXml.findall('computer_group'):
        groupCount += 1
        groupID = group.find('id').text
        groupName = group.find('name').text

        if group.find('is_smart').text == 'true':
            groupType = 'Smart'
            smartCount += 1
        else:
            groupType = 'Static'
            staticCount += 1

        print 'Group ID: ' + groupID + ', ' + 'Group Name: ' + groupName + 'Group Type: ' + groupType + '\n'

    print '\nThere are {} total Computer Groups in the JSS'.format(groupCount)
    print '\nThere are {} Smart Groups, and {} Static Groups\n'.format(smartCount, staticCount)
def wipeMobileDeviceNoConfirm(mobile_id, username, password):
    print "Running refactored wipeMobileDeviceNoConfirm...\n"
    postStr = jss_api_base_url + '/mobiledevicecommands/command/EraseDevice'

    postXML = "<mobile_device_command><command>EraseDevice</command><mobile_devices><mobile_device><id>" + mobile_id + "</id></mobile_device></mobile_devices></mobile_device_command>"
    print 'Issuing erase device command for mobile device id ' + mobile_id + ' ...'
    response = apirequests.sendAPIRequest(postStr, username, password, 'POST',
                                          postXML)
def wipeMobileDevice(mobileSearch, username, password, force):
    print "Running refactored wipeMobileDevice...\n"

    try:

        print 'Mobile Device wipe requested, getting information for mobile device ' + mobileSearch + ' ...'

        mobile_id = mobiledevice_core.getMobileDeviceId(
            mobileSearch, username, password)
        if str(mobile_id) == '-1':
            print 'Mobile device ' + mobileSearch + ' not found, please try again.'
            return -1
        elif str(mobile_id) == '-2':
            print 'More than one mobile device matching search string ' + str(
                mobileSearch) + ', please try again.'
            return -1

        if force == 'yes':
            print "Wiping device %s without confirmation" % mobile_id
            #return
            wipeMobileDeviceNoConfirm(mobile_id, username, password)
        else:

            postStr = jss_api_base_url + '/mobiledevicecommands/command/EraseDevice'

            postXML = "<mobile_device_command><command>EraseDevice</command><mobile_devices><mobile_device><id>" + mobile_id + "</id></mobile_device></mobile_devices></mobile_device_command>"

            mobiledevice_core.getMobileDeviceByID(mobile_id, username,
                                                  password)

            usrInput = raw_input(
                '\nAre you sure you want to wipe the mobile device listed above? [y/n]: '
            )

            if usrInput == 'y':
                print 'Issuing erase device command for mobile device ' + mobileSearch + ' ...'
                #return 1
                response = apirequests.sendAPIRequest(postStr, username,
                                                      password, 'POST',
                                                      postXML)

                if response == -1:
                    print 'Failed to issue wipe command for device ' + mobileSearch
                    return -1
                else:
                    print 'Successfully issued wipe command for device ' + mobileSearch
                    return 1
            else:
                print 'Aborting request to wipe mobile device...'
                return -1

    except TypeError as error:
        print 'There was a problem getting device details, unable to issue wipe command. \nCheck for irregular characters in the Device name.'
        continueInput = raw_input('\nPress ENTER to continue...')
        if continueInput != '':
            return
def getUserEmailByComputerID(compID, username, password):
	print 'Running refactored getUserEmailByComputerID...\n'
	reqStr = jss_api_base_url + '/computers/id/' + compID
	r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

	if r != 1:
		baseXml = r.read()
		#print baseXml
		responseXml = etree.fromstring(baseXml)
		email_address = responseXml.find('location/email_address').text
		return email_address
	else:
		return -1
def getComputerGroupMembers(groupSearch, username, password):
    print 'Running refactored getComputerGroupMembers...\n'
    print 'Printing CSV of all members of the group matching ' + groupSearch + '...'
    # Find computer group JSS ID
    computer_group_id = getComputerGroupId(groupSearch, username, password)
    if str(computer_group_id) == '-1':
        print 'Computer group ' + groupSearch + ' not found, please try again.'
        return

    reqStr = jss_api_base_url + '/computergroups/id/' + str(computer_group_id)

    try:
        r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')
        #responseCode = str(r.code)

        #if '200' in str(responseCode):
        if r != -1:
            xmlstring = r.read()
            #print str(xmlstring)

            xml = etree.fromstring(xmlstring)
            #print prettify(xml)

            computers = xml.find('computers')
            members = []

            ## Add Header Row for CSV
            headerRow = "Computer Name, JSS ID, Serial Number"
            members += [ headerRow ]

            for computer in computers.findall('computer'):
                #print str(computer)
                comp_id = computer.find('id').text
                name = computer.find('name').text
                serial_number = computer.find('serial_number').text
                #print str(comp_id)
                #computerInfo = str(name)
                #email_address = getUserEmailByComputerID(comp_id, username, password)
                computerInfo = str(name) + ', ' + str(comp_id) + ', ' + str(serial_number)
                computerInfo = cleanupOutput(computerInfo)
                #print computerInfo.encode('ascii', 'ignore')
                members += [ computerInfo ]

            print '\n'.join (sorted(members))
            print 'Total Computers: ' + str(len(members)-1)

        elif '401' in str(responseCode):
            print "Authorization failed"
    except urllib2.HTTPError, err:
        if '401' in str(err):
            print 'Authorization failed, goodbye.'
def getComputer(computerName, username, password, detail):
	print 'Running refactored getComputer ... with Serial Number option \n'

	reqStr = jss_api_base_url + '/computers/match/' + computerName
	#print reqStr
	#print detail

	r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

	if r == -1:
		return

	#responseCode = r.code
	baseXml = r.read()
	#print baseXml
	responseXml = etree.fromstring(baseXml)

	#print prettify(responseXml)
	#print etree.tostring(responseXml)

	#print 'Response Code: ' + str(responseCode)
	#print 'Root: ' + str(responseXml.tag)
	#print 'Attr: ' + str(responseXml.attrib)

	#for child in responseXml:
	#   print child.tag, child.attrib

	#for computer in responseXml.iter('computer'):
	#   print computer.attrib

	print 'All computers with ' + computerName + ' as part of the computer information:\n'

	for computer in responseXml.findall('computer'):
		name = computer.find('name').text
		asset_tag = computer.find('asset_tag').text
		sn = computer.find('serial_number').text
		mac_addr = computer.find('mac_address').text
		jssID = computer.find('id').text
		#fv2status = computer.find('filevault2_status').text

		#print 'FileVault2 Status: ' + fv2status + '\n'

		if detail == 'yes':
			getComputerByID(jssID, username, password)
		else:
			print 'Computer Name: ' + name
			print 'Asset Number: ' + str(asset_tag)
			print 'Serial Number: ' + sn
			print 'Mac Address: ' + str(mac_addr)
			print 'JSS Computer ID: ' + jssID + '\n'
def updateAssetTag(comp_id, asset_tag, username, password):
	print 'Running refactored updateAssetTag...\n'
	print 'Updating asset tag for computer ID ' + comp_id + ' with asset tag ' + asset_tag + '...'

	putStr = jss_api_base_url + '/computers/id/' + comp_id
	#print putStr

	putXML = "<computer><general><asset_tag>" + asset_tag + "</asset_tag></general></computer>"
	response = apirequests.sendAPIRequest(putStr, username, password, 'PUT', putXML)

	if response == -1:
		print 'Failed to update asset tag for computer ' + comp_id + ', see error above.'
		return
	else:
		print 'Successfully updated asset tag for computer ' + comp_id + '.'
Exemple #21
0
def listPolicyNamebyId(policyid, username, password):
    ''' Function to search for Policy ID by ID number and return name for
	use in functions '''

    reqStr = jss_api_base_url + '/policies/id/' + policyid + '/subset/General'

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r != -1:

        baseXml = r.read()
        responseXml = etree.fromstring(baseXml)
        general = responseXml.find('general')
        name = general.find('name').text

    return name
def lockMobileDevice(mobileSearch, username, password):
    print "Running refactored lockMobileDevice...\n"

    try:
        print 'Searching for mobile device ' + mobileSearch + '...'
        mobile_id = mobiledevice_core.getMobileDeviceId(
            mobileSearch, username, password)
        if str(mobile_id) == '-1':
            print 'Mobile device ' + mobileSearch + ' not found, please try again.'
            return -1
        elif str(mobile_id) == '-2':
            print 'More than one mobile device matching search string ' + str(
                mobileSearch) + ', please try again.'
            return -1

        postStr = jss_api_base_url + '/mobiledevicecommands/command/DeviceLock'
        postXML = "<mobile_device_command><command>DeviceLock</command><mobile_devices><mobile_device><id>" + mobile_id + "</id></mobile_device></mobile_devices></mobile_device_command>"
        #print postStr
        #print postXML
        #return

        mobiledevice_core.getMobileDeviceByID(mobile_id, username, password)

        usrInput = raw_input(
            '\nAre you sure you want to lock the mobile device listed above? [y/n]: '
        )
        if usrInput == 'y':
            print 'Issuing remote lock command...'
            #return 1
            response = apirequests.sendAPIRequest(postStr, username, password,
                                                  'POST', postXML)

            if response == -1:
                print 'Failed to issue lock command for device ' + mobileSearch
                return -1
            else:
                print 'Successfully issued lock command for device ' + mobileSearch
                return 1
        else:
            print 'Aborting request to lock mobile device...'
            return -1

    except TypeError as error:
        print 'There was a problem getting device details, unable to issue lock command. \nCheck for irregular characters in the Device name.'
        continueInput = raw_input('\nPress ENTER to continue...')
        if continueInput != '':
            return
def getMobileDeviceGroup(mobile_device_group_name, username, password):
    print "Running refactored getMobileDeviceGroup...\n"
    print 'Getting mobile device group named: ' + mobile_device_group_name + '...'
    mobile_device_group_name_normalized = urllib2.quote(mobile_device_group_name)

    reqStr = jss_api_base_url + '/mobiledevicegroups/name/' + mobile_device_group_name_normalized


    #print reqStr

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r != -1:
        responseCode = r.code

        #print 'Response Code: ' + str(responseCode)

        baseXml = r.read()
        responseXml = etree.fromstring(baseXml)

        mobileDeviceGroupId = responseXml.find('id').text
        mobileDeviceGroupSize = responseXml.find('mobile_devices/size').text

        #print prettify(responseXml)

        if str(mobileDeviceGroupSize) == '0':
            print 'No devices in this group'
            return mobileDeviceGroupId

        print 'Group ID: ' + mobileDeviceGroupId
        #print prettify(responseXml)
        mobiledevicemembers = responseXml.find('mobile_devices')

        mobiledevices = []
        for mobiledevice in mobiledevicemembers.findall('mobile_device'):
            mobiledevicename = mobiledevice.find('name').text
            mobiledeviceid = mobiledevice.find('id').text
            mobiledeviceserial = mobiledevice.find('serial_number').text
            mobiledeviceinfo = str(mobiledevicename) + ', ' + str(mobiledeviceid) + ', ' + str(mobiledeviceserial)
            mobiledevices += [ mobiledeviceinfo ]
        print 'All devices in group ' + mobile_device_group_name + ' [name, jss_id, serial_no]:\n'
        print '\n'.join (sorted (mobiledevices))
        print '\nTotal Devices: ' + str(len(mobiledevices))
        return mobileDeviceGroupId
    else:
        print 'Failed to find mobile device group with name ' + mobile_device_group_name
        return -1
Exemple #24
0
def listPolicyScopebyId(policyid, username, password):
    ''' Function to search for Policy ID by ID number and return scope details as a
	dict for use in functions '''

    reqStr = jss_api_base_url + '/policies/id/' + policyid + '/subset/Scope'

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    scopeData = []

    if r != -1:

        baseXml = r.read()
        responseXml = etree.fromstring(baseXml)
        scope = responseXml.find('scope')
        allcomputers = scope.find('all_computers').text
        groups = scope.find('computer_groups')
        comp_groups = []
        comp_groupIDs = []
        computers = scope.find('computers')
        members = []
        scope_details = {}

        for comp in computers.findall('computer'):
            if comp.find('name').text:
                name = comp.find('name').text
                members.append(name)

        for g in groups.findall('computer_group'):
            if g.find('name').text:
                group_name = g.find('name').text
                groupID = computergroups.getComputerGroupId(
                    group_name, username, password)
                comp_groups.append(group_name)
                comp_groupIDs.append(groupID)

        scope_details = {
            "Policy ID: ": policyid,
            "All computers?: ": allcomputers,
            "Computer groups: ": comp_groups,
            "Computer group IDs: ": comp_groupIDs,
            "Specific computers: ": members
        }

    return scope_details
Exemple #25
0
def listAllPolicyIds(username, password):
    ''' List all policy IDs in JSS - for function use - returns a list of Policy ID #s  '''

    reqStr = jss_api_base_url + '/policies'

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    baseXml = r.read()
    responseXml = etree.fromstring(baseXml)
    PolicyIDList = []
    for policy in responseXml.findall('policy'):
        policyID = policy.find('id').text
        PolicyIDList.append(policyID)

    return PolicyIDList
def deleteComputerByIDBulk(comp_id, username, password):
    ''' Same as deleteComputerbyID function with added error logging for playback '''

    compDict = computer_core.getComputerByIDShort(comp_id, username, password)

    # sure = raw_input('Are you sure you want to delete the computer above from the JSS? (y/n): ')

    # if sure == 'y':
    print "Deleting computer " + comp_id + "..."

    delStr = jss_api_base_url + '/computers/id/' + comp_id
    #print delStr
    response = apirequests.sendAPIRequest(delStr, username, password, 'DELETE')

    if response == -1:
        print 'Failed to delete computer. See errors above.'
        return compDict
    else:
        print 'Successfully deleted computer ' + comp_id
def getCompLocalAccounts(compID, username, password):
	''' Companion function for use in other methods, to look up Local accounts listed for JSS comp ID, and return usernames as list '''

	reqStr = jss_api_base_url + '/computers/id/' + compID
	r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

	if r != 1:
		baseXml = r.read()
		#print baseXml
		responseXml = etree.fromstring(baseXml)
		groups_accounts = responseXml.find('groups_accounts')
		local_accounts = groups_accounts.find('local_accounts')
		localusers = []
		for user in local_accounts.findall('user'):
			uname = user.find('name').text
			localusers.append(uname)
		return localusers
	else:
		return -1
def findComputer(computerName, username, password, detail, sn=False):
	''' Companion Function for use in other methods to lookup computer in JSS by search string (username) and return matching records as a list of JSS IDs '''

	if sn:
		reqStr = jss_api_base_url + '/computers/serialnumber/' + sn
	else:
		reqStr = jss_api_base_url + '/computers/match/' + computerName

	compMatches = []

	r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

	if r == -1:
		return

	#responseCode = r.code
	baseXml = r.read()
	#print baseXml
	responseXml = etree.fromstring(baseXml)

	if responseXml:
		print 'All computers with ' + computerName + ' as part of the computer information:\n'

		for computer in responseXml.findall('computer'):
			name = computer.find('name').text
			asset_tag = computer.find('asset_tag').text
			sn = computer.find('serial_number').text
			mac_addr = computer.find('mac_address').text
			jssID = computer.find('id').text
			#fv2status = computer.find('filevault2_status').text
			compMatches.append(jssID)

			print 'Computer Name: ' + name
			print 'Asset Number: ' + str(asset_tag)
			print 'Serial Number: ' + sn
			print 'Mac Address: ' + str(mac_addr)
			print 'JSS Computer ID: ' + jssID + '\n'

		return compMatches

	else:
		print "No computer matches found"
		return None
Exemple #29
0
def getAllPolicies(username, password):
    ''' List all policies in JSS to screen '''
    #print(username)

    print "We're Refactored!  Getting All JAMF Policies..."
    reqStr = jss_api_base_url + '/policies'

    r = apirequests.sendAPIRequest(reqStr, username, password, 'GET')

    if r == -1:
        return

    baseXml = r.read()
    responseXml = etree.fromstring(baseXml)

    for policy in responseXml.findall('policy'):
        policyName = policy.find('name').text
        policyID = policy.find('id').text

        print 'Policy ID: ' + policyID + ',  ' + 'Policy Name: ' + policyName + '\n'
def deleteMobileDeviceByID(mobile_id, username, password):
    print "Running refactored deleteMobileDeviceByID...\n"

    mobiledevice_core.getMobileDeviceByID(mobile_id, username, password)

    # Comment out raw input to remove deletion confirmations
    # sure = raw_input('Are you sure you want to delete the mobile device above from the JSS? (y/n): ')

    #if sure == 'y':

    print "Deleting mobile device " + mobile_id + "..."

    delStr = jss_api_base_url + '/mobiledevices/id/' + mobile_id
    #print delStr
    response = apirequests.sendAPIRequest(delStr, username, password, 'DELETE')

    if response == -1:
        print 'Failed to delete mobile device. See errors above.'
    else:
        print 'Successfully deleted mobile device ' + mobile_id