详情页标题前

阿里云日志服务SLS告警资源数据结构-云淘科技

详情页1

本文介绍告警资源数据的数据结构。

简介

告警资源数据包括用户、用户组、值班组、Webhook集成、告警策略(路由合并、抑制、静默)、行动策略、内容模板、自定义的其它资源数据等。

告警资源数据分为资源(Resource)和记录(Record)两类。例如用户本身属于一种资源,但是配置的每一条用户信息都是一条记录。

分类 属性 说明
资源(Resource) resource_name 标识资源的名称,例如用户的资源名称为sls.common.user。
记录(Record) id 该记录的唯一ID。字符串类型。
tag 为该记录打标签。字符串类型。
value 该记录完整的值。JSON字符串类型。

告警资源数据的结构

资源类型 resource_name字段 record_id字段 record_tag字段 示例 备注
用户 sls.common.user user_id user_name
{
    "user_id": "alex",
    "user_name": "Alex",
    "email": [
        "***@example.com"
    ],
    "country_code": "86",
    "phone": "133****3333",
    "enabled": true,
    "sms_enabled": true,
    "voice_enabled": true
}
用户组 sls.common.user_group user_group_id user_group_name
{
    "user_group_id": "devops",
    "user_group_name": "DevOps Team",
    "enabled": true,
    "members": [
        "alex"
    ]
}
值班组 sls.alert.oncall_group oncall_id oncall_name
{
    "oncall_id": "default_oncall",
    "oncall_name": "Default Oncall",
    "enabled": true,
    "overrides": [],
    "rotations": [
        {
            "targets": [
                {
                    "type": "user",
                    "target_id": "alex"
                },
                {
                    "type": "user_group",
                    "target_id": "devops"
                }
            ],
            "end_time": 0,
            "shift_day": "",
            "shift_time": "12:00",
            "shift_type": "day",
            "start_time": 1633017600,
            "shift_minute": 0,
            "end_time_type": "none",
            "shift_interval": 1,
            "shift_week_custom": null,
            "restriction_date_type": "workday",
            "restriction_time_type": "allday",
            "restriction_week_range": null,
            "restriction_time_custom_range": null
        }
    ],
    "calendar_id": "default_calendar"
}
配置复杂,建议通过控制台完成配置。
Webhook集成 sls.alert.action_webhook id name
{
    "id": "custom-webhook",
    "name": "Custom Webhook",
    "type": "custom",
    "url": "http://localhost:9099/data/webhook",
    "method": "POST",
    "headers": [
        {
            "key": "Content-Type",
            "value": "application/json"
        },
        {
            "key": "Foo",
            "value": "bar"
        }
    ]
}
{
    "id": "dingtalk",
    "name": "Dingtalk Webhook",
    "type": "dingtalk",
    "url": "https://oapi.dingtalk.com/robot/send?access_token=**********",
    "method": "POST",
    "secret": "SEC**********",
    "headers": []
}
  • type为Webhook类型,可选值如下:
    • dingtalk:钉钉。
    • wechat:企业微信。
    • lark:飞书。
    • slack:Slack。
    • custom:自定义Webhook。
  • 除了custom类型外,其余类型所涉及的method固定为POST,headers为空数组。
  • type为钉钉或飞书,且在钉钉或飞书侧设置安全校验方式为签名校验时,需要添加secret字段。

    您可以在钉钉或飞书机器人管理界面获取加签密钥。

