Resource operations

grafanarmadillo.find

Find Grafana dashboards and folders.

class grafanarmadillo.find.Finder(api: GrafanaApi, api_v: UID = 11, cache_mode: CacheMode | Cache = CacheMode.SESSION)[source]

Collection of methods for finding Grafana dashboards and folders.

If not using the latest Grafana version, set the api_v parameter to the major version. Some APIs have changed.

create_or_get_alert(path: GrafanaPath | str | Path | List[str]) Tuple[AlertSearchResult, Folder][source]

Get the information about an alert or create a new “empty” alert if it does not exist.

Creating an “empty” alert in Grafana requires filling in a rule. We can fake that with a math rule that always returns 0.

create_or_get_dashboard(path: GrafanaPath | str | Path | List[str]) Tuple[DashboardSearchResult, Folder | None][source]

Create a new empty dashboard if it does not exist.

Returns the search information if it does

create_or_get_folder(name: str) Folder[source]

Create a new folder if it does not exist.

Returns the search information if it does.

find_dashboards(name: str) List[DashboardSearchResult][source]

Find all dashboards with a name. Returns exact matches only.

get_alert(folder_name, alert_name) AlertSearchResult[source]

Get an alert by its parent folder and alert name.

get_alert_from_path(path: GrafanaPath | str | Path | List[str]) AlertSearchResult[source]

Get an alert from a string path like /folder0/alert0.

get_alerts_in_folders(folder_names: List[str]) List[AlertSearchResult][source]

Get all alerts in folders.

get_dashboard(folder_name: str, dashboard_name: str) DashboardSearchResult[source]

Get a dashboard by its parent folder and dashboard name.

Dashboards without a parent are children of the “General” folder.

get_dashboard_by_uid(uid: str) GrafanaPath[source]

Get a dashboard by its uid.

get_dashboards_in_folders(folder_names: List[str]) List[DashboardSearchResult][source]

Get all dashboards in folders.

get_folder(name) Folder[source]

Get a folder by name. Folders don’t nest, so this will return at most 1 folder.

get_from_path(path: GrafanaPath | str | Path | List[str]) DashboardSearchResult | AlertSearchResult[source]

Get a dashboard from a string path like /folder0/dashboard0.

list_alerts() List[AlertSearchResult][source]

List all alerts.

list_dashboards() List[DashboardSearchResult][source]

List all dashboards.

grafanarmadillo.dashboarder

Push and pull Grafana dashboards.

class grafanarmadillo.dashboarder.Dashboarder(api: GrafanaApi)[source]

Collection of methods for managing dashboards.

export_dashboard(dashboard: DashboardSearchResult) Tuple[DashboardContent, Folder | None][source]

Export a dashboard from grafana, with its folder information if applicable.

get_dashboard_content(dashboard: DashboardSearchResult) DashboardContent[source]

Get the contents of a Grafana dashboard.

import_dashboard(content: DashboardContent, folder: Folder | None = None)[source]

Import a dashboard into Grafana, optionally into a folder.

set_dashboard_content(dashboard: DashboardSearchResult, content: DashboardContent)[source]

Set the content of a Grafana dashboard.

This explicitly leaves out the identity information. That allows you to graft the contents of a dashboard into another

grafanarmadillo.alerter

Push and pull Grafana alerts.

class grafanarmadillo.alerter.Alerter(api: GrafanaApi, disable_provenance=True, cache_mode: CacheMode | Cache = CacheMode.SESSION)[source]

Collection of methods for managing alert rules.

export_alert(alert: AlertSearchResult) Tuple[AlertContent, Folder | None][source]

Export an alert from Grafana and its folder information too.

import_alert(content: AlertContent, folder: Folder)[source]

Import an alert into Grafana.

grafanarmadillo.templator

Make and fill templates for dashboards.

class grafanarmadillo.templator.Templator(make_template: ~typing.Callable[[DashboardContent], DashboardContent] = <function nop>, fill_template: ~typing.Callable[[DashboardContent], DashboardContent] = <function nop>)[source]

Collection of methods for filling and making templates.

chain(other) Templator[source]

Chain two templators.

make_dashboard_from_template(dashboard_info: DashboardSearchResult, template: DashboardContent) DashboardContent[source]

Inflate a template.

make_template_from_dashboard(dashboard: DashboardContent) DashboardContent[source]

Convert a dashboard into a one ready for templating.

grafanarmadillo.templator.alert_dashboarduid_templator(finder: Finder) Templator[source]

Resolve the dashboard uid associated with an alert.

grafanarmadillo.templator.combine_transformers(*transformers: Callable[[DashboardContent], DashboardContent]) Callable[[DashboardContent], DashboardContent][source]

Chain transformers together into one big transformer.

grafanarmadillo.templator.fill_grafana_templating_options(options: dict[str, Any]) DashboardTransformer[source]

Fill the options on a Grafana template (the kind of dashboard available from grafana.com).

grafanarmadillo.templator.findreplace(context: Dict[str, str]) Callable[[DashboardContent], DashboardContent][source]

Make DashboardTransformer to make replacements in strings in dashboards.

grafanarmadillo.templator.make_mapping_templator(mapping: EnvMapping, env_grafana: str, env_template: str) Templator[source]

Assemble the templator from the environment mapping.

grafanarmadillo.templator.nop(d: DashboardContent) DashboardContent[source]

Pass template through.

grafanarmadillo.templator.panel_transformer(f: Callable[[DashboardPanel], DashboardPanel]) Callable[[DashboardContent], DashboardContent][source]

Make DashboardTransformer which processes all panels in a dashboard.

Will omit a dashboard if function returns None

grafanarmadillo.templator.remove_edit_metadata_transformer(d: DashboardContent) DashboardContent[source]

Remove frequently-changing edit metadata, such as “updated”, “version”, and “provenance”.