文档中心>实践教程>日志服务>监控告警>告警对接 PagerDuty/Slack 等第三方平台

告警对接 PagerDuty/Slack 等第三方平台

最近更新时间:2025-06-18 19:38:01

我的收藏

简介

告警可通过自定义回调的方式对接 PagerDuty、Slack、Microsoft Teams、Jira Service Management、Google Chat,便于统一接收告警通知。

配置步骤

步骤1:新建通知内容模板

2. 在左侧导航栏中,选择监控告警 > 通知内容模板,进入通知内容模板管理页面。
3. 单击新建,在自定义回调标签中,根据需要对接的渠道,填写如下信息并保存。
PagerDuty
Slack
Microsoft Teams
Jira Service Management
Google Chat
说明:
CLS 通过 Events API V2与 PagerDuty 对接,如果当前 Service 未添加 Events API V2 Integration,请执行 Add Integrations to an Existing Service
请替换以下请求内容中的routing_key为 PagerDuty 中的 Integration Key。
请同时记录 PagerDuty 中的 Integration URL,便于后续步骤使用。
告警触发
请求头
Accept: application/json
Content-Type: application/json
请求内容
{
"payload": {
"summary": "{{escape .Alarm}}",
"timestamp": "{{fromUnixTime .NotifyTimeUnix}}",
"severity": "{{if eq .Level "Critical"}}critical{{else if eq .Level "Warn"}}warning{{else if eq .Level "Info"}}info{{end}}",
"source": "Tencent Cloud Log Service",
"custom_details": {
"Alarm Policy": "{{escape .Alarm}}",
"Trigger Condition": "{{escape .Condition}}",
"Current Data": "{{escape .TriggerParams}}",
"Additional Message": "{{escape .Message}}",
"Multidimensional Analysis": "{{escape .AnalysisResultFormat}}"
}
},
"routing_key": "R03ECCMUCxxxxxxxxxxxNGFE87CT",
"dedup_key": "{{.RecordGroupId}}",
"event_action": "trigger",
"client": "{{escape .Topic}}",
"client_url": "{{.QueryUrl}}",
"links": [
{
"href": "{{.DetailUrl}}",
"text": "Alert Detail"
}
]
}
告警恢复
请求头
Accept: application/json
Content-Type: application/json
请求内容
{
"payload": {
"summary": "{{escape .Alarm}}",
"timestamp": "{{fromUnixTime .NotifyTimeUnix}}",
"severity": "{{if eq .Level "Critical"}}critical{{else if eq .Level "Warn"}}warning{{else if eq .Level "Info"}}info{{end}}",
"source": "Tencent Cloud Log Service"
},
"routing_key": "R03ECCMUCxxxxxxxxxxxNGFE87CT",
"dedup_key": "{{.RecordGroupId}}",
"event_action": "resolve"
}
告警触发
请求头
Content-Type: application/x-www-form-urlencoded
请求内容
{{- define "subTemplate" -}}
Alarm triggered for the log service of account {{.UIN}} ({{.Nickname}}):
• Alarm Policy: {{.Alarm}}
• Alarm Level: {{.Level}}
• Monitoring Object: {{.Topic}}
• Trigger Condition: {{.Condition}}
• Current Data: {{.TriggerParams}}
• Trigger Time: {{.StartTime}}
{{- if (gt .Duration 0)}}
• Duration: {{.Duration}} minutes
{{- end}}
• Additional Message: {{.Message}}
• Multidimensional Analysis:
```{{.AnalysisResultFormat}}```
<{{.DetailUrl}}|DetailedReport> <{{.QueryUrl}}|QueryData>{{if .CanSilent}} <{{.DetailUrl}}|ClaimAlarm> <{{.SilentUrl}}|SilenceAlarm>{{end}}
{{- end -}}
payload={"username": "CLS Alert","icon_emoji": ":rotating_light:","blocks": [{"type":"header","text":{"type":"plain_text","text":":rotating_light:Alarm:{{escape .Alarm}}","emoji":true}},{"type": "section","text": {"type": "mrkdwn","text": "{{escape (substr (renderTemplate "subTemplate") 0 3500)}}"}}]}
告警恢复
请求头
Content-Type: application/x-www-form-urlencoded
请求内容
{{- define "subTemplate" -}}
A CLS alarm was resolved under your account (ID: {{.UIN}}; name: {{.Nickname}}):
• Alarm Policy: {{.Alarm}}
• Alarm Level: {{.Level}}
• Monitoring Object: {{.Topic}}
• Trigger Condition: {{.Condition}}
• Trigger Time: {{.StartTime}}
• Resolved Time: {{.NotifyTime}}
• Duration: {{.Duration}} minutes"
{{- end -}}
payload={"username": "CLS Alert","icon_emoji": ":green_circle:","blocks": [{"type":"header","text":{"type":"plain_text","text":":large_green_circle:Resolved:{{escape .Alarm}}","emoji":true}},{"type": "section","text": {"type": "mrkdwn","text": "{{escape (substr (renderTemplate "subTemplate") 0 3500)}}"}}]}
告警触发
请求头
Content-Type: application/json
请求内容
{{- define "subTemplate" -}}
**Alarm triggered for the log service of account {{.UIN}} ({{.Nickname}}):**
- Alarm Policy: {{.Alarm}}
- Alarm Level: {{.Level}}
- Monitoring Object: {{.Topic}}
- Trigger Condition: {{.Condition}}
- Current Data: {{.TriggerParams}}
- Trigger Time: {{.StartTime}}
{{- if (gt .Duration 0)}}
- Duration: {{.Duration}} minutes
{{- end}}
- Additional Message: {{.Message}}

{{- range $key,$value := .AnalysisResult}}

**{{$key}}**

{{$value}}
{{- end}}
{{- end -}}
{
"type": "message",
"attachments": [{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"msteams": {"width": "Full"},
"body": [
{
"type": "TextBlock",
"text": "Alarm:{{escape .Alarm}}",
"wrap": true,
"color": "{{if eq .Level "Critical"}}attention{{else if eq .Level "Warn"}}warning{{else if eq .Level "Info"}}accent{{end}}",
"size": "Large"
},
{
"type": "TextBlock",
"text": "{{- escape (substr (renderTemplate "subTemplate") 0 3500)}}",
"wrap": true
},
{
"type": "ActionSet",
"actions": [{"type":"Action.OpenUrl","title":"DetailedReport","url":"{{.DetailUrl}}"},{"type":"Action.OpenUrl","title":"QueryData","url":"{{.QueryUrl}}"}{{if.CanSilent}},{"type":"Action.OpenUrl","title":"ClaimAlarm","url":"{{.DetailUrl}}"},{"type":"Action.OpenUrl","title":"SilenceAlarm","url":"{{.SilentUrl}}"}{{end}}]
}]
}
}]
}
告警恢复
请求头
Content-Type: application/json
请求内容
{{- define "subTemplate" -}}
**A CLS alarm was resolved under your account (ID: {{.UIN}}; name: {{.Nickname}}):**
- Alarm Policy: {{.Alarm}}
- Alarm Level: {{.Level}}
- Monitoring Object: {{.Topic}}
- Trigger Condition: {{.Condition}}
- Trigger Time: {{.StartTime}}
- Resolved Time: {{.NotifyTime}}
- Duration: {{.Duration}} minutes"
{{- end -}}
{
"type": "message",
"attachments": [{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"msteams": {"width": "Full"},
"body": [
{
"type": "TextBlock",
"text": "Resolved:{{escape .Alarm}}",
"wrap": true,
"color": "good",
"size": "Large"
},
{
"type": "TextBlock",
"text": "{{- escape (substr (renderTemplate "subTemplate") 0 3500)}}",
"wrap": true
}]
}
}]
}
说明:
CLS 通过 API Integration 与 JSM(Jira Service Management) 对接,如果当前未添加 API Integration,请执行 Add a global integration。添加完成后启用该 Integration,并获取其中的 API key。
请替换以下请求头中的Authorization为 JSM 中的 API Key,格式为Basic+空格+Base64 编码后的 API Key
告警触发
请求头
Accept: application/json
Content-Type: application/json
Authorization: Basic YjdiYjI5MWXXXXXXXXXXXXXXXXXdhNDUyYjVmYjQw
请求内容
{{- define "subTemplate" -}}
Current Data:{{.TriggerParams}}
Additional Message:{{.Message}}
{{.AnalysisResultFormat}}
Detail Report:{{.DetailUrl}}
{{- end -}}
{
"message": "{{escape .Alarm}}",
"alias": "{{.RecordGroupId}}",
"description": "Alarm Policy:{{escape .Alarm}}\\nTrigger Condition:{{escape .Condition}}",
"entity": "{{escape .Topic}}",
"source": "Tencent Cloud Log Service",
"priority": "{{if eq .Level "Critical"}}P1{{else if eq .Level "Warn"}}P2{{else if eq .Level "Info"}}P5{{end}}",
"note": "{{escape (substr (renderTemplate "subTemplate") 0 3500)}}"
}
告警恢复
请求头
Accept: application/json
Content-Type: application/json
Authorization: Basic YjdiYjI5MWXXXXXXXXXXXXXXXXXdhNDUyYjVmYjQw
请求内容
{{- define "subTemplate" -}}
Alarm was resolved
Trigger Time:{{.StartTime}}
Resolved Time:{{.NotifyTime}}
Duration: {{.Duration}} minutes"
{{- end -}}
{
"message": "{{escape .Alarm}}",
"alias": "{{.RecordGroupId}}",
"description": "Alarm Policy:{{escape .Alarm}}\\nTrigger Condition:{{escape .Condition}}",
"entity": "{{escape .Topic}}",
"source": "Tencent Cloud Log Service",
"priority": "{{if eq .Level "Critical"}}P1{{else if eq .Level "Warn"}}P2{{else if eq .Level "Info"}}P5{{end}}",
"note": "{{escape (substr (renderTemplate "subTemplate") 0 3500)}}"
}
注意:
中国大陆地域(北京、广州、上海、重庆等)不支持直接对接 Google Chat。
告警触发
请求头
Content-Type: application/json; charset=UTF-8
请求内容
{{- define "subTemplate" -}}
*Alarm triggered for the log service of account {{.UIN}} ({{.Nickname}})*
* Alarm Policy: {{.Alarm}}
* Alarm Level: {{.Level}}
* Monitoring Object: {{.Topic}}
* Trigger Condition: {{.Condition}}
* Current Data: {{.TriggerParams}}
* Trigger Time: {{.StartTime}}
{{- if (gt .Duration 0)}}
* Duration: {{.Duration}} minutes
{{- end}}
* Additional Message: {{.Message}}
* Multidimensional Analysis:
```{{.AnalysisResultFormat}}```
<{{.DetailUrl}}|DetailedReport> <{{.QueryUrl}}|QueryData>{{if .CanSilent}} <{{.DetailUrl}}|ClaimAlarm> <{{.SilentUrl}}|SilenceAlarm>{{end}}
{{- end -}}
{"text": "{{escape (substr (renderTemplate "subTemplate") 0 3500)}}"}
告警恢复
请求头
Content-Type: application/json; charset=UTF-8
请求内容
{{- define "subTemplate" -}}
*A CLS alarm was resolved under your account (ID: {{.UIN}}; name: {{.Nickname}})*
* Alarm Policy: {{.Alarm}}
* Alarm Level: {{.Level}}
* Monitoring Object: {{.Topic}}
* Trigger Condition: {{.Condition}}
* Trigger Time: {{.StartTime}}
* Resolved Time: {{.NotifyTime}}
* Duration: {{.Duration}} minutes"
{{- end -}}
{"text": "{{escape (substr (renderTemplate "subTemplate") 0 3500)}}"}

步骤2:新建通知渠道组

1. 在左侧导航栏中,选择监控告警 > 通知渠道组,进入通知渠道组管理页面。
2. 单击新建,在通知规则中单击添加规则,在设置通知渠道中填写如下信息并保存:
渠道类型:自定义接口回调
Webhook地址:
PagerDuty:Add Integrations to an Existing Service 步骤中的 Integration URL。
Slack:CLS 通过 Incoming Webhooks 与 Slack 对接,如当前无合适的 Incoming Webhooks,请执行 Sending messages using incoming webhooks,创建 Incoming Webhook,获取其中的 Webhook URL。
Microsoft Teams:CLS 通过 Workflows 与 Teams 对接,请执行 Create incoming webhooks with Workflows for Microsoft Teams,以模板方式创建 workflow,获取其中的 URL。模板请选择 Post to a channel when a webhook request is received。
Jira Service Management:https://api.atlassian.com/jsm/ops/integration/v2/alerts。
Google Chat:CLS 通过 webhook 与 Google Chat 对接,如当前无合适的 webhook,请执行 Register the incoming webhook,创建 Webhook,获取其中的 webhook URL。
请求方法:POST
内容模板:选择 步骤1 新建的通知内容模板。
说明:
详细的配置说明可参考 管理通知渠道组

步骤3:在告警策略中选择通知渠道组

1. 在左侧导航栏中,选择监控告警 > 告警策略,进入告警策略管理页面。
2. 单击新建,开始配置告警策略,详细的配置说明可参考 配置告警策略。其中关联通知渠道组时选择 步骤2 新建的通知渠道组。