Forum Discussion

Stephen_C's avatar
Stephen_C
Icon for Neophyte rankNeophyte
2 months ago
Solved

Report/dashboard which contains groups that do not contain a specific resource?

It is possible to create a report/dashboard that contains groups that do not contain a specific resource? For example, I need to find all groups that do not contain resources starting with sw0.
  • Stuart_Weenig's avatar
    Stuart_Weenig
    2 months ago

    It's not a regex match (i originally was going to, but decided against it). Look at line 9. That takes care of making sure it starts with sw0.

    By intense, i mean long running. It has to make an API call for every group. You won't run into any limits though because the endpoint path is different for every call, so different rate limit buckets. You'd probably be fine running this once a day (and switching to CSV output).

    Pagination added:

    # Get groups without a certain device in them
    # warning this does not use pagination, may have incomplete results if you have more than 1000 groups or more than 1000 devices in a group.
    from lm import lm
    pattern = "sw0"
    groups_without_target_device = []
    groups = []
    end_found = False
    offset = 0
    size = 1000
    while not end_found:
        current = lm.get_device_group_list(size=size,offset=offset).items
        groups += current
        offset += len(current)
        end_found = len(current) != size
    for id,group_details in {x.id:x for x in groups}.items():
        members = []
        end_found = False
        offset = 0
        size = 1000
        while not end_found:
            current = lm.get_immediate_device_list_by_device_group_id(id, size=size,offset=offset).items
            members += current
            offset += len(current)
            end_found = len(current) != size
        matching_count = len([x for x in members if x.display_name.startswith(pattern)])
        full_path = '\\' if group_details.full_path == '' else group_details.full_path
        print(f"Group \"{full_path}\" contains {matching_count} devices starting with {pattern}")