List Event Threat Detection custom modules
Stay organized with collections
Save and categorize content based on your preferences.
Sample code for listing Event Threat Detection custom modules.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# List Event Threat Detection custom modules\n\nSample code for listing Event Threat Detection custom modules.\n\nCode sample\n-----------\n\n### Go\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\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tsecuritycentermanagement \"cloud.google.com/go/securitycentermanagement/apiv1\"\n \tsecuritycentermanagementpb \"cloud.google.com/go/securitycentermanagement/apiv1/securitycentermanagementpb\"\n \titerator \"google.golang.org/api/iterator\"\n )\n\n // listEventThreatDetectionCustomModule lists all custom modules for Event Threat Detection.\n func listEventThreatDetectionCustomModule(w io.Writer, parent string) error {\n \t// parent: Use any one of the following options:\n \t// - organizations/{organization_id}/locations/{location_id}\n \t// - folders/{folder_id}/locations/{location_id}\n \t// - projects/{project_id}/locations/{location_id}\n\n \tctx := context.Background()\n \tclient, err := securitycentermanagement.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycentermanagement/latest/apiv1.html#cloud_google_com_go_securitycentermanagement_apiv1_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"securitycentermanagement.NewClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycentermanagement/latest/apiv1.html#cloud_google_com_go_securitycentermanagement_apiv1_Client_Close()\n\n \treq := &securitycentermanagementpb.ListEventThreatDetectionCustomModulesRequest{\n \t\tParent: parent,\n \t}\n\n \t// List all Event Threat Detection custom modules present in the resource.\n \tit := client.ListEventThreatDetectionCustomModules(ctx, req)\n \tfor {\n \t\tresp, 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\tfmt.Fprintf(w, \"Custom Module Name: %s,\\n\", resp.Name)\n \t}\n \treturn nil\n }\n\n### Java\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 com.google.cloud.securitycentermanagement.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.ListEventThreatDetectionCustomModulesRequest.html;\n import com.google.cloud.securitycentermanagement.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.html;\n import com.google.cloud.securitycentermanagement.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.html.https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse.html;\n import java.io.IOException;\n\n public class ListEventThreatDetectionCustomModules {\n\n public static void main(String[] args) throws IOException {\n // https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.eventThreatDetectionCustomModules/list\n // TODO: Developer should replace project_id with a real project ID before running this code\n String projectId = \"project_id\";\n\n listEventThreatDetectionCustomModules(projectId);\n }\n\n public static https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse.html\n listEventThreatDetectionCustomModules(String projectId) throws IOException {\n\n // Initialize client that will be used to send requests. This client only needs\n // to be created\n // once, and can be reused for multiple requests.\n try (https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.html.create()) {\n\n String parent = String.format(\"projects/%s/locations/global\", projectId);\n\n https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.ListEventThreatDetectionCustomModulesRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.ListEventThreatDetectionCustomModulesRequest.html.newBuilder().setParent(parent).build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-securitycentermanagement/latest/com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse.html response =\n client.listEventThreatDetectionCustomModules(request);\n\n return response;\n }\n }\n }\n\n### Node.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 {SecurityCenterManagementClient} =\n require('https://cloud.google.com/nodejs/docs/reference/securitycentermanagement/latest/overview.html').v1;\n\n // Create a Security Center Management client\n const client = new https://cloud.google.com/nodejs/docs/reference/securitycentermanagement/latest/overview.html();\n\n /**\n * Required. The name of the parent resource of the list event threat detection custom module. Its\n * format is \"organizations/[organization_id]/locations/[location_id]\",\n * \"folders/[folder_id]/locations/[location_id]\", or\n * \"projects/[project_id]/locations/[location_id]\".\n */\n //TODO(developer): Update the following references for your own environment before running the sample.\n // const organizationId = 'YOUR_ORGANIZATION_ID';\n // const location = 'LOCATION_ID';\n const parent = `organizations/${organizationId}/locations/${location}`;\n\n // Build the request.\n const listEventThreatDetectionCustomModulesRequest = {\n parent: parent,\n };\n\n async function listEventThreatDetectionCustomModules() {\n // Call the API.\n const [modules] = await client.listEventThreatDetectionCustomModules(\n listEventThreatDetectionCustomModulesRequest\n );\n for (const module of modules) {\n console.log('Custom Module name:', module.name);\n }\n }\n\n listEventThreatDetectionCustomModules();\n\n### Python\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 def list_event_threat_detection_custom_module(parent: str):\n \"\"\"\n Retrieves list of Event Threat Detection custom module.\n Args:\n parent: Use any one of the following options:\n - organizations/{organization_id}/locations/{location_id}\n - folders/{folder_id}/locations/{location_id}\n - projects/{project_id}/locations/{location_id}\n Returns:\n List of retrieved Event Threat Detection custom modules.\n Raises:\n NotFound: If the specified custom module does not exist.\n \"\"\"\n\n client = securitycentermanagement_v1.SecurityCenterManagementClient()\n\n try:\n request = securitycentermanagement_v1.ListEventThreatDetectionCustomModulesRequest(\n parent=parent,\n )\n\n response = client.list_event_threat_detection_custom_modules(request=request)\n\n custom_modules = []\n for custom_module in response:\n print(f\"Custom Module: {custom_module.name}\")\n custom_modules.append(custom_module)\n return custom_modules\n except NotFound as e:\n print(f\"Parent resource not found: {parent}\")\n raise e\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]