Operations¶
grafanarmadillo.bulk¶
Perform bulk operations on Grafana.
BulkOperations defines the basic interface. It is meant to be parametrised in 2 phases: - information source: Subclasses of BulkOperations implement methods to get orgs and resources - actions: Subclasses of those classes implement the actions to take
- For example:
BulkGrafanaOperation uses a Grafana instance as its source BulkExporter uses BulkGrafanaOperations to list all objects and write them to disk
- class grafanarmadillo.bulk.BulkExporter(cfg: dict, root_directory: Path, templator: Templator)[source]¶
Export all resources from Grafana to files.
- each_alert(path: GrafanaPath, alert: AlertContent)[source]¶
Write each alert to files.
- each_dashboard(path: GrafanaPath, dashboard: DashboardContent)[source]¶
Write each dashboard to files.
- class grafanarmadillo.bulk.BulkFileOperation(cfg: dict, root_directory: Path)[source]¶
Bulk operation which uses a filetree as its source.
- all_orgs() Generator[Tuple[OrgMeta, GrafanaApi], None, None][source]¶
Iterate over all organisations in Grafana.
- get_all_alerts(org: OrgMeta, gfn: GrafanaApi) Generator[Tuple[GrafanaPath, AlertContent], None, None][source]¶
Get all alerts.
- get_all_dashboards(org: OrgMeta, gfn: GrafanaApi) Generator[Tuple[GrafanaPath, DashboardContent], None, None][source]¶
Get all dashboards.
- class grafanarmadillo.bulk.BulkGrafanaOperation(cfg: dict)[source]¶
Bulk operations which uses a Grafana instance as its source.
- all_orgs() Generator[Tuple[OrgMeta, GrafanaApi], None, None][source]¶
Iterate over all organisations in Grafana.
- get_all_alerts(org: OrgMeta, gfn: GrafanaApi) Generator[Tuple[GrafanaPath, AlertContent], None, None][source]¶
Get all alerts.
- get_all_dashboards(org: OrgMeta, gfn: GrafanaApi) Generator[Tuple[GrafanaPath, DashboardContent], None, None][source]¶
Get all dashboards.
- class grafanarmadillo.bulk.BulkImporter(cfg: dict, root_directory: Path, templator: Templator)[source]¶
Import all resources from files into Grafana.
- each_alert(path: GrafanaPath, alert: AlertContent)[source]¶
Import each alert into Grafana.
- each_dashboard(path: GrafanaPath, dashboard: DashboardContent)[source]¶
Import each dashboard into Grafana.
- class grafanarmadillo.bulk.BulkOperation(cfg: dict)[source]¶
Run bulk operations on Grafana.
- abstract all_orgs() Generator[Tuple[OrgMeta, GrafanaApi], None, None][source]¶
Iterate over all organisations.
This method should be implemented for each source of information.
- abstract each_alert(path: GrafanaPath, alert: AlertContent)[source]¶
Act on each alert in Grafana.
This method should be implemented for each operation.
- abstract each_dashboard(path: GrafanaPath, dashboard: DashboardContent)[source]¶
Act on each dashboard in Grafana.
This method should be implemented for each operation.
- abstract get_all_alerts(org: OrgMeta, gfn: GrafanaApi) Generator[Tuple[GrafanaPath, AlertContent], None, None][source]¶
Iterate over all alerts.
This method should be implemented for each source of information.
- abstract get_all_dashboards(org: OrgMeta, gfn: GrafanaApi) Generator[Tuple[GrafanaPath, DashboardContent], None, None][source]¶
Iterate over all dashboards.
This method should be implemented for each source of information.
grafanarmadillo.migrate¶
Migrate from Classic to Unified alerting.
- class grafanarmadillo.migrate.DockerContainer(container: Container, image: str, host_port: int)[source]¶
Handle on a docker container.
- property status¶
Get the status of the docker container.
- grafanarmadillo.migrate.exec_in_container(container: DockerContainer, command: str)[source]¶
Execute a command in a running docker container.
- grafanarmadillo.migrate.migrate(cfg: dict, grafana_image: str, grafana_db: Path, output_directory: Path, templator: Templator, extra_env_vars: Dict[str, str] | None = None, grafana_uid: int = 472, timeout: timedelta = datetime.timedelta(seconds=300), clone_db: bool = True) None[source]¶
Migrate from classic to Unified alerting.
- grafanarmadillo.migrate.read_container_logs(container: DockerContainer)[source]¶
Read logs from the docker container.
- grafanarmadillo.migrate.start_container(image_name, volume_path: Path, environment_vars: Dict[str, str])[source]¶
Start a container.
- grafanarmadillo.migrate.stop_container(container: DockerContainer)[source]¶
Stop container.