Files
ewoooc/n8n-workflows/05-crawler-monitor.json
OoO d6d8777e41
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
V10.601 收斂 Gemini 與密鑰治理
2026-06-06 14:52:46 +08:00

74 lines
4.5 KiB
JSON

{
"name": "爬蟲執行監控 (含自動重啟)",
"nodes": [
{
"parameters": { "rule": { "interval": [{ "field": "hours", "hoursInterval": 2 }] } },
"id": "schedule", "name": "每 2 小時", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.1, "position": [0, 0]
},
{
"parameters": { "url": "http://192.168.0.110:5001/api/system/crawler/status", "options": { "timeout": 10000 } },
"id": "http-check", "name": "檢查爬蟲狀態", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [220, 0]
},
{
"parameters": {
"jsCode": "const data = $input.first().json;\nconst tasks = data.tasks || {};\nlet unhealthy = [];\nfor (const [name, info] of Object.entries(tasks)) {\n if (info && !info.is_healthy) unhealthy.push(name + ': ' + (info.hours_ago || '?') + 'h 前執行');\n}\nreturn [{ json: { healthy: data.healthy, unhealthy, hasIssue: unhealthy.length > 0, issueText: unhealthy.join('\\n') }}];"
},
"id": "code", "name": "解析狀態", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [440, 0]
},
{
"parameters": {
"conditions": { "options": { "caseSensitive": true }, "conditions": [{ "id": "c1", "leftValue": "={{ $json.hasIssue }}", "rightValue": true, "operator": { "type": "boolean", "operation": "equals" } }], "combinator": "and" }
},
"id": "if-issue", "name": "爬蟲異常?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [660, 0]
},
{
"parameters": {
"jsCode": "const data = $input.first().json;\nconst text = '🟠 *爬蟲監控警告*\\n\\n' + data.issueText + '\\n\\n🔧 正在嘗試重啟 scheduler...';\nreturn [{ json: { ...data, telegramBody: { chat_id: '5619078117', text: text, parse_mode: 'Markdown' } } }];"
},
"id": "code-alert", "name": "組合告警訊息", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [880, 100]
},
{
"parameters": {
"method": "POST", "url": "https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/sendMessage",
"sendBody": true, "specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json.telegramBody) }}"
},
"id": "telegram-alert", "name": "告警通知", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [1100, 100]
},
{
"parameters": {
"method": "POST", "url": "http://192.168.0.110:5001/api/system/scheduler/restart",
"sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ service: 'scheduler' }) }}",
"options": { "timeout": 60000 }
},
"id": "restart", "name": "重啟 Scheduler", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [1320, 100]
},
{
"parameters": {
"jsCode": "const data = $input.first().json;\nconst text = data.success ? '✅ Scheduler 已重啟' : '❌ 重啟失敗: ' + (data.error || '未知錯誤');\nreturn [{ json: { telegramBody: { chat_id: '5619078117', text: text, parse_mode: 'Markdown' } } }];"
},
"id": "code-result", "name": "組合結果訊息", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [1540, 100]
},
{
"parameters": {
"method": "POST", "url": "https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/sendMessage",
"sendBody": true, "specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json.telegramBody) }}"
},
"id": "telegram-result", "name": "重啟結果", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [1760, 100]
},
{ "parameters": {}, "id": "no-op", "name": "爬蟲正常", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [880, -100] }
],
"connections": {
"每 2 小時": { "main": [[{ "node": "檢查爬蟲狀態", "type": "main", "index": 0 }]] },
"檢查爬蟲狀態": { "main": [[{ "node": "解析狀態", "type": "main", "index": 0 }]] },
"解析狀態": { "main": [[{ "node": "爬蟲異常?", "type": "main", "index": 0 }]] },
"爬蟲異常?": { "main": [[{ "node": "組合告警訊息", "type": "main", "index": 0 }], [{ "node": "爬蟲正常", "type": "main", "index": 0 }]] },
"組合告警訊息": { "main": [[{ "node": "告警通知", "type": "main", "index": 0 }]] },
"告警通知": { "main": [[{ "node": "重啟 Scheduler", "type": "main", "index": 0 }]] },
"重啟 Scheduler": { "main": [[{ "node": "組合結果訊息", "type": "main", "index": 0 }]] },
"組合結果訊息": { "main": [[{ "node": "重啟結果", "type": "main", "index": 0 }]] }
},
"settings": { "executionOrder": "v1" }
}