1. 程式人生 > 其它 >|NO.Z.00338|——————————|^^ 失敗 ^^|——|KuberNetes&運維.V55|-----------------------------------------------------------|Alertmanager.v02|微信告警.v02|模板|

|NO.Z.00338|——————————|^^ 失敗 ^^|——|KuberNetes&運維.V55|-----------------------------------------------------------|Alertmanager.v02|微信告警.v02|模板|



[CloudNative:KuberNetes&運維.V55]                                                                      [Applications.KuberNetes] [|DevOps|k8s|k8s運維|**3節點.V1**|Altermanager|Prometheus微信告警|Prometheus自定義告警模板|]








一、檢視微信告警資訊
### --- 檢視微信告警配置是否生效
### --- 通過企業微信接收告警資訊

~~~     ——>http://alert.test.com/——>status配置是否生效——>Config
二、Prometheus自定義告警模板
### --- 微信告警模板

[root@k8s-master01 Alarm]# vim wechat.tmpl 
{{ define "wechat.default.message" }}
{{ if gt (len .Alerts.Firing) 0 -}}
Alerts Firing:
{{ range .Alerts }}
告警級別:{{ .Labels.severity }}
告警型別:{{ .Labels.alertname }}
故障主機: {{ .Labels.instance }}
Job名稱: {{ .Labels.job }}
告警詳情: {{ .Annotations.message }}
觸發時間: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}
{{ if gt (len .Alerts.Resolved) 0 -}}
Alerts Resolved:
{{ range .Alerts }}
告警級別:{{ .Labels.severity }}
告警型別:{{ .Labels.alertname }}
故障主機: {{ .Labels.instance }}
Job名稱: {{ .Labels.job }}
告警主題: {{ .Annotations.message }}
觸發時間: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
恢復時間: {{ .EndsAt.Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}
告警連結:'http://alert.test.com'
{{- end }}
### --- 移動到掛載目錄下

[root@k8s-master01 Alarm]# cp wechat.tmpl  /etc/alertmanager/config/
三、在alertmanager-secrets下定義模板引數
### --- 定義模板引數

[root@k8s-master01 Alarm]# vim alertmanager-secrets.wechat.yaml 
# ~~~ 增加微信告警模板:
    templates:
    - '/etc/alertmanager/config/*.tmpl'                   # 模板來源
# ~~~ 設定傳送訊息的引數
    - name: 'wechat'
      wechat_configs:
      - send_resolved: true
        to_tag: '1'
        agent_id: '1000002'                               # 此行下新增如下內容
        message: '{{template"wechat.default.message".}}'  # 新增內容:新增這行引數內容;讓其訊息生效
### --- 重新觸發alertmanager-secrets

[root@k8s-master01 Alarm]# kubectl replace -f alertmanager-secrets.wechat.yaml -n monitoring
secret/alertmanager-main replaced
四、檢視收到的告警資訊 五、建立alertmanager.yaml的secret(使用熱更新的方案更新alertmanager的secrets)
### --- 建立alertmanager.yaml的secret

kubectl create secret generic  alertmanager-main --from-file=alertmanager.yaml -n monitoring
### --- 之後更改alertmanager.yaml可以使用熱載入去更新k8s的secret

kubectl create secret generic  alertmanager-main --from-file=alertmanager.yaml -n monitoring --dry-run -o yaml | kubectl replace -f -








===============================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)