Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Create/Update Advanced Computer Search Methods Sending Empty Criteria #55

Open
mhrono opened this issue Nov 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mhrono
Copy link

mhrono commented Nov 14, 2024

tl;dr when attempting to create or update an advanced computer search (using the create_advanced_computer_search or update_advanced_computer_search_by_id methods, respectively), the operation is completed successfully, except for the search criteria. Name and display fields are set as configured, but any criteria sent are seemingly ignored, and the search is created/updated with no criteria. This effectively places every device into the results for the advanced computer search.

Reproduction details below will be for creating a search, but the result is the same when attempting to update an existing search.

Steps to Reproduce

from jamf_pro_sdk import JamfProClient, SessionConfig
from jamf_pro_sdk.models.classic import computer_groups, advanced_computer_searches
from jamf_pro_sdk.models.classic.criteria import ClassicCriterion
from jamf_pro_sdk.clients.auth import ApiClientCredentialsProvider

jamfClient = JamfProClient(
	server=jamfURL,
	credentials=ApiClientCredentialsProvider(jamfClientID, jamfClientSecret),
	session_config=SessionConfig(**{"timeout": 30, "max_retries": 3}),
)

notUpdatedSearchData = advanced_computer_searches.ClassicAdvancedComputerSearch(
	name="macOS Version Not Current",
	criteria=[
		ClassicCriterion(
			name='Managed',
			priority=0,
			and_or='and',
			search_type='is',
			value='Managed',
			opening_paren=False,
			closing_paren=False
		),
		ClassicCriterion(
			name='Operating System Version',
			priority=1,
			and_or='and',
			search_type='less than',
			value='15.1',
			opening_paren=False,
			closing_paren=False
		)
	],
	display_fields=[
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="JSS Computer ID"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Last Check-in"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Serial Number"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Operating System Version"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Username"
		),
	],
)

searchID = jamfClient.classic_api.create_advanced_computer_search(data=notUpdatedSearchData)
searchData = jamfClient.classic_api.get_advanced_computer_search_by_id(advanced_search=searchID)
print(searchData)

Expected Result

Expected an advanced computer search to be created with the following criteria:
image

Actual Result

Advanced computer search created with no criteria:
image

id=6 name='macOS Version Not Current' site=ClassicSite(id=-1, name='None') criteria=[] display_fields=[ClassicAdvancedComputerSearchDisplayField(name='Username'), ClassicAdvancedComputerSearchDisplayField(name='Operating System Version'), ClassicAdvancedComputerSearchDisplayField(name='JSS Computer ID'), ClassicAdvancedComputerSearchDisplayField(name='Serial Number'), ClassicAdvancedComputerSearchDisplayField(name='Last Check-in')] 

(omitted computers from above output)

Additional Data

If I retrieve the criteria from an existing advanced computer search (with correct criteria) and feed that directly into the create method, I would definitely expect this criteria to be valid and accepted. Even doing this, the new search is created with no criteria:

knownGoodSearchCriteria = jamfClient.classic_api.get_advanced_computer_search_by_id(advanced_search=5).criteria
print(knownGoodSearchCriteria)

####
[ClassicCriterion(name='Managed', priority=0, and_or='and', search_type='is', value='Managed', opening_paren=False, closing_paren=False), ClassicCriterion(name='Operating System Version', priority=1, and_or='and', search_type='less than', value='15.1', opening_paren=False, closing_paren=False)]
####

notUpdatedSearchData = advanced_computer_searches.ClassicAdvancedComputerSearch(
	name="macOS Version Not Current",
	criteria=knownGoodSearchCriteria,
	display_fields=[
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="JSS Computer ID"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Last Check-in"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Serial Number"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Operating System Version"
		),
		advanced_computer_searches.ClassicAdvancedComputerSearchDisplayField(
			name="Username"
		),
	],
)

searchID = jamfClient.classic_api.create_advanced_computer_search(data=notUpdatedSearchData)
searchData = jamfClient.classic_api.get_advanced_computer_search_by_id(advanced_search=searchID)

print(searchData)

####
id=7 name='macOS Version Not Current' site=ClassicSite(id=-1, name='None') criteria=[] display_fields=[ClassicAdvancedComputerSearchDisplayField(name='Username'), ClassicAdvancedComputerSearchDisplayField(name='JSS Computer ID'), ClassicAdvancedComputerSearchDisplayField(name='Last Check-in'), ClassicAdvancedComputerSearchDisplayField(name='Serial Number'), ClassicAdvancedComputerSearchDisplayField(name='Operating System Version')]
####

(again omitted computers)

System Information

macOS 15.1
Python 3.12.1
SDK 0.6a2
Jamf Pro 11.10.2

@mhrono mhrono added the bug Something isn't working label Nov 14, 2024
@mhrono
Copy link
Author

mhrono commented Nov 14, 2024

After discussing with @brysontyrrell in Slack, I attempted to create a search by dumping the model to XML and using the classic_api_request method:

jamfClient.classic_api_request(method="POST", resource_path="advancedcomputersearches/id/0", data=notUpdatedSearchData.xml())

Unfortunately, this search was also created with no criteria. Examining the output of notUpdatedSearchData.xml() seems to point to the issue:

<?xml version="1.0" encoding="UTF-8" ?><advanced_computer_search><name>testxml</name><criteria><None><name>Managed</name><priority>0</priority><and_or>and</and_or><search_type>is</search_type><value>Managed</value><opening_paren>false</opening_paren><closing_paren>false</closing_paren></None><None><name>Operating System Version</name><priority>1</priority><and_or>and</and_or><search_type>less than</search_type><value>15.1</value><opening_paren>false</opening_paren><closing_paren>false</closing_paren></None></criteria><display_fields><display_field><name>JSS Computer ID</name></display_field><display_field><name>Last Check-in</name></display_field><display_field><name>Serial Number</name></display_field><display_field><name>Operating System Version</name></display_field><display_field><name>Username</name></display_field></display_fields></advanced_computer_search>

It looks like each criterion is being surrounded by a <None> tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant