Wire Node-RED update events to structured update log file

This commit is contained in:
beatz174-bit
2026-04-13 06:12:59 +10:00
parent 9f9cfaf4be
commit 232fdfbb36
4 changed files with 367 additions and 7 deletions
+170 -7
View File
@@ -936,7 +936,7 @@
"y": 200,
"wires": [
[
"0135d283b9edfb01"
"c1aa11bb22cc33dd"
]
]
},
@@ -972,7 +972,7 @@
"y": 300,
"wires": [
[
"4eafade32c867e40"
"d2aa11bb22cc33dd"
]
]
},
@@ -1008,7 +1008,7 @@
"y": 380,
"wires": [
[
"7d8200040f9b1e83"
"e3aa11bb22cc33dd"
]
]
},
@@ -1044,7 +1044,7 @@
"y": 460,
"wires": [
[
"c3d07241f4a570af"
"f4aa11bb22cc33dd"
]
]
},
@@ -1078,7 +1078,7 @@
"y": 520,
"wires": [
[
"d1346f7151103832"
"a5aa11bb22cc33dd"
]
]
},
@@ -1095,7 +1095,7 @@
"y": 580,
"wires": [
[
"1a9798d5c081240a"
"b6aa11bb22cc33dd"
]
]
},
@@ -1118,5 +1118,168 @@
"8630c7dfcdbcce50"
]
]
},
{
"id": "a1f8e9b2c3d4e5f6",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Build update log event",
"func": "const nowIso = new Date().toISOString();\nconst startedAt = msg.update_started_at || Date.now();\nconst durationMs = Math.max(0, Date.now() - startedAt);\n\nconst payload = (msg.payload && typeof msg.payload === \"object\") ? msg.payload : {};\nconst labels = payload.labels || {};\n\nconst status = (msg.update_status || payload.status || \"unknown\").toString().toLowerCase();\n\nmsg.payload = JSON.stringify({\n ts: nowIso,\n flow: \"docker-updates\",\n event: msg.update_event || \"attempt\",\n container: msg.container || labels.container || \"unknown\",\n project: labels.com_docker_compose_project || msg.project || \"unknown\",\n host: msg.host || \"unknown\",\n status,\n success: status === \"success\" ? 1 : 0,\n failed: [\"failed\", \"locked\"].includes(status) ? 1 : 0,\n duration_ms: durationMs,\n code: Number.isFinite(Number(payload.code)) ? Number(payload.code) : 0,\n error: (msg.update_error || payload.error || \"\").toString().slice(0, 300)\n});\n\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 660,
"wires": [
[
"b1c2d3e4f5a69788"
]
]
},
{
"id": "b1c2d3e4f5a69788",
"type": "file",
"z": "c5240b64a962ea54",
"name": "Write update event log",
"filename": "/data/update-events.ndjson",
"filenameType": "str",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"encoding": "none",
"x": 930,
"y": 660,
"wires": [
[]
]
},
{
"id": "c1aa11bb22cc33dd",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Mark Docker Pull Failed",
"func": "msg.update_status = \"failed\";\nmsg.update_event = \"completed\";\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 200,
"wires": [
[
"0135d283b9edfb01",
"a1f8e9b2c3d4e5f6"
]
]
},
{
"id": "d2aa11bb22cc33dd",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Mark Docker Test Failed",
"func": "msg.update_status = \"failed\";\nmsg.update_event = \"completed\";\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 300,
"wires": [
[
"4eafade32c867e40",
"a1f8e9b2c3d4e5f6"
]
]
},
{
"id": "e3aa11bb22cc33dd",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Mark Docker Update Success",
"func": "msg.update_status = \"success\";\nmsg.update_event = \"completed\";\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 380,
"wires": [
[
"7d8200040f9b1e83",
"a1f8e9b2c3d4e5f6"
]
]
},
{
"id": "f4aa11bb22cc33dd",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Mark Docker Unknown Project",
"func": "msg.update_status = \"failed\";\nmsg.update_event = \"completed\";\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 460,
"wires": [
[
"c3d07241f4a570af",
"a1f8e9b2c3d4e5f6"
]
]
},
{
"id": "a5aa11bb22cc33dd",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Mark Docker Update Attempt",
"func": "msg.update_status = \"attempt\";\nmsg.update_event = \"attempt\";\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 520,
"wires": [
[
"d1346f7151103832",
"a1f8e9b2c3d4e5f6"
]
]
},
{
"id": "b6aa11bb22cc33dd",
"type": "function",
"z": "c5240b64a962ea54",
"name": "Mark Docker Update Locked",
"func": "msg.update_status = \"locked\";\nmsg.update_event = \"completed\";\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 580,
"wires": [
[
"1a9798d5c081240a",
"a1f8e9b2c3d4e5f6"
]
]
}
]
]