Forum Discussion

Whitwa's avatar
8 years ago

Get all devices in all sub device groups via LogicMonitor REST API

Hi,

I am trying to use the LogicMonitor REST API get a list of allof the devices in a given device group, including all devices in all sub groups below in the hierarchy.

I have tried using the /device/groups/{id}/devices API but it just seems to return the devices in that immediate device group. This behaviour seems contrary to the /device/groups/{id}/alerts and /device/groups/{id}/sdts methods which do work with any sub groups below.

This was previously possible via the getHosts RPC API method. I believe it is still possible but we are looking to migrate away from the RPC API.

Can someone please advise on a solution for this issue?

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

    Hi,

    Alerts & SDTs roll up (in the UI and the API) - you'll see alerts for a subgroup under it's parent group Alerts & SDT Tabs, but devices don't roll up in this same manner.  So thats why the /device/groups/{id}/alerts and /device/groups/{id}/sdts resources return alerts and sdts for subgroups, while the /device/groups/{id}/devices resource does not.  You can get all devices under a group and it's subgroups by using the /device/groups/{id} resource to get subgroups, and iterating through those subgroups & the parent group to get their devices - this can be done with a simple script.  

    While it would be difficult to add the subgroup devices to /device/groups/{id}/devices resource in a RESTful manner, I'll keep this use case in mind as a feature request & see if we can come up with something clever.

    Thanks,

    Sarah

     

  • Thanks for the quick response Sarah.

    Unfortunately I don't think getting the subgroups and iterating that way would be an acceptable solution and would result in many required API calls taking a long time to get the full list of devices.

    This is part of a system which needs to be responsive to the end user. As I said above, the getHosts API method on the RPC API did provide this functionality in an acceptable manner.

    Any other suggestions?

  • hey there, we use groupings that show all the devices in the subgroups using dynamic groups. you can use the staticgroups device property to create your dynamic group that houses all devices for a particular folder structure. 

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

    Thanks, Tom! 

    @Whitwa Would you mind providing more detail re what your system does?  Our UI (responsive to the end user) is built on our API, but more context for your use case will help us find the best possible solution. 

  • Hi Sarah,

    A colleague of mine has since had correspondence with LogicMonitor confirming that this will be implemented in v.94 (inherited properties included in the /device/devices resource).

  • I tried to extract the data using 'device/groups/{id}/devices' hoping LM would return all devices under subgroups but it doesn't. 

    Worked out a 'workaround' for this using device/devices and filter on systemProperties. Not sure if there are any other ways to do this?...

    Try the below api, replace grouppath with your group path. For space and / you have to use url encode (space = %20, / = %2)

    $resourcePath = '/device/devices'
    $queryParams = '?size=500&filter=systemProperties~grouppath'