Utilities¶
grafanarmadillo.util¶
Helpers and generic functions.
- 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.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.