將發現項目分組
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
示範如何依屬性將結果分組
程式碼範例
Java
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to group findings by properties\n\nCode sample \n\nJava\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n static ImmutableList\u003cGroupResult\u003e groupFindings(OrganizationName organizationName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Input parameters for 'SourceName' must be in one of the following formats:\n // * OrganizationName organizationName = OrganizationName.of(\"organization-id\");\n // organizationName.getOrganization();\n // * ProjectName projectName = ProjectName.of(\"project-id\");\n // projectName.getProject();\n // * FolderName folderName = FolderName.of(\"folder-id\");\n // folderName.getFolder();\n SourceName sourceName = SourceName.of(organizationName.getOrganization(), \"-\");\n\n GroupFindingsRequest.Builder request =\n GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy(\"category\");\n\n // Call the API.\n GroupFindingsPagedResponse response = client.groupFindings(request.build());\n\n // This creates one list for all findings. If your organization has a large number of\n // findings\n // this can cause out of memory issues. You can process them batches by returning\n // the Iterable returned response.iterateAll() directly.\n ImmutableList\u003cGroupResult\u003e results = ImmutableList.copyOf(response.iterateAll());\n System.out.println(\"Findings:\");\n System.out.println(results);\n return results;\n } catch (IOException e) {\n throw new RuntimeException(\"Couldn't create client.\", e);\n }\n }\n\nPython\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import securitycenter_v1\n\n # Create a client.\n client = securitycenter_v1.SecurityCenterClient()\n\n # 'parent' must be in one of the following formats:\n # \"organizations/{organization_id}\"\n # \"projects/{project_id}\"\n # \"folders/{folder_id}\"\n parent = f\"organizations/{organization_id}\"\n # The \"sources/-\" suffix lists findings across all sources. You\n # also use a specific source_name instead.\n all_sources = f\"{parent}/sources/-\"\n group_result_iterator = client.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.services.security_center.SecurityCenterClient.html#google_cloud_securitycenter_v1_services_security_center_SecurityCenterClient_group_findings(\n request={\"parent\": all_sources, \"group_by\": \"category\"}\n )\n for i, group_result in enumerate(group_result_iterator):\n print((i + 1), group_result)\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]