Skip to content

Instantly share code, notes, and snippets.

@harryge00
Last active July 22, 2020 08:58
Show Gist options
  • Save harryge00/c0d865daad650e771ddbab429aa7a11c to your computer and use it in GitHub Desktop.
Save harryge00/c0d865daad650e771ddbab429aa7a11c to your computer and use it in GitHub Desktop.
Dingtalk Webhook Deployment for Prometheus
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-webhook-dingtalk-config
namespace: kubeaddons
data:
config.yml: |
targets:
webhook1:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxx
# secret for signature
secret: SEC09xxxxxxx
---
apiVersion: v1
kind: Service
metadata:
labels:
name: prometheus-webhook-dingtalk
name: prometheus-webhook-dingtalk
namespace: kubeaddons
spec:
ports:
- port: 8060
protocol: TCP
selector:
app: prometheus-webhook-dingtalk
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
name: prometheus-webhook-dingtalk
name: prometheus-webhook-dingtalk
namespace: kubeaddons
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-webhook-dingtalk
template:
metadata:
labels:
app: prometheus-webhook-dingtalk
spec:
containers:
- image: ccr.ccs.tencentyun.com/d2iq/prometheus-webhook-dingtalk:v1.4.0
name: prometheus-webhook-dingtalk
args:
- "--config.file=/dingtalk-config/config.yml"
- "--web.listen-address=:8060"
ports:
- containerPort: 8060
protocol: TCP
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 200m
memory: 256Mi
volumeMounts:
- name: conf
mountPath: /dingtalk-config
readOnly: true
volumes:
- name: conf
configMap:
name: prometheus-webhook-dingtalk-config
defaultMode: 0755
imagePullSecrets:
- name: IfNotPresent
@harryge00
Copy link
Author

access_token=xxxxxxx 改成钉钉机器人的token

@harryge00
Copy link
Author

prometheus-webhook-dingtalk:v1.4.0 is based on https://github.com/timonwong/prometheus-webhook-dingtalk

@harryge00
Copy link
Author

harryge00 commented Jul 22, 2020

receivers 中添加

webhook_configs:
- send_resolved: true
url: http://prometheus-webhook-dingtalk.kubeaddons.svc.cluster.local:8060/dingtalk/webhook1/send

完整的alertmanager.yaml:

global:
  resolve_timeout: 5m
  slack_api_url: https://hooks.slack.com/services/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

route:
  group_by: ['alertname']
  group_wait: 2m
  group_interval: 5m
  repeat_interval: 1h

  # If an alert isn't caught by a route, send it to slack.
  receiver: slack_and_dingtalk
  routes:
    - match:
        alertname: Watchdog
      receiver: "null"

receivers:
  - name: "null"
  - name: slack_and_dingtalk
    webhook_configs:
    - send_resolved: true
      url: http://prometheus-webhook-dingtalk.kubeaddons.svc.cluster.local:8060/dingtalk/webhook1/send
    slack_configs:
      - channel: '#k8s'
        icon_url: https://avatars3.githubusercontent.com/u/3380462
        send_resolved: true
        color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
        title: '{{ template "slack.default.title" . }}'
        title_link: '{{ template "slack.default.titlelink" . }}'
        pretext: '{{ template "slack.default.pretext" . }}'
        text: '{{ template "slack.default.text" . }}'
        fallback: '{{ template "slack.default.fallback" . }}'
        icon_emoji: '{{ template "slack.default.iconemoji" . }}'

templates:
  - '*.tmpl'

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