创建告警模板
功能介绍
该接口用于创建告警模板。
调用方法
请参见如何调用API。
URI
POST /v4/{project_id}/alarm-rules-template
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,可以从控制台获取,也可以从调用API处获取。获取方式请参见:获取项目ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token。获取方式请参见:获取Token。 |
Content-Type |
是 |
String |
消息体的类型(格式)。指定类型为“application/json”。 |
Enterprise-Project-Id |
否 |
String |
企业项目id。获取方式请参见:获取企业项目ID。
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
alarm_rule_template_name |
是 |
String |
告警模板的名称。最多可输入100个字符,只能包含中文、字母、数字、下划线和中划线,开头、结尾不允许输入下划线或中划线。 |
alarm_rule_template_description |
否 |
String |
模板的描述信息,最多可输入1024个字符。 |
templating |
否 |
Templating object |
告警规则模板变量列表。 |
alarm_template_spec_list |
是 |
Array of CreateOrUpdateAlarmRuleTemplateSpecWithCloudService objects |
告警模板规则列表。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
变量名称。 |
type |
否 |
String |
变量类型。 |
query |
否 |
String |
变量值。 |
description |
否 |
String |
变量描述。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
related_cloud_service |
否 |
String |
关联的云服务名称。支持的云服务名称:FunctionGraph、DRS、RDS、NAT、VPC、DCS、CSS、DC、CBR、DMS、ELB、EVS、OBS、DDS、WAF、CEFromProm、CCI2。
|
alarm_template_spec_items |
否 |
Array of CreateOrUpdateAlarmTemplateSpecItem objects |
告警模板列表。 |
related_prometheus_instances |
否 |
Array of strings |
告警模板关联的Prometheus实例名称列表。(该参数只针对非CCECCEFromProm有效) |
related_cce_clusters |
否 |
Array of strings |
告警模板关联的CCE集群名称列表。(该参数只针对CCEFromProm有效) |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
alarm_template_name |
是 |
String |
告警规则模板下单个告警规则名称。只含有汉字、数字、字母、下划线、中划线,不能以下划线等特殊符号开头和结尾,长度为 1 - 256 |
alarm_template_spec_type |
是 |
String |
告警规则模板下单个告警规则类型。
|
metric_alarm_template_spec |
否 |
指标告警模板。(创建CCEFromProm事件告警规则时,该参数为空,创建指标告警规则时,该参数必填) |
|
event_alarm_template_spec |
否 |
事件告警模板。(创建CCEFromProm事件告警规则时,该参数必填,创建指标告警规则时,该参数为空) |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
alarm_tags |
否 |
Array of AlarmTemplateAlarmTags objects |
告警标签。 |
monitor_type |
否 |
String |
监控类型。(如果metric_alarm_template_spec参数不为空,则该参数必填)
|
no_data_conditions |
否 |
Array of NoDataCondition objects |
无数据处理相关参数。(如果创建阈值告警规则时,该参数需关注,如果创建PromQL告警规则,该参数为空) |
recovery_conditions |
否 |
RecoveryCondition object |
告警恢复条件。(如果metric_alarm_template_spec参数不为空,则该参数必填) |
trigger_conditions |
否 |
Array of TemplateTriggerCondition objects |
告警触发条件。(如果metric_alarm_template_spec参数不为空,则该参数必填) |
resource_kind |
否 |
String |
资源类型。(如果创建阈值告警规则时,该参数必填,如果创建PromQL告警规则时,该参数为空) 格式为:"HC:云服务名称:METRICS" 例如FunctionGraph云服务的资源类型为:"HC:FunctionGraph:METRICS" |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
custom_tags |
否 |
Array of strings |
告警规则标签。(为告警规则添加标签,标签将同步到TMS服务,该标签可以用于搜索过滤、告警降噪分组条件,也可以在消息模板中以$event.metadata.标签名被引用。) |
custom_annotations |
否 |
Array of strings |
告警规则标注。(为告警规则添加键值对属性,标注不会同步给TMS标签服务,但是可以用于告警降噪分组条件,也可以在消息模板中以$event.metadata.标注名被引用。) |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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时,该参数为空)
枚举值:
|
notify_no_data |
否 |
Boolean |
无数据处理开关。true表示启用无数据处理,false表示关闭无数据处理。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
recovery_timeframe |
否 |
Integer |
告警恢复周期的个数。取值范围为1~3 (如果recovery_timeframe 参数不为空,该参数必填) |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
aggregation_type |
否 |
String |
检测规则:(如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填)
|
aggregation_window |
否 |
String |
统计周期。(如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填)
|
alarm_message_template |
否 |
String |
通知内容。(如果创建PromQL告警规则,该参数需关注,如果创建阈值告警规则,该参数为空) |
metric_name |
否 |
String |
指标名称。(如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填) |
metric_labels |
否 |
Array of strings |
指标维度。(如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填) |
metric_namespace |
否 |
String |
指标命名空间。(如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填) |
metric_query_mode |
否 |
String |
指标查询模式。(如果trigger_conditions参数不为空,该参数必填)
枚举值:
|
metric_unit |
否 |
String |
指标单位。 |
operator |
否 |
String |
判断条件:“>”,“<”,“=”,“>=”,“<=” (如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填) |
promql |
否 |
String |
Prometheus语句。(如果创建PromQL告警规则,该参数必填,如果创建阈值告警规则,该参数为空) |
promql_expr |
否 |
String |
Prometheus语句模板。(如果创建PromQL告警规则,该参数需关注,如果创建阈值告警规则,该参数为空)默认和promql的值保持一致。 |
promql_for |
否 |
String |
持续时间。(如果创建PromQL告警规则,该参数必填,如果创建阈值告警规则,该参数为空) 持续时间范围:
|
promql_monitor_templates |
否 |
Array of strings |
Prometheus监控模板。默认为cluster。 |
query_param |
否 |
String |
填写默认值:"{"defaultRule":{"label":"自定义","id":"custom"},"templateSelectd":null,"dimensionsList":[]}"(如果创建PromQL告警规则,该参数必填,如果创建阈值告警规则,该参数为空) |
thresholds |
否 |
Map<String,String> |
键值对形式,键为告警级别,值为告警阈值。PromQL告警规则告警阈值为0,阈值告警规则告警阈值为1。(如果trigger_conditions参数不为空,该参数必填) |
trigger_type |
否 |
String |
触发频率的类型:
PromQL告警规则,仅支持固定间隔“FIXED_RATE”。 枚举值:
|
trigger_interval |
否 |
String |
检查频率周期。
|
trigger_times |
否 |
String |
连续周期个数。(如果创建PromQL告警规则,该参数为空,如果创建阈值告警规则,该参数必填) 取值范围为:1~30 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
event_source |
否 |
String |
告警来源。仅支持CCE。 |
monitor_object_templates |
否 |
Array of strings |
监控对象模板。默认值为“clusterId”(如果event_alarm_template_spec参数不为空,该参数必填) |
monitor_objects |
否 |
Array of Map<String,String> objects |
监控对象列表。键值对形式,键值为:
|
trigger_conditions |
否 |
Array of EventTriggerCondition objects |
触发条件。(如果event_alarm_template_spec参数不为空,该参数必填) |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
event_name |
否 |
String |
事件名称。 |
trigger_type |
否 |
String |
触发方式:
枚举值:
|
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。
|
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
alarm_rule_templates |
Array of AlarmRuleTemplateItemResult objects |
告警模板列表。 |
error_code |
String |
错误码。 |
error_message |
String |
错误信息。 |
参数 |
参数类型 |
描述 |
---|---|---|
alarm_rule_template_name |
String |
告警模板名称。 |
alarm_rule_template_id |
String |
告警模板id。 |
状态码:400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 最小长度:12 最大长度:12 |
error_msg |
String |
错误信息。 最小长度:0 最大长度:1024 |
error_type |
String |
错误类型。 最小长度:0 最大长度:128 |
trace_id |
String |
请求id。 最小长度:32 最大长度:32 |
请求示例
-
创建CCE事件告警规则模板
https://{Endpoint}/v4/{project_id}/alarm-rules-template { "alarm_rule_template_description" : "aom事件规则模板", "alarm_rule_template_name" : "aom事件规则模板", "alarm_template_spec_list" : [ { "alarm_template_spec_items" : [ { "alarm_template_name" : "aom事件1", "alarm_template_spec_type" : "event", "event_alarm_template_spec" : { "event_source" : "CCE", "monitor_object_templates" : [ "clusterId" ], "monitor_objects" : [ { "event_name" : "" } ], "trigger_conditions" : [ { "aggregation_window" : 300, "event_name" : "", "frequency" : "1", "operator" : ">=", "thresholds" : { "Critical" : 2 }, "trigger_type" : "immediately" } ] } } ], "related_cce_clusters" : [ ], "related_cloud_service" : "CCEFromProm" } ], "templating" : { "list" : [ ] } }
-
创建CCE PromQL告警模板。
https://{Endpoint}/v4/{project_id}/alarm-rules-template { "alarm_rule_template_description" : null, "alarm_rule_template_name" : "aomCCEPromQL", "alarm_template_spec_list" : [ { "alarm_template_spec_items" : [ { "alarm_template_name" : "PromQl规则1", "alarm_template_spec_type" : "metric", "metric_alarm_template_spec" : { "alarm_tags" : [ { "custom_annotations" : [ ], "custom_tags" : [ ] } ], "monitor_type" : "promql", "recovery_conditions" : { "recovery_timeframe" : 1 }, "trigger_conditions" : [ { "alarm_message_template" : null, "metric_query_mode" : "NATIVE_PROM", "promql" : "aom_Node_cpuusage>0", "promql_expr" : "aom_Node_cpuusage>0", "promql_for" : "1m", "promql_monitor_templates" : [ "cluster" ], "query_param" : "{\"defaultRule\":{\"label\":\"自定义\",\"id\":\"custom\"},\"templateSelectd\":null,\"dimensionsList\":[]}", "thresholds" : { "Major" : 0 }, "trigger_interval" : "1m", "trigger_type" : "FIXED_RATE" } ] } } ], "related_cce_clusters" : [ ], "related_cloud_service" : "CCEFromProm" } ], "templating" : { "list" : [ ] } }
-
创建阈值告警模板。
https://{Endpoint}/v4/{project_id}/alarm-rules-template { "alarm_rule_template_description" : null, "alarm_rule_template_name" : "阈值规则模板", "alarm_template_spec_list" : [ { "alarm_template_spec_items" : [ { "alarm_template_name" : "fun阈值规则", "alarm_template_spec_type" : "metric", "metric_alarm_template_spec" : { "alarm_tags" : [ { "custom_annotations" : [ ], "custom_tags" : [ ] } ], "monitor_type" : "resource", "no_data_conditions" : [ { "no_data_alert_state" : "no_data", "no_data_timeframe" : 1, "notify_no_data" : true } ], "recovery_conditions" : { "recovery_timeframe" : 1 }, "resource_kind" : "HC:FunctionGraph:METRICS", "trigger_conditions" : [ { "aggregation_type" : "average", "aggregation_window" : "1m", "metric_labels" : [ "package_functionname" ], "metric_name" : "huaweicloud_sys_functiongraph_count", "metric_namespace" : "SYS.FunctionGraph", "metric_query_mode" : "PROM", "metric_unit" : "", "operator" : ">", "thresholds" : { "Critical" : 1 }, "trigger_interval" : "1m", "trigger_times" : 3, "trigger_type" : "FIXED_RATE" } ] } } ], "related_cloud_service" : "FunctionGraph", "related_prometheus_instances" : [ ] } ], "templating" : { "list" : [ ] } }
响应示例
状态码:200
OK 请求响应成功。
{
"alarm_rule_templates" : [ {
"alarm_rule_template_id" : "1356****3509****185",
"alarm_rule_template_name" : "aomtest"
} ],
"error_code" : "200",
"error_message" : "success"
}
状态码:400
BadRequest 非法请求。建议直接修改该请求,不要重试该请求。
{
"error_code" : "AOM.02017004",
"error_msg" : "templateName is exist!",
"trace_id" : ""
}
状态码
状态码 |
描述 |
---|---|
200 |
OK 请求响应成功。 |
400 |
BadRequest 非法请求。建议直接修改该请求,不要重试该请求。 |
错误码
请参见错误码。