ALIYUN::SLS::Alert类型用于创建告警。

语法

{
  "Type": "ALIYUN::SLS::Alert",
  "Properties": {
    "Project": String,
    "Detail": Map
  }
}

属性

属性名称 类型 必须 允许更新 描述 约束
Project String 日志项目名称。
Detail Map 告警详情。 更多信息,请参见Detail属性

Detail语法

"Detail": {
  "Type": String,
  "Description": String,
  "Configuration": Map,
  "State": String,
  "Schedule": Map,
  "DisplayName": String,
  "Name": String
}

Detail属性

属性名称 类型 必须 允许更新 描述 约束
Type String 告警类型。
Description String 告警描述信息。
Configuration Map 告警配置。 更多信息,请参见Configuration属性
State String 是否启用告警。 取值:
  • Enable:启用。
  • Disabled:不启用。
Schedule Map 日志服务评估警报规则的时间间隔。 在警报规则评估期间,如果查询返回的日志条目超过100个,则只检查前100个日志条目。

更多信息,请参见Schedule属性

DisplayName String 告警显示的名称。 长度为1~64个字符。
Name String 告警名称。

Configuration语法

"Configuration": {
  "Throttling": String,
  "Condition": String,
  "NotificationList": List,
  "NotifyThreshold": Integer,
  "Dashboard": String,
  "QueryList": List
}

Configuration属性

属性名称 类型 必须 允许更新 描述 约束
Throttling String 通知间隔。
Condition String 触发条件。 支持加( )、减(-)、乘(*)、除(/)、取模(%)5种基础运算符和大于(>)、大于等于(>=)、小于(<)、小于等于(<=)、等于(==)、不等于(!=)、正则匹配 (=~)、 正则不匹配(!~)8种比较运算符。

更多信息,请参见告警条件表达式语法

NotificationList List 通知列表。 更多信息,请参见NotificationList属性
NotifyThreshold Integer 触发通知阈值。
Dashboard String 所属仪表盘。
QueryList List 查询列表。 更多信息,请参见QueryList属性

NotificationList语法

"NotificationList": [
  {
    "Type": String,
    "MobileList": List,
    "ServiceUri": String,
    "Content": String,
    "EmailList": List
  }
]

NotificationList属性

属性名称 类型 必须 允许更新 描述 约束
Type String 通知类型。 取值:
  • SMS:短信。
  • Voice:语音。
  • Email:电子邮件。
  • MessageCenter:通知中心。
  • DingTalk:WebHook-钉钉机器人。
  • Webhook:WebHook-自定义。
Content String 通知内容。 支持使用模版变量:${Project}, ${Condition}, ${AlertName}, ${AlertID}, ${Dashboard}, ${FireTime}, ${Results}

更多信息,请参见通知方式

MobileList List 手机号码。

通知类型为短信、语音时该参数必填。

同一手机号码每天接收的通知不超过50条。

ServiceUri String 请求地址。 通知类型为WebHook-自定义或WebHook-钉钉机器人时该参数必填。
EmailList List 收件人。 通知类型为电子邮件时该参数必填。

同一邮箱每天接收的邮件不超过100条。

QueryList语法

"QueryList": [
  {
    "Query": String,
    "LogStore": String,
    "Start": String,
    "TimeSpanType": String,
    "End": String,
    "ChartTitle": String
  }
]

QueryList属性

属性名称 类型 必须 允许更新 描述 约束
Query String 查询语句。
LogStore String 日志库。
Start String 查询开始时间。
TimeSpanType String 查询区间。
End String 查询结束时间。
ChartTitle String 图表标题。

Schedule语法

"Schedule": {
  "Type": String,
  "Interval": String,
  "Hour": Integer,
  "DayOfWeek": Integer,
  "CronExpression": String,
  "Delay": Integer,
  "RunImmediately": Boolean
}

Schedule属性

属性名称 类型 必须 允许更新 描述 约束
Type String 类型。 取值:
  • Hourly:每小时。
  • Daily:每天。
  • Weekly:每周。
  • FixedRate:固定间隔。
  • Cron:Cron表达式。
Interval String 触发周期。 Type取值为FixedRate时该参数必须指定。

取值示例:

  • 10d:十天。
  • 10h:十小时。
  • 10m:十分钟。
Hour Integer 触发时间。 Type取值为Daily或Weekly时该参数必须指定。

取值范围:0~23。

DayOfWeek Integer 触发时间(星期)。 Type取值为Weekly时该参数必须指定。

取值范围:1~7。

CronExpression String Cron表达式。 Type取值为Cron时该参数必须指定。
RunImmediately Boolean 是否立即触发。 取值:
  • true
  • false
Delay Integer 延迟触发。

返回值

Fn::GetAtt

Name:告警名称。

示例

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "Project": {
      "Type": "String",
      "Description": "Project name:\n1. Only supports lowercase letters, numbers, hyphens (-) and underscores (_).\n2. Must start and end with lowercase letters and numbers.\n3. The name length is 3-63 characters.",
      "AllowedPattern": "^[a-zA-Z0-9_-] $",
      "MinLength": 3,
      "MaxLength": 63
    },
    "Detail": {
      "Type": "Json",
      "Description": ""
    }
  },
  "Resources": {
    "Alert": {
      "Type": "ALIYUN::SLS::Alert",
      "Properties": {
        "Project": {
          "Ref": "Project"
        },
        "Detail": {
          "Ref": "Detail"
        }
      }
    }
  },
  "Outputs": {
    "Name": {
      "Description": "Alert name.",
      "Value": {
        "Fn::GetAtt": [
          "Alert",
          "Name"
        ]
      }
    }
  }
}

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Project:
    Type: String
    Description: >-
      Project name:

      1. Only supports lowercase letters, numbers, hyphens (-) and underscores
      (_).

      2. Must start and end with lowercase letters and numbers.

      3. The name length is 3-63 characters.
    AllowedPattern: '^[a-zA-Z0-9_-] $'
    MinLength: 3
    MaxLength: 63
  Detail:
    Type: Json
    Description: ''
Resources:
  Alert:
    Type: 'ALIYUN::SLS::Alert'
    Properties:
      Project:
        Ref: Project
      Detail:
        Ref: Detail
Outputs:
  Name:
    Description: Alert name.
    Value:
      'Fn::GetAtt':
        - Alert
        - Name