diff --git a/collector/client.go b/collector/client.go index 5690fd0..9c73f8d 100644 --- a/collector/client.go +++ b/collector/client.go @@ -6,6 +6,7 @@ import ( "io" "net" "net/http" + "strings" "sync" "time" ) @@ -40,6 +41,11 @@ func NewClient(hosts []string, token string, tlsInsecure bool, maxConcurrent int TLSHandshakeTimeout: 5 * time.Second, } + // Normalize token: ensure it has the PVEAPIToken= prefix + if !strings.HasPrefix(token, "PVEAPIToken=") { + token = "PVEAPIToken=" + token + } + return &Client{ hosts: hosts, token: token, @@ -78,7 +84,7 @@ func (c *Client) Get(path string) ([]byte, error) { lastErr = fmt.Errorf("creating request for %s: %w", url, err) continue } - req.Header.Set("Authorization", "PVEAPIToken="+c.token) + req.Header.Set("Authorization", c.token) resp, err := c.httpClient.Do(req) if err != nil {