Group findings

Demonstrates how to group findings by properties

Code sample


static ImmutableList<GroupResult> groupFindings(OrganizationName organizationName) {
  try (SecurityCenterClient client = SecurityCenterClient.create()) {
    // OrganizationName organizationName = OrganizationName.of("123234324");
    SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");

    GroupFindingsRequest.Builder request =

    // Call the API.
    GroupFindingsPagedResponse response = client.groupFindings(;

    // This creates one list for all findings.  If your organization has a large number of
    // findings
    // this can cause out of memory issues.  You can process them batches by returning
    // the Iterable returned response.iterateAll() directly.
    ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
    return results;
  } catch (IOException e) {
    throw new RuntimeException("Couldn't create client.", e);


from import securitycenter

# Create a client.
client = securitycenter.SecurityCenterClient()

# organization_id is the numeric ID of the organization. e.g.:
# organization_id = "111122222444"
org_name = "organizations/{org_id}".format(org_id=organization_id)
# The "sources/-" suffix lists findings across all sources.  You
# also use a specific source_name instead.
all_sources = "{org_name}/sources/-".format(org_name=org_name)
group_result_iterator = client.group_findings(
    request={"parent": all_sources, "group_by": "category"}
for i, group_result in enumerate(group_result_iterator):
    print((i + 1), group_result)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser