Skip to content

Instantly share code, notes, and snippets.

@UlricQin
Last active September 12, 2025 03:47
Show Gist options
  • Select an option

  • Save UlricQin/4888000d2734dd2a8f1409c1f63c5caa to your computer and use it in GitHub Desktop.

Select an option

Save UlricQin/4888000d2734dd2a8f1409c1f63c5caa to your computer and use it in GitHub Desktop.
夜莺监控发送企微告警消息的模板
{{$time_duration := sub now.Unix $event.FirstTriggerTime }}{{if $event.IsRecovered}}{{$time_duration = sub $event.LastEvalTime $event.FirstTriggerTime }}{{end}}
{{if $event.IsRecovered}}🟢{{else}}🔴{{end}} {{$event.RuleName}}
---
**💨告警级别**: {{$event.Severity}}级
{{- if $event.RuleNote}}
**📜规则备注**: {{$event.RuleNote}}
{{- end -}}
{{if not $event.IsRecovered}}
**⏱️发送时间**: {{timeformat $event.TriggerTime}}
**🧭持续时长**: {{humanizeDurationInterface $time_duration}}
**📈告警时值**: {{$event.TriggerValue}}
{{else}}
{{- if $event.AnnotationsJSON.recovery_value}}
**📈恢复时值**: {{formatDecimal $event.AnnotationsJSON.recovery_value 4}}
{{- end}}
**⏱️恢复时间**: {{timeformat $event.LastEvalTime}}
**🧭告警持续时长**: {{humanizeDurationInterface $time_duration}}
{{end}}
{{- if $event.AnnotationsJSON}}
**📚附加信息**:
{{- range $key, $val := $event.AnnotationsJSON}}
> - {{$key}}: {{$val}}
{{- end}}
{{end}}
{{- if $event.TagsMap}}
**🏷️事件标签**:
```
{{- range $key, $val := $event.TagsMap}}
{{ if ne $key "rulename" }}{{$key}}: {{$val}}{{ end }}
{{- end -}}
```
{{- end}}
{{$domain := "http://localhost:17000" }}
[事件详情]({{$domain}}/share/alert-his-events/{{$event.Id}}) | [屏蔽1小时]({{$domain}}/alert-mutes/add?__event_id={{$event.Id}}){{if eq $event.Cate "prometheus"}} | [查看曲线]({{$domain}}/metric/explorer?__event_id={{$event.Id}}&mode=graph){{end}}
@UlricQin
Copy link
Author

UlricQin commented Sep 2, 2025

告警消息:
b4cc74bc76f9d7f8ccc9d42c102cbe59

恢复消息:
050070fa61b9523a87a280204bb808ce

@Wicky-Jiang
Copy link

这个地方反引号包错了要调整下,不然跳转会显示错误
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment