Files
ewoooc/n8n-workflows/06-k8s-pod-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

67 lines
4.0 KiB
JSON

{
"name": "K8s Pod 狀態監控 (含自動修復)",
"nodes": [
{
"parameters": { "rule": { "interval": [{ "field": "minutes", "minutesInterval": 10 }] } },
"id": "schedule", "name": "每 10 分鐘", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.1, "position": [0, 0]
},
{
"parameters": { "url": "http://192.168.0.110:5001/health", "options": { "timeout": 15000 } },
"id": "http-health", "name": "檢查應用健康", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [220, 0]
},
{
"parameters": {
"conditions": { "options": { "caseSensitive": true }, "conditions": [{ "id": "c1", "leftValue": "={{ $json.status }}", "rightValue": "healthy", "operator": { "type": "string", "operation": "notEquals" } }], "combinator": "and" }
},
"id": "if-unhealthy", "name": "不健康?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [440, 0]
},
{
"parameters": {
"jsCode": "const data = $input.first().json;\nconst text = '🔴 *K8s Pod 異常*\\n\\n' +\n '📍 狀態: ' + (data.status || '無回應') + '\\n' +\n '🗄️ 資料庫: ' + (data.database || '未知') + '\\n\\n' +\n '🔧 正在嘗試重啟...';\nreturn [{ json: { ...data, telegramBody: { chat_id: '5619078117', text: text, parse_mode: 'Markdown' } } }];"
},
"id": "code-alert", "name": "組合告警訊息", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [660, 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": [880, 100]
},
{
"parameters": {
"method": "POST", "url": "http://192.168.0.110:5001/api/system/scheduler/restart",
"sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ service: 'momo-app' }) }}",
"options": { "timeout": 60000 }
},
"id": "restart", "name": "重啟服務", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [1100, 100]
},
{
"parameters": {
"jsCode": "const data = $input.first().json;\nconst text = data.success ? '✅ momo-app 已重啟,等待恢復中...' : '❌ 重啟失敗: ' + (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": [1320, 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": [1540, 100]
},
{ "parameters": {}, "id": "no-op", "name": "Pod 正常", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [660, -100] }
],
"connections": {
"每 10 分鐘": { "main": [[{ "node": "檢查應用健康", "type": "main", "index": 0 }]] },
"檢查應用健康": { "main": [[{ "node": "不健康?", "type": "main", "index": 0 }]] },
"不健康?": { "main": [[{ "node": "組合告警訊息", "type": "main", "index": 0 }], [{ "node": "Pod 正常", "type": "main", "index": 0 }]] },
"組合告警訊息": { "main": [[{ "node": "告警通知", "type": "main", "index": 0 }]] },
"告警通知": { "main": [[{ "node": "重啟服務", "type": "main", "index": 0 }]] },
"重啟服務": { "main": [[{ "node": "組合結果訊息", "type": "main", "index": 0 }]] },
"組合結果訊息": { "main": [[{ "node": "重啟結果", "type": "main", "index": 0 }]] }
},
"settings": { "executionOrder": "v1" }
}