{
  "id": "5TGOTlmPdfRCmmfe",
  "name": "n8n-autoupdate",
  "tags": [],
  "nodes": [
    {
      "id": "f1b6e1f4-1de3-4334-8a6a-72917d5612e3",
      "name": "Portainer Webhook",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1184,
        80
      ],
      "parameters": {
        "url": "https://portainer.tld.com/api/stacks/webhooks/606e8503-8824-43b1-a67c-cf95abbee1a8",
        "method": "POST",
        "options": {
          "response": {
            "response": {}
          },
          "allowUnauthorizedCerts": false
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "8cde31ed-6b9c-4451-8ce7-95b846d7e356",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -80,
        80
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 16,
              "triggerAtMinute": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8756bed1-42d0-4f5f-904c-2d5294002f74",
      "name": "Get the latest n8n version",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        144,
        80
      ],
      "parameters": {
        "url": "https://registry.npmjs.org/n8n/latest",
        "options": {
          "fullResponse": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "938334e9-c0b1-476e-a816-4269946d7a41",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        864,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a2d169a3-7aa2-46f5-bdb2-f0d53a011b5c",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $('Get the latest n8n version').item.json.version }}",
              "rightValue": "={{ $json.versionCli }}"
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": false
    },
    {
      "id": "4802535d-c004-442a-bbd1-610d540e924d",
      "name": "local n8n version",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        80
      ],
      "parameters": {
        "jsCode": "const text = $input.first().json.data;\nconst match = text.match(/n8n_version_info\\{[^}]*version=\"(v[\\d.]+)\"/);\n\nif (match) {\n  const version = match[1].replace(/^v/, ''); // v entfernen\n  return [{ json: { versionCli: version } }];\n} else {\n  throw new Error(\"Version info not found in metrics output\");\n}\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cee62d71-075b-4bf0-a800-b4fa2fee9ebe",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        -16
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "## Cron\nEvery 16 Hours at minute 8"
      },
      "typeVersion": 1
    },
    {
      "id": "94d2e06e-daf3-4260-929c-584144fbe486",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -16
      ],
      "parameters": {
        "width": 208,
        "height": 272,
        "content": "## Latest Version\nFetch from npmjs"
      },
      "typeVersion": 1
    },
    {
      "id": "e1a8d5f8-d672-4475-9ea0-e2eda0028702",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        -16
      ],
      "parameters": {
        "width": 224,
        "height": 272,
        "content": "## Get Metrics\nFetch from local install"
      },
      "typeVersion": 1
    },
    {
      "id": "47c26e66-ba89-4903-a948-22b1162bf1e5",
      "name": "Get local n8n metrics",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        368,
        80
      ],
      "parameters": {
        "url": "https://127.0.0.1/metrics",
        "options": {
          "allowUnauthorizedCerts": true
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4bf82532-cc70-4071-83f6-3550392b1590",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        -16
      ],
      "parameters": {
        "width": 224,
        "height": 272,
        "content": "## Installed Version\nExtract from metrics"
      },
      "typeVersion": 1
    },
    {
      "id": "b11bd405-761f-4328-af3e-0a79c985f654",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -16
      ],
      "parameters": {
        "width": 256,
        "height": 272,
        "content": "## If Update available\nProceed with the workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "559a1933-1bc6-4fc4-bcb2-2ef76364dc0e",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        -16
      ],
      "parameters": {
        "width": 256,
        "height": 272,
        "content": "## Start Update\nUsing webhook, but SSH might be useful aswell"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1f5d34fd-158e-44a5-8438-f235f4265d00",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Portainer Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get the latest n8n version",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "local n8n version": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get local n8n metrics": {
      "main": [
        [
          {
            "node": "local n8n version",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get the latest n8n version": {
      "main": [
        [
          {
            "node": "Get local n8n metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}