配置Alertmanager发送报警到企业微信

配置Alertmanager发送报警到企业微信

一、配置步骤

1.1、注册企业微信

注册地址:https://work.weixin.qq.com/

找到应用管理,创建应用

image-20210712123746591

image-20210712123957294

AgentId:1000005

Secret:xGVnhrm2n2LhJcrBzULKrAH0rzIXGkQV4IiTFJYERHw

1.2、修改alertmanager-cm.yaml文件

[root@k8s-master1 prometheus]# cp alertmanager-cm.yaml alertmanager-cm-ding.yaml
[root@k8s-master1 prometheus]# cat  alertmanager-cm.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: alertmanager
  namespace: monitor-sa
data:
  alertmanager.yml: |-
    global:
      resolve_timeout: 1m
      smtp_smarthost: 'smtp.163.com:25'
      smtp_from: '18665870472@163.com'
      smtp_auth_username: '18665870472'
      smtp_auth_password: 'GGCTEDQDVLKPCIID'
      smtp_require_tls: false
    route:
      group_by: [alertname]
      group_wait: 10s
      group_interval: 10s
      repeat_interval: 10m
      receiver: prometheus
    receivers:
    - name: 'prometheus'
      wechat_configs:
      - corp_id: wwc84b5a8706c67480
        to_user: '@all'
        agent_id: 1000005
        api_secret: xGVnhrm2n2LhJcrBzULKrAH0rzIXGkQV4IiTFJYERHw

参数说明:

# 参数说明:
secret: 企业微信("企业应用"-->"自定应用"[Prometheus]--> "Secret") 
wechat是本人自创建应用名称
corp_id: 企业信息("我的企业"--->"CorpID"[在底部])
agent_id: 企业微信("企业应用"-->"自定应用"[Prometheus]--> "AgentId") 
wechat是自创建应用名称 #在这创建的应用名字是wechat,那么在配置route时,receiver也应该是Prometheus
to_user: '@all' :发送报警到所有人

1.3、更新服务

[root@k8s-master1 prometheus]# kubectl apply  -f alertmanager-cm.yaml
configmap/alertmanager configured
[root@k8s-master1 prometheus]# kubectl delete -f  prometheus-alertmanager-deploy.yaml
deployment.apps "prometheus-server" deleted
[root@k8s-master1 prometheus]# kubectl apply -f  prometheus-alertmanager-deploy.yaml
deployment.apps/prometheus-server created

[root@k8s-master1 prometheus]# kubectl get pods -n monitor-sa 
NAME                                 READY   STATUS    RESTARTS   AGE
node-exporter-nl5qz                  1/1     Running   0          16h
node-exporter-nxwkf                  1/1     Running   0          16h
node-exporter-x494t                  1/1     Running   0          16h
prometheus-server-76dd9f8dc6-fhggv   2/2     Running   0          26s

接收到的微信报警:

image-20210712125059199

posted @ 2021-07-12 13:24  运维人在路上  阅读(1787)  评论(2编辑  收藏  举报