文档首页/ 应用运维管理 AOM/ API参考/ API/ 告警/ 查询告警模板列表 - ListAlarmRuleTemplate
更新时间:2025-11-19 GMT+08:00
分享

查询告警模板列表 - ListAlarmRuleTemplate

功能介绍

该接口用于查询告警模板列表。

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    aom:alarmRuleTemplate:list

    List

    -

    -

    -

    -

URI

GET /v4/{project_id}/alarm-rules-template

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,可以从控制台获取,也可以从调用API处获取。获取方式请参见:获取项目ID

表2 Query参数

参数

是否必选

参数类型

描述

id

String

告警模板id。

type

String

告警模板类型。默认值为“template”

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token。获取方式请参见:获取Token

Content-Type

String

消息体的类型(格式)。指定类型为“application/json”。

Enterprise-Project-Id

String

企业项目id。获取方式请参见:获取企业项目ID

  • 查询单个企业项目下实例,填写企业项目id。

  • 查询所有企业项目下实例,填写“all_granted_eps”。

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

alarm_rule_templates

Array of AlarmRuleTemplateBody objects

告警模板列表。

count

Integer

告警模板总数。

表5 AlarmRuleTemplateBody

参数

参数类型

描述

alarm_rule_template_name

String

告警模板名称。

alarm_rule_template_name_en

String

告警模板英文名称。

alarm_rule_template_description

String

告警模板描述。

alarm_rule_template_id

String

告警模板id。

alarm_rule_template_project_id

String

项目ID,可以从控制台获取,也可以从调用API处获取。获取方式请参见:获取项目ID

alarm_rule_template_type

String

告警模板类型

  • “statics”:静态告警模板

  • “dynamic”:动态告警模板

alarm_rule_template_source

String

告警模板来源。

alarm_rule_template_binding

Map<String,String>

告警模板所绑定的告警规则。

alarm_template_spec_list

Array of AlarmRuleTemplateSpecWithCloudService objects

告警模板列表。

enterprise_project_id

String

企业项目id。获取方式请参见:获取企业项目ID

create_time

Long

创建时间。

modify_time

Long

更新时间。

templating

Templating object

告警模板变量列表。

template_version

String

告警模板版本。

表6 AlarmRuleTemplateSpecWithCloudService

参数

参数类型

描述

related_cloud_service

String

关联的云服务。

related_cce_clusters

Array of strings

关联的CCE集群。

related_prometheus_instances

Array of strings

关联的Prom实例。

alarm_notification

AlarmNotification object

通知信息。

alarm_template_spec_items

Array of AlarmTemplateSpecItem objects

告警模板列表。

表7 AlarmNotification

参数

参数类型

描述

notification_type

String

通知类型。

  • “direct”:直接告警

  • “alarm_policy”:告警降噪

枚举值:

  • direct

  • alarm_policy

route_group_enable

Boolean

启用告警分组规则。

  • 当通知类型为“alarm_policy”时:true

  • 当通知类型为“direct”时:false

如果告警触发“notify_triggered”或告警恢复“notify_resolved”都设置为false(即都不进行告警通知),则route_group_enable需设置为false。

枚举值:

  • true

  • false

route_group_rule

String

告警分组规则名称。

  • 当route_group_enable 为true时,填告警分组规则名称

  • 当route_group_enable 为false时,填“”

notification_enable

Boolean

是否启用告警通知规则。

  • 当通知类型为“direct”时,填true

  • 当通知类型为“alarm_policy”时,填false

如果告警触发“notify_triggered”或告警恢复“notify_resolved”都设置为false(即都不进行告警通知),则notification_enable需设置为false。

bind_notification_rule_id

String

告警行动策略id。

  • 当notification_enable为true时,填告警行动策略id

  • 当notification_enable为false时,填“”

notify_resolved

Boolean

告警解决是否通知。

  • true:通知

  • false:不通知

枚举值:

  • true

  • false

notify_triggered

Boolean

告警触发是否通知。

  • true:通知

  • false:不通知

枚举值:

  • true

  • false

notify_frequency

Integer

通知频率

  • 当通知类型为“alarm_policy”时,填“-1”

  • 当通知类型为“direct”时,

    • “0”:只告警一次

    • “300”:每5分钟

    • “600”:每10分钟

    • “900”:每15分钟

    • “1800”:每30分钟

    • “3600”:每1小时

    • “10800”:每3小时

    • “21600”:每6小时

    • “43200”:每12小时

    • “86400”:每天

表8 AlarmTemplateSpecItem

参数

参数类型

描述

alarm_template_name

String

告警模板下单个告警规则名称。

alarm_template_name_en

String

告警模板下单个告警规则英文名称。

desc

String

告警模板下单个告警规则描述。

desc_en

String

告警模板下单个告警规则英文描述。

alarm_template_spec_type

String

告警模板下单个告警规则类型。

