本文内容基于 k8s部署prometheus + grafana,只针对 dingtalk 部分进行修改。
vim dingtalk/config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: dingtalk-config
namespace: monitoring
data:
config.yml: |-
templates:
- /etc/prometheus-webhook-dingtalk/default.tmpl
targets:
webhook:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx #修改为钉钉机器人的webhook
# message:
# title: '{
{ template "legacy.title" . }}' #使用 Legacy(旧版) 模板
# text: '{
{ template "legacy.content" . }}'
mention:
all: true #@所有人
default.tmpl: |
{
{ define "__subject" }}[{
{ .Status | toUpper }}{
{ if eq .Status "firing" }}:{
{ .Alerts.Firing | len }}{
{ end }}] {
{ .GroupLabels.SortedPairs.Values | join " " }} {
{ if gt (len .CommonLabels) (len .GroupLabels) }}({
{ with .CommonLabels.Remove .GroupLabels.Names }}{
{ .Values | join " " }}{
{ end }}){
{ end }}{
{ end }}
{
{ define "__alertmanagerURL" }}{
{ .ExternalURL }}/d/9CWBz0bik/k8sji-qun-shou-ye?orgId=1 {
{ end }}
{
{
define "__text_alert_list" }}{
{
range . }}
**Labels**
{
{
range .Labels.SortedPairs }}> - {
{
.Name }}: {
{
.Value | markdown | html }}
{
{
end }}
**Annotations**
{
{
range .Annotations.SortedPairs }}> - {
{
.Name }}: {
{
.Value | markdown | html }}
{
{
end }}
*