Can I pull a specific system property in an API call?
Hi,
I’m writing an API call that pulls only specific fields. I can get all the normal fields, but I want to get system.groups. System.groups is inside the systemProperties array of variables and I haven’t been able to figure out if I can pull it.
I’m using: &fields=name,displayName,collectorDescription,hostStatus and want to add systemProperties[system.groups] but can’t find any syntax that will work. I’ve found examples on how to Filter on a property, but not how to just display it.
Anyone know how I can do this?
Thanks.
Kel L
10 comments
kendall
OP wanted to call /device/devices and filter based on the value of system.groups to only return devices where the system.groups value matches.
I thought it might be helpful to be able to get to that property and then go from there.
LM User
OP wanted to call /device/devices and filter based on the value of system.groups to only return devices where the system.groups value matches.
kendall
@Kelemvor ~ the script here will pull the system.groups value for you: https://github.com/krshearman/LMAPI_v3/blob/main/GetDeviceProperties_SystemGroups.py
Hope it helps!
LM User
Yeah, filtering doesn’t help me. I’m actually filtering on the hoststatus field to pull all the “Dead” devices. I just wanted to have the Group show up in the results so I can tell easier what something is.
Not a huge deal if I can’t but would be nice if I could.
I’m actually on a chat with LM support right now and am assuming he’s about to give me the same answer. :)
Why not make a group based on that property then query /device/groups/{id}/devices?
mnagel
Sorry, one more point -- I was checking our backup script and we don’t actually use /properties there except for grouping results (/properties gives you all properties in a list, so it is appropriate if you don’t know where to look for an input property name). Within device results, there are keys to arrays for systemProperties, customProperties, autoProperties inheritedProperties. So you just have to get the device (possibly filtered by one property/value pair) and then extract what you need from those lists, like so:
So for system.groups, that would be getprop($device->{systemProperties}, ‘system.groups’).
Kel L
OPYeah, filtering doesn’t help me. I’m actually filtering on the hoststatus field to pull all the “Dead” devices. I just wanted to have the Group show up in the results so I can tell easier what something is.
Not a huge deal if I can’t but would be nice if I could.
I’m actually on a chat with LM support right now and am assuming he’s about to give me the same answer. :)
LM User
This is what I do too. Instead of filtering in the call, I just fetch everything and filter afterwards.
mnagel
Here is the core chunk of a script that dumps all properties for each device. It was just a throaway POC I kept around, might be helpful. In Perl because I still Perl :). Get off my lawn!
mnagel
You cannot pull properties from the device endpoint, but you can filter -- the method is limited (supports only one property match). You can use a filter like so (if you wish to restrict to specific values of that property).
filter=systemProperties.name:system.groups,systemProperties.value:VALUEWe’ve generally ended up with a full dump of /device/devices/$device->{id}/properties into a hash and then we reference that data as needed with a simple wrapper function to lookup property values from the hash. It requires more API calls, but actually is useful and it works. I checked all our code and we pretty much never use that first method.
LM User
Following to see if LM has an answer. I haven’t been able to figure it out.