|
9 | 9 | from collections import OrderedDict
|
10 | 10 | from concurrent.futures.thread import ThreadPoolExecutor
|
11 | 11 | from urllib.parse import parse_qs, urljoin, urlparse
|
12 |
| -from tqdm.contrib.logging import tqdm_logging_redirect |
13 | 12 |
|
14 | 13 | import colored
|
15 | 14 | import requests
|
|
18 | 17 | from grafana_client.client import GrafanaClientError, GrafanaUnauthorizedError
|
19 | 18 | from munch import Munch, munchify
|
20 | 19 | from tqdm import tqdm
|
| 20 | +from tqdm.contrib.logging import tqdm_logging_redirect |
21 | 21 | from urllib3.exceptions import InsecureRequestWarning
|
22 | 22 |
|
23 | 23 | from grafana_wtf.model import (
|
@@ -492,20 +492,35 @@ def __init__(self, engine: GrafanaWtf):
|
492 | 492 | self.index()
|
493 | 493 |
|
494 | 494 | def index(self):
|
495 |
| - self.index_dashboards() |
496 | 495 | self.index_datasources()
|
| 496 | + self.index_dashboards() |
| 497 | + self.index_crossref() |
497 | 498 |
|
498 |
| - @staticmethod |
499 |
| - def collect_datasource_items(element): |
| 499 | + def collect_datasource_items(self, element): |
500 | 500 | element = element or []
|
501 | 501 | items = []
|
502 | 502 | for node in element:
|
| 503 | + ds = None |
| 504 | + |
| 505 | + # Directly defined datasources. |
503 | 506 | if "datasource" in node and node["datasource"]:
|
504 | 507 | ds = node.datasource
|
505 | 508 | if isinstance(ds, Munch):
|
506 | 509 | ds = dict(ds)
|
507 |
| - if ds not in items: |
508 |
| - items.append(ds) |
| 510 | + |
| 511 | + # Datasources defined as variables. |
| 512 | + if "type" in node and node["type"] == "datasource": |
| 513 | + ds_name = node.get("current", {}).get("value") |
| 514 | + datasource = self.datasource_by_name.get(ds_name, {}) |
| 515 | + ds = dict( |
| 516 | + type=datasource.get("type"), |
| 517 | + uid=datasource.get("uid"), |
| 518 | + name=datasource.get("name"), |
| 519 | + url=datasource.get("url"), |
| 520 | + ) |
| 521 | + |
| 522 | + if ds is not None and ds not in items: |
| 523 | + items.append(ds) |
509 | 524 | return items
|
510 | 525 |
|
511 | 526 | def index_dashboards(self):
|
@@ -548,6 +563,7 @@ def index_datasources(self):
|
548 | 563 | self.datasource_by_ident[datasource.uid] = datasource
|
549 | 564 | self.datasource_by_uid[datasource.uid] = datasource
|
550 | 565 |
|
| 566 | + def index_crossref(self): |
551 | 567 | for dashboard_uid, datasource_items in self.dashboard_datasource_index.items():
|
552 | 568 | datasource_item: DatasourceItem
|
553 | 569 | for datasource_item in datasource_items:
|
|
0 commit comments