|
37 | 37 | class GrafanaEngine:
|
38 | 38 | session = niquests.Session()
|
39 | 39 |
|
40 |
| - def __init__(self, grafana_url, grafana_token): |
| 40 | + def __init__(self, grafana_url, grafana_token=None): |
41 | 41 | self.grafana_url = grafana_url
|
42 | 42 | self.grafana_token = grafana_token
|
43 | 43 |
|
@@ -263,15 +263,10 @@ async def execute_parallel(self):
|
263 | 263 |
|
264 | 264 | class GrafanaWtf(GrafanaEngine):
|
265 | 265 | def info(self):
|
266 |
| - try: |
267 |
| - health = self.grafana.client.GET("/health") |
268 |
| - except Exception as ex: |
269 |
| - log.error(f"Request to /health endpoint failed: {ex}") |
270 |
| - health = {} |
271 | 266 |
|
272 | 267 | response = OrderedDict(
|
273 | 268 | grafana=OrderedDict(
|
274 |
| - version=health.get("version"), |
| 269 | + version=self.version, |
275 | 270 | url=self.grafana_url,
|
276 | 271 | ),
|
277 | 272 | statistics=OrderedDict(),
|
@@ -315,15 +310,29 @@ def info(self):
|
315 | 310 |
|
316 | 311 | return response
|
317 | 312 |
|
318 |
| - def version(self): |
| 313 | + @property |
| 314 | + def health(self): |
| 315 | + response = None |
| 316 | + error = None |
| 317 | + error_template = f"The request to {self.grafana_url.rstrip('/')}/api/health failed" |
319 | 318 | try:
|
320 |
| - health = self.grafana.client.GET("/health") |
| 319 | + response = self.grafana.client.GET("/health") |
| 320 | + if not isinstance(response, dict): |
| 321 | + error = f"{error_template}: Invalid response, content was: {response}" |
| 322 | + |
321 | 323 | except Exception as ex:
|
322 |
| - log.error(f"Request to /health endpoint failed: {ex}") |
323 |
| - health = {} |
| 324 | + error = f"{error_template}: {ex}" |
324 | 325 |
|
325 |
| - version = health.get("version") |
326 |
| - return version |
| 326 | + if error: |
| 327 | + log.critical(error) |
| 328 | + raise ConnectionError(error) |
| 329 | + |
| 330 | + if response: |
| 331 | + return Munch(response) |
| 332 | + |
| 333 | + @property |
| 334 | + def version(self): |
| 335 | + return self.health.get("version") |
327 | 336 |
|
328 | 337 | def dashboard_details(self):
|
329 | 338 | for dashboard in self.data.dashboards:
|
|
0 commit comments