Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配置使用自定义模板不生效 #86

Open
metadeng opened this issue Mar 10, 2020 · 3 comments
Open

配置使用自定义模板不生效 #86

metadeng opened this issue Mar 10, 2020 · 3 comments

Comments

@metadeng
Copy link

metadeng commented Mar 10, 2020

config:
templates:
  - /etc/prometheus-webhook-dingtalk/templates/default.tmpl
targets:
  k8s-dev:
    url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx
    # secret for signature
    secret: xxxxxxxx
    message:
      # Use legacy template
      title: '{{ template "legacy.title" . }}'
      text: '{{ template "legacy.content" . }}'
template:
{{/* Legacy */}}
{{ define "legacy.title" }}{{ template "__subject" . }}{{ end }}
{{ define "legacy.content" }}#### \[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}\] **[{{ index .GroupLabels "alertname" }}]**
{{- end }}

发现钉钉推送出来的信息还是default?

@chinaboy007
Copy link

我也是,一样的

@frui85
Copy link

frui85 commented Nov 8, 2021

template 底下加入这个试试,重新定一下 legacy.title legacy.content

{{ define "ding.link.title" }}{{ template "legacy.title" . }}{{ end }}
{{ define "ding.link.content" }}{{ template "legacy.content" . }}{{ end }}
{{ template "legacy.title" . }}
{{ template "legacy.content" . }}

@xixinming
Copy link

apiVersion: v1
kind: ConfigMap
metadata:
  name: dingtalk-config
  namespace: monitoring
data:
  config.yaml: |-
    templates:
      - /config/template.tmpl
    targets:
      webhook:
        url: https://oapi.dingtalk.com/robot/send?access_token=764c0b1deba4250042e3eb2844f75fe7de06b42b23c2ce15d8302ac24ee36468
        mention:
          all: true
  template.tmpl: |-
     {{ define "ding.link.title" }}监控报警{{ end }}
     {{ define "ding.link.content" }}

     {{- if gt (len .Alerts.Firing) 0 -}}
     {{- range $index, $alert := .Alerts -}}
     告警类型: {{ $alert.Labels.alertname }}
     告警级别: {{ $alert.Labels.severity }}
     告警主题: {{ $alert.Annotations.summary }}
     命名空间: {{ $alert.Labels.namespace }}
     告警详情: {{ $alert.Annotations.description }}
     故障时间: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
     {{- if gt (len $alert.Labels.instance) 0 }}
     实例信息: {{ $alert.Labels.instance }}
     {{- end }}
     {{- end }}
     {{- end }}
     {{- if gt (len .Alerts.Resolved) 0 }}
     {{- range $index, $alert := .Alerts }}
     告警类型: {{ $alert.Labels.alertname }}
     告警级别: {{ $alert.Labels.severity }}
     告警主题: {{ $alert.Annotations.summary }}
     命名空间: {{ $alert.Labels.namespace }}
     告警详情: {{ $alert.Annotations.description }}
     故障时间: {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
     恢复时间: {{ ($alert.EndsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
     {{- if gt (len $alert.Labels.instance) 0 }}
     实例信息: {{ $alert.Labels.instance }}
     {{- end }}
     {{- end }}
     {{- end }}

     {{ end }}

把你要定义的东西写在{{ define "ding.link.content" }}和 {{ end }}之间!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants