fix(backup-monitor): change DataTable getMany to getAll, remove unsupported filters param
This commit is contained in:
parent
9bb9abb438
commit
0ac58a3cb9
|
|
@ -152,23 +152,13 @@ reporter = {
|
|||
},
|
||||
{
|
||||
parameters: {
|
||||
resource: 'row',
|
||||
operation: 'getMany',
|
||||
operation: 'getAll',
|
||||
dataTableId: {
|
||||
'__rl' => true,
|
||||
mode: 'list',
|
||||
value: 'cWeJhlybF9eV43DB',
|
||||
cachedResultName: 'backup_runs'
|
||||
},
|
||||
filters: {
|
||||
conditions: [
|
||||
{
|
||||
keyName: 'timestamp',
|
||||
condition: 'gt',
|
||||
keyValue: '={{ $now.minus({days: 7}).toISO() }}'
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {}
|
||||
},
|
||||
id: SecureRandom.uuid,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"id": "ed22d29f-35f9-45ac-a7c7-b97ffa926736",
|
||||
"id": "bbf1d22b-1e8d-451e-9c69-2ca84976989c",
|
||||
"name": "Every Friday 8 AM",
|
||||
"type": "n8n-nodes-base.scheduleTrigger",
|
||||
"typeVersion": 1.2,
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
"assignments": {
|
||||
"assignments": [
|
||||
{
|
||||
"id": "212c8f16-8900-4cbf-93bb-4802ad9c3f33",
|
||||
"id": "c0e6d99b-ef1c-47ed-bdb4-85df7364e6ee",
|
||||
"name": "sources",
|
||||
"value": "={{ [{\"machine\":\"desktop\",\"destination\":\"synology\"},{\"machine\":\"desktop\",\"destination\":\"backblaze-b2\"},{\"machine\":\"vps-ovh-prod-01\",\"destination\":\"local\"}] }}",
|
||||
"type": "arrayValue"
|
||||
|
|
@ -42,7 +42,7 @@
|
|||
},
|
||||
"options": {}
|
||||
},
|
||||
"id": "3c3c5660-6075-4f73-9bb1-a7a70c91bfd6",
|
||||
"id": "65741758-2cad-43a7-8fdd-92e4ce2f88eb",
|
||||
"name": "Set sources",
|
||||
"type": "n8n-nodes-base.set",
|
||||
"typeVersion": 3.4,
|
||||
|
|
@ -53,26 +53,16 @@
|
|||
},
|
||||
{
|
||||
"parameters": {
|
||||
"resource": "row",
|
||||
"operation": "getMany",
|
||||
"operation": "getAll",
|
||||
"dataTableId": {
|
||||
"__rl": true,
|
||||
"mode": "list",
|
||||
"value": "cWeJhlybF9eV43DB",
|
||||
"cachedResultName": "backup_runs"
|
||||
},
|
||||
"filters": {
|
||||
"conditions": [
|
||||
{
|
||||
"keyName": "timestamp",
|
||||
"condition": "gt",
|
||||
"keyValue": "={{ $now.minus({days: 7}).toISO() }}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"id": "474f055d-08e6-4a47-8a1f-5f18818e7daf",
|
||||
"id": "0097ac86-8a65-46a8-a645-acc62515853e",
|
||||
"name": "Get backup_runs (last 7d)",
|
||||
"type": "n8n-nodes-base.dataTable",
|
||||
"typeVersion": 1,
|
||||
|
|
@ -87,7 +77,7 @@
|
|||
"language": "javaScript",
|
||||
"jsCode": "// Runs once for all items. References upstream nodes by exact name.\nconst sources = $('Set sources').first().json.sources;\nconst runs = $('Get backup_runs (last 7d)').all().map(item => item.json);\nconst weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);\n\nconst results = sources.map(source => {\n const sourceRuns = runs.filter(r =>\n r.machine === source.machine &&\n r.destination === source.destination &&\n new Date(r.timestamp) >= weekAgo\n );\n const hasSuccess = sourceRuns.some(r => r.status === 'success');\n const hasAnyRun = sourceRuns.length > 0;\n const status = hasSuccess ? 'green' : hasAnyRun ? 'yellow' : 'red';\n const lastSuccess = sourceRuns\n .filter(r => r.status === 'success')\n .sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp))[0] || null;\n return { ...source, status, runs: sourceRuns, lastSuccess };\n});\n\nconst overallStatus = results.some(r => r.status === 'red') ? 'red'\n : results.some(r => r.status === 'yellow') ? 'yellow' : 'green';\n\nreturn [{ json: { results, overallStatus } }];\n"
|
||||
},
|
||||
"id": "4211f3b0-1878-4979-a5be-eb01bdec2d63",
|
||||
"id": "92a9b777-0d75-4b40-9829-29b3f1d705ed",
|
||||
"name": "Evaluate Sources",
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
|
|
@ -102,7 +92,7 @@
|
|||
"language": "javaScript",
|
||||
"jsCode": "// Builds subject + body from Evaluate Sources output.\n// Uses an array of lines joined at the end to avoid \\n escape issues in JSON storage.\nconst { results, overallStatus } = $input.first().json;\nconst icon = { green: '✓', yellow: '⚠', red: '✗' };\nconst label = { green: 'Backups healthy', yellow: 'Backup warning', red: 'Backup failure' };\nconst weekOf = new Date().toLocaleDateString('en-US', { month: 'short', day: 'numeric' });\nconst subject = icon[overallStatus] + ' ' + label[overallStatus] + ' — week of ' + weekOf;\n\nconst fmt = ts => ts\n ? new Date(ts).toLocaleString('en-US', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })\n : 'unknown';\n\nconst L = [];\n\nif (overallStatus === 'green') {\n L.push('All backup sources ran successfully this week.');\n L.push('');\n results.forEach(r =>\n L.push('✓ ' + r.machine + ' / ' + r.destination +\n ' (last success: ' + fmt(r.lastSuccess && r.lastSuccess.timestamp) + ')')\n );\n} else {\n const problems = results.filter(r => r.status !== 'green');\n const healthy = results.filter(r => r.status === 'green');\n\n L.push(problems.length + ' source(s) need attention:');\n L.push('');\n\n problems.forEach(r => {\n L.push(icon[r.status] + ' ' + r.machine + ' / ' + r.destination);\n\n if (r.status === 'yellow') {\n L.push(' Ran this week but never succeeded.');\n r.runs.slice(0, 3).forEach(run => {\n var line = ' ' + fmt(run.timestamp) + ' [' + run.status + ']';\n if (run.log_path) line += ' log: ' + run.log_path;\n L.push(line);\n if (run.notes) L.push(' notes: ' + (run.notes || '').slice(0, 300));\n });\n L.push('');\n L.push(' Next steps:');\n L.push(' 1. Check the log at the path shown above');\n L.push(' 2. For Synology failures: verify LAN reachability (ssh synology) — disks need ~30s to spin up');\n L.push(' 3. Re-run manually: bash ~/.local/bin/backup.sh');\n L.push(' 4. One-off skip (power outage, travel) is expected — yellow is a heads-up, not an alarm');\n L.push('');\n }\n\n if (r.status === 'red') {\n L.push(' No runs reported all week — silent failure.');\n if (r.lastSuccess) {\n L.push(' Last known good run: ' + fmt(r.lastSuccess.timestamp));\n if (r.lastSuccess.log_path) L.push(' Last log: ' + r.lastSuccess.log_path);\n } else {\n L.push(' No history found in the datatable.');\n }\n L.push('');\n L.push(' Next steps:');\n L.push(' 1. Check systemd timer: systemctl --user status restic-backup.timer');\n L.push(' 2. Verify backup.sh calls notify_backup.rb at the end');\n L.push(' 3. Check n8n Workflow 1 execution log for webhook errors');\n L.push(' 4. Run manually: bash ~/.local/bin/backup.sh');\n L.push('');\n }\n });\n\n if (healthy.length > 0) {\n L.push('Healthy sources:');\n healthy.forEach(r => L.push('✓ ' + r.machine + ' / ' + r.destination));\n }\n}\n\nreturn [{ json: { subject, body: L.join('\\n') } }];\n"
|
||||
},
|
||||
"id": "99ace456-148e-493b-af7d-174ea62c1448",
|
||||
"id": "77d00688-d6db-41a8-b11e-598fc8c9c3b1",
|
||||
"name": "Build Email",
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
|
|
@ -122,7 +112,7 @@
|
|||
"jsonBody": "={{ { from: \"backups@swansoncloud.com\", to: \"jaredmswanson@gmail.com\", subject: $json.subject, text_body: $json.body } }}",
|
||||
"options": {}
|
||||
},
|
||||
"id": "cab8c0f5-8ebb-468f-ac83-8032c1020913",
|
||||
"id": "3d618450-473b-4263-94a5-7f050d5b3c24",
|
||||
"name": "Send via MailPace",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.2,
|
||||
|
|
|
|||
Loading…
Reference in New Issue