Forum Discussion

Vinusha's avatar
7 years ago
Solved

Get LM DeviceGroup Properties REST API

I'm accessing the get device group properties api by using name in filters to get the hostgroupID.

I need a confirmation on get device group properties api. In the response output, is the first "items"(response['data']['tems'][0]) having an ID value is the devicegroupid ?

Is there any other way I can get the hostroupID by just the name or customerprefix of the deployment.

 

  • Hi Vinusha,

    If you're trying to get device group id using the device group name, you can make a request like this:

    GET /device/groups?filter=name~"NAME"

    And the 'id', first field in the items object (as you've noted) is the group id. You can restrict the fields returned in the response using the 'fields' query parameter as well.

    You can also get device group id by filtering the request by property, like this:

    GET /device/groups?fields=customProperties,name,id&filter=customProperties.name:customer.name,customProperties.value:customerA

    This request will return the customProperties, name and id of groups that have a property customer.name set to customerA.

    Does this help with what you're trying to do?

    Thanks,

    Sarah

6 Replies

  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Hi Vinusha,

    If you're trying to get device group id using the device group name, you can make a request like this:

    GET /device/groups?filter=name~"NAME"

    And the 'id', first field in the items object (as you've noted) is the group id. You can restrict the fields returned in the response using the 'fields' query parameter as well.

    You can also get device group id by filtering the request by property, like this:

    GET /device/groups?fields=customProperties,name,id&filter=customProperties.name:customer.name,customProperties.value:customerA

    This request will return the customProperties, name and id of groups that have a property customer.name set to customerA.

    Does this help with what you're trying to do?

    Thanks,

    Sarah

  • On 1/9/2018 at 5:23 PM, Sarah Terry said:

     

    GET /device/groups?fields=customProperties,name,id&filter=customProperties.name:customer.name,customProperties.value:customerA

    This request will return the customProperties, name and id of groups that have a property customer.name set to customerA.


    @Sarah Terry,

    Though what you say is (strictly) true, it is misleading.  There is no way to filter a Device Group by the value of a specific custom property using the LogicMonitor API.

    Your query does NOT mean:

    • Device Groups that have a custom property (called "customer.name" and with value "customerA")

    It means:

    • Device Groups that have ANY custom property called "customer.name" and ANY custom property with value "customerA."

    Let's say you have two Device Groups:

    • Customer A
      • customer.name=customerA
      • customer.rival=customerB
    • Customer B
      • customer.name=customerB
      • customer.rival=customerA

    Your query would bring back both customers.

  • Feedback sent:

    The REST API filtering system for various entities by custom properties, inherited properties and effective properties BADLY needs an overhaul.

    There is no way to effectively filter by effective property.

    API consumers simply want a list of (e.g.) Dashboard Groups with token defaultResourceGroup = "Customer A".  They should not have to worry about whether that Group has the value applied directly or it is inherited.

    I propose a set of NEW filter parameters, which should be consistently useable across all entities that support custom properties (or similar concepts):

    • propertyNameAndValue:{ \"name\": \"customer\", \"value\": \"customerA\", \"operator\": \"equals\" }
    • effectivePropertyNameAndValue:{ \"name\": \"customer\", \"value\": \"customerA\", \"operator\": \"equals\" }
    • inheritedPropertyNameAndValue:{ \"name\": \"customer\", \"value\": \"customerA\", \"operator\": \"equals\" }

    The usual operators should be supported:

    • equals
    • notEquals
    • greaterThan
    • greaterThanOrEquals
    • lessThan
    • lessThanOrEquals
    • regexMatch
    • regexNotMatch
  • 13 hours ago, Sarah Terry said:

    Hi Sarah,

    Thank you for the confirmation. I tried using filters on customProperties but few of our customers are not having any custom properties. 

    Vinusha.

     

  • On 1/9/2018 at 12:23 PM, Sarah Terry said:

    Hi Vinusha,

    If you're trying to get device group id using the device group name, you can make a request like this:

    GET /device/groups?filter=name~"NAME"

    And the 'id', first field in the items object (as you've noted) is the group id. You can restrict the fields returned in the response using the 'fields' query parameter as well.

    You can also get device group id by filtering the request by property, like this:

    GET /device/groups?fields=customProperties,name,id&filter=customProperties.name:customer.name,customProperties.value:customerA

    This request will return the customProperties, name and id of groups that have a property customer.name set to customerA.

    Does this help with what you're trying to do?

    Thanks,

    Sarah

     

    Hi Sarah

    How would you get a list of of devices that do not have a custom property?

     

    Thanks

  • Anonymous's avatar
    Anonymous
    On 1/9/2018 at 11:23 AM, Sarah Terry said:
    GET /device/groups?fields=customProperties,name,id&filter=customProperties.name:customer.name,customProperties.value:customerA

     

    Gotta be careful with this one. It searches for any group that has a custom property called "customer.name" and also has a custom property with a value of "customerA". It doesn't necessarily only return those where customer.name is "customerA". 

    For the negative, look at this page.