用 n8n 和 Echobell 打造个人自动化告警中心
n8n 的工作流自动化能力很强,但内置通知功能较弱。搭配 Echobell 可以填补这一空缺:n8n 负责处理逻辑,Echobell 负责发送真正能触达你的推送通知或来电。
配置你的第一个告警工作流
一个实用的起点:当服务器 CPU 超过 80% 时发送通知。
第一步:创建 Echobell 频道
- 打开 Echobell → 新建频道
- 命名为"Server Alerts"
- 从频道设置中复制 Webhook URL
第二步:构建 n8n 工作流
{
"nodes": [
{
"name": "Cron",
"type": "n8n-nodes-base.cron",
"parameters": {
"rule": {
"interval": [{"field": "minutes", "minutesInterval": 5}]
}
}
},
{
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"url": "https://api.your-monitoring.com/stats",
"method": "GET"
}
},
{
"name": "IF",
"type": "n8n-nodes-base.if",
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.cpu_usage }}",
"operation": "gt",
"value2": 80
}
]
}
}
},
{
"name": "Echobell Alert",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"url": "YOUR_ECHOBELL_WEBHOOK_URL",
"method": "POST",
"bodyParameters": {
"parameters": [
{
"name": "server_name",
"value": "production-01"
},
{
"name": "cpu_usage",
"value": "={{ $json.cpu_usage }}"
},
{
"name": "alert_type",
"value": "CPU Alert"
}
]
}
}
}
]
}第三步:配置通知模板
在 Echobell 频道中设置:
Title: 🔥 Server {{server_name}} CPU Critical!
Body: CPU usage at {{cpu_usage}}%. Immediate attention needed.对于关键告警,将通知类型设置为来电。
更多工作流示例
GitHub Actions 失败告警
// n8n Webhook trigger configuration
{
"path": "github-actions",
"responseMode": "onReceived"
}将 GitHub Webhook 接入 n8n,过滤 action: completed 且 conclusion: failure 的事件,然后 POST 到你的 Echobell Webhook。
加密货币价格阈值告警
// In n8n's Function node
const price = $json.price;
const threshold = 50000;
if (price < threshold) {
return {
json: {
symbol: "BTC",
price: price,
alert: "Price dropped below $50,000"
}
};
}
return null;智能家居关键事件
通过 n8n 将 Home Assistant 的关键事件(漏水传感器、烟雾探测器、离家时的门窗传感器)转发给 Echobell。详见 Home Assistant 集成指南。
RSS/Newsletter 摘要
// Cron trigger → RSS Read → Filter new items → Echobell
{
"cron": "0 8 * * *",
"rss_url": "https://your-favorite-blog.com/feed",
"condition": "contains({{title}}, 'AI')"
}定时任务监控
const lastRun = new Date($json.last_execution);
const now = new Date();
const hoursSince = (now - lastRun) / (1000 * 60 * 60);
if (hoursSince > 24) {
return {
json: {
job: "daily-backup",
status: "OVERDUE",
last_run: lastRun.toISOString()
}
};
}最佳实践
按优先级使用不同频道
- 紧急:生产宕机、安全告警 → 来电
- 警告:磁盘空间、CPU 过高 → 时间敏感推送
- 信息:每日报告、摘要 → 普通推送
用条件减少噪音
Echobell 的条件功能可在投递层进行过滤:
// Only call during off-hours
hour < 8 || hour > 18保持模板简短可操作
Good: 🔴 Disk Full on server-01
Bad: The disk on server number one in the production environment has become completely full添加每周测试
// Every Friday at 5 PM
if (new Date().getDay() === 5 && new Date().getHours() === 17) {
return { json: { test: "Weekly system check" } };
}从一个工作流开始,逐步扩展。Webhook 文档涵盖完整的 Echobell API。