Forum Discussion

Arjuna's avatar
3 years ago

To obtain a report from LM of datasources and how many devices are using those datasources.

Do we have a way to obtain a report from LM of datasources and how many devices are using those datasources, like datasources and AppliedTo Combined

9 Replies

  • I would use the API to walk the list of devices, then scan devicedatasources for each device and tabulate the results.  AFAIK there is no builtin report for this.

  • Anonymous's avatar
    Anonymous

    Same. Although I used the SDK (references my custom lm library

    from lm import lm
    from pprint import pprint
    devices = lm.get_device_list(size=1000).to_dict()['items']
    result = {}
    for d in devices:
        datasources = lm.get_device_datasource_list(d['id']).to_dict()['items']
        for ds in datasources:
            # print(f"{d['display_name']}: {ds['data_source_display_name']} ({ds['instance_number']})")
            if d['display_name'] in result:
                result[d['display_name']] += ds['instance_number']
            else:
                result[d['display_name']] = ds['instance_number']
    for k,v in result.items():
        print(f"{k}: {v}")

     

  • Anonymous's avatar
    Anonymous

    Just realized i left an errant print statement in there. Fixed.

  • Anonymous's avatar
    Anonymous

    This would need logic to handle portals with more than 1000 devices in it since the first api call only gets the first 1000 devices. The subsequent calls would also need to take into consideration rate limiting and probably introduce some throttling. 

  • 1 hour ago, mnagel said:

    I would use the API to walk the list of devices, then scan devicedatasources for each device and tabulate the results.  AFAIK there is no builtin report for this.

    Can you please direct me to helpful API document and Articles!

  • Anonymous's avatar
    Anonymous
    /topic/1964-accessing-the-logicmonitor-rest-api-with-postman-and-lmv1-api-token-authentication/

    https://www.logicmonitor.com/swagger-ui-master/dist/

    https://www.logicmonitor.com/support/rest-api-developers-guide/overview/using-logicmonitors-rest-api

    There's also a course in the training portal about the API: https://logicmonitor.skilljar.com/api-course. (You need to already have an active session in Skilljar for this link to take you directly there. To get an active session, log into your portal and click the "Training" link in the top right corner. Then the link will work.)

  • 1 hour ago, Stuart Weenig said:

    This would need logic to handle portals with more than 1000 devices in it since the first api call only gets the first 1000 devices. The subsequent calls would also need to take into consideration rate limiting and probably introduce some throttling. 

    I never really think about that since we built in paging support in our module from the beginning.  I have seen some of the LM modules also use hardcoded page sizes and it makes me sad.  Still waiting for library support within the module system...

  • On 12/17/2021 at 10:53 AM, Stuart Weenig said:

    This would need logic to handle portals with more than 1000 devices in it since the first api call only gets the first 1000 devices. The subsequent calls would also need to take into consideration rate limiting and probably introduce some throttling. 

     

    @Arjuna You might be able to use the module mentioned in this thread

    /topic/1581-datasources_list-propertysource/

    Then you could run an inventory report and add that property to the report. 

     

    Hijacking the thread a bit...
    @Stuart WeenigDo you have an example on how to access the return headers when using the SDK? I've been tinkering with it and have hit the rate limit a few times but couldn't figure out how to get the headers using the base functions. I ended up calling the subfunctions in each class that returns the tuple object instead of the actual object class, but I feel like there's a better way.  For instance, instead of using add_device_group() I used add_device_group_with_http_info() then I could access the headers. 

  • Anonymous's avatar
    Anonymous
    On 12/22/2021 at 7:43 AM, asims@cspire.com said:

    used add_device_group_with_http_info() then I could access the headers

    AFAIK, this is the most graceful way.