prometheus-operator-钉钉告警和alertmanager告警规则


dingding.yaml

[root@xx prometheus-rule]# cat dingding.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: webhook-dingtalk
  name: webhook-dingtalk
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webhook-dingtalk
  template:
    metadata:
      labels:
        app: webhook-dingtalk
    spec:
      containers:
      - image: timonwong/prometheus-webhook-dingtalk:latest
        name: webhook-dingtalk
        args:
        - --ding.profile=webhook1=https://oapi.dingtalk.com/robot/send?access_token=8fa4c053f5fe4184eaa01d14ccc200b6b414a1884earceaeewsx3
        #上面创建的钉钉机器人hook
        ports:
        - containerPort: 8060
          protocol: TCP
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 500m
            memory: 500Mi
      imagePullSecrets:
        - name: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: webhook-dingtalk
  name: webhook-dingtalk
  namespace: monitoring
  #需要和alertmanager在同一个namespace
spec:
  ports:
  - name: http
    port: 8060
    protocol: TCP
    targetPort: 8060
  selector:
    app: webhook-dingtalk
  type: ClusterIP


 kubectl  apply -f dingding.yaml


[root@xx prometheus-rule]# cat alertmanager.yaml 
global:
  resolve_timeout: 5m
receivers:
- name: 'webhook'
  webhook_configs:
  - url: 'http://webhook-dingtalk.monitoring.svc.cluster.local:8060/dingtalk/webhook1/send'
    send_resolved: true
- name: "wechat"
  wechat_configs:
  - send_resolved: true
    agent_id: '1000002'
    to_user: '@all'
    corp_id: '企业id'
    api_secret: '企业微信密钥'
- name: 'kong'
route:
  group_by: ['alertname','service','job']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 12h
  receiver: 'kong'
  routes:
  - match_re:
      service: ^(kubernetes|kube-controller-manager|kube-scheduler|kubelet|kube-state-metrics)$
    receiver: 'webhook'
  - match_re:
      job: 'kube-state-metrics'
      namespace: 'xx'
    receiver: 'webhook'

kubectl delete  secret alertmanager-main -n monitoring
kubectl create  secret generic alertmanager-main --from-file=alertmanager.yaml -n monitoring

你可能感兴趣的:(prometheus-operator-钉钉告警和alertmanager告警规则)