diff --git a/grafana_wtf/core.py b/grafana_wtf/core.py index 74afe07..af7aae9 100644 --- a/grafana_wtf/core.py +++ b/grafana_wtf/core.py @@ -321,15 +321,20 @@ def info(self): return response @property - def health(self): + def build_info(self): response = None error = None - error_template = f"The request to {self.grafana_url.rstrip('/')}/api/health failed" + error_template = f"The request to {self.grafana_url.rstrip('/')}/api/frontend/settings failed" try: - response = self.grafana.client.GET("/health") + response = self.grafana.client.GET("/frontend/settings") if not isinstance(response, dict): error = f"{error_template}: Invalid response, content was: {response}" + response = Munch(response) + response = response.get("buildInfo") + if not response: + error = f"{error_template}: No buildInfo found in the settings response" + except Exception as ex: error = f"{error_template}: {ex}" @@ -337,12 +342,11 @@ def health(self): log.critical(error) raise ConnectionError(error) - if response: - return Munch(response) + return response @property def version(self): - return self.health.get("version") + return self.build_info.get("version") def dashboard_details(self): for dashboard in self.data.dashboards: diff --git a/tests/test_core.py b/tests/test_core.py index ea097fb..53bb15b 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -40,23 +40,22 @@ def test_collect_datasource_items_variable_all(): def test_connect_success(): wtf = GrafanaWtf("https://play.grafana.org") - health = wtf.health - assert "commit" in health - assert "version" in health - assert health.database == "ok" + build_info = wtf.build_info + assert "commit" in build_info + assert "version" in build_info def test_connect_failure(): wtf = GrafanaWtf("http://localhost:1234") with pytest.raises(ConnectionError) as ex: - _ = wtf.health - assert ex.match("The request to http://localhost:1234/api/health failed") + _ = wtf.build_info + assert ex.match("The request to http://localhost:1234/api/frontend/settings failed") @patch("grafana_client.client.GrafanaClient.__getattr__") def test_connect_version(mock_get): mock_get.return_value = Mock() - mock_get.return_value.return_value = {"commit": "14e988bd22", "database": "ok", "version": "9.0.1"} + mock_get.return_value.return_value = {"buildInfo": {"version": "9.0.1", "commit": "14e988bd22"}} wtf = GrafanaWtf("http://localhost:1234") assert wtf.version == "9.0.1" @@ -64,5 +63,5 @@ def test_connect_version(mock_get): def test_connect_non_json_response(): wtf = GrafanaWtf("https://example.org/") with pytest.raises(ConnectionError) as ex: - _ = wtf.health - assert ex.match("The request to https://example.org/api/health failed") + _ = wtf.build_info + assert ex.match("The request to https://example.org/api/frontend/settings failed")