“metric”:指标告警

“event”:事件告警

metric_alarm_template_spec

MetricAlarmTemplateSpec object

指标告警模板。

event_alarm_template_spec

EventAlarmTemplateSpec object

事件告警模板。

表9 MetricAlarmTemplateSpec

参数

参数类型

描述

alarm_subtype

String

告警规则类别。

alarm_source

String

告警规则来源云服务:CCE 创建标识。

monitor_type

String

监控类型。

trigger_conditions

Array of TemplateTriggerCondition objects

触发条件。

no_data_conditions

Array of NoDataCondition objects

数据不足条件。

alarm_tags

Array of AlarmTags objects

告警标签。

recovery_conditions

RecoveryCondition object

告警恢复条件。

表10 TemplateTriggerCondition

参数

参数类型

描述

metric_query_mode

String

指标查询模式。

  • “AOM”:AOM原生

  • “PROM”:AOM Prometheus

  • “NATIVE_PROM”:原生Prometheus

枚举值:

  • AOM

  • PROM

  • NATIVE_PROM

metric_namespace

String

指标命名空间。

metric_name

String

指标名称。

metric_unit

String

指标单位。

metric_labels

Array of strings

指标维度。

promql

String

Prometheus语句。

promql_expr

String

Prometheus语句模板。

trigger_times

Integer

连续周期个数。

trigger_interval

String

检查频率周期。

  • 当trigger_type 为“HOURLY”时,填“”

  • 当trigger_type为“DAILY”时,格式为:“小时” 。例如每天凌晨三点"03:00"。

  • 当trigger_type为“WEEKLY”时,格式为:“星期 小时”。例如每周一凌晨三点 “1 03:00”。

  • 当trigger_type为“CRON”时,格式为标准CRON表达式。

  • 当trigger_type为“FIXED_RATE”时,秒的取值为15s,30s,分钟为 1~59,小时为 1~24。例如“15s”,“30s”,“1min”,“1h”。

trigger_type

String

触发频率的类型:

  • “FIXED_RATE”:固定间隔

  • “HOURLY”:每小时

  • “DAILY”:每天

  • “WEEKLY”:每周

  • “CRON”:Cron表达式

枚举值:

  • FIXED_RATE

  • HOURLY

  • DAILY

  • WEEKLY

  • CRON

promql_for

String

持续时间。

持续时间范围:

  • “0”:立即

  • “15s”:15秒

  • “30s”:30秒

  • “1m”:1分钟

aggregation_type

String

检测规则:

  • average:平均值

  • minimum:最小值

  • maximum:最大值

  • sum:总计

  • sampleCount:样本

operator

String

判断条件:“>”,“<”,“=”,“>=”,“<=”

thresholds

Map<String,String>

键值对形式,键为告警级别,值为告警阈值

aggregation_window

String

统计周期。

  • “15s”:15秒

  • “30s”:30秒

  • “1m”:1分钟

  • “5m”:5分钟

  • “15m”:15分钟

  • “1h”:1小时

cmdb

CmdbInfo object

cmdb信息。

query_match

String

查询筛选条件。

aom_monitor_level

String

监控层级。

aggregate_type

String

聚合方式。

  • “by”:不分组

  • “avg”

  • “max”

  • “min”

  • “sum”

枚举值:

  • by

  • avg

  • max

  • min

  • sum

metric_statistic_method

String

当配置方式为全量指标时可选择的指标运算方式。

  • “single”:单个指标进行运算

  • “mix”:多个指标进行混合运算

枚举值:

  • single

  • mix

expression

String

混合运算的表达式。

mix_promql

String

混合运算的promQL。

alarm_message_template

String

通知内容。

promql_monitor_templates

Array of strings

Prometheus监控模板。默认为cluster。

query_param

Object

  • PromQL告警规则,该参数为"{"defaultRule":{"label":"自定义","id":"custom"},"templateSelectd":null,"dimensionsList":[]}"

  • 阈值告警规则,该参数为空。

表11 CmdbInfo

参数

参数类型

描述

app_id

String

应用id。

node_ids

Array of NodeInfo objects

节点信息列表。

表12 NodeInfo

参数

参数类型

描述

node_type

String

节点类型。

node_id

String

节点id。

表13 NoDataCondition

参数

参数类型

描述

no_data_timeframe

Integer

无数据处理连续周期。取值范围为1~5。(当"notify_no_data"为true时,该参数必填,当"notify_no_data"为false时,该参数为空)

no_data_alert_state

String

数据不足时,阈值规则的状态。(当"notify_no_data"为true时,该参数必填,当"notify_no_data"为false时,该参数为空)

  • “no_data”:数据不足并发送通知

  • “alerting”:告警

  • “ok”:正常

  • “pre_state”:保持上一个状态

枚举值:

  • no_data

  • alerting

  • ok

  • pre_state

