配置Alertmanager发送报警到钉钉

配置Alertmanager发送报警到钉钉

一、配置步骤

1.1、创建钉钉机器人

打开电脑版钉钉,创建一个群,创建自定义机器人,按如下步骤创建:https://developers.dingtalk.com/document/app/custom-robot-access

群设置-->智能群助手-->添加机器人-->自定义-->添加

image-20210712113702229

image-20210712113844332

image-20210712113904067

image-20210712114040788

image-20210712114057660

webhook:https://oapi.dingtalk.com/robot/send?access_token=7e7368e227cf8ac68f37c8690d7f8a13db5bbd1fcb109470ace31501b9051ee6

1.2、安装钉钉的webhook插件

下载地址:链接:https://pan.baidu.com/s/1_HtVZsItq2KsYvOlkIP9DQ 提取码:d59o

# 在k8s的控制节点k8s-master1操作
tar zxvf prometheus-webhook-dingtalk-0.3.0.linux-amd64.tar.gz

# 启动钉钉报警插件
cd prometheus-webhook-dingtalk-0.3.0.linux-amd64
nohup ./prometheus-webhook-dingtalk --web.listen-address="0.0.0.0:8060" --ding.profile="cluster1=https://oapi.dingtalk.com/robot/send?access_token=7e7368e227cf8ac68f37c8690d7f8a13db5bbd1fcb109470ace31501b9051ee6" &

[root@k8s-master1 ~]# ss -lntp|grep 8060
LISTEN     0      128         :::8060                    :::*                   users:(("prometheus-webh",pid=78242,fd=3))

1.3、创建alertmanager-cm.yaml文件

# 对原来的文件备份
[root@k8s-master1 prometheus]# cp alertmanager-cm.yaml alertmanager-cm.yaml.bak
[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: cluster1
    receivers:
    - name: cluster1
      webhook_configs:
      - url: 'http://192.168.40.180:8060/dingtalk/cluster1/send'
        send_resolved: true
        
# 更新
[root@k8s-master1 prometheus]# kubectl  delete -f  alertmanager-cm.yaml
[root@k8s-master1 prometheus]# kubectl apply  -f alertmanager-cm.yaml
[root@k8s-master1 prometheus]# kubectl  delete -f prometheus-alertmanager-cfg.yaml
[root@k8s-master1 prometheus]# kubectl apply -f prometheus-alertmanager-cfg.yaml
[root@k8s-master1 prometheus]# kubectl delete -f  prometheus-alertmanager-deploy.yaml
[root@k8s-master1 prometheus]# kubectl apply -f  prometheus-alertmanager-deploy.yaml

image-20210712120638976

作者:Lawrence

-------------------------------------------

个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!

扫描上面二维码关注我
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
原文地址:https://www.cnblogs.com/hujinzhong/p/15001529.html