Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(proxmox): move hostname extraction logic before exception handling
- Move hostname parsing logic inside try block for cleaner error handling
- Maintain fallback to vm_name when API call fails
- Improve code readability and exception flow

Co-authored-by: sarah-witt <[email protected]>
Signed-off-by: puretension <[email protected]>
Signed-off-by: sarah-witt <[email protected]>
  • Loading branch information
puretension and sarah-witt committed Oct 8, 2025
commit b9c0041ba8bf7814c011ea0c2f2375da0782f6e7
3 changes: 1 addition & 2 deletions proxmox/datadog_checks/proxmox/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def _get_vm_hostname(self, vm_id, vm_name, node):
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",
Expand All @@ -154,8 +155,6 @@ def _get_vm_hostname(self, vm_id, vm_name, node):
e,
)
hostname = vm_name
return hostname
hostname = hostname_json.get("data", {}).get("result", {}).get("host-name", vm_name)
return hostname

def _create_dd_event_for_task(self, task, node_name):
Expand Down
Loading