Alertmanager配置短信告警
Prometheus是以operator方式部署。
這裏僅僅提供一個思路,萬變不離其宗。
使用短信告警以前須要本身購買短信服務,而後定義好短信模板,通常都有現成的sdk,本身簡單包裝一下就能夠使用了。node
思路:經過自定義webhook的方式進行發送。
我簡單寫了一個webhook,項目地址:https://github.com/cool-ops/prometheus-alert-sms.git
git
部署
一、下載代碼
github
git clone https://github.com/cool-ops/prometheus-alert-sms.git
二、編譯代碼
web
cd prometheus-alert-sms/
sh build.sh
三、打包鏡像
docker
docker build -t registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7 .
注:鏡像地址更換成本身的倉庫地址
四、推送鏡像到鏡像倉庫
api
docker push registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7
五、修改項目目錄下的prometheus-alert-sms.yaml
微信
apiVersion: v1
kind: ConfigMap
metadata:
name: sms-conf
namespace: monitoring
data:
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/v1
kind: Deployment
metadata:
name: prometheus-alert-sms
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-alert-sms
template:
metadata:
labels:
app: prometheus-alert-sms
spec:
containers:
- name: prometheus-alert-sms
image: registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthCheck
port: tcp-9000
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 2
readinessProbe:
failureThreshold: 3
httpGet:
path: /healthCheck
port: tcp-9000
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 2
env:
- name: CONFIG_PATH
value: /app/conf/sms.yaml
ports:
- name: app-port
containerPort: 9000
protocol: TCP
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 500m
memory: 1Gi
volumeMounts:
- name: sms-conf
mountPath: /app/conf/sms.yaml
subPath: sms.yaml
volumes:
- name: sms-conf
configMap:
name: sms-conf
---
apiVersion: v1
kind: Service
metadata:
name: prometheus-alter-sms
namespace: monitoring
spec:
selector:
app: prometheus-alert-sms
ports:
- name: app-port
port: 9000
targetPort: 9000
protocol: TCP
到本身購買的短信服務獲取對應的信息。
七、部署yaml文件
app
kubectl apply -f prometheus-alert-sms.yaml
八、修改alertmanager的報警媒介
運維
......
- receiver: sms
group_wait: 10s
match:
filesystem: node
receivers:
- name: 'sms'
webhook_configs:
- url: "http://prometheus-alter-sms.monitoring.svc:9000"
send_resolved: true
......
而後若是有報警就能夠正常接受到報警了。
tcp
說明:代碼裏面僅僅是針對我本身的短信模板作了改變,因此不必定適合你。有興趣的朋友能夠本身作相應的修改。
完
-----------------------
公衆號:極客運維圈(ID:qiaobiangushi)
知乎: 喬邊故事
博客:極客運維圈
永遠不要高估本身,作一個謙遜又自信的人。
-----------------------
掃碼二維碼關注公衆號,不按期維護優質內容,技術乾貨!
舒適提示
若是你喜歡本文,請分享到朋友圈,想要得到更多信息,請關注我。
本文分享自微信公衆號 - 極客運維圈(qiaobiangushi)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。