diff --git a/docs/configs/proxmox.md b/docs/configs/proxmox.md index 6a210b272..79625e471 100644 --- a/docs/configs/proxmox.md +++ b/docs/configs/proxmox.md @@ -4,11 +4,13 @@ description: Proxmox Configuration --- The Proxmox connection is configured in the `proxmox.yaml` file. See [Create token](#create-token) section below for details on how to generate the required API token. +You can configure multiple nodes - be sure to use the exact `proxmoxNode` identifier! ```yaml -url: https://proxmox.host.or.ip:8006 -token: username@pam!Token ID -secret: secret +pve: + url: https://proxmox.host.or.ip:8006 + token: username@pam!Token ID + secret: secret ``` ## Services @@ -17,7 +19,7 @@ Once the Proxmox connection is configured, individual services can be configured ### Configuration Options -- `proxmoxNode`: The name of the Proxmox node where your VM/LXC is running +- `proxmoxNode`: The name of the Proxmox node where your VM/LXC is running, must match with a node configured in the `proxmox.yaml` - `proxmoxVMID`: The ID of the Proxmox VM or LXC container - `proxmoxType`: (Optional) The type of Proxmox virtual machine. Defaults to `qemu` for VMs, but can be set to `lxc` for LXC containers diff --git a/src/pages/api/proxmox/stats/[...service].js b/src/pages/api/proxmox/stats/[...service].js index 96cdb5019..a053b5856 100644 --- a/src/pages/api/proxmox/stats/[...service].js +++ b/src/pages/api/proxmox/stats/[...service].js @@ -24,9 +24,28 @@ export default async function handler(req, res) { }); } - const baseUrl = `${proxmoxConfig.url}/api2/json`; + // Prefer per-node config (new format), fall back to legacy flat creds. + const nodeConfig = + (node && proxmoxConfig && proxmoxConfig[node]) || + (proxmoxConfig && proxmoxConfig.url && proxmoxConfig.token && proxmoxConfig.secret + ? { + url: proxmoxConfig.url, + token: proxmoxConfig.token, + secret: proxmoxConfig.secret, + } + : null); + + if (!nodeConfig) { + return res.status(400).json({ + error: + "Proxmox config not found for the specified node and no legacy credentials detected. " + + "Add a node block in proxmox.yaml (e.g., 'pve: { url, token, secret }') or restore legacy top-level url/token/secret.", + }); + } + + const baseUrl = `${nodeConfig.url}/api2/json`; const headers = { - Authorization: `PVEAPIToken=${proxmoxConfig.token}=${proxmoxConfig.secret}`, + Authorization: `PVEAPIToken=${nodeConfig.token}=${nodeConfig.secret}`, }; const statusUrl = `${baseUrl}/nodes/${node}/${vmType}/${vmid}/status/current`; diff --git a/src/skeleton/proxmox.yaml b/src/skeleton/proxmox.yaml index 9fd1836ac..90aacd756 100644 --- a/src/skeleton/proxmox.yaml +++ b/src/skeleton/proxmox.yaml @@ -1,4 +1,5 @@ --- -# url: https://proxmox.host.or.ip:8006 -# token: username@pam!Token ID -# secret: secret +# pve: +# url: https://proxmox.host.or.ip:8006 +# token: username@pam!Token ID +# secret: secret