@@ -3,19 +3,22 @@ package proxmox
33import (
44 "encoding/json"
55 "errors"
6- "github.com/influxdata/telegraf"
7- "github.com/influxdata/telegraf/plugins/inputs"
86 "io/ioutil"
97 "net/http"
108 "net/url"
119 "os"
1210 "strings"
11+
12+ "github.com/influxdata/telegraf"
13+ "github.com/influxdata/telegraf/plugins/inputs"
1314)
1415
1516var sampleConfig = `
1617 ## API connection configuration. The API token was introduced in Proxmox v6.2. Required permissions for user and token: PVEAuditor role on /.
1718 base_url = "https://localhost:8006/api2/json"
1819 api_token = "USER@REALM!TOKENID=UUID"
20+ ## Node name, defaults to OS hostname
21+ # node_name = ""
1922
2023 ## Optional TLS Config
2124 # tls_ca = "/etc/telegraf/ca.pem"
@@ -49,9 +52,10 @@ func (px *Proxmox) Gather(acc telegraf.Accumulator) error {
4952}
5053
5154func (px * Proxmox ) Init () error {
52-
55+ // Set hostname as default node name for backwards compatibility
5356 if px .NodeName == "" {
54- return errors .New ("node_name must be configured" )
57+ hostname , _ := os .Hostname ()
58+ px .NodeName = hostname
5559 }
5660
5761 tlsCfg , err := px .ClientConfig .TLSConfig ()
@@ -69,15 +73,11 @@ func (px *Proxmox) Init() error {
6973}
7074
7175func init () {
72- px := Proxmox {
73- requestFunction : performRequest ,
74- }
75-
76- // Set hostname as default node name for backwards compatibility
77- hostname , _ := os .Hostname ()
78- px .NodeName = hostname
79-
80- inputs .Add ("proxmox" , func () telegraf.Input { return & px })
76+ inputs .Add ("proxmox" , func () telegraf.Input {
77+ return & Proxmox {
78+ requestFunction : performRequest ,
79+ }
80+ })
8181}
8282
8383func getNodeSearchDomain (px * Proxmox ) error {
@@ -94,7 +94,7 @@ func getNodeSearchDomain(px *Proxmox) error {
9494 }
9595
9696 if nodeDns .Data .Searchdomain == "" {
97- return errors .New ("node_name not found " )
97+ return errors .New ("search domain is not set " )
9898 }
9999 px .nodeSearchDomain = nodeDns .Data .Searchdomain
100100
@@ -141,20 +141,28 @@ func gatherVmData(px *Proxmox, acc telegraf.Accumulator, rt ResourceType) {
141141 for _ , vmStat := range vmStats .Data {
142142 vmConfig , err := getVmConfig (px , vmStat .ID , rt )
143143 if err != nil {
144- px .Log .Error ("Error getting VM config: %v" , err )
144+ px .Log .Errorf ("Error getting VM config: %v" , err )
145145 return
146146 }
147+
148+ if vmConfig .Data .Template == 1 {
149+ px .Log .Debugf ("Ignoring template VM %s (%s)" , vmStat .ID , vmStat .Name )
150+ continue
151+ }
152+
147153 tags := getTags (px , vmStat .Name , vmConfig , rt )
148154 currentVMStatus , err := getCurrentVMStatus (px , rt , vmStat .ID )
149155 if err != nil {
150- px .Log .Error ("Error getting VM curent VM status: %v" , err )
156+ px .Log .Errorf ("Error getting VM curent VM status: %v" , err )
151157 return
152158 }
159+
153160 fields , err := getFields (currentVMStatus )
154161 if err != nil {
155- px .Log .Error ("Error getting VM measurements: %v" , err )
162+ px .Log .Errorf ("Error getting VM measurements: %v" , err )
156163 return
157164 }
165+
158166 acc .AddFields ("proxmox" , fields , tags )
159167 }
160168}
0 commit comments