一、Prometheus企业微信配置
### --- 企业微信配置

~~~     地址:https://work.weixin.qq.com/wework_admin/frame#apps
~~~     应用管理——>创建应用(负责被Prometheus调用,并发送告警信息)
~~~     ——>添加创建应用配置信息——>部门ID:2——>
~~~     Agentld:1000002
~~~     Secret:xsJAXzMNLVdl_fDwu9u999o-4Sr3kvwAHDIQEUVlryo
~~~     企业ID:我的企业——>企业ID:ww6bf214de14e370a4
~~~     Prometheus_Java.BBS:部门ID:1
|NO.Z.00337|——————————|^^  失败  ^^|——|KuberNetes&运维.V54|——|Alertmanager.v01|微信告警.v01|_4s
|NO.Z.00337|——————————|^^  失败  ^^|——|KuberNetes&运维.V54|——|Alertmanager.v01|微信告警.v01|_4s_02

一、创建微信告警资源文件
### --- 查看alertmanger的po、secrets运行容器
~~~     在altermanager-secrets中配置邮件告警配置参数

[root@k8s-master01 Alarm]# kubectl get secrets -n monitoring
NAME                              TYPE                                  DATA   AGE
alertmanager-main                 Opaque                                1      62m
[root@k8s-master01 Alarm]# kubectl get po -n monitoring
NAME                                   READY   STATUS    RESTARTS   AGE
alertmanager-main-0                    2/2     Running   0          60m
二、在altermanager-secrets创建微信告警配置参数:发件收件参数配置
### --- 配置altermanager-secrets配置文件微信告警参数

[root@k8s-master01 Alarm]# vim alertmanager-secrets.wechat.yaml
apiVersion: v1
data: {}
kind: Secret
metadata:
  name: alertmanager-main
  namespace: monitoring
stringData:
  alertmanager.yaml: |-
    "global":
      "resolve_timeout": "2h"
      smtp_from: "yanqi_vip@yeah.net"
      smtp_smarthost: "smtp.yeah.net:465"
      smtp_hello: "yanqi-yeah.net"
      smtp_auth_username: "yanqi_vip@yeah.net"
      smtp_auth_password: "DXQINUVKZENYIROU"
      smtp_require_tls: false
      # wechat
      wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
      wechat_api_secret: 'xsJAXzMNLVdl_fDwu9u999o-4Sr3kvwAHDIQEUVlryo'
      wechat_api_corp_id: 'ww6bf214de14e370a4'
    templates:
    - '/etc/alertmanager/config/*.tmpl'
    "inhibit_rules":
    - "equal":
      - "namespace"
      - "alertname"
      "source_match":
        "severity": "critical"
      "target_match_re":
        "severity": "warning|info"
    - "equal":
      - "namespace"
      - "alertname"
      "source_match":
        "severity": "warning"
      "target_match_re":
        "severity": "info"
    "receivers":
    - "name": "Default"
      "email_configs": 
      - to: "yanqi_vip@yeah.net"
        send_resolved: true
    - "name": "Watchdog"
      "email_configs": 
      - to: "yanqi_vip@yeah.net"
        send_resolved: true
    - "name": "Critical"
      "email_configs": 
      - to: "yanqi_vip@yeah.net"
        send_resolved: true
    - name: 'wechat'
      wechat_configs:
      - send_resolved: true
        to_tag: '1'
        agent_id: '1000002'
        message: '{{template"wechat.default.message".}}'
    "route":
      "group_by":
      - "namespace"
      "group_interval": "1m"
      "group_wait": "30s"
      "receiver": "Default"
      "repeat_interval": "1m"
      "routes":
      - "match":
          "alertname": "Watchdog"
        "receiver": "wechat"
      - "match":
          "severity": "critical"
        "receiver": "Critical"
三、在altermanager-secrets创建微信告警配置参数:发件收件参数说明
### --- 配置altermanager-secrets配置文件微信告警参数

[root@k8s-master01 Alarm]# vim alertmanager-secrets.wechat.yaml 
# ~~~ 配置企业微信配置信息
      # wechat
      wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'           # 固定的,不用变
      wechat_api_secret: 'xsJAXzMNLVdl_fDwu9u999o-4Sr3kvwAHDIQEUVlryo' # secret
      wechat_api_corp_id: 'ww6bf214de14e370a4'                         # 企业ID
# ~~~ 配置receivers:微信模板
    - name: 'wechat'
      wechat_configs:
      - send_resolved: true                                            # 是否接受恢复通知
        to_tag: '1'                                                    # 部门的tag
        agent_id: '1000002'                                            # 应用ID
# ~~~ 修改为微信的告警
      "routes":
      - "match":
          "alertname": "Watchdog"
        "receiver": "wechat"
### --- replace-alertmanager-secrets

[root@k8s-master01 Alarm]# kubectl replace -f alertmanager-secrets.wechat.yaml -n monitoring
secret/alertmanager-main replaced
### --- 查看alertmanager-secrets的日志;是否加载成功

[root@k8s-master01 Alarm]# kubectl logs -f alertmanager-main-0  -n monitoring alertmanager
level=info ts=2021-05-29T04:39:45.218Z caller=coordinator.go:119 component=configuration msg="Loading configuration file" file=/etc/alertmanager/config/alertmanager.yaml
level=info ts=2021-05-29T04:39:45.220Z caller=coordinator.go:131 component=configuration msg="Completed loading of configuration file" file=/etc/alertmanager/config/alertmanager.yaml
level=info ts=2021-05-29T04:39:45.222Z caller=main.go:416 component=configuration msg="skipping creation of receiver not referenced by any route" receiver=Watchdog

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor