フィルタを使用したアセットのグループ化
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
アセットをタイプでフィルタし、グループ化する方法を説明します。
コードサンプル
Java
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 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 filter and group assets by type\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 groupAssetsWithFilter(OrganizationName organizationName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Start setting up a request to filter all assets by type and group them by project in an\n // organization.\n // You can also use a project or folder as a parent resource and filter assets in them\n // respectively.\n GroupAssetsRequest.Builder request =\n GroupAssetsRequest.newBuilder()\n .setFilter(\n \"security_center_properties.resource_type=\\\"google.cloud.resourcemanager.Project\\\"\")\n .setGroupBy(\"security_center_properties.resource_project\")\n .setParent(organizationName.toString());\n\n // Call the API.\n GroupAssetsPagedResponse response = client.groupAssets(request.build());\n\n // This creates one list for all assets. If your organization has a large number of assets\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(\"All assets:\");\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\n\n client = securitycenter.SecurityCenterClient()\n\n # 'organization_id' is the numeric ID of the organization.\n # organization_id = \"1234567777\"\n org_name = f\"organizations/{organization_id}\"\n\n group_by_type = \"security_center_properties.resource_type\"\n only_projects = (\n \"security_center_properties.resource_type=\"\n + '\"google.cloud.resourcemanager.Project\"'\n )\n # You can also use a project/ folder as a parent resource and filter assets in them\n # respectively.\n 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_assets(\n request={\"parent\": org_name, \"group_by\": group_by_type, \"filter\": only_projects}\n )\n for i, result in enumerate(result_iterator):\n print((i + 1), 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)."]]