Blog Post

Tech Talk
1 MIN READ

Nice little trick when needing to match against a number of devices

Michael_Baker's avatar
3 months ago

We have many situations where we need to address a number of devices based on certain properties so we made a small function take you choice of language hit up the API you get a list of devices back with the device id which you can use  in further loops

Endpoint /santaba/rest/functions comes back in a object under currentMatches

JSON body:

{
"type": "testAppliesTo",
"originalAppliesTo": "your-applies-to-filter",
"currentAppliesTo": "your-applies-to-filter"
}

An example of us using it was we needed to identify and tag hundreds of devices using this combined with LM python wrapper made it simple much nicer than making a CSV and looping

Would be nice to see this as a method in the SDK rather than a monkey patch though ;) 

Published 3 months ago
Version 1.0

3 Comments

  • It took me a while to figure out what you’re doing. You are posting to /functions and the response contains the list of devices that match. You do this so that you can target a list of devices using an AppliesTo expression rather than a filter. 

    You can accomplish the same thing without doing an additional API call and not have to use an unsupported endpoint by using advanced filtering.

    Much easier than using filters when you have multiple teams… ./do-thing.py -f ‘getPropValue(“….”) && getPropValue(“wmi.user”) =~ “” && getPropValue(“..”) && (thing | that)” 

    Much easier than writing advanced filters ;) especially when that output is then used in opther monkey patched calls..

  • It took me a while to figure out what you’re doing. You are posting to /functions and the response contains the list of devices that match. You do this so that you can target a list of devices using an AppliesTo expression rather than a filter. 

    You can accomplish the same thing without doing an additional API call and not have to use an unsupported endpoint by using advanced filtering.

  • I like this as a way to use appliesTo to make sure that you will get the same results with the same language in/out of the portal.  Using this to drive ad hoc reports using powershell and the RestAPI to overcome the limitations of the reports in portal is a big win from my perspective.

    This is a good find, thank you for sharing.