{
  "name": "資料庫備份監控",
  "nodes": [
    {
      "parameters": { "rule": { "interval": [{ "field": "cronExpression", "expression": "0 10 * * *" }] } },
      "id": "schedule", "name": "每日 10:00", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.1, "position": [0, 0]
    },
    {
      "parameters": { "url": "http://192.168.0.110:5001/api/system/backup/status", "options": { "timeout": 10000 } },
      "id": "http-check", "name": "檢查備份狀態", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [220, 0]
    },
    {
      "parameters": {
        "conditions": { "options": { "caseSensitive": true }, "conditions": [{ "id": "c1", "leftValue": "={{ $json.healthy }}", "rightValue": false, "operator": { "type": "boolean", "operation": "equals" } }], "combinator": "and" }
      },
      "id": "if-unhealthy", "name": "備份異常?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [440, 0]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nlet msg = '';\nif (data.error) {\n  msg = '❌ ' + data.error;\n} else if (data.last_backup) {\n  msg = '⏰ 最後備份: ' + data.last_backup.name + ' (' + data.last_backup.hours_ago + ' 小時前)';\n} else {\n  msg = '⏰ 無備份記錄';\n}\nconst text = '🟠 *備份監控警告*\\n\\n' + msg + '\\n\\n💡 請檢查備份排程';\n\nreturn [{ json: { 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/bot8075645931:AAH-EGKMo8ZC4QJs-Nc1_0s92xHrGdQvdpg/sendMessage",
        "sendBody": true, "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.telegramBody) }}"
      },
      "id": "telegram", "name": "告警通知", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [880, 100]
    },
    { "parameters": {}, "id": "no-op", "name": "備份正常", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [660, -100] }
  ],
  "connections": {
    "每日 10:00": { "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 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
