背景:现在的办公都使用钉钉,告警很多地方也用到了钉钉机器人的webhook,但是研究了rancher的告警好一会才知道rancher原来是不支持钉钉webhook。真的是吐血~
系统环境
centos7.8
rancher v2.4.5
docker 19.03.12
步骤
- rancher-ui启用集群监控
- rancher-ui启用项目监控 (这里注意如果启用持久化存储,grafana pvc挂载的权限问题,会导致grafana异常,创建的pv目录权限给足就行)
我这里使用开源大佬的timonwong/prometheus-webhook-dingtalk来转发消息,更详细的直接GitHub上搜。
编辑服务发现:
yaml文件内容如下:
kind: Service apiVersion: v1 metadata: name: webhook-dingtalk namespace: my-public spec: selector: app: webhook-dingtalk type: ClusterIP ports: - protocol: TCP port: 80 targetPort: 8060 --- apiVersion: apps/v1 kind: Deployment metadata: name: webhook-dingtalk namespace: my-public labels: app: webhook-dingtalk spec: replicas: 1 selector: matchLabels: app: template: metadata: labels: app: webhook-dingtalk spec: imagePullSecrets: - name: pipeline-docker-registry containers: - name: webhook-dingtalk image: timonwong/prometheus-webhook-dingtalk args: - --ding.profile=webhook1=xxxxxxxxxxxxxxxx ports: - containerPort: 8060
添加通知示例
http://webhook-dingtalk.my-public.svc.cluster.local/dingtalk/webhook1/send
大家将my-public修改为自己的服务所在的命名空间名称即可,如果要使用多个群组机器人,在yaml文件中spec.containers.args字段下,添加多个ding.profile即可,然后通知栏uri修改为你自定义的webhook名称,比如webhook2