ServerChan(Server酱)是一款简单易用的消息推送服务,可以将服务器告警、监控信息等推送到微信。以下是详细的使用方法:
注册ServerChan账号
获取SCKEY
SCU123456789abcdefg
)绑定微信
https://sc.ftqq.com/SCKEY.send?text=标题&desp=内容
示例(将SCKEY替换为你自己的):
curl "https://sc.ftqq.com/SCU123456789abcdefg.send?text=服务器告警&desp=CPU使用率超过90%"
curl -X POST \
https://sc.ftqq.com/SCU123456789abcdefg.send \
-d "text=服务器告警" \
-d "desp=CPU使用率超过90%"
在desp
参数中使用Markdown语法:
curl -X POST \
https://sc.ftqq.com/SCU123456789abcdefg.send \
-d "text=服务器详细告警" \
-d "desp=### 服务器状态\n- **CPU**: 95%\n- **内存**: 85%\n- **磁盘**: 78%"
Bash脚本示例:
#!/bin/bash
SCKEY="你的SCKEY"
ALERT_MSG="服务器CPU使用率超过阈值!"
curl -s -X POST \
"https://sc.ftqq.com/$SCKEY.send" \
-d "text=服务器告警" \
-d "desp=$ALERT_MSG"
Python脚本示例:
import requests
def send_wechat_alert(title, content):
sckey = "你的SCKEY"
url = f"https://sc.ftqq.com/{sckey}.send"
data = {
"text": title,
"desp": content
}
response = requests.post(url, data=data)
return response.json()
# 使用示例
send_wechat_alert("数据库备份失败", "今天凌晨的数据库备份任务执行失败,请检查!")
在Zabbix的报警媒介中添加Webhook:
ServerChan
Webhook
https://sc.ftqq.com/{SCKEY}.send
{"text":"{ALERT.SUBJECT}","desp":"{ALERT.MESSAGE}"}
在Alertmanager配置中添加webhook:
receivers:
- name: 'wechat'
webhook_configs:
- url: 'https://sc.ftqq.com/SCU123456789abcdefg.send'
send_resolved: true
收不到消息:
API返回错误:
通过以上步骤,你可以轻松地将ServerChan集成到你的监控系统中,实现微信实时告警推送。