fix(inputs.proxmox): Allow search domain to be empty (#16511)
This commit is contained in:
parent
32ad4618a6
commit
5e51e4e051
|
|
@ -25,9 +25,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
api_token = "USER@REALM!TOKENID=UUID"
|
api_token = "USER@REALM!TOKENID=UUID"
|
||||||
|
|
||||||
## Node name, defaults to OS hostname
|
## Node name, defaults to OS hostname
|
||||||
## Unless Telegraf is on the same host as Proxmox, setting this is required
|
## Unless Telegraf is on the same host as Proxmox, setting this is required.
|
||||||
## for Telegraf to successfully connect to Proxmox. If not on the same host,
|
|
||||||
## leaving this empty will often lead to a "search domain is not set" error.
|
|
||||||
# node_name = ""
|
# node_name = ""
|
||||||
|
|
||||||
## Additional tags of the VM stats data to add as a tag
|
## Additional tags of the VM stats data to add as a tag
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ package proxmox
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -78,7 +77,7 @@ func (px *Proxmox) Init() error {
|
||||||
|
|
||||||
func (px *Proxmox) Gather(acc telegraf.Accumulator) error {
|
func (px *Proxmox) Gather(acc telegraf.Accumulator) error {
|
||||||
if err := px.getNodeSearchDomain(); err != nil {
|
if err := px.getNodeSearchDomain(); err != nil {
|
||||||
return err
|
return fmt.Errorf("getting search domain failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
px.gatherVMData(acc, lxc)
|
px.gatherVMData(acc, lxc)
|
||||||
|
|
@ -91,17 +90,12 @@ func (px *Proxmox) getNodeSearchDomain() error {
|
||||||
apiURL := "/nodes/" + px.NodeName + "/dns"
|
apiURL := "/nodes/" + px.NodeName + "/dns"
|
||||||
jsonData, err := px.requestFunction(apiURL, http.MethodGet, nil)
|
jsonData, err := px.requestFunction(apiURL, http.MethodGet, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("requesting data failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodeDNS nodeDNS
|
var nodeDNS nodeDNS
|
||||||
err = json.Unmarshal(jsonData, &nodeDNS)
|
if err := json.Unmarshal(jsonData, &nodeDNS); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("decoding message failed: %w", err)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if nodeDNS.Data.Searchdomain == "" {
|
|
||||||
return errors.New("search domain is not set")
|
|
||||||
}
|
}
|
||||||
px.nodeSearchDomain = nodeDNS.Data.Searchdomain
|
px.nodeSearchDomain = nodeDNS.Data.Searchdomain
|
||||||
|
|
||||||
|
|
@ -154,20 +148,27 @@ func (px *Proxmox) gatherVMData(acc telegraf.Accumulator, rt resourceType) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hostname := vmConfig.Data.Hostname
|
vmFQDN := vmConfig.Data.Hostname
|
||||||
if hostname == "" {
|
if vmFQDN == "" {
|
||||||
hostname = vmStat.Name
|
vmFQDN = vmStat.Name
|
||||||
}
|
}
|
||||||
domain := vmConfig.Data.Searchdomain
|
domain := vmConfig.Data.Searchdomain
|
||||||
if domain == "" {
|
if domain == "" {
|
||||||
domain = px.nodeSearchDomain
|
domain = px.nodeSearchDomain
|
||||||
}
|
}
|
||||||
fqdn := hostname + "." + domain
|
if domain != "" {
|
||||||
|
vmFQDN += "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeFQDN := px.NodeName
|
||||||
|
if px.nodeSearchDomain != "" {
|
||||||
|
nodeFQDN += "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"node_fqdn": px.NodeName + "." + px.nodeSearchDomain,
|
"node_fqdn": nodeFQDN,
|
||||||
"vm_name": vmStat.Name,
|
"vm_name": vmStat.Name,
|
||||||
"vm_fqdn": fqdn,
|
"vm_fqdn": vmFQDN,
|
||||||
"vm_type": string(rt),
|
"vm_type": string(rt),
|
||||||
}
|
}
|
||||||
if slices.Contains(px.AdditionalVmstatsTags, "vmid") {
|
if slices.Contains(px.AdditionalVmstatsTags, "vmid") {
|
||||||
|
|
@ -204,7 +205,6 @@ func (px *Proxmox) gatherVMData(acc telegraf.Accumulator, rt resourceType) {
|
||||||
|
|
||||||
func (px *Proxmox) getCurrentVMStatus(rt resourceType, id json.Number) (vmStat, error) {
|
func (px *Proxmox) getCurrentVMStatus(rt resourceType, id json.Number) (vmStat, error) {
|
||||||
apiURL := "/nodes/" + px.NodeName + "/" + string(rt) + "/" + string(id) + "/status/current"
|
apiURL := "/nodes/" + px.NodeName + "/" + string(rt) + "/" + string(id) + "/status/current"
|
||||||
|
|
||||||
jsonData, err := px.requestFunction(apiURL, http.MethodGet, nil)
|
jsonData, err := px.requestFunction(apiURL, http.MethodGet, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vmStat{}, err
|
return vmStat{}, err
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@
|
||||||
api_token = "USER@REALM!TOKENID=UUID"
|
api_token = "USER@REALM!TOKENID=UUID"
|
||||||
|
|
||||||
## Node name, defaults to OS hostname
|
## Node name, defaults to OS hostname
|
||||||
## Unless Telegraf is on the same host as Proxmox, setting this is required
|
## Unless Telegraf is on the same host as Proxmox, setting this is required.
|
||||||
## for Telegraf to successfully connect to Proxmox. If not on the same host,
|
|
||||||
## leaving this empty will often lead to a "search domain is not set" error.
|
|
||||||
# node_name = ""
|
# node_name = ""
|
||||||
|
|
||||||
## Additional tags of the VM stats data to add as a tag
|
## Additional tags of the VM stats data to add as a tag
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue