-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
Hi,
the Proxmox integration uses the API to fetch the actual hostnames of the virtual guests (check.py).
The endpoint on the Proxmox API is: /api2/json/nodes/virtual/qemu/100/agent/get-host-name
An example result is:
{"data":{"result":{"host-name":"myhostname"}}}
The problem is that the /agent/get-host-name
endpoint relies on the Qemu Agent being installed. If this is not the case (or if it even can't be installed), the integration throws an error because it tries to get the Attributes which does not exist:
hostname = hostname_json.get("data", {}).get("result", {}).get("host-name", vm_name)
My suggestion is to either implement an additional Exception handling for this case, or as a quick fix just add the AttributeError to the existing implementation and use the vm_name as fallback:
def _get_vm_hostname(self, vm_id, vm_name, node):
try:
url = f"{self.config.proxmox_server}/nodes/{node}/qemu/{vm_id}/agent/get-host-name"
hostname_response = self.http.get(url)
hostname_json = hostname_response.json()
hostname = hostname_json.get("data", {}).get("result", {}).get("host-name", vm_name)
except (HTTPError, InvalidURL, ConnectionError, Timeout, JSONDecodeError, AttributeError) as e:
self.log.info(
"Failed to get hostname for vm %s on node %s; endpoint: %s; %s",
vm_id,
node,
self.config.proxmox_server,
e,
)
hostname = vm_name
return hostname
Metadata
Metadata
Assignees
Labels
No labels