列出发现结果
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
演示如何列出组织中的所有发现结果
代码示例
Go
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
Java
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
Node.js
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
Python
如需向 Security Command Center 进行身份验证,请设置应用默认凭证。
如需了解详情,请参阅为本地开发环境设置身份验证。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。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 list all findings in an organization\n\nCode sample \n\nGo\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 import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tsecuritycenter \"cloud.google.com/go/securitycenter/apiv1\"\n \t\"cloud.google.com/go/securitycenter/apiv1/securitycenterpb\"\n \t\"google.golang.org/api/iterator\"\n )\n\n // listFindings prints all findings in orgID to w. orgID is the numeric\n // identifier of the organization.\n func listFindings(w io.Writer, orgID string) error {\n \t// orgID := \"12321311\"\n \t// Instantiate a context and a security service client to make API calls.\n \tctx := context.Background()\n \tclient, err := securitycenter.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycenter/latest/apiv1.html#cloud_google_com_go_securitycenter_apiv1_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"securitycenter.NewClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycenter/latest/apiv1.html#cloud_google_com_go_securitycenter_apiv1_Client_Close() // Closing the client safely cleans up background resources.\n\n \treq := &securitycenterpb.ListFindingsRequest{\n \t\t// List findings across all sources.\n \t\t// Parent must be in one of the following formats:\n \t\t//\t\t\"organizations/{orgId}/sources/-\"\n \t\t//\t\t\"projects/{projectId}/sources/-\"\n \t\t//\t\t\"folders/{folderId}/sources/-\"\n \t\tParent: fmt.Sprintf(\"organizations/%s/sources/-\", orgID),\n \t}\n \tit := client.ListFindings(ctx, req)\n \tfor {\n \t\tresult, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn fmt.Errorf(\"it.Next: %w\", err)\n \t\t}\n \t\tfinding := result.Finding\n \t\tfmt.Fprintf(w, \"Finding Name: %s, \", finding.Name)\n \t\tfmt.Fprintf(w, \"Resource Name %s, \", finding.ResourceName)\n \t\tfmt.Fprintf(w, \"Category: %s\\n\", finding.Category)\n \t}\n \treturn nil\n }\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\u003cListFindingsResult\u003e listAllFindings(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 //\n // \"-\" Indicates listing across all sources.\n SourceName sourceName = SourceName.of(organizationName.getOrganization(), \"-\");\n\n ListFindingsRequest.Builder request =\n ListFindingsRequest.newBuilder().setParent(sourceName.toString());\n\n // Call the API.\n ListFindingsPagedResponse response = client.listFindings(request.build());\n\n // This creates one list for all findings. If your organization has a large number of\n // findings this can cause out of memory issues. You can process them in incrementally\n // by returning the Iterable returned response.iterateAll() directly.\n ImmutableList\u003cListFindingsResult\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\nNode.js\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 // Imports the Google Cloud client library.\n const {SecurityCenterClient} = require('https://cloud.google.com/nodejs/docs/reference/security-center/latest/overview.html');\n\n // Creates a new client.\n const client = new https://cloud.google.com/nodejs/docs/reference/security-center/latest/overview.html();\n // organizationId is the numeric ID of the organization.\n /*\n * TODO(developer): Uncomment the following lines\n */\n // const organizationId = \"1234567777\";\n\n async function listAllFindings() {\n const [response] = await client.listFindings({\n // List findings across all sources.\n // parent: must be in one of the following formats:\n // `organizations/${organization_id}/sources/-`\n // `projects/${project_id}/sources/-`\n // `folders/${folder_id}/sources/-`\n parent: `organizations/${organizationId}/sources/-`,\n });\n let count = 0;\n Array.from(response).forEach(result =\u003e\n console.log(\n `${++count} ${result.finding.name} ${result.finding.resourceName}`\n )\n );\n }\n await listAllFindings();\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 finding_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_list_findings(request={\"parent\": all_sources})\n for i, finding_result in enumerate(finding_result_iterator):\n print(\n \"{}: name: {} resource: {}\".format(\n i, finding_result.finding.name, finding_result.finding.resource_name\n )\n )\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)."]]