{
  "name": "Proxmox VE Cluster Management",
  "nodes": [
    {
      "parameters": {
        "content": "## Developed by Pratap bhandari ",
        "height": 515.4734551650874,
        "width": 475.27306699862953,
        "color": 4
      },
      "id": "sticky-note-credit",
      "name": "Developer Credit",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -600,
        100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute",
              "minute": 5
            }
          ]
        },
        "triggerOn": "schedule"
      },
      "id": "schedule-trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "content": "={\n  \"operation\": \"get_node_status\",\n  \"servers\": [\n    {\n      \"name\": \"psb1\",\n      \"host\": \"10.11.12.101\",\n      \"port\": 8006\n    },\n    {\n      \"name\": \"psb2\", \n      \"host\": \"10.11.12.102\",\n      \"port\": 8006\n    },\n    {\n      \"name\": \"psb3\",\n      \"host\": \"10.11.12.103\", \n      \"port\": 8006\n    }\n  ],\n  \"endpoints\": {\n    \"node_status\": \"/nodes\",\n    \"vm_list\": \"/nodes/{node}/qemu\",\n    \"container_list\": \"/nodes/{node}/lxc\",\n    \"cluster_status\": \"/cluster/status\",\n    \"version\": \"/version\"\n  }\n}",
        "options": {}
      },
      "id": "config-node",
      "name": "Configuration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "auth_token",
              "name": "auth_token",
              "type": "string",
              "value": ""
            },
            {
              "id": "csrf_token",
              "name": "csrf_token",
              "type": "string",
              "value": ""
            }
          ]
        },
        "options": {}
      },
      "id": "auth-setup",
      "name": "Authentication Setup",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "url": "=https://{{ $json.servers[0].host }}:{{ $json.servers[0].port }}/api2/json/access/ticket",
        "authentication": "none",
        "requestMethod": "POST",
        "sendBody": true,
        "specifyBodyType": true,
        "bodyContentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "username",
              "value": "root@pam"
            },
            {
              "name": "password",
              "value": "{{ $vars.PROXMOX_PASSWORD }}"
            }
          ]
        },
        "responseFormat": "json",
        "options": {
          "redirect": {
            "redirect": {}
          },
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "proxmox-auth",
      "name": "Proxmox Authentication",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "auth_token",
              "name": "auth_token",
              "type": "string",
              "value": "={{ $json.data.ticket }}"
            },
            {
              "id": "csrf_token",
              "name": "csrf_token",
              "type": "string",
              "value": "={{ $json.data.CSRFPreventionToken }}"
            },
            {
              "id": "operation",
              "name": "operation",
              "type": "string",
              "value": "={{ $('Configuration').item.json.operation }}"
            },
            {
              "id": "servers",
              "name": "servers",
              "type": "object",
              "value": "={{ $('Configuration').item.json.servers }}"
            },
            {
              "id": "endpoints",
              "name": "endpoints",
              "type": "object",
              "value": "={{ $('Configuration').item.json.endpoints }}"
            }
          ]
        },
        "options": {}
      },
      "id": "extract-tokens",
      "name": "Extract Auth Tokens",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "servers",
        "options": {}
      },
      "id": "split-servers",
      "name": "Split Servers",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "current_server",
              "name": "current_server",
              "type": "object",
              "value": "={{ $json.servers }}"
            },
            {
              "id": "api_endpoint",
              "name": "api_endpoint",
              "type": "string",
              "value": "={{ $json.endpoints.node_status }}"
            },
            {
              "id": "full_url",
              "name": "full_url",
              "type": "string",
              "value": "=https://{{ $json.servers.host }}:{{ $json.servers.port }}/api2/json{{ $json.endpoints.node_status }}"
            }
          ]
        },
        "options": {}
      },
      "id": "prepare-request",
      "name": "Prepare Request Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1300,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.full_url }}",
        "authentication": "none",
        "requestMethod": "GET",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Cookie",
              "value": "=PVEAuthCookie={{ $('Extract Auth Tokens').item.json.auth_token }}"
            },
            {
              "name": "CSRFPreventionToken",
              "value": "={{ $('Extract Auth Tokens').item.json.csrf_token }}"
            }
          ]
        },
        "responseFormat": "json",
        "options": {
          "redirect": {
            "redirect": {}
          },
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "proxmox-api-call",
      "name": "Proxmox API Call",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1500,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "server_name",
              "name": "server_name",
              "type": "string",
              "value": "={{ $('Prepare Request Data').item.json.current_server.name }}"
            },
            {
              "id": "server_host",
              "name": "server_host",
              "type": "string",
              "value": "={{ $('Prepare Request Data').item.json.current_server.host }}"
            },
            {
              "id": "response_data",
              "name": "response_data",
              "type": "object",
              "value": "={{ $json }}"
            },
            {
              "id": "timestamp",
              "name": "timestamp",
              "type": "string",
              "value": "={{ $now }}"
            },
            {
              "id": "status",
              "name": "status",
              "type": "string",
              "value": "={{ $json.data ? 'success' : 'error' }}"
            }
          ]
        },
        "options": {}
      },
      "id": "format-response",
      "name": "Format Response",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1700,
        300
      ]
    },
    {
      "parameters": {
        "operation": "aggregateItems",
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "merge-responses",
      "name": "Merge All Responses",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1900,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "success_condition",
              "leftValue": "={{ $json.status }}",
              "rightValue": "success",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "success-filter",
      "name": "Filter Successful Responses",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        2100,
        200
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "error_condition",
              "leftValue": "={{ $json.status }}",
              "rightValue": "error",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "error-filter",
      "name": "Filter Error Responses",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        2100,
        400
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "id": "final-merge",
      "name": "Final Results Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        2300,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "summary",
              "name": "summary",
              "type": "object",
              "value": "={\n  \"workflow_execution\": {\n    \"timestamp\": \"{{ $now }}\",\n    \"total_servers\": {{ $json.length }},\n    \"successful_responses\": {{ $('Filter Successful Responses').all().length }},\n    \"error_responses\": {{ $('Filter Error Responses').all().length }}\n  },\n  \"server_results\": {{ $json }}\n}"
            }
          ]
        },
        "options": {}
      },
      "id": "final-summary",
      "name": "Create Final Summary",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2500,
        300
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configuration": {
      "main": [
        [
          {
            "node": "Authentication Setup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Authentication Setup": {
      "main": [
        [
          {
            "node": "Proxmox Authentication",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Proxmox Authentication": {
      "main": [
        [
          {
            "node": "Extract Auth Tokens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Auth Tokens": {
      "main": [
        [
          {
            "node": "Split Servers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Servers": {
      "main": [
        [
          {
            "node": "Prepare Request Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Request Data": {
      "main": [
        [
          {
            "node": "Proxmox API Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Proxmox API Call": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response": {
      "main": [
        [
          {
            "node": "Merge All Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Responses": {
      "main": [
        [
          {
            "node": "Filter Successful Responses",
            "type": "main",
            "index": 0
          },
          {
            "node": "Filter Error Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Successful Responses": {
      "main": [
        [
          {
            "node": "Final Results Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Error Responses": {
      "main": [
        [
          {
            "node": "Final Results Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Final Results Merge": {
      "main": [
        [
          {
            "node": "Create Final Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "proxmox",
    "infrastructure",
    "monitoring"
  ],
  "triggerCount": 0,
  "updatedAt": "2024-12-01T00:00:00.000Z",
  "versionId": "1"
}