Utilities¶
grafanarmadillo.types¶
Type hints for Grafana interaction.
- class grafanarmadillo.types.AlertSearchResult(*args, **kwargs)[source]¶
Relevant keys returned for an alert.
- class grafanarmadillo.types.AnySearchResult(*args, **kwargs)[source]¶
Metadata for both Grafana dashboards and alerts.
- class grafanarmadillo.types.Dashboard(*args, **kwargs)[source]¶
Relevant keys returned by GET of a Grafana dashboard.
grafanarmadillo.paths¶
Tools for manipulating path-like objects into references to Grafana objects or file-safe paths.
- class grafanarmadillo.paths.PathCodec[source]¶
Safely encode paths which may contain invalid characters, such as forward slashes.
- static encode_grafana(path: GrafanaPath) Path[source]¶
Encode a GrafanaPath.
- static parse_grafana(parts: Sequence[str]) GrafanaPath[source]¶
Assemble segments into an orderly GrafanaPath.
- static try_parse(o: GrafanaPath | str | Path | List[str]) GrafanaPath[source]¶
Try to decode a pathlike object.
grafanarmadillo.util¶
Helpers and generic functions.
- class grafanarmadillo.util.CacheMode(value)[source]¶
Caching mode for interacting with Grafana.
None: no caching Session: lifetime of the Finder object Global: all Finders share the same cache
You can disable caching globally by setting grafanarmadillo.util.global_cache = grafanarmadillo.util.NoneCache()
- grafanarmadillo.util.erase_alert_rule_identity(alertlike) Dict[source]¶
Delete the fields of an alert_rule which are used for determining identity.
- grafanarmadillo.util.erase_dashboard_identity(dashboardlike: DashboardSearchResult | DashboardContent) Dict[source]¶
Delete the fields of a dashboard which are used for determining identity.
- grafanarmadillo.util.exactly_one(items: List[A], message: str | None = None) A[source]¶
Throws if list does not contain exactly 1 item.
>>> exactly_one([1]) 1
>>> exactly_one([1,2]) Traceback (most recent call last): ValueError: expected exactly 1 item, found=2 message=None
>>> exactly_one([]) Traceback (most recent call last): ValueError: expected exactly 1 item, found=0 message=None
- grafanarmadillo.util.flat_map(f, xs)[source]¶
Flatmap: Map on a list and then merge the results.
>>> and_reversed = lambda s: [s,s[::-1]]
>>> flat_map(and_reversed, []) []
>>> flat_map(and_reversed, ['hi']) ['hi', 'ih']
>>> flat_map(and_reversed, ['hi', 'hello']) ['hi', 'ih', 'hello', 'olleh']
- grafanarmadillo.util.map_json_strings(f: Callable[[str], str], obj: JSON) JSON[source]¶
Transform all strings in an object made of JSON primitives.
>>> f = lambda s: s.upper() >>> map_json_strings(f, 's') 'S' >>> map_json_strings(f, 1) 1 >>> map_json_strings(f, ['s']) ['S'] >>> map_json_strings(f, ['s', 1]) ['S', 1] >>> map_json_strings(f, {'a': 's'}) {'a': 'S'} >>> map_json_strings(f, {'a': ['s', 1]}) {'a': ['S', 1]}
- grafanarmadillo.util.project_dashboard_identity(dashboardlike: DashboardSearchResult | DashboardContent) Dict[source]¶
Project only the fields of a dashboard which are used for determining identity.
- grafanarmadillo.util.project_dict(d: Dict, keys: set, inverse: bool = False) Dict[source]¶
Select the given fields from a dictionary.
>>> project_dict({'a': 1, 'b': 2}, {'a'}) {'a': 1}
>>> project_dict({'a': 1, 'b': 2}, {'a'}, inverse=True) {'b': 2}
- grafanarmadillo.util.resolve_filepath_to_object(base_path: Path, path: Path) GrafanaPath[source]¶
Extract the “/folder/object” format from the file on disk that contains the template.
- grafanarmadillo.util.resolve_object_to_filepath(base_path: Path, name: GrafanaPath | str | Path | List[str])[source]¶
Transform the “/folder/object” format to the path on disk that contains the template.