创建通知策略时,您可以将告警通知发送到自定义的Webhook地址中。ARMS告警管理支持对飞书、微信、钉钉等群组发送Webhook告警,本文以飞书为例,介绍如何创建Webhook告警。
步骤一:获取Webhook地址
- 打开并登录飞书。
- 单击+图标,然后单击创建群组,新建一个用于发送告警的群组。
- 单击群组设置图标,然后单击群机器人页签。
- 在群机器人页签,单击添加机器人。
- 在添加机器人面板选择Custom Bot。
- 在配置页设置显示名称和描述,然后单击添加。
- 在添加情况区域,单击复制链接,然后单击完成。
步骤二:创建Webhook联系人
- 登录EDAS控制台。
- 在应用列表页面顶部菜单栏选择地域,在页面中选择微服务空间,在集群类型下拉列表中选择ECS集群,然后单击目标应用名称。
- 在左侧导航栏,选择 。
- 在通知对象页面,单击Webhook集成页签,然后单击右上角的新建webhook。
- 在新建Webhook面板输入配置信息。
配置项 说明 Webhook名称 必填,自定义Webhook名称。 请求方法 - 必填,设置请求方法。
- 包括Post和Get两种。
- URL不可超过100个字符。
此例中选择Post,并将步骤一:获取Webhook地址中保存的Webhook地址粘贴至右侧文本框。
请求头 - 非必填,设置请求头。
- 包括Header和Param两种。
- 不可超过200个字符。
单击+添加,添加其他Header信息或Param信息。
说明- 默认请求头为Content-Type: text/plain; charset=UTF-8。
- Header和Param个数总数不能超过6个。
此例中设置以下两个 Header:Arms-Content-Type : json
Content-Type : application/json
通知模板 告警触发时发送的通知模板,非必填,在Post方法下出现,可使用 $content
占位符输出通知内容,不可超过500个字符。通知模板如下:{ "告警名称":"{{ .commonLabels.alertname }}{{if .commonLabels.clustername }}", "集群名称":"{{ .commonLabels.clustername }} {{ end }}{{if eq "app" .commonLabels._aliyun_arms_involvedObject_kind }}", "应用名称":"{{ .commonLabels._aliyun_arms_involvedObject_name }} {{ end }}", "通知策略":"{{ .dispatchRuleName }}", "告警时间":"{{ .startTime }}", "告警内容":"{{ for .alerts }} {{ .annotations.message }} {{ end }}" }
此处以飞书为例可以设置如下文本格式.{ "msg_type": "text", "content": { "text": "报警名称: {{ .commonLabels.alertname }}\n报警时间: {{ .startTime }}\n报警内容: {{ for .alerts }} {{ .annotations.message }} {{if .generatorURL }} 详情链接: {{.generatorURL}} {{ end }} \n {{ end }}" } }
恢复模板 告警恢复时发送的通知模板,非必填,在Post方法下出现,可使用 $content
占位符输出通知内容,不可超过500个字符。恢复模板如下:{ "告警名称":"{{ .commonLabels.alertname }}{{if .commonLabels.clustername }}", "集群名称":"{{ .commonLabels.clustername }} {{ end }}{{if eq "app" .commonLabels._aliyun_arms_involvedObject_kind }}", "应用名称":"{{ .commonLabels._aliyun_arms_involvedObject_name }} {{ end }}", "通知策略":"{{ .dispatchRuleName }}", "恢复时间":"{{ .endTime }}", "告警内容":"{{ for .alerts }} {{ .annotations.message }} {{ end }}" }
此处以飞书为例可以设置如下文本格式.。{ "msg_type": "text", "content": { "text": "报警名称: {{ .commonLabels.alertname }}\n恢复时间: {{ .endTime }}\n报警内容: {{ for .alerts }} {{ .annotations.message }} {{if .generatorURL }} 详情链接: {{.generatorURL}} {{ end }} \n {{ end }}" } }
- 可选:单击发送测试,验证配置是否成功。
- 单击确定。
步骤三:设置通知策略
在通知策略中需要选择通知方式为WebHook才能在自定义的Webhook中接收告警。
新建或编辑通知策略,选择通知人为Webhook联系人,在通知方式区域,选中WebHook。具体操作,请参见通知策略。
说明 Webhook告警的超时时间为5秒,如果发出请求后5秒内没有返回,即没有收到告警信息,则表示发送失败。