更新时间:2024-05-21 GMT+08:00
分享

查询关键操作通知

功能介绍

查询创建的关键操作通知规则。

调用方法

请参见如何调用API

URI

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

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,参见获取账号ID和项目ID章节。

notification_type

String

通知类型。 -smn:消息通知服务。 -fun:函数工作流。

枚举值:

  • smn

  • fun

表2 Query参数

参数

是否必选

参数类型

描述

notification_name

String

标识关键操作通知名称。 在不传入该字段的情况下,将查询当前租户所有的关键操作通知。

请求参数

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

notifications

Array of NotificationsResponseBody objects

关键操作通知列表。

表4 NotificationsResponseBody

参数

参数类型

描述

notification_name

String

标识关键操作名称。

operation_type

String

标识操作类型。 目前支持的操作类型有完整类型(complete)和自定义类型(customized)。 完整类型下,CTS发送通知的对象为已对接服务的所有事件。 自定义类型下,CTS发送通知的对象是在operations列表中指定的事件。

枚举值:

  • customized

  • complete

operations

Array of Operations objects

操作事件列表。

notify_user_list

Array of NotificationUsers objects

通知用户列表,目前最多支持对10个用户组和50个用户发起的操作进行配置。

status

String

标识关键操作通知状态,包括正常(enabled),停止(disabled)两种状态。

枚举值:

  • enabled

  • disabled

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。

notification_id

String

关键操作通知的唯一标识。

notification_type

String

关键操作通知类型,根据topic_id区分为消息通知服务(smn)和函数工作流(fun)。

枚举值:

  • smn

  • fun

project_id

String

项目ID。

create_time

Long

关键操作通知创建时间戳。

filter

Filter object

关键操作通知高级筛选条件。

表5 Operations

参数

参数类型

描述

service_type

String

标识云服务类型。必须为已对接CTS的云服务的英文缩写,且服务类型一般为大写字母。 已对接的云服务列表参见《云审计服务用户指南》“支持审计的服务及详细操作列表”章节,单击对应云服务的文档链接,可以查看到该云服务的英文缩写。

resource_type

String

标识资源类型。

trace_names

Array of strings

标识事件名称。

表6 NotificationUsers

参数

参数类型

描述

user_group

String

IAM用户组。

user_list

Array of strings

IAM用户。

表7 Filter

参数

参数类型

描述

condition

String

多条件关系。

  • AND(默认值) 表示所有过滤条件满足后生效。

  • OR 表示有任意一个条件满足时生效。

枚举值:

  • 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

表8 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 401

表9 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 403

表10 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 404

表11 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 500

表12 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 503

表13 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

请求示例

响应示例

状态码: 200

查询成功。

{
  "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"
  } ]
}

SDK代码示例

SDK代码示例如下。

 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());
        }
    }
}
 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)
 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)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

查询成功。

400

服务器未能处理请求。

401

请求鉴权校验失败,访问被拒绝。

403

请求权限校验失败,访问被禁止。

404

服务器无法找到被请求的资源或部分关键操作通知删除失败。

500

服务内部异常,请求未完成;或部分追踪器删除失败。

503

被请求的服务无效。建议直接修改该请求,不要重试该请求。

错误码

请参见错误码

分享:

    相关文档

    相关产品