notify_no_data

Boolean

无数据处理开关。true表示启用无数据处理,false表示关闭无数据处理。

表14 AlarmTags

参数

参数类型

描述

auto_tags

Array of strings

自动标签。

custom_tags

Array of strings

自定义标签。

custom_annotations

Array of strings

告警标注。

表15 RecoveryCondition

参数

参数类型

描述

recovery_timeframe

Integer

告警恢复周期的个数。取值范围为1~3 (如果recovery_timeframe 参数不为空,该参数必填)

表16 EventAlarmTemplateSpec

参数

参数类型

描述

alarm_subtype

String

告警规则类别。

alarm_source

String

告警规则来源云服务:CCE 创建标识。

event_source

String

告警来源。

monitor_object_templates

Array of strings

监控对象模板(创建告警时需要补齐里面的内容)。

monitor_objects

Array of Map<String,String> objects

监控对象列表。键值对形式,键值为:

  • “event_type”:通知类型

  • “event_severity”:告警级别

  • “event_name”:事件名称

  • “namespace”:命名空间

  • “clusterId”:集群id

  • “customField”:用户自定义字段

trigger_conditions

Array of EventTriggerCondition objects

触发条件。

表17 EventTriggerCondition

参数

参数类型

描述

event_name

String

事件名称。

trigger_type

String

触发方式:

  • “immediately”:立即触发

  • “accumulative”:累计触发

枚举值:

  • immediately

  • accumulative

aggregation_window

Long

监控周期。单位为秒,例如 1小时 填“3600”,当trigger_type为“immediately”时 该参数为空,当trigger_type为“accumulative”时 该参数必填。

监控周期范围:

5分钟,20分钟,1小时,4小时,24小时。

operator

String

判断条件:“>”,“<”,“=”,“>=”,“<=”,当trigger_type为“immediately”时 该参数为空。当trigger_type为“accumulative”时 该参数必填。

thresholds

Map<String,Integer>

键值对形式,键为告警级别,值为累计次数,当trigger_type为“immediately”时 累计次数为1。当当trigger_type为“accumulative”时 累计次数范围为1~100 (如果trigger_conditions参数不为空,该参数必填)

frequency

String

事件类告警频率。当trigger_type为“immediately”时 值为-1。

  • “-1”:N/A

  • “0”:只告警一次

  • “300”:每5分钟

  • “600”:每10分钟:

  • “900”:每15分钟:

  • “1800”:每30分钟:

  • “3600”:每1小时:

  • “10800”:每3小时:

  • “21600”:每6小时:

  • “43200”:每12小时:

  • “86400”:每天:

表18 Templating

参数

参数类型

描述

list

Array of TemplateInfo objects

变量列表。

表19 TemplateInfo

参数

参数类型

描述

name

String

变量名称。

type

String

变量类型。

query

String

变量值。

description

String

变量描述。

请求示例

  • 查询告警模板列表

    https://{Endpoint}/v4/{project_id}/alarm-rules-template
  • 查询告警模板id为12142546931的告警模板

    https://{Endpoint}/v4/{project_id}/alarm-rules-template?id=1214****2546****931

响应示例

状态码:200

OK 请求响应成功。

{
  "alarm_rule_templates" : [ {
    "alarm_rule_template_binding" : { },
    "alarm_rule_template_id" : "130****1802****3121",
    "alarm_rule_template_name" : "aomTemplate",
    "alarm_rule_template_project_id" : "2a47****cca5****8373****1bff****",
    "alarm_rule_template_type" : "statics",
    "alarm_template_spec_list" : [ {
      "alarm_template_spec_items" : [ ],
      "related_cce_clusters" : [ ],
      "related_cloud_service" : "VPC",
      "related_prometheus_instances" : [ ]
    } ],
    "create_time" : 1732266984780,
    "enterprise_project_id" : "0",
    "modify_time" : 1732266984780
  } ],
  "count" : 119
}

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
47
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.aom.v2.region.AomRegion;
import com.huaweicloud.sdk.aom.v2.*;
import com.huaweicloud.sdk.aom.v2.model.*;


public class ListAlarmRuleTemplateSolution {

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

        AomClient client = AomClient.newBuilder()
                .withCredential(auth)
                .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                .build();
        ListAlarmRuleTemplateRequest request = new ListAlarmRuleTemplateRequest();
        try {
            ListAlarmRuleTemplateResponse response = client.listAlarmRuleTemplate(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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkaom.v2.region.aom_region import AomRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkaom.v2 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 = AomClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(AomRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListAlarmRuleTemplateRequest()
        response = client.list_alarm_rule_template(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"
    aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/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 := aom.NewAomClient(
        aom.AomClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListAlarmRuleTemplateRequest{}
	response, err := client.ListAlarmRuleTemplate(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK 请求响应成功。

错误码

请参见错误码

相关文档