
# 创建关键操作通知 - CreateNotification
#### 功能介绍
配置关键操作通知，可在发生特定操作时，使用预先创建好的SMN主题，向用户手机、邮箱发送消息，也可直接发送http/https消息。常用于实时感知高危操作、触发特定操作或对接用户自有审计分析系统。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-cts/cts_api_0006.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-cts/cts_api_1001.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                     | 访问级别  | 资源类型（\*为必须） | 条件键 | 别名 | 依赖的授权项                                                                                                                                                                                                                                                                                                  |
  |:---|:---|:---|:---|:---|:---|
  | cts:notification:create | Write | -           | -   | -  | - smn:topic:listTopic  - iam:users:listUsers  - iam:groups:listGroups   |
     
  
 
#### URI
POST /v3/{project_id}/notifications
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                 |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，参见[获取账号ID和项目ID](https://support.huaweicloud.com/api-cts/cts_api_0005.html)章节。 |
   
#### 请求参数
表2请求Body参数 
| 参数                | 是否必选 | 参数类型                                                                           | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| notification_name | 是    | String                                                                         | 标识关键操作通知名称。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| operation_type    | 是    | String                                                                         | 标识操作类型。 目前支持的操作类型有完整类型(complete)和自定义类型(customized)。 完整类型下，CTS发送通知的对象为已对接服务的所有事件，此时不用指定operations和notify_user_list字段。 自定义类型下，CTS发送通知的对象是在operations列表中指定的事件。                                                                                                                                                                                                                                                                                                                |
| operations        | 否    | Array of [Operations] objects               | 操作事件列表。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| notify_user_list  | 否    | Array of [NotificationUsers] objects | 通知用户列表，目前最多支持对10个用户组和50个用户发起的操作进行配置。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| topic_id          | 否    | String                                                                         | 消息通知服务的topic_urn或者函数工作流的func_urn。 - 消息通知服务的topic_urn可以通过消息通知服务的查询主题列表API获取，示例：urn:smn:regionId:f96188c7ccaf4ffba0c9aa149ab2bd57:test_topic_v2。   - 函数工作流的func_urn可以通过函数工作流的获取函数列表API获取，示例：urn:fss:xxxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test。    |
| filter            | 否    | [Filter] object                                 | 关键操作通知高级过滤条件。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| agency_name       | 否    | String                                                                         | 云服务委托名称。 参数值为"cts_admin_trust"时，创建关键操作通知时会自动创建云服务委托：cts_admin_trust。                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
   
 表3Operations 
| 参数            | 是否必选 | 参数类型             | 描述                                                                                                                                             |
|:---|:---|:---|:---|
| service_type  | 是    | String           | 标识云服务类型。必须为已对接CTS的云服务的英文缩写，且服务类型一般为大写字母。 已对接的云服务列表参见《云审计服务用户指南》"支持审计的服务及详细操作列表"章节，单击对应云服务的文档链接，可以查看到该云服务的英文缩写。 |
| resource_type | 是    | String           | 标识资源类型。                                                                                                                                        |
| trace_names   | 是    | Array of strings | 标识事件名称。                                                                                                                                        |
   
 表4NotificationUsers 
| 参数         | 是否必选 | 参数类型             | 描述      |
|:---|:---|:---|:---|
| user_group | 是    | String           | IAM用户组。 |
| user_list  | 是    | Array of strings | IAM用户。  |
   
 表5Filter 
| 参数                | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|:---|
| condition         | 是    | String           | 多条件关系。 - AND(默认值) 表示所有过滤条件满足后生效。   - OR 表示有任意一个条件满足时生效。    |
| is_support_filter | 是    | Boolean          | 是否打开高级筛选开关。                                                                                                                                                                                                                                                                                                                                                    |
| rule              | 是    | Array of strings | 高级过滤条件规则，示例如下："key != value"，格式为：字段 规则 值。-字段取值范围：api_version,code,trace_rating,trace_type,resource_id,resource_name。-规则：!= 或 =。- 值：api_version正则约束：\^(a-zA-Z0-9_-.){1,64}$；code：最小长度1，最大长度256；trace_rating枚举值："normal", "warning", "incident"；trace_type枚举值："ConsoleAction", "ApiCall", "SystemAction"；resource_id：最小长度1，最大长度350；resource_name：最小长度1，最大长度256   |
   
#### 响应参数
**状态码：201**
表6响应Body参数 
| 参数                | 参数类型                                                                            | 描述                                                                                                                                                                                                                                                                                                                                                                                                        |
|:---|:---|:---|
| notification_name | String                                                                          | 通知名称。                                                                                                                                                                                                                                                                                                                                                                                                     |
| operation_type    | String                                                                          | 操作类型。完整类型和自定义类型。 - complete：完整类型，对所有已对接云审计服务的所有操作发送SMN通知。   - customized：自定义类型，对指定云服务的指定操作发送SMN通知。    |
| operations        | Array of [Operations] objects               | 操作事件列表。                                                                                                                                                                                                                                                                                                                                                                                                   |
| notify_user_list  | Array of [NotificationUsers] objects | 通知用户列表，目前最多支持对10个用户组和50个用户发起的操作进行配置。                                                                                                                                                                                                                                                                                                                                                                      |
| status            | String                                                                          | 通知状态。启用和停用。 - disabled：停用关键操作通知。   - enabled：启用关键操作通知。                                                |
| topic_id          | String                                                                          | 消息通知服务(SMN)主题的唯一的资源标识，可通过查询主题列表获取该标识。                                                                                                                                                                                                                                                                                                                                                                     |
| notification_id   | String                                                                          | 通知的唯一标识ID。                                                                                                                                                                                                                                                                                                                                                                                                |
| notification_type | String                                                                          | 通知类型。 -smn：消息通知服务。 -fun：函数工作流。                                                                                                                                                                                                                                                                                                            |
| project_id        | String                                                                          | 项目ID。                                                                                                                                                                                                                                                                                                                                                                                                     |
| create_time       | Long                                                                            | 通知规则创建时间。                                                                                                                                                                                                                                                                                                                                                                                                 |
| filter            | [Filter] object                                 | 关键操作通知高级筛选条件。                                                                                                                                                                                                                                                                                                                                                                                             |
| agency_name       | String                                                                          | 云服务委托名称。 参数值为"cts_admin_trust"时，创建关键操作通知时会自动创建云服务委托：cts_admin_trust。                                                                                                                                                                                                                                                                                                      |
   
 表7Operations 
| 参数            | 参数类型             | 描述                                                                                                                                             |
|:---|:---|:---|
| service_type  | String           | 标识云服务类型。必须为已对接CTS的云服务的英文缩写，且服务类型一般为大写字母。 已对接的云服务列表参见《云审计服务用户指南》"支持审计的服务及详细操作列表"章节，单击对应云服务的文档链接，可以查看到该云服务的英文缩写。 |
| resource_type | String           | 标识资源类型。                                                                                                                                        |
| trace_names   | Array of strings | 标识事件名称。                                                                                                                                        |
   
 表8NotificationUsers 
| 参数         | 参数类型             | 描述      |
|:---|:---|:---|
| user_group | String           | IAM用户组。 |
| user_list  | Array of strings | IAM用户。  |
   
 表9Filter 
| 参数                | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|
| condition         | String           | 多条件关系。 - AND(默认值) 表示所有过滤条件满足后生效。   - OR 表示有任意一个条件满足时生效。    |
| is_support_filter | Boolean          | 是否打开高级筛选开关。                                                                                                                                                                                                                                                                                                                                                    |
| rule              | Array of strings | 高级过滤条件规则，示例如下："key != value"，格式为：字段 规则 值。-字段取值范围：api_version,code,trace_rating,trace_type,resource_id,resource_name。-规则：!= 或 =。- 值：api_version正则约束：\^(a-zA-Z0-9_-.){1,64}$；code：最小长度1，最大长度256；trace_rating枚举值："normal", "warning", "incident"；trace_type枚举值："ConsoleAction", "ApiCall", "SystemAction"；resource_id：最小长度1，最大长度350；resource_name：最小长度1，最大长度256   |
   
**状态码：400**
表10响应Body参数 
| 参数         | 参数类型   | 描述             |
|:---|:---|:---|
| error_code | String | 错误码标识，CTS.XXX。 |
| error_msg  | String | 错误描述。          |
   
**状态码：401**
表11响应Body参数 
| 参数         | 参数类型   | 描述             |
|:---|:---|:---|
| error_code | String | 错误码标识，CTS.XXX。 |
| error_msg  | String | 错误描述。          |
   
**状态码：403**
表12响应Body参数 
| 参数         | 参数类型   | 描述             |
|:---|:---|:---|
| error_code | String | 错误码标识，CTS.XXX。 |
| error_msg  | String | 错误描述。          |
   
**状态码：404**
表13响应Body参数 
| 参数         | 参数类型   | 描述             |
|:---|:---|:---|
| error_code | String | 错误码标识，CTS.XXX。 |
| error_msg  | String | 错误描述。          |
   
**状态码：500**
表14响应Body参数 
| 参数         | 参数类型   | 描述             |
|:---|:---|:---|
| error_code | String | 错误码标识，CTS.XXX。 |
| error_msg  | String | 错误描述。          |
   
**状态码：503**
表15响应Body参数 
| 参数         | 参数类型   | 描述             |
|:---|:---|:---|
| error_code | String | 错误码标识，CTS.XXX。 |
| error_msg  | String | 错误描述。          |
   
#### 请求示例
- 创建完整类型关键操作通知请求样例。
  ```
  POST https://{endpoint}/v3/{project_id}/notifications
  {
    "notification_name" : "test",
    "filter" : {
      "is_support_filter" : true,
      "rule" : [ "code != 200", "api_version = v1.0", "trace_rating = normal", "trace_type != ApiCall", "resource_id = xxx", "resource_name = xxx" ],
      "condition" : "OR"
    },
    "operation_type" : "complete",
    "agency_name" : "cts_admin_trust",
    "topic_id" : "urn:smn:cn-north-7:24edf66e79d04187acb99a463e610764:test"
  }
  ```
  
- 创建自定义类型关键操作通知请求样例。
  ```
  POST https://{endpoint}/v3/{project_id}/notifications
  {
    "notification_name" : "test",
    "operation_type" : "customized",
    "agency_name" : "cts_admin_trust",
    "filter" : {
      "is_support_filter" : true,
      "rule" : [ "code != 200", "api_version = v1.0", "trace_rating = normal", "trace_type != ApiCall", "resource_id = xxx", "resource_name = xxx" ],
      "condition" : "OR"
    },
    "operations" : [ {
      "service_type" : "CTS",
      "resource_type" : "tracker",
      "trace_names" : [ "createTracker", "deleteTracker" ]
    }, {
      "service_type" : "CTS",
      "resource_type" : "notification",
      "trace_names" : [ "deleteNotification", "updateNotification" ]
    }, {
      "service_type" : "AOM",
      "resource_type" : "pe",
      "trace_names" : [ "deletePolicyGroup", "updatePolicyGroup", "createPolicyGroup" ]
    } ],
    "notify_user_list" : [ {
      "user_group" : "admin",
      "user_list" : [ "test1", "test2" ]
    }, {
      "user_group" : "CTS view",
      "user_list" : [ "test3", "test4" ]
    } ],
    "topic_id" : "urn:smn:{regionid}:24edf66e79d04187acb99a463e610764:test"
  }
  ```
  
 
#### 响应示例
**状态码：201**
创建成功。
```
{
  "create_time" : 1634001495876,
  "notification_id" : "cda8fd83-d08c-46f0-b914-1453a6a85c00",
  "notification_name" : "test",
  "agency_name" : "cts_admin_trust",
  "notification_type" : "smn",
  "notify_user_list" : [ {
    "user_group" : "admin",
    "user_list" : [ "test1", "test2" ]
  }, {
    "user_group" : "CTS view",
    "user_list" : [ "test3", "test4" ]
  } ],
  "operation_type" : "customized",
  "operations" : [ {
    "resource_type" : "tracker",
    "service_type" : "CTS",
    "trace_names" : [ "createTracker", "deleteTracker" ]
  }, {
    "resource_type" : "notification",
    "service_type" : "CTS",
    "trace_names" : [ "deleteNotification", "updateNotification" ]
  }, {
    "resource_type" : "pe",
    "service_type" : "AOM",
    "trace_names" : [ "deletePolicyGroup", "updatePolicyGroup", "createPolicyGroup" ]
  } ],
  "project_id" : "24edf66e79d04187acb99a463e610764",
  "status" : "enabled",
  "topic_id" : "urn:smn:cn-north-7:24edf66e79d04187acb99a463e610764:test"
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  - 创建完整类型关键操作通知请求样例。
    ```
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cts.v3.region.CtsRegion;
    import com.huaweicloud.sdk.cts.v3.*;
    import com.huaweicloud.sdk.cts.v3.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class CreateNotificationSolution {
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
            CtsClient client = CtsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CtsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateNotificationRequest request = new CreateNotificationRequest();
            CreateNotificationRequestBody body = new CreateNotificationRequestBody();
            List<String> listFilterRule = new ArrayList<>();
            listFilterRule.add("code != 200");
            listFilterRule.add("api_version = v1.0");
            listFilterRule.add("trace_rating = normal");
            listFilterRule.add("trace_type != ApiCall");
            listFilterRule.add("resource_id = xxx");
            listFilterRule.add("resource_name = xxx");
            Filter filterbody = new Filter();
            filterbody.withCondition(Filter.ConditionEnum.fromValue("OR"))
                .withIsSupportFilter(true)
                .withRule(listFilterRule);
            body.withFilter(filterbody);
            body.withTopicId("urn:smn:cn-north-7:24edf66e79d04187acb99a463e610764:test");
            body.withAgencyName(CreateNotificationRequestBody.CreateNotificationRequestBody.fromValue("cts_admin_trust"));
            body.withOperationType(CreateNotificationRequestBody.CreateNotificationRequestBody.fromValue("complete"));
            body.withNotificationName("test");
            request.withBody(body);
            try {
                CreateNotificationResponse response = client.createNotification(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    ```
    
  
  - 创建自定义类型关键操作通知请求样例。
    ```
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.cts.v3.region.CtsRegion;
    import com.huaweicloud.sdk.cts.v3.*;
    import com.huaweicloud.sdk.cts.v3.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class CreateNotificationSolution {
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
            CtsClient client = CtsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(CtsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateNotificationRequest request = new CreateNotificationRequest();
            CreateNotificationRequestBody body = new CreateNotificationRequestBody();
            List<String> listFilterRule = new ArrayList<>();
            listFilterRule.add("code != 200");
            listFilterRule.add("api_version = v1.0");
            listFilterRule.add("trace_rating = normal");
            listFilterRule.add("trace_type != ApiCall");
            listFilterRule.add("resource_id = xxx");
            listFilterRule.add("resource_name = xxx");
            Filter filterbody = new Filter();
            filterbody.withCondition(Filter.ConditionEnum.fromValue("OR"))
                .withIsSupportFilter(true)
                .withRule(listFilterRule);
            List<String> listNotifyUserListUserList = new ArrayList<>();
            listNotifyUserListUserList.add("test3");
            listNotifyUserListUserList.add("test4");
            List<String> listNotifyUserListUserList1 = new ArrayList<>();
            listNotifyUserListUserList1.add("test1");
            listNotifyUserListUserList1.add("test2");
            List<NotificationUsers> listbodyNotifyUserList = new ArrayList<>();
            listbodyNotifyUserList.add(
                new NotificationUsers()
                    .withUserGroup("admin")
                    .withUserList(listNotifyUserListUserList1)
            );
            listbodyNotifyUserList.add(
                new NotificationUsers()
                    .withUserGroup("CTS view")
                    .withUserList(listNotifyUserListUserList)
            );
            List<String> listOperationsTraceNames = new ArrayList<>();
            listOperationsTraceNames.add("deletePolicyGroup");
            listOperationsTraceNames.add("updatePolicyGroup");
            listOperationsTraceNames.add("createPolicyGroup");
            List<String> listOperationsTraceNames1 = new ArrayList<>();
            listOperationsTraceNames1.add("deleteNotification");
            listOperationsTraceNames1.add("updateNotification");
            List<String> listOperationsTraceNames2 = new ArrayList<>();
            listOperationsTraceNames2.add("createTracker");
            listOperationsTraceNames2.add("deleteTracker");
            List<Operations> listbodyOperations = new ArrayList<>();
            listbodyOperations.add(
                new Operations()
                    .withServiceType("CTS")
                    .withResourceType("tracker")
                    .withTraceNames(listOperationsTraceNames2)
            );
            listbodyOperations.add(
                new Operations()
                    .withServiceType("CTS")
                    .withResourceType("notification")
                    .withTraceNames(listOperationsTraceNames1)
            );
            listbodyOperations.add(
                new Operations()
                    .withServiceType("AOM")
                    .withResourceType("pe")
                    .withTraceNames(listOperationsTraceNames)
            );
            body.withFilter(filterbody);
            body.withTopicId("urn:smn:{regionid}:24edf66e79d04187acb99a463e610764:test");
            body.withNotifyUserList(listbodyNotifyUserList);
            body.withOperations(listbodyOperations);
            body.withAgencyName(CreateNotificationRequestBody.CreateNotificationRequestBody.fromValue("cts_admin_trust"));
            body.withOperationType(CreateNotificationRequestBody.CreateNotificationRequestBody.fromValue("customized"));
            body.withNotificationName("test");
            request.withBody(body);
            try {
                CreateNotificationResponse response = client.createNotification(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    ```
    
   
- [Python]
  - 创建完整类型关键操作通知请求样例。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcts.v3.region.cts_region import CtsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcts.v3 import *
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
        credentials = BasicCredentials(ak, sk, projectId)
        client = CtsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CtsRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = CreateNotificationRequest()
            listRuleFilter = [
                "code != 200",
                "api_version = v1.0",
                "trace_rating = normal",
                "trace_type != ApiCall",
                "resource_id = xxx",
                "resource_name = xxx"
            ]
            filterbody = Filter(
                condition="OR",
                is_support_filter=True,
                rule=listRuleFilter
            )
            request.body = CreateNotificationRequestBody(
                filter=filterbody,
                topic_id="urn:smn:cn-north-7:24edf66e79d04187acb99a463e610764:test",
                agency_name="cts_admin_trust",
                operation_type="complete",
                notification_name="test"
            )
            response = client.create_notification(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
  
  - 创建自定义类型关键操作通知请求样例。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcts.v3.region.cts_region import CtsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcts.v3 import *
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
        credentials = BasicCredentials(ak, sk, projectId)
        client = CtsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(CtsRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = CreateNotificationRequest()
            listRuleFilter = [
                "code != 200",
                "api_version = v1.0",
                "trace_rating = normal",
                "trace_type != ApiCall",
                "resource_id = xxx",
                "resource_name = xxx"
            ]
            filterbody = Filter(
                condition="OR",
                is_support_filter=True,
                rule=listRuleFilter
            )
            listUserListNotifyUserList = [
                "test3",
                "test4"
            ]
            listUserListNotifyUserList1 = [
                "test1",
                "test2"
            ]
            listNotifyUserListbody = [
                NotificationUsers(
                    user_group="admin",
                    user_list=listUserListNotifyUserList1
                ),
                NotificationUsers(
                    user_group="CTS view",
                    user_list=listUserListNotifyUserList
                )
            ]
            listTraceNamesOperations = [
                "deletePolicyGroup",
                "updatePolicyGroup",
                "createPolicyGroup"
            ]
            listTraceNamesOperations1 = [
                "deleteNotification",
                "updateNotification"
            ]
            listTraceNamesOperations2 = [
                "createTracker",
                "deleteTracker"
            ]
            listOperationsbody = [
                Operations(
                    service_type="CTS",
                    resource_type="tracker",
                    trace_names=listTraceNamesOperations2
                ),
                Operations(
                    service_type="CTS",
                    resource_type="notification",
                    trace_names=listTraceNamesOperations1
                ),
                Operations(
                    service_type="AOM",
                    resource_type="pe",
                    trace_names=listTraceNamesOperations
                )
            ]
            request.body = CreateNotificationRequestBody(
                filter=filterbody,
                topic_id="urn:smn:{regionid}:24edf66e79d04187acb99a463e610764:test",
                notify_user_list=listNotifyUserListbody,
                operations=listOperationsbody,
                agency_name="cts_admin_trust",
                operation_type="customized",
                notification_name="test"
            )
            response = client.create_notification(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
   
- [Go]
  - 创建完整类型关键操作通知请求样例。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/region"
    )
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        hcClient, err := cts.CtsClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := cts.NewCtsClient(hcClient)
        request := &model.CreateNotificationRequest{}
    var listRuleFilter = []string{
            "code != 200",
        "api_version = v1.0",
        "trace_rating = normal",
        "trace_type != ApiCall",
        "resource_id = xxx",
        "resource_name = xxx",
        }
    filterbody := &model.Filter{
    Condition: model.GetFilterConditionEnum().OR,
    IsSupportFilter: true,
    Rule: listRuleFilter,
    }
    topicIdCreateNotificationRequestBody:= "urn:smn:cn-north-7:24edf66e79d04187acb99a463e610764:test"
    agencyNameCreateNotificationRequestBody:= model.GetCreateNotificationRequestBodyAgencyNameEnum().CTS_ADMIN_TRUST
    request.Body = &model.CreateNotificationRequestBody{
    Filter: filterbody,
    TopicId: &topicIdCreateNotificationRequestBody,
    AgencyName: &agencyNameCreateNotificationRequestBody,
    OperationType: model.GetCreateNotificationRequestBodyOperationTypeEnum().COMPLETE,
    NotificationName: "test",
    }
    response, err := client.CreateNotification(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
  
  - 创建自定义类型关键操作通知请求样例。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/region"
    )
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        hcClient, err := cts.CtsClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := cts.NewCtsClient(hcClient)
        request := &model.CreateNotificationRequest{}
    var listRuleFilter = []string{
            "code != 200",
        "api_version = v1.0",
        "trace_rating = normal",
        "trace_type != ApiCall",
        "resource_id = xxx",
        "resource_name = xxx",
        }
    filterbody := &model.Filter{
    Condition: model.GetFilterConditionEnum().OR,
    IsSupportFilter: true,
    Rule: listRuleFilter,
    }
    var listUserListNotifyUserList = []string{
            "test3",
        "test4",
        }
    var listUserListNotifyUserList1 = []string{
            "test1",
        "test2",
        }
    var listNotifyUserListbody = []model.NotificationUsers{
            {
                UserGroup: "admin",
                UserList: listUserListNotifyUserList1,
            },
            {
                UserGroup: "CTS view",
                UserList: listUserListNotifyUserList,
            },
        }
    var listTraceNamesOperations = []string{
            "deletePolicyGroup",
        "updatePolicyGroup",
        "createPolicyGroup",
        }
    var listTraceNamesOperations1 = []string{
            "deleteNotification",
        "updateNotification",
        }
    var listTraceNamesOperations2 = []string{
            "createTracker",
        "deleteTracker",
        }
    var listOperationsbody = []model.Operations{
            {
                ServiceType: "CTS",
                ResourceType: "tracker",
                TraceNames: listTraceNamesOperations2,
            },
            {
                ServiceType: "CTS",
                ResourceType: "notification",
                TraceNames: listTraceNamesOperations1,
            },
            {
                ServiceType: "AOM",
                ResourceType: "pe",
                TraceNames: listTraceNamesOperations,
            },
        }
    topicIdCreateNotificationRequestBody:= "urn:smn:{regionid}:24edf66e79d04187acb99a463e610764:test"
    agencyNameCreateNotificationRequestBody:= model.GetCreateNotificationRequestBodyAgencyNameEnum().CTS_ADMIN_TRUST
    request.Body = &model.CreateNotificationRequestBody{
    Filter: filterbody,
    TopicId: &topicIdCreateNotificationRequestBody,
    NotifyUserList: &listNotifyUserListbody,
    Operations: &listOperationsbody,
    AgencyName: &agencyNameCreateNotificationRequestBody,
    OperationType: model.GetCreateNotificationRequestBodyOperationTypeEnum().CUSTOMIZED,
    NotificationName: "test",
    }
    response, err := client.CreateNotification(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
   
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CTS/sdk?api=CreateNotification)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                          |
|:---|:---|
| 201 | 创建成功。                       |
| 400 | 服务器未能处理请求。                  |
| 401 | 请求鉴权校验失败，访问被拒绝。             |
| 403 | 请求权限校验失败，访问被禁止。             |
| 404 | 服务器无法找到被请求的资源或部分关键操作通知删除失败。 |
| 500 | 服务内部异常，请求未完成；或部分追踪器删除失败。    |
| 503 | 被请求的服务无效。建议直接修改该请求，不要重试该请求。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-cts/ErrorCode.html)。
