Creating a Key Event Notification
Function
This API is used to configure notifications for key events. When specified operations are detected, the system uses Simple Message Notification (SMN) topics to notify users via SMS, email, or HTTP/HTTPS messages. This helps you detect high-risk operations promptly. These notifications can also be used as triggers for specific operations or be integrated with your own audit systems.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, the following identity policy-based permissions are required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
cts:notification:create
Write
-
-
-
- smn:topic:listTopic
- iam:users:listUsers
- iam:groups:listGroups
URI
POST /v3/{project_id}/notifications
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Project ID. For details, see Obtaining an Account ID and Project ID. |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
notification_name |
Yes |
String |
Key event notification name. |
|
operation_type |
Yes |
String |
Operation type. Possible options include complete and customized. If you choose complete, operations and notify_user_list parameters are not required, and notifications will be triggered for any supported operation on any connected cloud service. If you choose customized, notifications will only be sent when the specific operations defined in operations occur. |
|
operations |
No |
Array of Operations objects |
Operation list. |
|
notify_user_list |
No |
Array of NotificationUsers objects |
List of users whose operations will trigger notifications. Currently, up to 50 users in 10 user groups can be configured. |
|
topic_id |
No |
String |
SMN topic URN or FunctionGraph function URN. To obtain the topic URN, call the SMN API for querying topics. Example URN: urn:smn:regionId:f96188c7ccaf4ffba0c9aa149ab2bd57:test_topic_v2 To obtain the function URN, call the FunctionGraph API for querying functions. Example URN urn:fss:xxxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test |
|
filter |
No |
Filter object |
Advanced filter of the key event notification. |
|
agency_name |
No |
String |
Cloud service agency name. If this parameter is set to cts_admin_trust, a cloud service agency named cts_admin_trust is automatically created during key event notification creation. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
service_type |
Yes |
String |
Cloud service. The value must be the uppercase acronym of a cloud service connected with CTS. For cloud services that can be connected with CTS, see section "Supported Services and Operations" in Cloud Trace Service User Guide. You can click the document link of each cloud service to view its acronym. |
|
resource_type |
Yes |
String |
Resource type. |
|
trace_names |
Yes |
Array of strings |
Trace name. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
user_group |
Yes |
String |
IAM user group. |
|
user_list |
Yes |
Array of strings |
IAM user. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
condition |
Yes |
String |
Relationship between conditions.
|
|
is_support_filter |
Yes |
Boolean |
Whether to enable the advanced filter. |
|
rule |
Yes |
Array of strings |
Advanced filter criteria rule. Example: key != value. Format: field rule value- Field value range: api_version, code, trace_rating, trace_type, resource_id, and resource_name.- Rule: != or =.- Value: api_version: ^(a-zA-Z0-9_-.){1,64}$; code: 1 to 256 characters; trace_rating: normal, warning, or incident; trace_type: *ConsoleAction, ApiCall, or SystemAction; *resource_id: 1 to 350 characters; resource_name: 1 to 256 characters. |
Response Parameters
Status code: 201
|
Parameter |
Type |
Description |
|---|---|---|
|
notification_name |
String |
Notification name. |
|
operation_type |
String |
Operation type. Possible options include complete and customized.
|
|
operations |
Array of Operations objects |
Operation list. |
|
notify_user_list |
Array of NotificationUsers objects |
List of users whose operations will trigger notifications. Currently, up to 50 users in 10 user groups can be configured. |
|
status |
String |
Notification status. Possible options include disabled and enabled.
|
|
topic_id |
String |
Unique resource ID of an SMN topic. You can obtain the ID by querying the topic list. |
|
notification_id |
String |
Unique notification ID. |
|
notification_type |
String |
Notification type.
|
|
project_id |
String |
Project ID. |
|
create_time |
Long |
Time when a notification rule was created. |
|
filter |
Filter object |
Advanced filter of the key event notification. |
|
agency_name |
String |
Cloud service agency name. If this parameter is set to cts_admin_trust, a cloud service agency named cts_admin_trust is automatically created during key event notification creation. |
|
Parameter |
Type |
Description |
|---|---|---|
|
service_type |
String |
Cloud service. The value must be the uppercase acronym of a cloud service connected with CTS. For cloud services that can be connected with CTS, see section "Supported Services and Operations" in Cloud Trace Service User Guide. You can click the document link of each cloud service to view its acronym. |
|
resource_type |
String |
Resource type. |
|
trace_names |
Array of strings |
Trace name. |
|
Parameter |
Type |
Description |
|---|---|---|
|
user_group |
String |
IAM user group. |
|
user_list |
Array of strings |
IAM user. |
|
Parameter |
Type |
Description |
|---|---|---|
|
condition |
String |
Relationship between conditions.
|
|
is_support_filter |
Boolean |
Whether to enable the advanced filter. |
|
rule |
Array of strings |
Advanced filter criteria rule. Example: key != value. Format: field rule value- Field value range: api_version, code, trace_rating, trace_type, resource_id, and resource_name.- Rule: != or =.- Value: api_version: ^(a-zA-Z0-9_-.){1,64}$; code: 1 to 256 characters; trace_rating: normal, warning, or incident; trace_type: *ConsoleAction, ApiCall, or SystemAction; *resource_id: 1 to 350 characters; resource_name: 1 to 256 characters. |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 401
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 403
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 404
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 500
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 503
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Example Requests
-
Create a complete key event notification.
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:{regionid}:24edf66e79d04187acb99a463e610764:test" } -
Create a custom key event notification.
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" }
Example Responses
Status code: 201
Creation succeeded.
{
"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:{regionid}:24edf66e79d04187acb99a463e610764:test"
}
SDK Sample Code
The SDK sample code is as follows.
Java
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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:{regionid}:24edf66e79d04187acb99a463e610764:test"); body.withAgencyName(CreateNotificationRequestBody.AgencyNameEnum.fromValue("cts_admin_trust")); body.withOperationType(CreateNotificationRequestBody.OperationTypeEnum.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()); } } }
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
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.AgencyNameEnum.fromValue("cts_admin_trust")); body.withOperationType(CreateNotificationRequestBody.OperationTypeEnum.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
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# 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:{regionid}: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)
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
# 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
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cts.NewCtsClient( cts.CtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateNotificationRequest{} var listRuleFilter = List<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:{regionid}: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) } }
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cts.NewCtsClient( cts.CtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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) } }
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
201 |
Creation succeeded. |
|
400 |
The server failed to process the request. |
|
401 |
The request is rejected due to authentication failure. |
|
403 |
The server understood the request but refused to authorize it. |
|
404 |
The server failed to find the requested resource or some key event notifications failed to be deleted. |
|
500 |
The request failed to be executed or some trackers failed to be deleted. |
|
503 |
The requested service is invalid. The client should not repeat the request without modifications. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot