Updated on 2024-05-22 GMT+08:00

Querying a Key Event Notification

Function

This API is used to query a key event notification.

API Calling

For details, see Calling APIs.

URI

GET /v3/{project_id}/notifications/{notification_type}

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining an Account ID and Project ID.

notification_type

Yes

String

Notification type. - smn: Simple Message Notification (SMN). - fun: FunctionGraph.

Enumerated values:

  • smn

  • fun

Table 2 Query parameters

Parameter

Mandatory

Type

Description

notification_name

No

String

Notification name. If this parameter is not specified, all key event notifications configured in the current tenant account are returned.

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

notifications

Array of NotificationsResponseBody objects

Notification list.

Table 4 NotificationsResponseBody

Parameter

Type

Description

notification_name

String

Notification name.

operation_type

String

Operation type. Possible options include complete and customized. If you choose complete, notifications will be sent when any supported operation occurs on any of the connected cloud services. If you choose customized, notifications will be sent when operations defined in operations occur.

Enumerated values:

  • customized

  • complete

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 enabled and disabled.

Enumerated values:

  • enabled

  • disabled

topic_id

String

Topic URN or 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

notification_id

String

Unique notification ID.

notification_type

String

Notification type identified based on topic_id. Possible options include SMN (smn) and FunctionGraph (fun).

Enumerated values:

  • smn

  • fun

project_id

String

Project ID.

create_time

Long

Timestamp when a notification was created.

filter

Filter object

Advanced filter of key event notifications.

Table 5 Operations

Parameter

Type

Description

service_type

String

Cloud service. The value must be the acronym of a cloud service that has been connected with CTS. It is a word composed of uppercase letters. 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.

Table 6 NotificationUsers

Parameter

Type

Description

user_group

String

IAM user group.

user_list

Array of strings

IAM user.

Table 7 Filter

Parameter

Type

Description

condition

String

Relationship between conditions.

  • AND (default value) indicates that a rule takes effect after all filtering criteria are met.

  • OR indicates that a rule takes effect when one of the filtering criteria is met.

Enumerated values:

  • AND (default value)

  • OR

is_support_filter

Boolean

Whether to enable the advanced filter.

rule

Array of strings

Advanced filter criteria rule. Example: key != value. The format is field rule value. - Field options: api_version, code, trace_rating, trace_type, resource_id, or 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

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 401

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 403

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 404

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 500

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 503

Table 13 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Example Request

None

Example Response

Status code: 200

The query is successful.

{
  "notifications" : [ {
    "create_time" : 1633933167385,
    "notify_user_list" : [ {
      "user_group" : "admin",
      "user_list" : [ "test1", "test2" ]
    }, {
      "user_group" : "CTS view",
      "user_list" : [ "test3", "test4" ]
    } ],
    "notification_id" : "0b98e1c2-2fd6-4e33-a355-f9e12eaab88a",
    "notification_name" : "test2",
    "notification_type" : "smn",
    "operation_type" : "customized",
    "operations" : [ {
      "resource_type" : "tracker",
      "service_type" : "CTS",
      "trace_names" : [ "createTracker" ]
    }, {
      "resource_type" : "notification",
      "service_type" : "CTS",
      "trace_names" : [ "deleteNotification", "updateNotification" ]
    }, {
      "resource_type" : "pe",
      "service_type" : "AOM",
      "trace_names" : [ "createPolicyGroup", "updatePolicyGroup", "deletePolicyGroup" ]
    } ],
    "project_id" : "24edf66e79d04187acb99a463e610764",
    "status" : "enabled",
    "topic_id" : "urn:smn:{regionid}:24edf66e79d04187acb99a463e610764:test"
  }, {
    "create_time" : 1633924057706,
    "notify_user_list" : [ {
      "user_group" : "admin",
      "user_list" : [ "test1", "test2" ]
    }, {
      "user_group" : "CTS view",
      "user_list" : [ "test3", "test4" ]
    } ],
    "notification_id" : "6d4a09bb-aa8e-40db-9e87-0d5e203823a8",
    "notification_name" : "test1",
    "notification_type" : "smn",
    "operation_type" : "complete",
    "operations" : [ ],
    "project_id" : "24edf66e79d04187acb99a463e610764",
    "status" : "disabled"
  } ]
}

Example SDK Code

The example SDK 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
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.*;


public class ListNotificationsSolution {

    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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CtsClient client = CtsClient.newBuilder()
                .withCredential(auth)
                .withRegion(CtsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListNotificationsRequest request = new ListNotificationsRequest();
        request.withNotificationName("<notification_name>");
        try {
            ListNotificationsResponse response = client.listNotifications(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
# coding: utf-8

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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = CtsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CtsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListNotificationsRequest()
        request.notification_name = "<notification_name>"
        response = client.list_notifications(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
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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cts.NewCtsClient(
        cts.CtsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListNotificationsRequest{}
	notificationNameRequest:= "<notification_name>"
	request.NotificationName = &notificationNameRequest
	response, err := client.ListNotifications(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

More

For SDK sample code in other programming languages, see the Sample Code tab in the API Explorer.

Status Codes

Status Code

Description

200

The query is successful.

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 Code

For details, see Error Codes.