def request_computer_groups(self):
     api_instance = deepsecurity.ComputerGroupsApi(deepsecurity.ApiClient(self.api_config))
     try:
         api_response = api_instance.list_computer_groups(self.api_version)
     except deepsecurity.rest.ApiException as e:
         self.handle_api_exception(e,"COMPUTERS")
     except urllib3.exceptions.MaxRetryError as e:
         raise Exception(self.MAX_RETRY_ERROR_MSG)
     except urllib3.exceptions.LocationParseError:
         raise TypeError( ("API Configuration values on {} are NOT VALID".format(self.API_CONFIG_PATH)))
     except Exception as e:
         raise Exception("Generic connection error!" + str(e) + "Generic connection error!")
     return api_response
Ejemplo n.º 2
0
    def GetAllGroups(self, configuration):
        # Set search criteria
        search_criteria = api.SearchCriteria()
        search_criteria.id_value = 0
        search_criteria.id_test = "greater-than"
        # Create a search filter with maximum returned items
        page_size = 5000
        search_filter = api.SearchFilter()
        search_filter.max_items = page_size
        search_filter.search_criteria = [search_criteria]

        groupsapi = api.ComputerGroupsApi(api.ApiClient(configuration))

        paged_groups = []
        try:
            while True:
                t0 = time.time()
                groups = groupsapi.search_computer_groups(
                    api_version, search_filter=search_filter)
                t1 = time.time()
                num_found = len(groups.computer_groups)
                if num_found == 0:
                    print("No groups found.")
                    break
                paged_groups.extend(groups.computer_groups)
                # Get the ID of the last group in the page and return it with the number of groups on the page
                last_id = groups.computer_groups[-1].id
                search_criteria.id_value = last_id
                print("Last ID: " + str(last_id),
                      "Groups found: " + str(num_found))
                print("Return rate: {0} groups/sec".format(num_found /
                                                           (t1 - t0)))
                if num_found != page_size:
                    print("Num_found {0} - Page size is {1}".format(
                        num_found, page_size))

        except api_exception as e:
            return "Exception: " + str(e)

        return paged_groups