Delete a mute rule
Stay organized with collections
Save and categorize content based on your preferences.
Demonstrates how to delete a mute rule
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,["# Delete a mute rule\n\nDemonstrates how to delete a mute rule\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 \tsecuritycenter \"cloud.google.com/go/securitycenter/apiv1\"\n \t\"cloud.google.com/go/securitycenter/apiv1/securitycenterpb\"\n )\n\n // deleteMuteRule deletes a mute configuration given its resource name.\n // Note: Previously muted findings are not affected when a mute config is deleted.\n func deleteMuteRule(w io.Writer, parent string, muteConfigId string) error {\n \t// parent: Use any one of the following options:\n \t// - organizations/{organization_id}\n \t// - folders/{folder_id}\n \t// - projects/{project_id}\n \t// parent := fmt.Sprintf(\"projects/%s\", \"your-google-cloud-project-id\")\n \t//\n \t// muteConfigId: Specify the name of the mute config to delete.\n \t// muteConfigId := \"mute-config-id\"\n \tctx := context.Background()\n \tclient, err := securitycenter.NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"securitycenter.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \treq := &securitycenterpb.DeleteMuteConfigRequest{\n \t\tName: fmt.Sprintf(\"%s/muteConfigs/%s\", parent, muteConfigId),\n \t}\n\n \tif err := client.DeleteMuteConfig(ctx, req); err != nil {\n \t\treturn fmt.Errorf(\"failed to delete Muteconfig: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Mute rule deleted successfully: %s\", muteConfigId)\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\n import com.google.cloud.securitycenter.v1.MuteConfigName;\n import com.google.cloud.securitycenter.v1.SecurityCenterClient;\n import java.io.IOException;\n\n public class DeleteMuteRule {\n\n public static void main(String[] args) {\n // TODO(Developer): Replace the following variables\n // parentPath: Use any one of the following options:\n // - organizations/{organization_id}\n // - folders/{folder_id}\n // - projects/{project_id}\n String parentPath = String.format(\"projects/%s\", \"your-google-cloud-project-id\");\n\n // muteConfigId: Specify the name of the mute config to delete.\n String muteConfigId = \"mute-config-id\";\n\n deleteMuteRule(parentPath, muteConfigId);\n }\n\n // Deletes a mute configuration given its resource name.\n // Note: Previously muted findings are not affected when a mute config is deleted.\n public static void deleteMuteRule(String projectId, String muteConfigId) {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Use appropriate MuteConfigName methods depending on the type of parent.\n // org -\u003e MuteConfigName.ofOrganizationMuteConfigName()\n // folder -\u003e MuteConfigName.ofFolderMuteConfigName()\n // project -\u003e MuteConfigName.ofProjectMuteConfigName)\n client.deleteMuteConfig(MuteConfigName.ofProjectMuteConfigName(projectId, muteConfigId));\n\n System.out.println(\"Mute rule deleted successfully: \" + muteConfigId);\n } catch (IOException e) {\n System.out.println(\"Mute rule deletion failed! \\n Exception: \" + e);\n }\n }\n }\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 delete_mute_rule(mute_config_name: str) -\u003e None:\n \"\"\"\n Deletes a mute configuration given its resource name.\n Note: Previously muted findings are not affected when a mute config is deleted.\n Args:\n mute_config_name: Specify the name of the mute config to delete.\n Use any one of the following formats:\n - organizations/{organization}/muteConfigs/{config_id}\n - folders/{folder}/muteConfigs/{config_id} or\n - projects/{project}/muteConfigs/{config_id}\n \"\"\"\n from google.cloud import securitycenter\n\n client = securitycenter.SecurityCenterClient()\n\n request = securitycenter.DeleteMuteConfigRequest()\n request.name = mute_config_name\n\n client.delete_mute_config(request)\n print(f\"Mute rule deleted successfully: {mute_config_name}\")\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)."]]