Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions proxmox/changelog.d/21399.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle AttributeError when Qemu Agent is not available
6 changes: 3 additions & 3 deletions proxmox/datadog_checks/proxmox/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ 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()
except (HTTPError, InvalidURL, ConnectionError, Timeout, JSONDecodeError) as e:
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_json = {}
hostname = hostname_json.get("data", {}).get("result", {}).get("host-name", vm_name)
hostname = vm_name
return hostname

def _create_dd_event_for_task(self, task, node_name):
Expand Down
10 changes: 10 additions & 0 deletions proxmox/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def test_resource_up_metrics(dd_run_check, aggregator, instance):
},
id='404',
),
pytest.param(
{
'http_error': {
'/api2/json/nodes/ip-122-82-3-112/qemu/100/agent/get-host-name': MockResponse(
status_code=200, json_data={"data": None, "message": "No QEMU guest agent configured\n"}
)
}
},
id='qemu_agent_not_configured',
),
],
indirect=['mock_http_get'],
)
Expand Down
Loading