1. 程式人生 > 其它 >|NO.Z.00335|——————————|CloudNative|——|KuberNetes&運維.V52|-----------------------------------------------------------|Alertmanager.v02|Prometheus郵件告警|

|NO.Z.00335|——————————|CloudNative|——|KuberNetes&運維.V52|-----------------------------------------------------------|Alertmanager.v02|Prometheus郵件告警|



[CloudNative:KuberNetes&運維.V52]                                                           [Applications.KuberNetes] [|Altermanager|Prometheus郵件告警|Altermanager例項操作|]








一、Prometheus郵件告警
### --- 檢視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]# cat alertmanager-secrets.email.yaml 
apiVersion: v1
data: {}
kind: Secret
metadata:
  name: alertmanager-main
  namespace: monitoring
stringData:
  alertmanager.yaml: |-
    "global":
      "resolve_timeout": "2h"
      smtp_from: "[email protected]"
      smtp_smarthost: "smtp.yeah.net:465"
      smtp_hello: "yanqi-yeah.net"
      smtp_auth_username: "[email protected]"
      smtp_auth_password: "DXQINUVKZENYIROU"
      smtp_require_tls: false
      # wechat
      wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
      wechat_api_secret: 'ZZQt0Ue9mtplH9u1g8PhxR_RxEnRu512CQtmBn6R2x0'
      wechat_api_corp_id: 'wwef86a30130f04f2b'
    "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: "[email protected]"
        send_resolved: true
    - "name": "Watchdog"
      "email_configs": 
      - to: "[email protected]"
        send_resolved: true
    - "name": "Critical"
      "email_configs": 
      - to: "[email protected]"
        send_resolved: true
    - name: 'wechat'
      wechat_configs:
      - send_resolved: true
        to_tag: '1'
        agent_id: '1000003'
    "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.email.yaml
# 發件郵箱配置:郵件引數配置
   alertmanager.yaml: |-
     "global":
       "resolve_timeout": "2h"                # 此行下添加發件郵箱配置引數
       smtp_from: "[email protected]"        # 此為發件郵箱服務配置引數
       smtp_smarthost: "smtp.yeah.net:465"
       smtp_hello: "yanqi-yeah.net"
       smtp_auth_username: "[email protected]"
       smtp_auth_password: "DXQINUVKZENYIROU"
       smtp_require_tls: false
# 收件郵箱配置:郵件引數配置
     "receivers":
     - "name": "Default"                      # 此行下新增收件郵箱改配置
       "email_configs":                       # 此為收件郵箱服務配置引數
       - to: "[email protected]"
         send_resolved: true
     - "name": "Watchdog"
       "email_configs":
       - to: "[email protected]"
         send_resolved: true
     - "name": "Critical"
       "email_configs":
       - to: "[email protected]"
         send_resolved: true
四、replace alertmanager.secrets.yaml
### --- 重新replace alertmanager.secrets.yaml

[root@k8s-master01 Alarm]# kubectl replace -f alertmanager-secrets.email.yaml -n monitoring
secret/alertmanager-main replaced
~~~     # 檢視alertmanager-secrets.email.yaml和alertmanager-pod

[root@k8s-master01 Alarm]# kubectl get secrets -n monitoring
NAME                              TYPE                                  DATA   AGE
alertmanager-main                 Opaque                                1      70m
### --- 重新觸發altermanager-pod

[root@k8s-master01 Alarm]# kubectl delete po alertmanager-main-0 -n monitoring
pod "alertmanager-main-0" deleted
~~~     # 檢視altermanager-pod

[root@k8s-master01 Alarm]# kubectl get po -n monitoring -owide
NAME                                   READY   STATUS    RESTARTS   AGE     IP               NODE           NOMINATED NODE   READINESS GATES
alertmanager-main-0                    2/2     Running   2          2d10h   172.25.244.224   k8s-master01   <none>           <none>








===============================END===============================


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



來自為知筆記(Wiz)