Forum Discussion

DamienC's avatar
2 years ago

API call - Postman - select specific systemProperties - ?fields=

Hello everyone !

This could be a noob question. I tried to find the answer on the forum but did not. Sorry if I missed a thread mentioning it. 

I found how to use ?filters= on systemProperties stuff. But I can't figure how to select specific data in the result, with ?fields=.
I'm willing to go through a file with my devicesID.
For each of these device, I want to get the value for the property "system.azure.tag.vm", which is part of 'systemproperties'.

I'm comfortable with "fields=" for whatever is part of the 'data' array.

But no clue when it comes to these;

Can anyone help me determine the proper syntax for my Get ?

Thanks.

9 Replies

  • On 9/16/2022 at 2:08 PM, DamienC said:

    Well,... I hardly see why anyone would not want to implement his stuff to be able to filter/parse data with a decent level of granularity.

    You're not the only one baffled. 

  • v1 and v2 (and to my knowledge v3) of the API allow you to specify that you want to filter for any records where there's a property with a specific name and a property with a specific value; however, you cannot filter for a specific property with a specific name and a specific value.

    Example:

    Device1: prop1: A, prop2: A
    Device2: prop1: B, prop2: A

    filter="name:\"prop1\",value:\"A\"" will return any devices that have a property called "prop1" and also contain any property with a value of "A". This filter will match on both Device1 and on Device2. This is because the "value" criteria, while it's ANDed with the name criteria doesn't mean "prop1 has a value of A" it means, "is there a value of A". IMO, this makes filtering by properties pretty much useless and you have to do something else to filter by properties.

    For this reason in most of my calls, I don't filter by properties. I either: 1) create a dynamic group and grab /device/groups/{id}/devices or 2) I apply any other filtering in my API call, then as soon as I have the data, I create a single new dictionary under the device called properties using the name as the key and the value as the value. In python this is done this way:

    devices = lm.get_device_list(size=1000).items #should do something to account for page size
    for d in devices:
        properties = {x.name:x.value for x in (d.system_properties + d.auto_properties + d.inherited_properties + d.custom_properties)}

     

  • That was a super fast reply. Thanks.
    That's interesting... (and slightly depressing)

    I used the following call and had success with it;
    {{url}}/device/devices/?filter=autoProperties.name:auto.network.names,autoProperties.value:{{deviceIP}}&fields=displayName,id

    Which allows me to only target the device with Property1:A. 
    If I understood right, that worked only because I don't have two devices with the same IP...
    That's rough. I thought I got something to work the way I wanted and now I learn I just got lucky. :D

    I'll probably need to re-read your reply tomorrow morning, when my brain is functional... But it looks like I can't easily achieve what I wanted.
    I thought API calls were super versatile.

    Note that my initial question is about 'filtering' the result (fields=), not filtering the devices I'm getting (?filter=). Though I guess what you say applies to both.

    Thanks again for your detailed reply.

  • 19 hours ago, DamienC said:

    my initial question is about 'filtering' the result (fields=)

    Whoa, I totally went into destructive teaching mode there and didn't even answer your question, sorry about that. Still applies and sorry to burst your bubble. Yes, REST APIs are very versatile, but they are still built by humans with certain intended uses in mind. Unfortunately, when the filtering capability was built, the human either didn't envision (<-- ha!) the need to filter by a specific property/value combo or they did think about it but didn't deem the need worth the work it would take to implement. All APIs have drawbacks and inconveniences, LM's is no exception. 

    Now on to your original question:

    I haven't found a way to specify that only a certain property is returned. The best I've been able to do is pull the entire systemProperties and filter after pulling it back. The way i look at it, filter and field are a convenience if they work for a given situation, but if they don't you just have to do it the inconvenient way: slice and dice the data after pulling it back.

  • Thanks for the update, Stuart.

    Well,... I hardly see why anyone would not want to implement his stuff to be able to filter/parse data with a decent level of granularity.

    Anyways. It's gonna be a good opportunity for me to work on my scripting skills, I guess. There is good in this.

  • Based on this discussion I'm looking at this example in the API documentation:

    https://www.logicmonitor.com/support/rest-api-developers-guide/v1/devices/get-devices#Example-Request-5--GET-all-devices-that-have-a-spe

    And wondering about this example filter:

    filter=customProperties.name:snmp.version,customProperties.value:v2c

    It seems like what it should be doing is filtering on devices that have a customProperty named snmp.version with a value of "v2c". But what it may actually be doing is filtering on devices that have a customProperty with name snmp.version and/or (question?) a customProperty with a value of "v2c". Since all devices probably have the first condition it is probably moot, and also since no other property probably has a value of v2c it may actually work. But that's a bit of a stretch for any name:value pairs on real devices. Am I misunderstanding this?

    I'm wanting to make a filter on system.collector equals true, but if the above is true, then all devices would match having a property with that name and matching a value of false is also equally useless. Any ideas how to return a list of devices via API that are collectors?

  • 13 hours ago, Jason said:

    what it may actually be doing is filtering on devices that have a customProperty with name snmp.version and/or (question?) a customProperty with a value of "v2c"

    This is what it's doing. Fetch all and filter in script.

  • Not to beat this dead horse, I’m assuming this also applies to the “fields” parameter as well? 

    Like I’m trying to just pull back an easy list of devices in a device group folder and I only want a handful of fields to return, but I can’t seem to get that to work either.