告警策略 sls.alert.alert_policy policy_id policy_name
{
    "policy_id": "sls.builtin",
    "policy_name": "SLS Builtin Alert Policy",
    "parent_id": "sls.root",
    "is_default": false,
    "group_script": "fire(action_policy=\"sls.builtin\", group={\"project\": \"__a__\", \"uid\": alert.aliuid}, group_wait=\"5s\", group_interval=\"2m\", repeat_interval=\"2m\")
stop()
fire(action_policy=\"sls.builtin\", group={\"alert_id\": alert.alert_id}, group_wait=\"5s\", group_interval=\"10s\", repeat_interval=\"2m\")
if alert.labels.name ~= \"^\\w+s$\":
	fire(action_policy=\"sls.builtin\", group={\"product\": \"xxs\"}, group_wait=\"5s\", group_interval=\"10s\", repeat_interval=\"2m\")
	stop()
stop()
fire(action_policy=\"sls.builtin\", group={\"label_name\": alert.labels.name}, group_wait=\"10s\", group_interval=\"10s\", repeat_interval=\"2m\")",
    "inhibit_script": "if alert.severity >= 8:
    silence alert.severity < 6",
    "silence_script": ""
}
  • is_default固定设置为false即可。
  • group_script为路由合并策略。
  • inhibit_script为抑制策略。
  • silence_script为静默策略。
  • 通过SDK配置时,group_script、inhibit_script和silence_script只包含DSL脚本信息,无UI配置信息,因此控制台上无法看到相应的图形结构。
行动策略 sls.alert.action_policy action_policy_id action_policy_name
{
    "action_policy_id": "sls.builtin",
    "action_policy_name": "SLS Builtin Action Policy",
    "labels": {},
    "is_default": false,
    "primary_policy_script": "fire(type=\"webhook_integration\", integration_type=\"dingtalk\", webhook_id=\"dingtalk-test\", template_id=\"default-template\", period=\"any\")",
    "secondary_policy_script": "fire(type=\"voice\", users=[\"jizhi\"], groups=[\"group-jizhi\"], template_id=\"default-template\")",
    "escalation_start_enabled": false,
    "escalation_start_timeout": "10s",
    "escalation_inprogress_enabled": false,
    "escalation_inprogress_timeout": "10s",
    "escalation_enabled": false,
    "escalation_timeout": "4h0m0s"
}
  • is_default固定设置为false即可。
  • labels为保留参数,固定为空对象即可。
  • primary_policy_script为第一行动策略。
  • secondary_policy_script为第二行动策略。
  • escalation_*为控制第二行动策略是否开启的配置,可参见控制台中的配置项。
  • 通过SDK配置时,primary_policy_script和secondary_policy_script只包含DSL脚本信息,无UI配置信息,因此控制台上无法看到相应的图形结构。
内容模板 sls.alert.content_template template_id template_name
{
    "template_id": "default-template",
    "template_name": "Default Template",
    "is_default": false,
    "templates": {
        "fc": {
            "limit": 0,
            "locale": "zh-CN",
            "content": "",
            "send_type": "merged"
        },
        "sms": {
            "locale": "zh-CN",
            "content": ""
        },
        "lark": {
            "title": "Alerthub告警测试 ${alert_name}",
            "locale": "zh-CN",
            "content": ""
        },
        "email": {
            "locale": "zh-CN",
            "content": "",
            "subject": "SLS告警测试-jizhi-test"
        },
        "slack": {
            "title": "Alerthub告警测试 ${alert_name}",
            "locale": "zh-CN",
            "content": ""
        },
        "voice": {
            "locale": "zh-CN",
            "content": ""
        },
        "wechat": {
            "title": "Alerthub告警测试 ${alert_name}",
            "locale": "zh-CN",
            "content": ""
        },
        "webhook": {
            "limit": 0,
            "locale": "zh-CN",
            "content": "",
            "send_type": "batch"
        },
        "dingtalk": {
            "title": "Alerthub告警测试 ${alert_name}",
            "locale": "zh-CN",
            "content": ""
        },
        "event_bridge": {
            "locale": "zh-CN",
            "content": "",
            "subject": "wkb-test"
        },
        "message_center": {
            "locale": "zh-CN",
            "content": ""
        }
    }
}
  • is_default固定设置为false即可。
  • templates中包含每个渠道的模板配置,如果某个渠道的content值为空,则表示使用系统默认的模板。更多信,请参见默认内容模板。
  • locale取值为zh-CN或en-US。
  • webhook和fc渠道的send_type取值为single或者batch,表示逐条通知或者合并通知。
默认日历 sls.common.calendar calendar_id calendar_name
{
    "calendar_id": "default_calendar",
    "calendar_name": "Default Calendar",
    "timezone": "Asia/Shanghai",
    "workdays": [
        1,
        2,
        3,
        4,
        5
    ],
    "worktime": [
        {
            "end_time": "21:00",
            "start_time": "09:00"
        }
    ],
    "reset_days": [],
    "holiday_sync": "china"
}
  • 默认日历的ID固定为 default_calendar。
  • 配置复杂,建议通过控制台完成配置。

DSL语法说明

简单的DSL配置示例如下所示。

重要 DSL配置复杂,建议您先在控制台完成配置,然后查看Network请求所发送的Payload内容。设置路由合并策略

  • 控制台配置阿里云日志服务SLS告警资源数据结构-云淘科技
  • DSL配置
    if alert.severity >= 8:
        fire(action_policy="sls.builtin", group={"alert.project": alert.project, "alert.alert_id": alert.alert_id}, group_by_all_labels=true, group_wait="15s", group_interval="5m", repeat_interval="1h")
        stop()
    fire(action_policy="sls.builtin", group={"alert.project": alert.project}, group_by_all_labels=false, group_wait="15s", group_interval="5m", repeat_interval="1h")

    基本语法说明如下:

    • if alert.severity >= 8为条件节点。
    • fire( )为路由合并节点。
      • action_policy为行动策略ID。
      • group为合并基准,dict类型。
      • group_by_all_labels为是否根据所有标签合并,取值为true、false。
      • group_wait为首次等待时间。
      • group_interval为变化等待时间。
      • repeat_interval为重复等待时间。
    • stop()为结束节点。

设置抑制策略

  • 控制台配置阿里云日志服务SLS告警资源数据结构-云淘科技
  • DSL配置
    if alert.severity >= 8:
        silence alert.severity < 8
        stop()

    基本语法说明如下:

    • if alert.severity >= 8为条件节点。
    • silence alert.severity < 8为抑制节点。
    • stop()为结束节点。

设置静默策略

  • 控制台配置阿里云日志服务SLS告警资源数据结构-云淘科技
  • DSL配置
    drop(end=1638189177) alert.alert_name == "test-alert"
    accept alert.labels.env == "prod"

    基本语法说明如下:

    • drop表示静默。
    • accept表示不静默。
    • start和end表示时间范围,Unix时间戳(单位为秒)。
      • 特定时间范围:需设置start和end。
      • 特定时间为止:只需设置end。
      • 一段时间:只需设置end。
      • 持续:不需要设置start和end。

设置行动策略

  • 控制台配置阿里云日志服务SLS告警资源数据结构-云淘科技
  • DSL配置
    if alert.severity >= 8:
        fire(type="sms", users=[], groups=[], oncall_groups=["alert-test-oncall"], template_id="sls.builtin.cn", check_quota="true", period="any")
        stop()
    if alerts.severity < 8:
        fire(type="webhook_integration", integration_type="dingtalk", webhook_id="jizhi-test", template_id="sls.builtin.cn", period="any")
        stop()

    重要

    • if alert.xxx表示任意告警满足条件。
    • if alerts.xxx表示所有告警满足条件。

其中,每个渠道的配置示例如下:

  • 控制台配置阿里云日志服务SLS告警资源数据结构-云淘科技
  • DSL配置
    fire(type="sms", users=["jizhi"], groups=[], oncall_groups=[], template_id="sls.builtin.cn", check_quota="true", period="workday")
    fire(type="voice", users=[], groups=[], oncall_groups=["alert-test-oncall"], template_id="sls.builtin.cn", check_quota="true", period="worktime")
    fire(type="email", users=[], groups=["alert-test"], oncall_groups=[], template_id="sls.builtin.cn", check_quota="true", period="any")
    fire(type="webhook_integration", integration_type="dingtalk", webhook_id="jizhi-test", template_id="sls.builtin.cn", period="any")
    fire(type="webhook_integration", integration_type="wechat", webhook_id="wechat-test", template_id="sls.builtin.cn", period="any")
    fire(type="message_center", template_id="sls.builtin.cn", check_quota="true", period="any")
    fire(type="event_bridge", region="cn-hangzhou", bus_name="bus-demo", template_id="sls.builtin.cn", period="any")
    fire(type="fc", region="cn-shanghai", service="jizhi-test", qualifier="LATEST", function="sls-ops-1", template_id="sls.builtin.cn", period="any")
    fire(type="set_ticket_owner", choice="random", users=[], groups=[], oncall_groups=["alert-test-oncall"])

    基本语法说明如下:

    通过fire(),设置通知渠道。更多信息,请参见通知渠道说明。

内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家

阿里云企业补贴进行中: 马上申请

腾讯云限时活动1折起,即将结束: 马上收藏

同尘科技为腾讯云授权服务中心。

购买腾讯云产品享受折上折,更有现金返利:同意关联,立享优惠

转转请注明出处:https://www.yunxiaoer.com/164587.html

(0)
上一篇 2023年12月10日
下一篇 2023年12月10日
详情页2

相关推荐

  • 阿里云大数据开发治理平台 DataWorksPostgreSQL数据源-云淘科技

    PostgreSQL数据源为您提供读取和写入PostgreSQL双向通道的功能,方便您后续可以通过向导模式和脚本模式配置数据同步任务。本文为您介绍DataWorks的PostgreSQL数据同步能力支持情况。 支持的版本 目前仅支持配置PostgreSQL数据源为PostgreSQL10、11、12、13、14、15版本。您可以通过如下语句查看Postgre…

  • 阿里云人工智能平台PAI文字检测识别组件-云淘科技

    文字检测识别组件基于PAI团队自研的OCR算法和阿里云大数据,能够对OCR模型进行离线推理。本文介绍文字检测识别组件的配置方法及使用示例。 前提条件 已开通OSS并完成授权,详情请参见开通OSS服务和为PAI-Studio授予OSS访问权限。 使用限制 仅PAI-Designer提供该算法组件。 算法简介 文字检测识别组件位于组件库音视觉算法文件夹下的离线模…

    2023年12月10日
  • 阿里云云原生大数据计算服务 MaxComputeHive数据迁移-云淘科技

    本文为您介绍通过Hive UDTF迁移Hive数据的方法。 准备事项 ⽹络环境要求。 Hive集群各节点能够访问MaxCompute。 MMA所在服务器能够访问Hive MetaStore Server、Hive Server。 创建⽤于迁移数据的Hive UDTF。 在MMA的帮助⻚⾯下载对应版本的UDTF的jar包,如mma-udtf.jar。 执行以下…

  • 阿里云对象存储OSSEMR Flink写入OSS-HDFS服务-云淘科技

    可恢复性写入功能支持将数据以EXACTLY_ONCE语义写入存储介质。本文介绍Flink如何通过EMR集群的方式可恢复性写入OSS-HDFS服务。 前提条件 已创建EMR-3.42.0及以上版本或EMR-5.8.0及以上版本的集群。具体步骤,请参见创建集群。 已开通并授权访问OSS-HDFS服务。具体操作,请参见开通并授权访问OSS-HDFS服务。 在Fli…

    阿里云对象存储 2023年12月10日
  • 信息流广告,信息流部分建议宽度830px,只针对默认列表样式,顺序随机
  • 阿里云负载均衡LoadBalancerLeaveSecurityGroup – 解绑安全组-云淘科技

    为网络型负载均衡实例解绑安全组。 接口说明 LoadBalancerLeaveSecurityGroup接口属于异步接口,即系统返回一个请求ID,但该网络型负载均衡实例的安全组尚未解绑成功,系统后台的解绑任务仍在进行。您可以调用GetJobStatus查询安全组的解绑状态: 当任务状态处于Succeeded时,表示安全组解绑成功。 当任务状态处于Proces…

    阿里云负载均衡 2023年12月10日

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
本站为广大会员提供阿里云、腾讯云、华为云、百度云等一线大厂的购买,续费优惠,保证底价,买贵退差。