diff --git a/proxmox/changelog.d/21399.fixed b/proxmox/changelog.d/21399.fixed new file mode 100644 index 0000000000000..b554c37859311 --- /dev/null +++ b/proxmox/changelog.d/21399.fixed @@ -0,0 +1 @@ +Handle AttributeError when Qemu Agent is not available diff --git a/proxmox/datadog_checks/proxmox/check.py b/proxmox/datadog_checks/proxmox/check.py index 74caefcec7c5c..47b6af1456a10 100644 --- a/proxmox/datadog_checks/proxmox/check.py +++ b/proxmox/datadog_checks/proxmox/check.py @@ -145,7 +145,8 @@ 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, @@ -153,8 +154,7 @@ def _get_vm_hostname(self, vm_id, vm_name, 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): diff --git a/proxmox/tests/test_unit.py b/proxmox/tests/test_unit.py index e009e4f1229b2..f13222d3fa35e 100644 --- a/proxmox/tests/test_unit.py +++ b/proxmox/tests/test_unit.py @@ -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'], )