|NO.Z.00337|——————————|^^ 失敗 ^^|——|KuberNetes&運維.V54|-----------------------------------------------------------|Alertmanager.v01|微信告警.v01|
阿新 • • 發佈:2022-04-01
[CloudNative:KuberNetes&運維.V54] [Applications.KuberNetes] [|DevOps|k8s|k8s運維|**3節點.V1**|Altermanager|Prometheus微信告警|Prometheus自定義告警模板|]
一、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
一、建立微信告警資原始檔
二、在altermanager-secrets建立微信告警配置引數:發件收件引數配置### --- 檢視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: "[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: '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: "[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: '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配置檔案微信告警引數
[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
===============================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)