Prometheus是以operator方式部署 这里仅仅提供一个思路,万变不离其宗。 使用短信告警之前需要自己购买短信服务,然后定义好短信模板,一般都有现成的sdk,自己简单包装一下就可以使用了。
思路:通过自定义webhook的方式进行发送。
我简单写了一个webhook,项目地址:https://github.com/cool-ops/prometheus-alert-sms.git
部署
1、下载代码
git clone https://github.com/cool-ops/prometheus-alert-sms.git
2、编译代码
cd prometheus-alert-sms/sh build.sh
3、打包镜像
docker build -t registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7 .
注:镜像地址更换成自己的仓库地址
4、推送镜像到镜像仓库
docker push registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7
5、修改项目目录下的prometheus-alert-sms.yaml
apiVersion: v1kind: ConfigMapmetadata:name: sms-confnamespace: monitoringdata:sms.yaml: |adapter:adapter_name: "RongLianYun"RongLianYun:baseUrl : "https://app.cloopen.com:8883"accountSid : "xxxxxx"appToken : "xxxxxx"appId : "xxxxx"templateId : "xxx"phones : ["11111111111","22222222222"]AliYun:aliRegion: "cn-hangzhou"accessKeyId: "xxxx"accessSecret: "xxxx"phoneNumbers: "11111111111,22222222222"signName: "xxxx"templateCode: "xxxx"---apiVersion: apps/v1kind: Deploymentmetadata:name: prometheus-alert-smsnamespace: monitoringspec:replicas: 1selector:matchLabels:app: prometheus-alert-smstemplate:metadata:labels:app: prometheus-alert-smsspec:containers:- name: prometheus-alert-smsimage: registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7imagePullPolicy: IfNotPresentlivenessProbe:failureThreshold: 3httpGet:path: /healthCheckport: tcp-9000scheme: HTTPinitialDelaySeconds: 30periodSeconds: 10successThreshold: 1timeoutSeconds: 2readinessProbe:failureThreshold: 3httpGet:path: /healthCheckport: tcp-9000scheme: HTTPinitialDelaySeconds: 30periodSeconds: 10successThreshold: 1timeoutSeconds: 2env:- name: CONFIG_PATHvalue: /app/conf/sms.yamlports:- name: app-portcontainerPort: 9000protocol: TCPresources:limits:cpu: 500mmemory: 1Girequests:cpu: 500mmemory: 1GivolumeMounts:- name: sms-confmountPath: /app/conf/sms.yamlsubPath: sms.yamlvolumes:- name: sms-confconfigMap:name: sms-conf---apiVersion: v1kind: Servicemetadata:name: prometheus-alter-smsnamespace: monitoringspec:selector:app: prometheus-alert-smsports:- name: app-portport: 9000targetPort: 9000protocol: TCP
到自己购买的短信服务获取对应的信息。
7、部署yaml文件
kubectl apply -f prometheus-alert-sms.yaml
8、修改alertmanager的报警媒介
......- receiver: smsgroup_wait: 10smatch:filesystem: nodereceivers:- name: 'sms'webhook_configs:- url: "http://prometheus-alter-sms.monitoring.svc:9000"send_resolved: true......
然后如果有报警就可以正常接受到报警了。
